Class: Rock
- Inherits:
-
Object
- Object
- Rock
- Defined in:
- lib/bloomy/operations/rocks.rb
Overview
Class to handle all the operations related to rocks
Instance Method Summary collapse
-
#create(title:, meeting_id:, user_id: @user_id) ⇒ Hash
Creates a new rock.
-
#delete(rock_id) ⇒ Hash
Deletes a rock.
-
#initialize(conn, user_id) ⇒ Rock
constructor
Initializes a new Rock instance.
-
#list(user_id: @user_id, archived: false) ⇒ Array<Hash>
Lists all rocks for a specific user.
-
#update(rock_id:, title:, accountable_user: @user_id) ⇒ Hash
Updates a rock.
Constructor Details
#initialize(conn, user_id) ⇒ Rock
Initializes a new Rock instance
9 10 11 12 |
# File 'lib/bloomy/operations/rocks.rb', line 9 def initialize(conn, user_id) @conn = conn @user_id = user_id end |
Instance Method Details
#create(title:, meeting_id:, user_id: @user_id) ⇒ Hash
Creates a new rock
47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/bloomy/operations/rocks.rb', line 47 def create(title:, meeting_id:, user_id: @user_id) payload = {title: title, accountableUserId: user_id}.to_json response = @conn.post("/api/v1/L10/#{meeting_id}/rocks", payload).body { rock_id: response["Id"], title: title, meeting_id: meeting_id, meeting_name: response["Origins"][0]["Name"], user_id: user_id, user_name: response["Owner"]["Name"], created_at: DateTime.parse(response["CreateTime"]) } end |
#delete(rock_id) ⇒ Hash
Deletes a rock
68 69 70 71 |
# File 'lib/bloomy/operations/rocks.rb', line 68 def delete(rock_id) response = @conn.delete("/api/v1/rocks/#{rock_id}") {status: response.status} end |
#list(user_id: @user_id, archived: false) ⇒ Array<Hash>
Lists all rocks for a specific user
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/bloomy/operations/rocks.rb', line 22 def list(user_id: @user_id, archived: false) active_rocks = @conn.get("rocks/user/#{user_id}?include_origin=true").body.map do |rock| { id: rock["Id"], title: rock["Name"], created_at: rock["CreateTime"], due_date: rock["DueDate"], status: rock["Complete"] ? "Completed" : "Incomplete", meeting_id: rock["Origins"].empty? ? nil : rock["Origins"][0]["Id"], meeting_name: rock["Origins"].empty? ? nil : rock["Origins"][0]["Name"] } end archived ? {active: active_rocks, archived: get_archived_rocks(user_id: @user_id)} : active_rocks end |
#update(rock_id:, title:, accountable_user: @user_id) ⇒ Hash
Updates a rock
82 83 84 85 86 |
# File 'lib/bloomy/operations/rocks.rb', line 82 def update(rock_id:, title:, accountable_user: @user_id) payload = {title: title, accountableUserId: accountable_user}.to_json response = @conn.put("/api/v1/rocks/#{rock_id}", payload) {status: response.status} end |