codewars_api 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/codewars_api.gemspec +3 -5
- data/lib/codewars_api.rb +2 -1
- data/lib/codewars_api/attempt_solution.rb +1 -1
- data/lib/codewars_api/deferred_response.rb +1 -1
- data/lib/codewars_api/finalize_solution.rb +1 -1
- data/lib/codewars_api/helpers/request_helper.rb +51 -0
- data/lib/codewars_api/helpers/response_checker.rb +7 -0
- data/lib/codewars_api/kata_info.rb +1 -1
- data/lib/codewars_api/train_next_kata.rb +1 -1
- data/lib/codewars_api/train_specific_kata.rb +1 -1
- data/lib/codewars_api/user.rb +1 -1
- data/lib/codewars_api/version.rb +1 -1
- metadata +10 -37
- data/lib/codewars_api/request_helper.rb +0 -20
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8e358b5d3492ac331673e4e194549c75751262f6
|
4
|
+
data.tar.gz: 1802474bae44ea03f2cd68e50d5beb19ff9b862b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d8657851f10677e18ce4c9fcff03ee05735e55674cbbc11b0fe014103b985d889d1fd81aca7c5d5de10eff93b5a61a8b8534af20e18e9990080a3141f39bf101
|
7
|
+
data.tar.gz: 33f017f8937798e332a969b6ae8507532b496282954738bb6369a599de5a34406bb6f66219862d35d79809875dd5f1f27173e86194fc65e35a43717a4e17c64d
|
data/codewars_api.gemspec
CHANGED
@@ -21,15 +21,13 @@ Gem::Specification.new do |spec|
|
|
21
21
|
|
22
22
|
spec.add_development_dependency 'bundler', '~> 1.10'
|
23
23
|
spec.add_development_dependency 'rake', '~> 10.0'
|
24
|
-
spec.add_development_dependency 'rspec', '~> 3.3
|
25
|
-
spec.add_development_dependency 'webmock', '~> 1.21
|
24
|
+
spec.add_development_dependency 'rspec', '~> 3.3'
|
25
|
+
spec.add_development_dependency 'webmock', '~> 1.21'
|
26
26
|
spec.add_development_dependency 'pry-byebug'
|
27
27
|
spec.add_development_dependency 'simplecov'
|
28
28
|
spec.add_development_dependency 'yard'
|
29
29
|
spec.add_development_dependency 'redcarpet'
|
30
30
|
spec.add_development_dependency 'rubocop'
|
31
31
|
|
32
|
-
spec.add_dependency '
|
33
|
-
spec.add_dependency 'json', '~> 1.8.3'
|
34
|
-
spec.add_dependency 'andand', '~> 1.3.3'
|
32
|
+
spec.add_dependency 'andand', '~> 1.3'
|
35
33
|
end
|
data/lib/codewars_api.rb
CHANGED
@@ -18,7 +18,6 @@ end
|
|
18
18
|
|
19
19
|
require 'andand'
|
20
20
|
require 'codewars_api/common'
|
21
|
-
require 'codewars_api/request_helper'
|
22
21
|
require 'codewars_api/version'
|
23
22
|
require 'codewars_api/client'
|
24
23
|
require 'codewars_api/user'
|
@@ -28,3 +27,5 @@ require 'codewars_api/train_specific_kata'
|
|
28
27
|
require 'codewars_api/attempt_solution'
|
29
28
|
require 'codewars_api/finalize_solution'
|
30
29
|
require 'codewars_api/deferred_response'
|
30
|
+
require 'codewars_api/helpers/request_helper'
|
31
|
+
require 'codewars_api/helpers/response_checker'
|
@@ -10,7 +10,7 @@ module CodewarsApi
|
|
10
10
|
request_options = RequestHelper.add_api_key(request_options, api_key)
|
11
11
|
|
12
12
|
@response = RequestHelper.get("#{CodewarsApi::API_URL}/deferred/#{dmid}", request_options)
|
13
|
-
|
13
|
+
ResponseChecker.check_errors(@response)
|
14
14
|
end
|
15
15
|
|
16
16
|
def dmid
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'uri'
|
2
|
+
require 'net/http'
|
3
|
+
require 'net/https'
|
4
|
+
require 'json'
|
5
|
+
|
6
|
+
module CodewarsApi
|
7
|
+
module RequestHelper
|
8
|
+
def self.add_api_key(request_options, api_key)
|
9
|
+
request_options = request_options.dup
|
10
|
+
request_options[:headers] = { 'Authorization' => api_key }
|
11
|
+
request_options
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.add_body_options(request_options, body_options)
|
15
|
+
request_options = request_options.dup
|
16
|
+
request_options[:body] = body_options
|
17
|
+
request_options
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.post(url, options = {})
|
21
|
+
uri = URI(CodewarsApi::BASE_URL + url)
|
22
|
+
headers = { 'Content-Type' => 'application/json' }
|
23
|
+
headers.merge! options[:headers] if options
|
24
|
+
request = Net::HTTP::Post.new(uri.path, headers)
|
25
|
+
request.body = options[:body].to_json if options
|
26
|
+
https(uri).request(request)
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.get(url, options = nil)
|
30
|
+
uri = URI(CodewarsApi::BASE_URL + url)
|
31
|
+
headers = options[:headers] if options
|
32
|
+
https(uri).request_get uri, headers
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def self.https(uri)
|
38
|
+
https = Net::HTTP.new(uri.host, uri.port)
|
39
|
+
https.use_ssl = true
|
40
|
+
https
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
module Net
|
46
|
+
class HTTPResponse
|
47
|
+
def to_h
|
48
|
+
JSON.parse(body).to_h
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
data/lib/codewars_api/user.rb
CHANGED
@@ -5,7 +5,7 @@ module CodewarsApi
|
|
5
5
|
def initialize(id_or_username)
|
6
6
|
fail 'Username or id is not set' unless id_or_username
|
7
7
|
@response = RequestHelper.get("#{CodewarsApi::API_URL}/users/#{id_or_username}")
|
8
|
-
|
8
|
+
ResponseChecker.check_errors(@response)
|
9
9
|
end
|
10
10
|
|
11
11
|
def username
|
data/lib/codewars_api/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: codewars_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Evgeny Morozov
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-01-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -44,28 +44,28 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: 3.3
|
47
|
+
version: '3.3'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: 3.3
|
54
|
+
version: '3.3'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: webmock
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: 1.21
|
61
|
+
version: '1.21'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: 1.21
|
68
|
+
version: '1.21'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: pry-byebug
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -136,48 +136,20 @@ dependencies:
|
|
136
136
|
- - ">="
|
137
137
|
- !ruby/object:Gem::Version
|
138
138
|
version: '0'
|
139
|
-
- !ruby/object:Gem::Dependency
|
140
|
-
name: httparty
|
141
|
-
requirement: !ruby/object:Gem::Requirement
|
142
|
-
requirements:
|
143
|
-
- - "~>"
|
144
|
-
- !ruby/object:Gem::Version
|
145
|
-
version: 0.13.7
|
146
|
-
type: :runtime
|
147
|
-
prerelease: false
|
148
|
-
version_requirements: !ruby/object:Gem::Requirement
|
149
|
-
requirements:
|
150
|
-
- - "~>"
|
151
|
-
- !ruby/object:Gem::Version
|
152
|
-
version: 0.13.7
|
153
|
-
- !ruby/object:Gem::Dependency
|
154
|
-
name: json
|
155
|
-
requirement: !ruby/object:Gem::Requirement
|
156
|
-
requirements:
|
157
|
-
- - "~>"
|
158
|
-
- !ruby/object:Gem::Version
|
159
|
-
version: 1.8.3
|
160
|
-
type: :runtime
|
161
|
-
prerelease: false
|
162
|
-
version_requirements: !ruby/object:Gem::Requirement
|
163
|
-
requirements:
|
164
|
-
- - "~>"
|
165
|
-
- !ruby/object:Gem::Version
|
166
|
-
version: 1.8.3
|
167
139
|
- !ruby/object:Gem::Dependency
|
168
140
|
name: andand
|
169
141
|
requirement: !ruby/object:Gem::Requirement
|
170
142
|
requirements:
|
171
143
|
- - "~>"
|
172
144
|
- !ruby/object:Gem::Version
|
173
|
-
version: 1.3
|
145
|
+
version: '1.3'
|
174
146
|
type: :runtime
|
175
147
|
prerelease: false
|
176
148
|
version_requirements: !ruby/object:Gem::Requirement
|
177
149
|
requirements:
|
178
150
|
- - "~>"
|
179
151
|
- !ruby/object:Gem::Version
|
180
|
-
version: 1.3
|
152
|
+
version: '1.3'
|
181
153
|
description:
|
182
154
|
email:
|
183
155
|
- evmorov@gmail.com
|
@@ -201,8 +173,9 @@ files:
|
|
201
173
|
- lib/codewars_api/common.rb
|
202
174
|
- lib/codewars_api/deferred_response.rb
|
203
175
|
- lib/codewars_api/finalize_solution.rb
|
176
|
+
- lib/codewars_api/helpers/request_helper.rb
|
177
|
+
- lib/codewars_api/helpers/response_checker.rb
|
204
178
|
- lib/codewars_api/kata_info.rb
|
205
|
-
- lib/codewars_api/request_helper.rb
|
206
179
|
- lib/codewars_api/train_next_kata.rb
|
207
180
|
- lib/codewars_api/train_specific_kata.rb
|
208
181
|
- lib/codewars_api/user.rb
|
@@ -1,20 +0,0 @@
|
|
1
|
-
require 'httparty'
|
2
|
-
|
3
|
-
module CodewarsApi
|
4
|
-
module RequestHelper
|
5
|
-
include HTTParty
|
6
|
-
base_uri CodewarsApi::BASE_URL
|
7
|
-
|
8
|
-
def self.add_api_key(request_options, api_key)
|
9
|
-
request_options = request_options.dup
|
10
|
-
request_options[:headers] = { 'Authorization' => api_key }
|
11
|
-
request_options
|
12
|
-
end
|
13
|
-
|
14
|
-
def self.add_body_options(request_options, body_options)
|
15
|
-
request_options = request_options.dup
|
16
|
-
request_options[:body] = body_options
|
17
|
-
request_options
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|