Module: NetologyGroup::TasksClient
- Defined in:
- lib/netology_group/tasks_client.rb,
lib/netology_group/tasks_client/error.rb,
lib/netology_group/tasks_client/client.rb,
lib/netology_group/tasks_client/config.rb,
lib/netology_group/tasks_client/version.rb,
lib/netology_group/tasks_client/response.rb,
lib/netology_group/tasks_client/task_response.rb
Defined Under Namespace
Classes: Client, Config, Error, Response, TaskResponse
Constant Summary
collapse
- VERSION =
'0.3.0'.freeze
Class Method Summary
collapse
Class Method Details
.client ⇒ Object
19
20
21
|
# File 'lib/netology_group/tasks_client.rb', line 19
def client
@client ||= Client.new
end
|
11
12
13
|
# File 'lib/netology_group/tasks_client.rb', line 11
def configure
yield Config
end
|
15
16
17
|
# File 'lib/netology_group/tasks_client.rb', line 15
def configured?
!Config.endpoint.nil?
end
|
.create_task(task_params, options = {}) ⇒ Object
51
52
53
54
55
56
57
58
|
# File 'lib/netology_group/tasks_client.rb', line 51
def create_task(task_params, options = {})
params = {
method: :post,
path: '/tasks',
body: task_params.to_json
}
client.request(params.merge(options))
end
|
.delete_task(task_id, options = {}) ⇒ Object
74
75
76
77
78
79
80
|
# File 'lib/netology_group/tasks_client.rb', line 74
def delete_task(task_id, options = {})
params = {
method: :delete,
path: "/tasks/#{task_id}"
}
client.request(params.merge(options))
end
|
.find_task(task_id, options = {}) ⇒ Object
40
41
42
43
44
45
46
47
|
# File 'lib/netology_group/tasks_client.rb', line 40
def find_task(task_id, options = {})
params = {
method: :get,
path: "/tasks/#{task_id}",
response_class: TaskResponse
}
client.request(params.merge(options))
end
|
.send_answer(task_id, answer_params, options = {}) ⇒ Object
85
86
87
88
89
90
91
92
|
# File 'lib/netology_group/tasks_client.rb', line 85
def send_answer(task_id, answer_params, options = {})
params = {
method: :post,
path: "/tasks/#{task_id}/answer_attempts",
body: answer_params.to_json
}
client.request(params.merge(options))
end
|
.tasks_list(options = {}) ⇒ Object
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/netology_group/tasks_client.rb', line 25
def tasks_list(options = {})
params = {
method: :get,
path: '/tasks'
}
page = options.delete(:page)
if page
params[:query] = { page: page }
end
client.request(params.merge(options))
end
|
.update_task(task_id, task_params, options = {}) ⇒ Object
63
64
65
66
67
68
69
70
|
# File 'lib/netology_group/tasks_client.rb', line 63
def update_task(task_id, task_params, options = {})
params = {
method: :patch,
path: "/tasks/#{task_id}",
body: task_params.to_json
}
client.request(params.merge(options))
end
|