Class: Bloomy::Goal
- Inherits:
-
Object
- Object
- Bloomy::Goal
- Includes:
- Utilities::UserIdUtility
- Defined in:
- lib/bloomy/operations/goals.rb
Overview
Note:
This class is already initialized via the client and usable as ‘client.goal.method`
Class to handle all the operations related to goals (also known as “rocks”)
Instance Method Summary collapse
-
#archive(goal_id) ⇒ Boolean
Archives a rock with the specified goal ID.
-
#create(title:, meeting_id:, user_id: self.user_id) ⇒ Hash
Creates a new goal.
-
#delete(goal_id) ⇒ Hash
Deletes a goal.
-
#initialize(conn) ⇒ Goal
constructor
Initializes a new Goal instance.
-
#list(user_id = self.user_id, archived: false) ⇒ Array<Hash>, Hash
Lists all goals for a specific user.
-
#restore(goal_id) ⇒ Boolean
Restores a previously archived goal identified by the provided goal ID.
-
#update(goal_id:, title: nil, accountable_user: user_id, status: nil) ⇒ Boolean
Updates a goal.
Methods included from Utilities::UserIdUtility
Constructor Details
#initialize(conn) ⇒ Goal
Initializes a new Goal instance
14 15 16 |
# File 'lib/bloomy/operations/goals.rb', line 14 def initialize(conn) @conn = conn end |
Instance Method Details
#archive(goal_id) ⇒ Boolean
Archives a rock with the specified goal ID.
121 122 123 124 |
# File 'lib/bloomy/operations/goals.rb', line 121 def archive(goal_id) response = @conn.put("rocks/#{goal_id}/archive") response.success? end |
#create(title:, meeting_id:, user_id: self.user_id) ⇒ Hash
Creates a new goal
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/bloomy/operations/goals.rb', line 62 def create(title:, meeting_id:, user_id: self.user_id) payload = {title: title, accountableUserId: user_id}.to_json response = @conn.post("L10/#{meeting_id}/rocks", payload).body { id: response["Id"], user_id: user_id, user_name: response["Owner"]["Name"], title: title, meeting_id: meeting_id, meeting_title: response["Origins"][0]["Name"], status: {complete: 2, on: 1, off: 0}.key(response["Completion"]).to_s, created_at: response["CreateTime"] } end |
#delete(goal_id) ⇒ Hash
Deletes a goal
85 86 87 88 |
# File 'lib/bloomy/operations/goals.rb', line 85 def delete(goal_id) response = @conn.delete("rocks/#{goal_id}") response.success? end |
#list(user_id = self.user_id, archived: false) ⇒ Array<Hash>, Hash
Lists all goals for a specific user
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/bloomy/operations/goals.rb', line 35 def list(user_id = self.user_id, archived: false) active_goals = @conn.get("rocks/user/#{user_id}?include_origin=true").body.map do |goal| { id: goal["Id"], user_id: goal["Owner"]["Id"], user_name: goal["Owner"]["Name"], title: goal["Name"], created_at: goal["CreateTime"], due_date: goal["DueDate"], status: goal["Complete"] ? "Completed" : "Incomplete", meeting_id: goal["Origins"].empty? ? nil : goal["Origins"][0]["Id"], meeting_title: goal["Origins"].empty? ? nil : goal["Origins"][0]["Name"] } end archived ? {active: active_goals, archived: get_archived_goals(user_id)} : active_goals end |
#restore(goal_id) ⇒ Boolean
Restores a previously archived goal identified by the provided goal ID.
132 133 134 135 |
# File 'lib/bloomy/operations/goals.rb', line 132 def restore(goal_id) response = @conn.put("rocks/#{goal_id}/restore") response.success? end |
#update(goal_id:, title: nil, accountable_user: user_id, status: nil) ⇒ Boolean
Updates a goal
101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/bloomy/operations/goals.rb', line 101 def update(goal_id:, title: nil, accountable_user: user_id, status: nil) if status valid_status = {on: "OnTrack", off: "AtRisk", complete: "Complete"} status_key = status.downcase.to_sym unless valid_status.key?(status_key) raise ArgumentError, "Invalid status value. Must be 'on', 'off', or 'complete'." end status = valid_status[status_key] end payload = {title: title, accountableUserId: accountable_user, completion: status}.to_json response = @conn.put("rocks/#{goal_id}", payload) response.success? end |