codewars_api 0.3.0 → 0.4.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c31a61ef6b89ac543fab501370416a3261d4fed0
4
- data.tar.gz: 5ff59fe70dd05db40722220981ffe4bea473645f
3
+ metadata.gz: 8e358b5d3492ac331673e4e194549c75751262f6
4
+ data.tar.gz: 1802474bae44ea03f2cd68e50d5beb19ff9b862b
5
5
  SHA512:
6
- metadata.gz: 5724f7693ee7618f08af73d8519627f24bcc84faf45388661d519444f8abc5daf7feb75f9ba08ef36ce5bf6bf551ff5010c9578a2d75ae48a698d4b4bca46650
7
- data.tar.gz: 946e364ef13e02e5891fd6ad95711d48185312f4a9d96b86509f9fb88e30141a56520adb1397281f92513d9e4182cb9bd09fd7136e4f22f65de342aadee20a53
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.0'
25
- spec.add_development_dependency 'webmock', '~> 1.21.0'
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 'httparty', '~> 0.13.7'
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'
@@ -16,7 +16,7 @@ module CodewarsApi
16
16
  "/code-challenges/projects/#{project_id}/solutions/#{solution_id}/attempt",
17
17
  request_options
18
18
  )
19
- fail @response.message if @response.code == 500
19
+ ResponseChecker.check_errors(@response)
20
20
  end
21
21
 
22
22
  def dmid
@@ -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
- fail @response.message if @response.code == 500
13
+ ResponseChecker.check_errors(@response)
14
14
  end
15
15
 
16
16
  def dmid
@@ -15,7 +15,7 @@ module CodewarsApi
15
15
  "/code-challenges/projects/#{project_id}/solutions/#{solution_id}/finalize",
16
16
  request_options
17
17
  )
18
- fail @response.message if @response.code == 500
18
+ ResponseChecker.check_errors(@response)
19
19
  end
20
20
  end
21
21
  end
@@ -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
@@ -0,0 +1,7 @@
1
+ module CodewarsApi
2
+ class ResponseChecker
3
+ def self.check_errors(response)
4
+ fail response.message if response.code == 500
5
+ end
6
+ end
7
+ end
@@ -4,7 +4,7 @@ module CodewarsApi
4
4
 
5
5
  def initialize(id)
6
6
  @response = RequestHelper.get("#{CodewarsApi::API_URL}/code-challenges/#{id}")
7
- fail @response.message if @response.code == 500
7
+ ResponseChecker.check_errors(@response)
8
8
  end
9
9
 
10
10
  def id
@@ -14,7 +14,7 @@ module CodewarsApi
14
14
  "#{CodewarsApi::API_URL}/code-challenges/#{language}/train",
15
15
  request_options
16
16
  )
17
- fail @response.message if @response.code == 500
17
+ ResponseChecker.check_errors(@response)
18
18
  end
19
19
 
20
20
  def name
@@ -14,7 +14,7 @@ module CodewarsApi
14
14
  "#{CodewarsApi::API_URL}/code-challenges/#{id_or_slug}/#{language}/train",
15
15
  request_options
16
16
  )
17
- fail @response.message if @response.code == 500
17
+ ResponseChecker.check_errors(@response)
18
18
  end
19
19
 
20
20
  def name
@@ -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
- fail @response.message if @response.code == 500
8
+ ResponseChecker.check_errors(@response)
9
9
  end
10
10
 
11
11
  def username
@@ -1,3 +1,3 @@
1
1
  module CodewarsApi
2
- VERSION = '0.3.0'
2
+ VERSION = '0.4.0'
3
3
  end
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.3.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: 2015-12-06 00:00:00.000000000 Z
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.0
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.0
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.0
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.0
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.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.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