Class: BaseCRM::TasksService
- Inherits:
-
Object
- Object
- BaseCRM::TasksService
- Defined in:
- lib/basecrm/services/tasks_service.rb
Constant Summary collapse
- OPTS_KEYS_TO_PERSIST =
Set[:completed, :content, :due_date, :owner_id, :remind_at, :resource_id, :resource_type]
Instance Method Summary collapse
-
#all ⇒ Enumerable
Retrieve all tasks.
-
#create(task) ⇒ Task
Create a task.
-
#destroy(id) ⇒ Boolean
Delete a task.
-
#find(id) ⇒ Task
Retrieve a single task.
-
#initialize(client) ⇒ TasksService
constructor
A new instance of TasksService.
-
#update(task) ⇒ Task
Update a task.
-
#where(options = {}) ⇒ Array<Task>
Retrieve all tasks.
Constructor Details
#initialize(client) ⇒ TasksService
Returns a new instance of TasksService.
7 8 9 |
# File 'lib/basecrm/services/tasks_service.rb', line 7 def initialize(client) @client = client end |
Instance Method Details
#all ⇒ Enumerable
Retrieve all tasks
get ‘/tasks’
If you want to use filtering or sorting (see #where).
17 18 19 |
# File 'lib/basecrm/services/tasks_service.rb', line 17 def all PaginatedResource.new(self) end |
#create(task) ⇒ Task
Create a task
post ‘/tasks’
Creates a new task You can create either a floating task or create a related task and associate it with one of the resource types below:
-
[Leads](/docs/rest/reference/leads)
-
[Contacts](/docs/rest/reference/contacts)
-
[Deals](/docs/rest/reference/deals)
63 64 65 66 67 68 69 70 |
# File 'lib/basecrm/services/tasks_service.rb', line 63 def create(task) validate_type!(task) attributes = sanitize(task) _, _, root = @client.post("/tasks", attributes) Task.new(root[:data]) end |
#destroy(id) ⇒ Boolean
Delete a task
delete ‘/tasks/BaseCRM#id’
Delete an existing task If the specified task does not exist, this query will return an error This operation cannot be undone
120 121 122 123 |
# File 'lib/basecrm/services/tasks_service.rb', line 120 def destroy(id) status, _, _ = @client.delete("/tasks/#{id}") status == 204 end |
#find(id) ⇒ Task
Retrieve a single task
get ‘/tasks/BaseCRM#id’
Returns a single task available to the user according to the unique task ID provided If the specified task does not exist, this query will return an error
82 83 84 85 86 |
# File 'lib/basecrm/services/tasks_service.rb', line 82 def find(id) _, _, root = @client.get("/tasks/#{id}") Task.new(root[:data]) end |
#update(task) ⇒ Task
Update a task
put ‘/tasks/BaseCRM#id’
Updates task information If the specified task does not exist, this query will return an error
98 99 100 101 102 103 104 105 106 107 |
# File 'lib/basecrm/services/tasks_service.rb', line 98 def update(task) validate_type!(task) params = extract_params!(task, :id) id = params[:id] attributes = sanitize(task) _, _, root = @client.put("/tasks/#{id}", attributes) Task.new(root[:data]) end |
#where(options = {}) ⇒ Array<Task>
Retrieve all tasks
get ‘/tasks’
Returns all tasks available to the user, according to the parameters provided If you ask for tasks without any parameter provided Base API will return you both floating and related tasks Although you can narrow the search set to either of them via query parameters
44 45 46 47 48 |
# File 'lib/basecrm/services/tasks_service.rb', line 44 def where( = {}) _, _, root = @client.get("/tasks", ) root[:items].map{ |item| Task.new(item[:data]) } end |