Class: Todo
- Inherits:
-
Object
- Object
- Todo
- Defined in:
- lib/bloomy/operations/todos.rb
Overview
Class to handle all the operations related to todos
Instance Method Summary collapse
-
#complete(todo_id) ⇒ Hash
Marks a todo as complete.
-
#create(title:, meeting_id:, due_date: nil, user_id: @user_id) ⇒ Hash
Creates a new todo.
-
#initialize(conn, user_id) ⇒ Todo
constructor
Initializes a new Todo instance.
-
#list(user_id: @user_id) ⇒ Array<Hash>
Lists all todos for a specific user.
Constructor Details
#initialize(conn, user_id) ⇒ Todo
Initializes a new Todo instance
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
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
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
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 |