bloomy 0.2.1 → 0.4.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 492d10b82ab6034c0113b74c8d70352ef604039018f9fcfeca60924ded9414da
4
- data.tar.gz: 2ff5fe5f2e515ee6949ed33caaa67112a24caf47a07cada9c2dfaf88edceaedd
3
+ metadata.gz: 453b980c92f83f6acf3d9a1191dcf94484a9a3acbc57811509f534964d0d15d7
4
+ data.tar.gz: 2c1e08c2351256c4d16b37729ce8173f144ed3680cbdd2e46f55c2a7e57b23f7
5
5
  SHA512:
6
- metadata.gz: 7414ba3b18b68878812929e5b82ce23253051d1f04a1ee2dbfcec418871db4255c44253d7497b6305cf86b7b60398affe0eade73bd16838fbb4a4d31bf2c1858
7
- data.tar.gz: 067e2ab5d9b5f92a8da3c9489c8bb3318bd5818a9adeb21e867fd05e7357bf3e24ce986c8250c31128435e8e084ede3199aeee3cbab749fa1922cb4dbbd69ce7
6
+ metadata.gz: 2ae681b285f824f3ee6c5f5a9806a205d86d2c01fefe84263aa0b1d1d34bd1a3996b17dc98330051125a1b79d0f9e868ed79d7dc015294ba39a5fb71e3032ede
7
+ data.tar.gz: 9a7710243dc62d7bb21e6b1fb0f2795c44dbb034b0fab8f787a5b3d93c942be7ff9d25ed9bde6552e10859bfd52565d090d8b0d3f576dda31afe4da440a88707
data/lib/bloomy/client.rb CHANGED
@@ -3,7 +3,7 @@
3
3
  require "faraday"
4
4
  require_relative "operations/users"
5
5
  require_relative "operations/todos"
6
- require_relative "operations/rocks"
6
+ require_relative "operations/goals"
7
7
  require_relative "operations/meetings"
8
8
  require_relative "operations/scorecard"
9
9
  require_relative "operations/issues"
@@ -13,7 +13,7 @@ module Bloomy
13
13
  # The Client class is the main entry point for interacting with the Bloomy API.
14
14
  # It provides methods for managing Bloom Growth features.
15
15
  class Client
16
- attr_reader :configuration, :user, :todo, :rock, :meeting, :scorecard, :issue, :headline
16
+ attr_reader :configuration, :user, :todo, :goal, :meeting, :scorecard, :issue, :headline
17
17
 
18
18
  # Initializes a new Client instance
19
19
  #
@@ -34,13 +34,12 @@ module Bloomy
34
34
  faraday.headers["Authorization"] = "Bearer #{@api_key}"
35
35
  end
36
36
  @user = User.new(@conn)
37
- @user_id = @user.default_user_id
38
- @todo = Todo.new(@conn, @user_id)
39
- @rock = Rock.new(@conn, @user_id)
40
- @meeting = Meeting.new(@conn, @user_id)
41
- @scorecard = Scorecard.new(@conn, @user_id)
42
- @issue = Issue.new(@conn, @user_id)
43
- @headline = Headline.new(@conn, @user_id)
37
+ @todo = Todo.new(@conn)
38
+ @goal = Goal.new(@conn)
39
+ @meeting = Meeting.new(@conn)
40
+ @scorecard = Scorecard.new(@conn)
41
+ @issue = Issue.new(@conn)
42
+ @headline = Headline.new(@conn)
44
43
  end
45
44
  end
46
45
  end
@@ -0,0 +1,110 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bloomy/utils/get_user_id"
4
+
5
+ # Class to handle all the operations related to goals
6
+ class Goal
7
+ include Bloomy::Utilities::UserIdUtility
8
+ # Initializes a new Goal instance
9
+ #
10
+ # @param conn [Object] the connection object to interact with the API
11
+ def initialize(conn)
12
+ @conn = conn
13
+ end
14
+
15
+ # Lists all goals for a specific user
16
+ #
17
+ # @param user_id [Integer] the ID of the user (default is the initialized user ID)
18
+ # @param archived [Boolean] whether to include archived goals (default: false)
19
+ # @return [Array<Hash>] an array of hashes containing goal details or a hash with active and archived goals
20
+ # @example
21
+ # client.goal.list
22
+ # #=> [{ id: 1, title: "Complete project", created_at: "2024-06-10", ... }, ...]
23
+ def list(user_id = self.user_id, archived: false)
24
+ active_goals = @conn.get("rocks/user/#{user_id}?include_origin=true").body.map do |goal|
25
+ {
26
+ id: goal["Id"],
27
+ title: goal["Name"],
28
+ created_at: goal["CreateTime"],
29
+ due_date: goal["DueDate"],
30
+ status: goal["Complete"] ? "Completed" : "Incomplete",
31
+ meeting_id: goal["Origins"].empty? ? nil : goal["Origins"][0]["Id"],
32
+ meeting_name: goal["Origins"].empty? ? nil : goal["Origins"][0]["Name"]
33
+ }
34
+ end
35
+
36
+ archived ? {active: active_goals, archived: get_archived_goals(self.user_id)} : active_goals
37
+ end
38
+
39
+ # Creates a new goal
40
+ #
41
+ # @param title [String] the title of the new goal
42
+ # @param meeting_id [Integer] the ID of the meeting associated with the goal
43
+ # @param user_id [Integer] the ID of the user responsible for the goal (default: initialized user ID)
44
+ # @return [Hash] a hash containing the new goal's details
45
+ # @example
46
+ # client.goal.create(title: "New Goal", meeting_id: 1)
47
+ # #=> { goal_id: 1, title: "New Goal", meeting_id: 1, ... }
48
+ def create(title:, meeting_id:, user_id: self.user_id)
49
+ payload = {title: title, accountableUserId: user_id}.to_json
50
+ response = @conn.post("/api/v1/L10/#{meeting_id}/rocks", payload).body
51
+ {
52
+ goal_id: response["Id"],
53
+ title: title,
54
+ meeting_id: meeting_id,
55
+ meeting_name: response["Origins"][0]["Name"],
56
+ user_id: user_id,
57
+ user_name: response["Owner"]["Name"],
58
+ created_at: DateTime.parse(response["CreateTime"])
59
+ }
60
+ end
61
+
62
+ # Deletes a goal
63
+ #
64
+ # @param goal_id [Integer] the ID of the goal to delete
65
+ # @return [Hash] a hash containing the status of the delete operation
66
+ # @example
67
+ # client.goal.delete(1)
68
+ # #=> { status: 200 }
69
+ def delete(goal_id)
70
+ response = @conn.delete("/api/v1/rocks/#{goal_id}")
71
+ {status: response.status}
72
+ end
73
+
74
+ # Updates a goal
75
+ #
76
+ # @param goal_id [Integer] the ID of the goal to update
77
+ # @param title [String] the new title of the goal
78
+ # @param accountable_user [Integer] the ID of the user responsible for the goal (default: initialized user ID)
79
+ # @return [Hash] a hash containing the status of the update operation
80
+ # @example
81
+ # client.goal.update(goal_id: 1, title: "Updated Goal")
82
+ # #=> { status: 200 }
83
+ def update(goal_id:, title:, accountable_user: user_id)
84
+ payload = {title: title, accountableUserId: accountable_user}.to_json
85
+ response = @conn.put("/api/v1/rocks/#{goal_id}", payload)
86
+ {status: response.status}
87
+ end
88
+
89
+ private
90
+
91
+ # Retrieves all archived goals for a specific user (private method)
92
+ #
93
+ # @param user_id [Integer] the ID of the user (default is the initialized user ID)
94
+ # @return [Array<Hash>] an array of hashes containing archived goal details
95
+ # @example
96
+ # goal.send(:get_archived_goals)
97
+ # #=> [{ id: 1, title: "Archived Goal", created_at: "2024-06-10", ... }, ...]
98
+ def get_archived_goals(user_id = self.user_id)
99
+ response = @conn.get("archivedrocks/user/#{user_id}").body
100
+ response.map do |goal|
101
+ {
102
+ id: goal["Id"],
103
+ title: goal["Name"],
104
+ created_at: goal["CreateTime"],
105
+ due_date: goal["DueDate"],
106
+ status: goal["Complete"] ? "Complete" : "Incomplete"
107
+ }
108
+ end
109
+ end
110
+ end
@@ -1,23 +1,24 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "bloomy/utils/get_user_id"
4
+
3
5
  class Headline
6
+ include Bloomy::Utilities::UserIdUtility
4
7
  # Initializes a new headline instance
5
8
  #
6
9
  # @param conn [Object] the connection object to interact with the API
7
- # @param user_id [Integer] the ID of the user
8
- def initialize(conn, user_id)
10
+ def initialize(conn)
9
11
  @conn = conn
10
- @user_id = user_id
11
12
  end
12
13
 
13
14
  # Creates a new headline
14
15
  #
15
16
  # @param meeting_id [Integer] the ID of the meeting
16
17
  # @param title [String] the title of the headline
17
- # @param owner_id [Integer] the ID of the owner
18
+ # @param owner_id [Integer] the ID of the headline owner
18
19
  # @param notes [String] additional notes for the headline
19
20
  # @return [Hash] the created headline details
20
- def create(meeting_id, title, owner_id: @user_id, notes: nil)
21
+ def create(meeting_id, title, owner_id: user_id, notes: nil)
21
22
  response = @conn.post("/api/v1/L10/#{meeting_id}/headlines",
22
23
  {title: title, ownerId: owner_id, notes: notes}.to_json)
23
24
  raise "Failed to create headline" unless response.status == 200
@@ -26,7 +27,7 @@ class Headline
26
27
  id: response.body["Id"],
27
28
  title: response.body["Title"],
28
29
  owner_id: response.body["OwnerId"],
29
- notes: response.body["Notes"]
30
+ notes_url: response.body["DetailsUrl"]
30
31
  }
31
32
  end
32
33
 
@@ -52,6 +53,7 @@ class Headline
52
53
  {
53
54
  id: response.body["Id"],
54
55
  title: response.body["Name"],
56
+ notes_url: response.body["DetailsUrl"],
55
57
  meeting_details: {
56
58
  id: response.body["OriginId"],
57
59
  name: response.body["Origin"]
@@ -66,13 +68,30 @@ class Headline
66
68
  }
67
69
  end
68
70
 
69
- # Get user headlines
71
+ # Get headlines for a user or a meeting.
70
72
  #
71
- # @param user_id [Integer] the ID of the user
72
- # @return [Array] the list of headlines for the user
73
- def user_headlines(user_id: @user_id)
74
- response = @conn.get("/api/v1/headline/users/#{user_id}")
75
- raise "Failed to list headlines" unless response.status == 200
73
+ # @param user_id [Integer, nil] the ID of the user (defaults to initialized user_id)
74
+ # @param meeting_id [Integer, nil] the ID of the meeting
75
+ # @raise [ArgumentError] if both `user_id` and `meeting_id` are provided
76
+ # @return [Array<Hash>] the list of headlines
77
+ # @example
78
+ # # Fetch headlines for a user
79
+ # client.headline.list
80
+ # #=> [{ id: 1, title: "Headline Title", meeting_details: { id: 1, name: "Team Meeting" }, ... }, ...]
81
+ def list(user_id: nil, meeting_id: nil)
82
+ if user_id && meeting_id
83
+ raise ArgumentError, "Please provide either `user_id` or `meeting_id`, not both."
84
+ end
85
+
86
+ if meeting_id
87
+ response = @conn.get("/api/v1/l10/#{meeting_id}/headlines")
88
+ else
89
+ user_id ||= self.user_id
90
+ response = @conn.get("/api/v1/headline/users/#{user_id}")
91
+ end
92
+
93
+ raise "Failed to list headlines" unless response.success?
94
+
76
95
  response.body.map do |headline|
77
96
  {
78
97
  id: headline["Id"],
@@ -1,16 +1,16 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "json"
4
+ require "bloomy/utils/get_user_id"
4
5
 
5
6
  # Class to handle all the operations related to issues
6
7
  class Issue
8
+ include Bloomy::Utilities::UserIdUtility
7
9
  # Initializes a new Issue instance
8
10
  #
9
11
  # @param conn [Object] the connection object to interact with the API
10
- # @param user_id [Integer] the ID of the user
11
- def initialize(conn, user_id)
12
+ def initialize(conn)
12
13
  @conn = conn
13
- @user_id = user_id
14
14
  end
15
15
 
16
16
  # Retrieves details of a specific issue
@@ -39,15 +39,33 @@ class Issue
39
39
  }
40
40
  end
41
41
 
42
- # Lists issues for a specific user
42
+ # Lists issues for a specific user or meeting
43
43
  #
44
- # @param user_id [Integer] the ID of the user (default is the initialized user ID)
44
+ # @param user_id [Integer, nil] the ID of the user (defaults to initialized user_id)
45
+ # @param meeting_id [Integer, nil] the ID of the meeting
46
+ # @raise [ArgumentError] if both `user_id` and `meeting_id` are provided
45
47
  # @return [Array<Hash>] an array of hashes containing issues details
46
48
  # @example
49
+ # # Fetch issues for the current user
47
50
  # issue.list
48
- # #=> [{ id: 123, title: "Issue Title", notes_url: "http://details.url", ... }, ...]
49
- def list(user_id: @user_id)
50
- response = @conn.get("issues/users/#{user_id}").body
51
+ #
52
+ # # Fetch issues for a specific user
53
+ # issue.list(user_id: 42)
54
+ #
55
+ # # Fetch issues for a specific meeting
56
+ # issue.list(meeting_id: 99)
57
+ def list(user_id: nil, meeting_id: nil)
58
+ if user_id && meeting_id
59
+ raise ArgumentError, "Please provide either `user_id` or `meeting_id`, not both."
60
+ end
61
+
62
+ if meeting_id
63
+ response = @conn.get("l10/#{meeting_id}/issues").body
64
+ else
65
+ user_id ||= self.user_id
66
+ response = @conn.get("issues/users/#{user_id}").body
67
+ end
68
+
51
69
  response.map do |issue|
52
70
  {
53
71
  id: issue["Id"],
@@ -74,13 +92,15 @@ class Issue
74
92
 
75
93
  # Creates a new issue
76
94
  #
77
- # @param title [String] the title of the new issue
78
95
  # @param meeting_id [Integer] the ID of the meeting associated with the issue
96
+ # @param title [String] the title of the new issue
97
+ # @param user_id [Integer] the ID of the user responsible for the issue (default: initialized user ID)
98
+ # @param notes [String, nil] the notes for the issue (optional)
79
99
  # @return [Hash] a hash containing the new issue's ID and title
80
100
  # @example
81
- # issue.create("New Issue", 456)
101
+ # issue.create(meeting_id: 123, title: "New Issue")
82
102
  # #=> { id: 789, title: "New Issue" }
83
- def create(meeting_id:, title:, user_id: @user_id, notes: nil)
103
+ def create(meeting_id:, title:, user_id: self.user_id, notes: nil)
84
104
  response = @conn.post("issues/create", {title: title, meetingid: meeting_id, ownerid: user_id, notes: notes}.to_json)
85
105
  {
86
106
  id: response.body["Id"],
@@ -88,7 +108,7 @@ class Issue
88
108
  meeting_title: response.body["Origin"],
89
109
  title: response.body["Name"],
90
110
  user_id: response.body["Owner"]["Id"],
91
- details_url: response.body["DetailsUrl"]
111
+ notes_url: response.body["DetailsUrl"]
92
112
  }
93
113
  end
94
114
  end
@@ -1,16 +1,17 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "bloomy/utils/get_user_id"
4
+
3
5
  # Class to handle all the operations related to meeting
4
6
  # @note
5
7
  # This class is already initialized via the client and usable as `client.measurable.method`
6
8
  class Meeting
9
+ include Bloomy::Utilities::UserIdUtility
7
10
  # Initializes a new Meeting instance
8
11
  #
9
12
  # @param conn [Object] the connection object to interact with the API
10
- # @param user_id [Integer] the ID of the user
11
- def initialize(conn, user_id)
13
+ def initialize(conn)
12
14
  @conn = conn
13
- @user_id = user_id
14
15
  end
15
16
 
16
17
  # Lists all meetings for a specific user
@@ -20,7 +21,7 @@ class Meeting
20
21
  # @example
21
22
  # client.meeting.list
22
23
  # #=> [{ id: 123, name: "Team Meeting" }, ...]
23
- def list(user_id: @user_id)
24
+ def list(user_id = self.user_id)
24
25
  response = @conn.get("L10/#{user_id}/list").body
25
26
  response.map { |meeting| {id: meeting["Id"], name: meeting["Name"]} }
26
27
  end
@@ -148,7 +149,7 @@ class Meeting
148
149
  # @example
149
150
  # client.meeting.create(title: "New Meeting", attendees: [2, 3])
150
151
  # #=> { meeting_id: 1, title: "New Meeting", attendees: [2, 3] }
151
- def create(title:, add_self: true, attendees: [])
152
+ def create(title, add_self: true, attendees: [])
152
153
  payload = {title: title, addSelf: add_self}.to_json
153
154
  response = @conn.post("L10/create", payload).body
154
155
  meeting_id = response["meetingId"]
@@ -1,18 +1,19 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "json"
4
+ require "bloomy/utils/get_user_id"
4
5
 
5
6
  # Class to handle all the operations related to scorecards
6
7
  # @note
7
8
  # This class is already initialized via the client and usable as `client.scorecard.method`
8
9
  class Scorecard
10
+ include Bloomy::Utilities::UserIdUtility
11
+
9
12
  # Initializes a new Scorecard instance
10
13
  #
11
14
  # @param conn [Object] the connection object to interact with the API
12
- # @param user_id [Integer] the ID of the user
13
- def initialize(conn, user_id)
15
+ def initialize(conn)
14
16
  @conn = conn
15
- @user_id = user_id
16
17
  end
17
18
 
18
19
  # Retrieves the current week details
@@ -56,7 +57,7 @@ class Scorecard
56
57
  if meeting_id
57
58
  response = @conn.get("scorecard/meeting/#{meeting_id}").body
58
59
  else
59
- user_id ||= @user_id
60
+ user_id ||= self.user_id
60
61
  response = @conn.get("scorecard/user/#{user_id}").body
61
62
  end
62
63
 
@@ -1,31 +1,54 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "date"
4
+ require_relative "../utils/get_user_id"
4
5
 
5
6
  # Class to handle all the operations related to todos
6
7
  class Todo
8
+ include Bloomy::Utilities::UserIdUtility
9
+
7
10
  # Initializes a new Todo instance
8
11
  #
9
12
  # @param conn [Object] the connection object to interact with the API
10
- # @param user_id [Integer] the ID of the user
11
- def initialize(conn, user_id)
13
+ def initialize(conn)
12
14
  @conn = conn
13
- @user_id = user_id
14
15
  end
15
16
 
16
- # Lists all todos for a specific user
17
+ # Lists all todos for a specific user or meeting
17
18
  #
18
- # @param user_id [Integer] the ID of the user (default is the initialized user ID)
19
+ # @param user_id [Integer, nil] the ID of the user (default is the initialized user ID)
20
+ # @param meeting_id [Integer, nil] the ID of the meeting
19
21
  # @return [Array<Hash>] an array of hashes containing todo details
22
+ # @raise [ArgumentError] if both `user_id` and `meeting_id` are provided
20
23
  # @example
24
+ # # Fetch todos for the current user
21
25
  # client.todo.list
22
- # #=> [{ id: 1, title: "Finish report", due_date: "2024-06-10", ... }, ...]
23
- def list(user_id: @user_id)
24
- response = @conn.get("todo/user/#{user_id}").body
26
+ # #=> [{ id: 1, title: "New Todo", due_date: "2024-06-15", ... }]
27
+ #
28
+ # # Fetch todos for a specific user
29
+ # client.todo.list(user_id: 42)
30
+ # # => [{ id: 1, title: "New Todo", due_date: "2024-06-15", ... }]
31
+ #
32
+ # # Fetch todos for a specific meeting
33
+ # client.todo.list(meeting_id: 99)
34
+ # # => [{ id: 1, title: "New Todo", due_date: "2024-06-15", ... }]
35
+ def list(user_id: nil, meeting_id: nil)
36
+ if user_id && meeting_id
37
+ raise ArgumentError, "Please provide either `user_id` or `meeting_id`, not both."
38
+ end
39
+
40
+ if meeting_id
41
+ response = @conn.get("l10/#{meeting_id}/todos").body
42
+ else
43
+ user_id ||= self.user_id
44
+ response = @conn.get("todo/user/#{user_id}").body
45
+ end
46
+
25
47
  response.map do |todo|
26
48
  {
27
49
  id: todo["Id"],
28
50
  title: todo["Name"],
51
+ notes_url: todo["DetailsUrl"],
29
52
  due_date: todo["DueDate"],
30
53
  created_at: todo["CreateTime"],
31
54
  completed_at: todo["CompleteTime"],
@@ -40,12 +63,13 @@ class Todo
40
63
  # @param meeting_id [Integer] the ID of the meeting associated with the todo
41
64
  # @param due_date [String, nil] the due date of the todo (optional)
42
65
  # @param user_id [Integer] the ID of the user responsible for the todo (default: initialized user ID)
66
+ # @param notes [String, nil] additional notes for the todo (optional)
43
67
  # @return [Hash] a hash containing the new todo's details
44
68
  # @example
45
69
  # client.todo.create(title: "New Todo", meeting_id: 1, due_date: "2024-06-15")
46
70
  # #=> { id: 1, title: "New Todo", meeting_name: "Team Meeting", ... }
47
- def create(title:, meeting_id:, due_date: nil, user_id: @user_id)
48
- payload = {title: title, accountableUserId: user_id}
71
+ def create(title:, meeting_id:, due_date: nil, user_id: self.user_id, notes: nil)
72
+ payload = {title: title, accountableUserId: user_id, notes: notes}
49
73
  payload[:dueDate] = due_date if due_date
50
74
  response = @conn.post("/api/v1/L10/#{meeting_id}/todos", payload.to_json).body
51
75
 
@@ -54,7 +78,8 @@ class Todo
54
78
  title: response["Name"],
55
79
  meeting_name: response["Origin"],
56
80
  meeting_id: response["OriginId"],
57
- due_date: response["DueDate"]
81
+ due_date: response["DueDate"],
82
+ notes_url: response["DetailsUrl"]
58
83
  }
59
84
  end
60
85
 
@@ -96,4 +121,29 @@ class Todo
96
121
  updated_at: DateTime.now.to_s
97
122
  }
98
123
  end
124
+
125
+ # Retrieves the details of a specific todo item by its ID.
126
+ #
127
+ # @param todo_id [String] The ID of the todo item to retrieve.
128
+ # @return [Hash] A hash containing the details of the todo item.
129
+ # @raise [RuntimeError] If the request to retrieve the todo details fails.
130
+ # @example
131
+ # client.todo.details(1)
132
+ # #=> { id: 1, title: "Updated Todo", due_date: "2024-11-01T01:41:41.528Z", ... }
133
+ def details(todo_id)
134
+ response = @conn.get("/api/v1/todo/#{todo_id}")
135
+ raise "Failed to get todo details. Status: #{response.status}" unless response.success?
136
+
137
+ todo = response.body
138
+ {
139
+ id: todo["Id"],
140
+ meeting_id: todo["OriginId"],
141
+ title: todo["Name"],
142
+ notes_url: todo["DetailsUrl"],
143
+ due_date: todo["DueDate"],
144
+ created_at: todo["CreateTime"],
145
+ completed_at: todo["CompleteTime"],
146
+ status: todo["Complete"] ? "Complete" : "Incomplete"
147
+ }
148
+ end
99
149
  end
@@ -1,26 +1,16 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "bloomy/utils/get_user_id"
4
+
3
5
  # Class to handle all the operations related to users
4
6
  class User
5
- attr_reader :default_user_id
7
+ include Bloomy::Utilities::UserIdUtility
6
8
 
7
9
  # Initializes a new User instance
8
10
  #
9
11
  # @param conn [Object] the connection object to interact with the API
10
12
  def initialize(conn)
11
13
  @conn = conn
12
- @default_user_id = current_user_id
13
- end
14
-
15
- # Retrieves the current user's ID
16
- #
17
- # @return [Integer] the ID of the current user
18
- # @example
19
- # client.user.current_user_id
20
- # #=> 1
21
- def current_user_id
22
- response = @conn.get("users/mine").body
23
- response["Id"]
24
14
  end
25
15
 
26
16
  # Retrieves details of a specific user
@@ -33,13 +23,12 @@ class User
33
23
  # @example
34
24
  # client.user.details
35
25
  # #=> {name: "John Doe", id: 1, image_url: "http://example.com/image.jpg", ...}
36
- def details(user_id: @default_user_id, direct_reports: false, positions: false, all: false)
26
+ def details(user_id = self.user_id, direct_reports: false, positions: false, all: false)
37
27
  response = @conn.get("users/#{user_id}").body
38
28
  user_details = {name: response["Name"], id: response["Id"], image_url: response["ImageUrl"]}
39
29
 
40
- user_details[:direct_reports] = direct_reports(user_id: user_id) if direct_reports || all
41
- user_details[:positions] = positions(user_id: user_id) if positions || all
42
-
30
+ user_details[:direct_reports] = direct_reports(user_id) if direct_reports || all
31
+ user_details[:positions] = positions(user_id) if positions || all
43
32
  user_details
44
33
  end
45
34
 
@@ -50,7 +39,7 @@ class User
50
39
  # @example
51
40
  # client.user.direct_reports
52
41
  # #=> [{name: "Jane Smith", id: 2, image_url: "http://example.com/image.jpg"}, ...]
53
- def direct_reports(user_id: @default_user_id)
42
+ def direct_reports(user_id = self.user_id)
54
43
  direct_reports_response = @conn.get("users/#{user_id}/directreports").body
55
44
  direct_reports_response.map { |report| {name: report["Name"], id: report["Id"], image_url: report["ImageUrl"]} }
56
45
  end
@@ -62,7 +51,7 @@ class User
62
51
  # @example
63
52
  # user.positions
64
53
  # #=> [{name: "Manager", id: 3}, ...]
65
- def positions(user_id: @default_user_id)
54
+ def positions(user_id = self.user_id)
66
55
  position_response = @conn.get("users/#{user_id}/seats").body
67
56
  position_response.map do |position|
68
57
  {name: position["Group"]["Position"]["Name"], id: position["Group"]["Position"]["Id"]}
@@ -0,0 +1,22 @@
1
+ module Bloomy
2
+ module Utilities
3
+ module UserIdUtility
4
+ # Lazy loads the user_id of the default user
5
+ #
6
+ # @return [String] the user_id of the default user
7
+ def user_id
8
+ @user_id ||= default_user_id
9
+ end
10
+
11
+ private
12
+
13
+ # Returns the user_id of the default user
14
+ #
15
+ # @return [String] The user_id of the default user
16
+ def default_user_id
17
+ response = @conn.get("users/mine").body
18
+ response["Id"]
19
+ end
20
+ end
21
+ end
22
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Bloomy
4
- VERSION = "0.2.1"
4
+ VERSION = "0.4.2"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bloomy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Franccesco Orozco
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-11-03 00:00:00.000000000 Z
11
+ date: 2024-11-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -57,13 +57,14 @@ files:
57
57
  - lib/bloomy.rb
58
58
  - lib/bloomy/client.rb
59
59
  - lib/bloomy/configuration.rb
60
+ - lib/bloomy/operations/goals.rb
60
61
  - lib/bloomy/operations/headlines.rb
61
62
  - lib/bloomy/operations/issues.rb
62
63
  - lib/bloomy/operations/meetings.rb
63
- - lib/bloomy/operations/rocks.rb
64
64
  - lib/bloomy/operations/scorecard.rb
65
65
  - lib/bloomy/operations/todos.rb
66
66
  - lib/bloomy/operations/users.rb
67
+ - lib/bloomy/utils/get_user_id.rb
67
68
  - lib/bloomy/version.rb
68
69
  - sig/bloomy.rbs
69
70
  homepage: https://github.com/franccesco/bloomy
@@ -1,109 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Class to handle all the operations related to rocks
4
- class Rock
5
- # Initializes a new Rock instance
6
- #
7
- # @param conn [Object] the connection object to interact with the API
8
- # @param user_id [Integer] the ID of the user
9
- def initialize(conn, user_id)
10
- @conn = conn
11
- @user_id = user_id
12
- end
13
-
14
- # Lists all rocks for a specific user
15
- #
16
- # @param user_id [Integer] the ID of the user (default is the initialized user ID)
17
- # @param archived [Boolean] whether to include archived rocks (default: false)
18
- # @return [Array<Hash>] an array of hashes containing rock details or a hash with active and archived rocks
19
- # @example
20
- # client.rock.list
21
- # #=> [{ id: 1, title: "Complete project", created_at: "2024-06-10", ... }, ...]
22
- def list(user_id: @user_id, archived: false)
23
- active_rocks = @conn.get("rocks/user/#{user_id}?include_origin=true").body.map do |rock|
24
- {
25
- id: rock["Id"],
26
- title: rock["Name"],
27
- created_at: rock["CreateTime"],
28
- due_date: rock["DueDate"],
29
- status: rock["Complete"] ? "Completed" : "Incomplete",
30
- meeting_id: rock["Origins"].empty? ? nil : rock["Origins"][0]["Id"],
31
- meeting_name: rock["Origins"].empty? ? nil : rock["Origins"][0]["Name"]
32
- }
33
- end
34
-
35
- archived ? {active: active_rocks, archived: get_archived_rocks(user_id: @user_id)} : active_rocks
36
- end
37
-
38
- # Creates a new rock
39
- #
40
- # @param title [String] the title of the new rock
41
- # @param meeting_id [Integer] the ID of the meeting associated with the rock
42
- # @param user_id [Integer] the ID of the user responsible for the rock (default: initialized user ID)
43
- # @return [Hash] a hash containing the new rock's details
44
- # @example
45
- # client.rock.create(title: "New Rock", meeting_id: 1)
46
- # #=> { rock_id: 1, title: "New Rock", meeting_id: 1, ... }
47
- def create(title:, meeting_id:, user_id: @user_id)
48
- payload = {title: title, accountableUserId: user_id}.to_json
49
- response = @conn.post("/api/v1/L10/#{meeting_id}/rocks", payload).body
50
- {
51
- rock_id: response["Id"],
52
- title: title,
53
- meeting_id: meeting_id,
54
- meeting_name: response["Origins"][0]["Name"],
55
- user_id: user_id,
56
- user_name: response["Owner"]["Name"],
57
- created_at: DateTime.parse(response["CreateTime"])
58
- }
59
- end
60
-
61
- # Deletes a rock
62
- #
63
- # @param rock_id [Integer] the ID of the rock to delete
64
- # @return [Hash] a hash containing the status of the delete operation
65
- # @example
66
- # client.rock.delete(1)
67
- # #=> { status: 200 }
68
- def delete(rock_id)
69
- response = @conn.delete("/api/v1/rocks/#{rock_id}")
70
- {status: response.status}
71
- end
72
-
73
- # Updates a rock
74
- #
75
- # @param rock_id [Integer] the ID of the rock to update
76
- # @param title [String] the new title of the rock
77
- # @param accountable_user [Integer] the ID of the user responsible for the rock (default: initialized user ID)
78
- # @return [Hash] a hash containing the status of the update operation
79
- # @example
80
- # client.rock.update(rock_id: 1, title: "Updated Rock")
81
- # #=> { status: 200 }
82
- def update(rock_id:, title:, accountable_user: @user_id)
83
- payload = {title: title, accountableUserId: accountable_user}.to_json
84
- response = @conn.put("/api/v1/rocks/#{rock_id}", payload)
85
- {status: response.status}
86
- end
87
-
88
- private
89
-
90
- # Retrieves all archived rocks for a specific user (private method)
91
- #
92
- # @param user_id [Integer] the ID of the user (default is the initialized user ID)
93
- # @return [Array<Hash>] an array of hashes containing archived rock details
94
- # @example
95
- # rock.send(:get_archived_rocks)
96
- # #=> [{ id: 1, title: "Archived Rock", created_at: "2024-06-10", ... }, ...]
97
- def get_archived_rocks(user_id: @user_id)
98
- response = @conn.get("archivedrocks/user/#{user_id}").body
99
- response.map do |rock|
100
- {
101
- id: rock["Id"],
102
- title: rock["Name"],
103
- created_at: rock["CreateTime"],
104
- due_date: rock["DueDate"],
105
- status: rock["Complete"] ? "Complete" : "Incomplete"
106
- }
107
- end
108
- end
109
- end