Class: Rock

Inherits:
Object
  • Object
show all
Defined in:
lib/bloomy/operations/rocks.rb

Overview

Class to handle all the operations related to rocks

Instance Method Summary collapse

Constructor Details

#initialize(conn, user_id) ⇒ Rock

Initializes a new Rock instance

Parameters:

  • conn (Object)

    the connection object to interact with the API

  • user_id (Integer)

    the ID of the user



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

Examples:

client.rock.create(title: "New Rock", meeting_id: 1)
#=> { rock_id: 1, title: "New Rock", meeting_id: 1, ... }

Parameters:

  • title (String)

    the title of the new rock

  • meeting_id (Integer)

    the ID of the meeting associated with the rock

  • user_id (Integer) (defaults to: @user_id)

    the ID of the user responsible for the rock (default: initialized user ID)

Returns:

  • (Hash)

    a hash containing the new rock’s details



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

Examples:

client.rock.delete(1)
#=> { status: 200 }

Parameters:

  • rock_id (Integer)

    the ID of the rock to delete

Returns:

  • (Hash)

    a hash containing the status of the delete operation



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

Examples:

client.rock.list
 #=> [{ id: 1, title: "Complete project", created_at: "2024-06-10", ... }, ...]

Parameters:

  • user_id (Integer) (defaults to: @user_id)

    the ID of the user (default is the initialized user ID)

  • archived (Boolean) (defaults to: false)

    whether to include archived rocks (default: false)

Returns:

  • (Array<Hash>)

    an array of hashes containing rock details or a hash with active and archived rocks



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

Examples:

client.rock.update(rock_id: 1, title: "Updated Rock")
#=> { status: 200 }

Parameters:

  • rock_id (Integer)

    the ID of the rock to update

  • title (String)

    the new title of the rock

  • accountable_user (Integer) (defaults to: @user_id)

    the ID of the user responsible for the rock (default: initialized user ID)

Returns:

  • (Hash)

    a hash containing the status of the update operation



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