Class: Bloomy::Issue

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

Overview

Handles CRUD operations for issues in the system. Provides functionality to create, retrieve, list, and solve issues associated with meetings and users.

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) ⇒ Issue

Initializes a new Issue instance

Parameters:

  • conn (Faraday::Connection)

    Connection object for making API requests



19
20
21
# File 'lib/bloomy/operations/issues.rb', line 19

def initialize(conn)
  @conn = conn
end

Instance Method Details

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

Creates a new issue in the system

Parameters:

  • meeting_id (Integer)

    Unique identifier of the associated meeting

  • title (String)

    Title/name of the issue

  • user_id (Integer) (defaults to: self.user_id)

    Unique identifier of the issue owner (defaults to current user)

  • notes (String, nil) (defaults to: nil)

    Additional notes or description for the issue (optional)

Returns:

  • (HashWithIndifferentAccess)

    Newly created issue details

Raises:

  • (ArgumentError)

    if title is empty or meeting_id is invalid

  • (NotFoundError)

    when meeting is not found

  • (ApiError)

    when the API request fails



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/bloomy/operations/issues.rb', line 100

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

  response = @conn.post("issues/create", {title: title, meetingid: meeting_id, ownerid: user_id, notes: notes}.to_json)
  data = handle_response(response, context: "create issue")

  transform_response({
    id: data.dig("Id"),
    meeting_id: data.dig("OriginId"),
    meeting_title: data.dig("Origin"),
    title: data.dig("Name"),
    user_id: data.dig("Owner", "Id"),
    notes_url: data.dig("DetailsUrl")
  })
end

#delete(issue_id, meeting_id:) ⇒ Boolean

Deletes an issue from a meeting

Examples:

client.issue.delete(123, meeting_id: 456)
#=> true

Parameters:

  • issue_id (Integer)

    Unique identifier of the issue to delete

  • meeting_id (Integer)

    Unique identifier of the meeting containing the issue

Returns:

  • (Boolean)

    true if issue was successfully deleted

Raises:

  • (ArgumentError)

    if issue_id or meeting_id is invalid

  • (NotFoundError)

    when issue or meeting is not found

  • (ApiError)

    when the API request fails



149
150
151
152
153
154
155
# File 'lib/bloomy/operations/issues.rb', line 149

def delete(issue_id, meeting_id:)
  validate_id!(issue_id, context: "issue_id")
  validate_id!(meeting_id, context: "meeting_id")

  response = @conn.delete("L10/#{meeting_id}/issues/#{issue_id}")
  handle_response!(response, context: "delete issue")
end

#details(issue_id) ⇒ HashWithIndifferentAccess

Retrieves detailed information about a specific issue

Parameters:

  • issue_id (Integer)

    Unique identifier of the issue

Returns:

  • (HashWithIndifferentAccess)

    Detailed information about the issue

Raises:



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

def details(issue_id)
  response = @conn.get("issues/#{issue_id}")
  data = handle_response(response, context: "get issue details")

  transform_response({
    id: data.dig("Id"),
    title: data.dig("Name"),
    notes_url: data.dig("DetailsUrl"),
    created_at: data.dig("CreateTime"),
    completed_at: data.dig("CloseTime"),
    meeting_id: data.dig("OriginId"),
    meeting_title: data.dig("Origin"),
    user_id: data.dig("Owner", "Id"),
    user_name: data.dig("Owner", "Name")
  })
end

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

Lists issues filtered by user or meeting

Parameters:

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

    Unique identifier of the user (optional)

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

    Unique identifier of the meeting (optional)

Returns:

  • (Array<HashWithIndifferentAccess>)

    List of issues matching the filter criteria

Raises:

  • (ArgumentError)

    When both user_id and meeting_id are provided

  • (NotFoundError)

    when user or meeting is not found

  • (ApiError)

    when the API request fails



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/bloomy/operations/issues.rb', line 54

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

  if meeting_id
    response = @conn.get("l10/#{meeting_id}/issues")
    data = handle_response(response, context: "list meeting issues")
  else
    response = @conn.get("issues/users/#{user_id || self.user_id}")
    data = handle_response(response, context: "list user issues")
  end

  transform_array(data.map do |issue|
    {
      id: issue.dig("Id"),
      title: issue.dig("Name"),
      notes_url: issue.dig("DetailsUrl"),
      created_at: issue.dig("CreateTime"),
      meeting_id: issue.dig("OriginId"),
      meeting_title: issue.dig("Origin")
    }
  end)
end

#solve(issue_id) ⇒ Boolean

Marks an issue as completed/solved

Parameters:

  • issue_id (Integer)

    Unique identifier of the issue to be solved

Returns:

  • (Boolean)

    true if issue was successfully solved

Raises:



85
86
87
88
# File 'lib/bloomy/operations/issues.rb', line 85

def solve(issue_id)
  response = @conn.post("issues/#{issue_id}/complete", {complete: true}.to_json)
  handle_response!(response, context: "solve issue")
end

#update(issue_id:, title: nil, notes: nil) ⇒ HashWithIndifferentAccess

Updates an existing issue’s title or notes

Parameters:

  • issue_id (Integer)

    Unique identifier of the issue to update

  • title (String, nil) (defaults to: nil)

    New title for the issue (optional)

  • notes (String, nil) (defaults to: nil)

    New notes for the issue (optional)

Returns:

  • (HashWithIndifferentAccess)

    Updated issue details

Raises:

  • (ArgumentError)

    When neither title nor notes is provided

  • (NotFoundError)

    when issue is not found

  • (ApiError)

    when the API request fails



126
127
128
129
130
131
132
133
134
135
136
# File 'lib/bloomy/operations/issues.rb', line 126

def update(issue_id:, title: nil, notes: nil)
  raise ArgumentError, "Provide at least one field to update" if title.nil? && notes.nil?

  payload = {}
  payload[:title] = title if title
  payload[:notes] = notes if notes
  response = @conn.put("issues/#{issue_id}", payload.to_json)
  handle_response!(response, context: "update issue")

  details(issue_id)
end