Class: Bloomy::Headline

Inherits:
Object
  • Object
show all
Includes:
Utilities::UserIdUtility
Defined in:
lib/bloomy/operations/headlines.rb

Instance Method Summary collapse

Methods included from Utilities::UserIdUtility

#user_id

Constructor Details

#initialize(conn) ⇒ Headline

Initializes a new headline instance

Parameters:

  • conn (Object)

    the connection object to interact with the API



11
12
13
# File 'lib/bloomy/operations/headlines.rb', line 11

def initialize(conn)
  @conn = conn
end

Instance Method Details

#create(meeting_id:, title:, owner_id: user_id, notes: nil) ⇒ Hash

Creates a new headline

Parameters:

  • meeting_id (Integer)

    the ID of the meeting

  • title (String)

    the title of the headline

  • owner_id (Integer) (defaults to: user_id)

    the ID of the headline owner

  • notes (String) (defaults to: nil)

    additional notes for the headline

Returns:

  • (Hash)

    containing id, title, owner_details, and notes_url



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/bloomy/operations/headlines.rb', line 22

def create(meeting_id:, title:, owner_id: user_id, notes: nil)
  response = @conn.post("/api/v1/L10/#{meeting_id}/headlines",
    {title: title, ownerId: owner_id, notes: notes}.to_json)
  raise "Failed to create headline" unless response.status == 200

  {
    id: response.body["Id"],
    title: response.body["Name"],
    owner_details: {id: response.body["OwnerId"]},
    notes_url: response.body["DetailsUrl"]
  }
end

#delete(headline_id) ⇒ Boolean

Deletes a headline

Parameters:

  • headline_id (Integer)

    the ID of the headline to delete

Returns:

  • (Boolean)

    true if the deletion was successful



134
135
136
137
# File 'lib/bloomy/operations/headlines.rb', line 134

def delete(headline_id)
  response = @conn.delete("/api/v1/headline/#{headline_id}")
  response.success?
end

#details(headline_id) ⇒ Hash

Get headline details

Parameters:

  • headline_id (Integer)

    the ID of the headline

Returns:

  • (Hash)

    containing id, title, notes_url, meeting_details, owner_details, archived, created_at, and closed_at



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/bloomy/operations/headlines.rb', line 51

def details(headline_id)
  response = @conn.get("/api/v1/headline/#{headline_id}?Include_Origin=true")
  raise "Failed to get headline details" unless response.status == 200

  {
    id: response.body["Id"],
    title: response.body["Name"],
    notes_url: response.body["DetailsUrl"],
    meeting_details: {
      id: response.body["OriginId"],
      title: response.body["Origin"]
    },
    owner_details: {
      id: response.body["Owner"]["Id"],
      name: response.body["Owner"]["Name"]
    },
    archived: response.body["Archived"],
    created_at: response.body["CreateTime"],
    closed_at: response.body["CloseTime"]
  }
end

#list(user_id: nil, meeting_id: nil) ⇒ Array<Hash>

Get headlines for a user or a meeting.

Examples:

client.headline.list
#=> [
  {
    id: 1,
    title: "Headline Title",
    meeting_details: { id: 1, title: "Team Meeting" },
    owner_details: { id: 1, name: "John Doe" },
    archived: false,
    created_at: "2023-01-01",
    closed_at: nil
  }
]

Parameters:

  • user_id (Integer, nil) (defaults to: nil)

    the ID of the user (defaults to initialized user_id)

  • meeting_id (Integer, nil) (defaults to: nil)

    the ID of the meeting

Returns:

  • (Array<Hash>)

    a list of headlines containing:

    • id

    • title

    • meeting_details

    • owner_details

    • archived

    • created_at

    • closed_at

Raises:

  • (ArgumentError)

    if both ‘user_id` and `meeting_id` are provided



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/bloomy/operations/headlines.rb', line 99

def list(user_id: nil, meeting_id: nil)
  raise ArgumentError, "Please provide either `user_id` or `meeting_id`, not both." if user_id && meeting_id

  if meeting_id
    response = @conn.get("/api/v1/l10/#{meeting_id}/headlines")
  else
    user_id ||= self.user_id
    response = @conn.get("/api/v1/headline/users/#{user_id}")
  end

  raise "Failed to list headlines" unless response.success?

  response.body.map do |headline|
    {
      id: headline["Id"],
      title: headline["Name"],
      meeting_details: {
        id: headline["OriginId"],
        title: headline["Origin"]
      },
      owner_details: {
        id: headline["Owner"]["Id"],
        name: headline["Owner"]["Name"]
      },
      archived: headline["Archived"],
      created_at: headline["CreateTime"],
      closed_at: headline["CloseTime"]
    }
  end
end

#update(headline_id:, title:) ⇒ Boolean

Updates a headline

Parameters:

  • headline_id (Integer)

    the ID of the headline to update

  • title (String)

    the new title of the headline

Returns:

  • (Boolean)

    true if update was successful



40
41
42
43
44
# File 'lib/bloomy/operations/headlines.rb', line 40

def update(headline_id:, title:)
  response = @conn.put("/api/v1/headline/#{headline_id}", {title: title}.to_json)
  raise "Failed to update headline" unless response.status == 200
  true
end