Class: Bloomy::Todo
- Inherits:
-
Object
- Object
- Bloomy::Todo
- Defined in:
- lib/bloomy/operations/todos.rb
Overview
Class to handle all the operations related to todos
Constant Summary
Constants included from Utilities::Transform
Utilities::Transform::DATE_FIELDS
Instance Method Summary collapse
-
#complete(todo_id) ⇒ Boolean
Marks a todo as complete.
-
#create(title:, meeting_id:, due_date: nil, user_id: self.user_id, notes: nil) ⇒ HashWithIndifferentAccess
Creates a new todo.
-
#details(todo_id) ⇒ HashWithIndifferentAccess
Retrieves the details of a specific todo item by its ID.
-
#initialize(conn) ⇒ Todo
constructor
Initializes a new Todo instance.
-
#list(user_id: nil, meeting_id: nil) ⇒ Array<HashWithIndifferentAccess>
Lists all todos for a specific user or meeting.
-
#update(todo_id:, title: nil, due_date: nil) ⇒ HashWithIndifferentAccess
Updates an existing todo.
Methods included from Utilities::Validation
#validate_id!, #validate_title!
Methods included from Utilities::Transform
#transform_array, #transform_response
Methods included from Utilities::UserIdUtility
Constructor Details
#initialize(conn) ⇒ Todo
Initializes a new Todo instance
16 17 18 |
# File 'lib/bloomy/operations/todos.rb', line 16 def initialize(conn) @conn = conn end |
Instance Method Details
#complete(todo_id) ⇒ Boolean
Marks a todo as complete
89 90 91 92 |
# File 'lib/bloomy/operations/todos.rb', line 89 def complete(todo_id) response = @conn.post("todo/#{todo_id}/complete?status=true") handle_response!(response, context: "complete todo") end |
#create(title:, meeting_id:, due_date: nil, user_id: self.user_id, notes: nil) ⇒ HashWithIndifferentAccess
Creates a new todo
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/bloomy/operations/todos.rb', line 61 def create(title:, meeting_id:, due_date: nil, user_id: self.user_id, notes: nil) validate_title!(title) validate_id!(meeting_id, context: "meeting_id") payload = {title: title, accountableUserId: user_id, notes: notes} payload[:dueDate] = due_date if due_date response = @conn.post("L10/#{meeting_id}/todos", payload.to_json) data = handle_response(response, context: "create todo") transform_response({ id: data.dig("Id"), title: data.dig("Name"), notes_url: data.dig("DetailsUrl"), due_date: data.dig("DueDate"), created_at: DateTime.now.to_s, status: "Incomplete" }) end |
#details(todo_id) ⇒ HashWithIndifferentAccess
Retrieves the details of a specific todo item by its ID.
134 135 136 137 138 139 |
# File 'lib/bloomy/operations/todos.rb', line 134 def details(todo_id) response = @conn.get("todo/#{todo_id}") data = handle_response(response, context: "get todo details") transform_response(build_todo_hash(data)) end |
#list(user_id: nil, meeting_id: nil) ⇒ Array<HashWithIndifferentAccess>
Lists all todos for a specific user or meeting
32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/bloomy/operations/todos.rb', line 32 def list(user_id: nil, meeting_id: nil) raise ArgumentError, "Please provide either `user_id` or `meeting_id`, not both." if user_id && meeting_id if meeting_id response = @conn.get("l10/#{meeting_id}/todos") data = handle_response(response, context: "list meeting todos") else user_id ||= self.user_id response = @conn.get("todo/user/#{user_id}") data = handle_response(response, context: "list user todos") end transform_array(data.map { |todo| build_todo_hash(todo) }) end |
#update(todo_id:, title: nil, due_date: nil) ⇒ HashWithIndifferentAccess
Updates an existing todo
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/bloomy/operations/todos.rb', line 106 def update(todo_id:, title: nil, due_date: nil) payload = {} payload[:title] = title if title payload[:dueDate] = due_date if due_date raise ArgumentError, "At least one field must be provided" if payload.empty? response = @conn.put("todo/#{todo_id}", payload.to_json) handle_response!(response, context: "update todo") transform_response({ id: todo_id, title: title, due_date: due_date, created_at: nil, status: "Incomplete" }) end |