netology-tasks_client 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +41 -0
- data/README.md +21 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/netology-tasks_client.rb +1 -0
- data/lib/netology_group/tasks_client.rb +93 -0
- data/lib/netology_group/tasks_client/client.rb +31 -0
- data/lib/netology_group/tasks_client/config.rb +20 -0
- data/lib/netology_group/tasks_client/error.rb +32 -0
- data/lib/netology_group/tasks_client/response.rb +42 -0
- data/lib/netology_group/tasks_client/version.rb +5 -0
- data/netology-tasks_client.gemspec +32 -0
- metadata +143 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: ebb54b9d10c5a651e2532deb77f9b7a898785c1a6ed568ad4653e1545e2d4435
|
4
|
+
data.tar.gz: ec0290232e8e5966a6803b1739fa46592a0bd4cb14058708a2b54ae957c4c021
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c95d6bea36c3f8f9b2c1ac58548ccbfc04d91f9e260f01486d107c45c7f1507158e46f0535bfc69074b176f31c2463cb82639cb26c7193e5aee2a90f5bb78566
|
7
|
+
data.tar.gz: 12656485674c46092f56be70c46aef259cfb70dce2368d3d3fbf92e2924b2dbb3c05d49c3d7473ff86bb808bea95735a556875b4276b39b6b1458043a1e4b47d
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
netology-tasks_client (0.1.0)
|
5
|
+
concurrent-ruby (~> 1.0)
|
6
|
+
excon (~> 0.62)
|
7
|
+
nitlink (~> 1.1)
|
8
|
+
|
9
|
+
GEM
|
10
|
+
remote: https://rubygems.org/
|
11
|
+
specs:
|
12
|
+
concurrent-ruby (1.0.5)
|
13
|
+
diff-lcs (1.3)
|
14
|
+
excon (0.62.0)
|
15
|
+
nitlink (1.1.0)
|
16
|
+
rake (10.5.0)
|
17
|
+
rspec (3.7.0)
|
18
|
+
rspec-core (~> 3.7.0)
|
19
|
+
rspec-expectations (~> 3.7.0)
|
20
|
+
rspec-mocks (~> 3.7.0)
|
21
|
+
rspec-core (3.7.1)
|
22
|
+
rspec-support (~> 3.7.0)
|
23
|
+
rspec-expectations (3.7.0)
|
24
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
25
|
+
rspec-support (~> 3.7.0)
|
26
|
+
rspec-mocks (3.7.0)
|
27
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
28
|
+
rspec-support (~> 3.7.0)
|
29
|
+
rspec-support (3.7.1)
|
30
|
+
|
31
|
+
PLATFORMS
|
32
|
+
ruby
|
33
|
+
|
34
|
+
DEPENDENCIES
|
35
|
+
bundler (~> 1.16)
|
36
|
+
netology-tasks_client!
|
37
|
+
rake (~> 10.0)
|
38
|
+
rspec (~> 3.0)
|
39
|
+
|
40
|
+
BUNDLED WITH
|
41
|
+
1.16.1
|
data/README.md
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# NetologyGroup::TasksClient
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/netology_group/tasks_client`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'netology-tasks_client'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install netolog-tasks_client
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'netology_group/tasks_client'
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require 'irb'
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'netology_group/tasks_client'
|
@@ -0,0 +1,93 @@
|
|
1
|
+
require 'netology_group/tasks_client/version'
|
2
|
+
require 'netology_group/tasks_client/config'
|
3
|
+
require 'netology_group/tasks_client/error'
|
4
|
+
require 'netology_group/tasks_client/response'
|
5
|
+
require 'netology_group/tasks_client/client'
|
6
|
+
|
7
|
+
module NetologyGroup
|
8
|
+
module TasksClient
|
9
|
+
class << self
|
10
|
+
def configure
|
11
|
+
yield Config
|
12
|
+
end
|
13
|
+
|
14
|
+
def configured?
|
15
|
+
!Config.endpoint.nil?
|
16
|
+
end
|
17
|
+
|
18
|
+
def client
|
19
|
+
@client ||= Client.new
|
20
|
+
end
|
21
|
+
|
22
|
+
# @param [Hash] options
|
23
|
+
# @option options [Integer] :page
|
24
|
+
def tasks_list(options = {})
|
25
|
+
params = {
|
26
|
+
method: :get,
|
27
|
+
path: '/tasks'
|
28
|
+
}
|
29
|
+
|
30
|
+
page = options.delete(:page)
|
31
|
+
if page
|
32
|
+
params[:query] = { page: page }
|
33
|
+
end
|
34
|
+
client.request(params.merge(options))
|
35
|
+
end
|
36
|
+
|
37
|
+
# @param [Integer] task_id
|
38
|
+
# @param [Hash] options
|
39
|
+
def find_task(task_id, options = {})
|
40
|
+
params = {
|
41
|
+
method: :get,
|
42
|
+
path: "/tasks/#{task_id}"
|
43
|
+
}
|
44
|
+
client.request(params.merge(options))
|
45
|
+
end
|
46
|
+
|
47
|
+
# @param [Hash] task_params
|
48
|
+
# @param [Hash] options
|
49
|
+
def create_task(task_params, options = {})
|
50
|
+
params = {
|
51
|
+
method: :post,
|
52
|
+
path: '/tasks',
|
53
|
+
body: task_params.to_json
|
54
|
+
}
|
55
|
+
client.request(params.merge(options))
|
56
|
+
end
|
57
|
+
|
58
|
+
# @param [Integer] task_id
|
59
|
+
# @param [Hash] task_params
|
60
|
+
# @param [Hash] options
|
61
|
+
def update_task(task_id, task_params, options = {})
|
62
|
+
params = {
|
63
|
+
method: :patch,
|
64
|
+
path: "/tasks/#{task_id}",
|
65
|
+
body: task_params.to_json
|
66
|
+
}
|
67
|
+
client.request(params.merge(options))
|
68
|
+
end
|
69
|
+
|
70
|
+
# @param [Integer] task_id
|
71
|
+
# @param [Hash] options
|
72
|
+
def delete_task(task_id, options = {})
|
73
|
+
params = {
|
74
|
+
method: :delete,
|
75
|
+
path: "/tasks/#{task_id}"
|
76
|
+
}
|
77
|
+
client.request(params.merge(options))
|
78
|
+
end
|
79
|
+
|
80
|
+
# @param [Hash] task_id
|
81
|
+
# @param [Hash] answer_params
|
82
|
+
# @param [Hash] options
|
83
|
+
def send_answer(task_id, answer_params, options = {})
|
84
|
+
params = {
|
85
|
+
method: :post,
|
86
|
+
path: "/tasks/#{task_id}/answer_attempts",
|
87
|
+
body: answer_params.to_json
|
88
|
+
}
|
89
|
+
client.request(params.merge(options))
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module NetologyGroup
|
2
|
+
module TasksClient
|
3
|
+
class Client
|
4
|
+
def initialize;
|
5
|
+
end
|
6
|
+
|
7
|
+
# @return [Hash]
|
8
|
+
def request(method:, path:, body: nil, api_version: nil, query: nil, expects: [200, 201, 422])
|
9
|
+
response =
|
10
|
+
connection.request(
|
11
|
+
method: method,
|
12
|
+
path: "/api/v#{api_version || Config.default_api_version}#{path}",
|
13
|
+
body: body,
|
14
|
+
query: query,
|
15
|
+
expects: expects
|
16
|
+
)
|
17
|
+
Response.new(response)
|
18
|
+
# rescue Excon::Error
|
19
|
+
# raise Error
|
20
|
+
end
|
21
|
+
|
22
|
+
def connection
|
23
|
+
@connection ||=
|
24
|
+
Excon.new(
|
25
|
+
Config.endpoint.to_s,
|
26
|
+
headers: { 'Content-Type' => 'application/json' }
|
27
|
+
)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module NetologyGroup
|
2
|
+
module TasksClient
|
3
|
+
class Config
|
4
|
+
class << self
|
5
|
+
attr_accessor :endpoint
|
6
|
+
attr_accessor :client_name
|
7
|
+
attr_writer :api_versions
|
8
|
+
attr_writer :default_api_version
|
9
|
+
|
10
|
+
def api_versions
|
11
|
+
@api_versions || [1]
|
12
|
+
end
|
13
|
+
|
14
|
+
def default_api_version
|
15
|
+
@default_api_version || 1
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module NetologyGroup
|
2
|
+
module TasksClient
|
3
|
+
class Error < StandardError
|
4
|
+
attr_reader :response, :status, :body
|
5
|
+
|
6
|
+
# @param [Excon::Response] response
|
7
|
+
def initialize
|
8
|
+
# @response = response
|
9
|
+
# @status = response.status
|
10
|
+
# @body = json_response
|
11
|
+
#
|
12
|
+
# super(default_error_message)
|
13
|
+
super
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def default_error_message
|
19
|
+
message = "HTTP status: #{status}"
|
20
|
+
if body['message']
|
21
|
+
message << ", #{body['message']}"
|
22
|
+
end
|
23
|
+
|
24
|
+
message
|
25
|
+
end
|
26
|
+
|
27
|
+
def json_response
|
28
|
+
JSON.parse(response.body) rescue {}
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'nitlink'
|
2
|
+
|
3
|
+
module NetologyGroup
|
4
|
+
module TasksClient
|
5
|
+
class Response
|
6
|
+
attr_reader :excon_response, :status, :body
|
7
|
+
attr_reader :next_page_url, :previous_page_url
|
8
|
+
|
9
|
+
# @param [Excon::Response] response
|
10
|
+
def initialize(excon_response)
|
11
|
+
@excon_response = excon_response
|
12
|
+
@status = excon_response.status
|
13
|
+
@body = JSON.parse(excon_response.body) rescue {}
|
14
|
+
|
15
|
+
@links = Nitlink::Parser.new.parse(excon_response)
|
16
|
+
end
|
17
|
+
|
18
|
+
def success?
|
19
|
+
[200, 201].include?(excon_response.status)
|
20
|
+
end
|
21
|
+
|
22
|
+
def next_page
|
23
|
+
page_number_from_link('next')
|
24
|
+
end
|
25
|
+
|
26
|
+
def previous_page
|
27
|
+
page_number_from_link('previous')
|
28
|
+
end
|
29
|
+
|
30
|
+
def inspect
|
31
|
+
"#{self} @status=#{status} @body=#{body}"
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def page_number_from_link(relation_type)
|
37
|
+
link = @links.by_rel(relation_type)&.target&.request_uri
|
38
|
+
link&.match(/page=(?<page>\d+)/) { |matches| matches[:page] }
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
lib = File.expand_path('lib', __dir__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require 'netology_group/tasks_client/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'netology-tasks_client'
|
7
|
+
spec.version = NetologyGroup::TasksClient::VERSION
|
8
|
+
spec.authors = ['Andrey Skuryatin']
|
9
|
+
spec.email = ['skat@foxford.ru']
|
10
|
+
|
11
|
+
spec.summary = 'Ruby client for Netology Group tasks service.'
|
12
|
+
spec.homepage = 'https://netology-group.ru'
|
13
|
+
|
14
|
+
# spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
15
|
+
# f.match(%r{^(test|spec|features)/})
|
16
|
+
# end
|
17
|
+
|
18
|
+
spec.files = Dir.glob('**/*').reject do |file|
|
19
|
+
file.match(%r{^(test|spec|features)/})
|
20
|
+
end
|
21
|
+
spec.bindir = 'bin'
|
22
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
23
|
+
spec.require_paths = ['lib']
|
24
|
+
|
25
|
+
spec.add_runtime_dependency 'concurrent-ruby', '~> 1.0'
|
26
|
+
spec.add_runtime_dependency 'excon', '~> 0.62'
|
27
|
+
spec.add_runtime_dependency 'nitlink', '~> 1.1'
|
28
|
+
|
29
|
+
spec.add_development_dependency 'bundler', '~> 1.16'
|
30
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
31
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
32
|
+
end
|
metadata
ADDED
@@ -0,0 +1,143 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: netology-tasks_client
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Andrey Skuryatin
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-05-14 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: concurrent-ruby
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: excon
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.62'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.62'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: nitlink
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.1'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.1'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: bundler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.16'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.16'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '10.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '10.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '3.0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '3.0'
|
97
|
+
description:
|
98
|
+
email:
|
99
|
+
- skat@foxford.ru
|
100
|
+
executables:
|
101
|
+
- console
|
102
|
+
- setup
|
103
|
+
extensions: []
|
104
|
+
extra_rdoc_files: []
|
105
|
+
files:
|
106
|
+
- Gemfile
|
107
|
+
- Gemfile.lock
|
108
|
+
- README.md
|
109
|
+
- Rakefile
|
110
|
+
- bin/console
|
111
|
+
- bin/setup
|
112
|
+
- lib/netology-tasks_client.rb
|
113
|
+
- lib/netology_group/tasks_client.rb
|
114
|
+
- lib/netology_group/tasks_client/client.rb
|
115
|
+
- lib/netology_group/tasks_client/config.rb
|
116
|
+
- lib/netology_group/tasks_client/error.rb
|
117
|
+
- lib/netology_group/tasks_client/response.rb
|
118
|
+
- lib/netology_group/tasks_client/version.rb
|
119
|
+
- netology-tasks_client.gemspec
|
120
|
+
homepage: https://netology-group.ru
|
121
|
+
licenses: []
|
122
|
+
metadata: {}
|
123
|
+
post_install_message:
|
124
|
+
rdoc_options: []
|
125
|
+
require_paths:
|
126
|
+
- lib
|
127
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
133
|
+
requirements:
|
134
|
+
- - ">="
|
135
|
+
- !ruby/object:Gem::Version
|
136
|
+
version: '0'
|
137
|
+
requirements: []
|
138
|
+
rubyforge_project:
|
139
|
+
rubygems_version: 2.7.3
|
140
|
+
signing_key:
|
141
|
+
specification_version: 4
|
142
|
+
summary: Ruby client for Netology Group tasks service.
|
143
|
+
test_files: []
|