Class: Todo

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

Overview

Class to handle all the operations related to todos

Instance Method Summary collapse

Constructor Details

#initialize(conn, user_id) ⇒ Todo

Initializes a new Todo 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/todos.rb', line 9

def initialize(conn, user_id)
  @conn = conn
  @user_id = user_id
end

Instance Method Details

#complete(todo_id) ⇒ Hash

Marks a todo as complete

Examples:

todo.complete(1)
#=> { status: 200 }

Parameters:

  • todo_id (Integer)

    the ID of the todo to complete

Returns:

  • (Hash)

    a hash containing the status of the complete operation



66
67
68
69
# File 'lib/bloomy/operations/todos.rb', line 66

def complete(todo_id)
  response = @conn.post("/api/v1/todo/#{todo_id}/complete?status=true")
  {status: response.status}
end

#create(title:, meeting_id:, due_date: nil, user_id: @user_id) ⇒ Hash

Creates a new todo

Examples:

client.todo.create(title: "New Todo", meeting_id: 1, due_date: "2024-06-15")
#=> { id: 1, title: "New Todo", meeting_name: "Team Meeting", ... }

Parameters:

  • title (String)

    the title of the new todo

  • meeting_id (Integer)

    the ID of the meeting associated with the todo

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

    the due date of the todo (optional)

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

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

Returns:

  • (Hash)

    a hash containing the new todo’s details



45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/bloomy/operations/todos.rb', line 45

def create(title:, meeting_id:, due_date: nil, user_id: @user_id)
  payload = {title: title, accountableUserId: user_id}
  payload[:dueDate] = due_date if due_date
  response = @conn.post("/api/v1/L10/#{meeting_id}/todos", payload.to_json).body

  {
    id: response["Id"],
    title: response["Name"],
    meeting_name: response["Origin"],
    meeting_id: response["OriginId"],
    due_date: response["DueDate"]
  }
end

#list(user_id: @user_id) ⇒ Array<Hash>

Lists all todos for a specific user

Examples:

client.todo.list
#=> [{ id: 1, title: "Finish report", due_date: "2024-06-10", ... }, ...]

Parameters:

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

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

Returns:

  • (Array<Hash>)

    an array of hashes containing todo details



21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/bloomy/operations/todos.rb', line 21

def list(user_id: @user_id)
  response = @conn.get("todo/user/#{user_id}").body
  response.map do |todo|
    {
      id: todo["Id"],
      title: todo["Name"],
      due_date: todo["DueDate"],
      created_at: todo["CreateTime"],
      completed_at: todo["CompleteTime"],
      status: todo["Complete"] ? "Complete" : "Incomplete"
    }
  end
end