Class: Bloomy::Headline

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

Constant Summary

Constants included from Utilities::Transform

Utilities::Transform::DATE_FIELDS

Instance Method Summary collapse

Methods included from Utilities::Validation

#validate_id!, #validate_title!

Methods included from Utilities::Transform

#transform_array, #transform_response

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



14
15
16
# File 'lib/bloomy/operations/headlines.rb', line 14

def initialize(conn)
  @conn = conn
end

Instance Method Details

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

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:

  • (HashWithIndifferentAccess)

    containing id, title, owner_details, and notes_url

Raises:

  • (ArgumentError)

    if title is empty or meeting_id is invalid

  • (NotFoundError)

    when meeting is not found

  • (ApiError)

    when the API request fails



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/bloomy/operations/headlines.rb', line 28

def create(meeting_id:, title:, owner_id: user_id, notes: nil)
  validate_title!(title)
  validate_id!(meeting_id, context: "meeting_id")

  response = @conn.post("L10/#{meeting_id}/headlines",
    {title: title, ownerId: owner_id, notes: notes}.to_json)
  data = handle_response(response, context: "create headline")

  transform_response({
    id: data.dig("Id"),
    title: data.dig("Name"),
    owner_details: {id: data.dig("OwnerId")},
    notes_url: data.dig("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

Raises:



152
153
154
155
# File 'lib/bloomy/operations/headlines.rb', line 152

def delete(headline_id)
  response = @conn.delete("headline/#{headline_id}")
  handle_response!(response, context: "delete headline")
end

#details(headline_id) ⇒ HashWithIndifferentAccess

Get headline details

Parameters:

  • headline_id (Integer)

    the ID of the headline

Returns:

  • (HashWithIndifferentAccess)

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

Raises:



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/bloomy/operations/headlines.rb', line 65

def details(headline_id)
  response = @conn.get("headline/#{headline_id}?Include_Origin=true")
  data = handle_response(response, context: "get headline details")

  transform_response({
    id: data.dig("Id"),
    title: data.dig("Name"),
    notes_url: data.dig("DetailsUrl"),
    meeting_details: {
      id: data.dig("OriginId"),
      title: data.dig("Origin")
    },
    owner_details: {
      id: data.dig("Owner", "Id"),
      name: data.dig("Owner", "Name")
    },
    archived: data.dig("Archived"),
    created_at: data.dig("CreateTime"),
    closed_at: data.dig("CloseTime")
  })
end

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

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<HashWithIndifferentAccess>)

    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

  • (NotFoundError)

    when user or meeting is not found

  • (ApiError)

    when the API request fails



115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'lib/bloomy/operations/headlines.rb', line 115

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("l10/#{meeting_id}/headlines")
    data = handle_response(response, context: "list meeting headlines")
  else
    user_id ||= self.user_id
    response = @conn.get("headline/users/#{user_id}")
    data = handle_response(response, context: "list user headlines")
  end

  transform_array(data.map do |headline|
    {
      id: headline.dig("Id"),
      title: headline.dig("Name"),
      meeting_details: {
        id: headline.dig("OriginId"),
        title: headline.dig("Origin")
      },
      owner_details: {
        id: headline.dig("Owner", "Id"),
        name: headline.dig("Owner", "Name")
      },
      archived: headline.dig("Archived"),
      created_at: headline.dig("CreateTime"),
      closed_at: headline.dig("CloseTime")
    }
  end)
end

#update(headline_id:, title:) ⇒ HashWithIndifferentAccess

Updates a headline

Parameters:

  • headline_id (Integer)

    the ID of the headline to update

  • title (String)

    the new title of the headline

Returns:

  • (HashWithIndifferentAccess)

    the updated headline details

Raises:



51
52
53
54
55
56
# File 'lib/bloomy/operations/headlines.rb', line 51

def update(headline_id:, title:)
  response = @conn.put("headline/#{headline_id}", {title: title}.to_json)
  handle_response!(response, context: "update headline")

  details(headline_id)
end