codewars_api 0.1.1 → 0.2.1

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: 0c94c13a29f542cda33e4c103f0017a3a52edc09
4
- data.tar.gz: 9e307ef5d80a9a6f069c41718b3ad905815cfacd
3
+ metadata.gz: b0d50013fa7b3be16d2e5b8761306ba17566fd27
4
+ data.tar.gz: ffda58c75b54c0bd3eb783a5fdcc23591347bef8
5
5
  SHA512:
6
- metadata.gz: b318d4da06af8af757918d8e058d38581f7788e5e475421ebca487fb4cbf54587436d6e3937e20b11f509f51fec949540ef4ec87e54a7cc022e80f19a27965c4
7
- data.tar.gz: ff4897b9bb419a019411ab54ed3370e36f750503c2f2161a9c7eb2b4fba1cd5ffc58403adca1747eeb593958773e4b4ac8590c249fa8b79aeb9d816255141e46
6
+ metadata.gz: 77924b541c9bd1e4bd72778d7a6afd336f4e0c7651f2b1bb987c401de7ed57123dc77483928945613875ffeddf38e3b3b35c6e58c9f41fed4130fb734a4e51a6
7
+ data.tar.gz: d38ed424d7d2c6310a73ff8b3aeaeb005acc191e1b832a6ecae962f63d5df77b2871bdab07d531e6e4385251bc0df9934fee698acda964f84fa043b98e6538a5
data/Rakefile CHANGED
@@ -1,6 +1,6 @@
1
1
  require 'bundler/gem_tasks'
2
- require 'rspec/core/rake_task'
3
2
 
3
+ require 'rspec/core/rake_task'
4
4
  RSpec::Core::RakeTask.new(:spec)
5
5
  task test: :spec
6
6
 
@@ -1,5 +1,7 @@
1
1
  module CodewarsApi
2
2
  class AttemptSolution
3
+ include Common
4
+
3
5
  def initialize(options)
4
6
  api_key = options.delete!(:api_key)
5
7
  project_id = options.delete!(:project_id)
@@ -16,16 +18,8 @@ module CodewarsApi
16
18
  )
17
19
  end
18
20
 
19
- def success
20
- @response.to_h['success']
21
- end
22
-
23
21
  def dmid
24
22
  @response.to_h['dmid']
25
23
  end
26
-
27
- def to_h
28
- @response.to_h
29
- end
30
24
  end
31
25
  end
@@ -2,8 +2,8 @@ module CodewarsApi
2
2
  class Client
3
3
  attr_reader :api_key
4
4
 
5
- def initialize(options)
6
- @api_key = options[:api_key] if options[:api_key]
5
+ def initialize(options = nil)
6
+ @api_key = options[:api_key] if options
7
7
  end
8
8
 
9
9
  def user(username)
@@ -0,0 +1,15 @@
1
+ module CodewarsApi
2
+ module Common
3
+ def success
4
+ @response.to_h['success']
5
+ end
6
+
7
+ def reason
8
+ @response.to_h['reason']
9
+ end
10
+
11
+ def to_h
12
+ @response.to_h
13
+ end
14
+ end
15
+ end
@@ -1,5 +1,7 @@
1
1
  module CodewarsApi
2
2
  class DeferredResponse
3
+ include Common
4
+
3
5
  def initialize(options)
4
6
  api_key = options.delete!(:api_key)
5
7
  dmid = options.delete!(:dmid)
@@ -10,10 +12,6 @@ module CodewarsApi
10
12
  @response = RequestHelper.get("#{CodewarsApi::API_URL}/deferred/#{dmid}", request_options)
11
13
  end
12
14
 
13
- def success
14
- @response.to_h['success']
15
- end
16
-
17
15
  def dmid
18
16
  @response.to_h['dmid']
19
17
  end
@@ -58,10 +56,6 @@ module CodewarsApi
58
56
  @response.to_h['summary'].andand['errors']
59
57
  end
60
58
 
61
- def reason
62
- @response.to_h['reason']
63
- end
64
-
65
59
  def output
66
60
  @response.to_h['output']
67
61
  end
@@ -73,9 +67,5 @@ module CodewarsApi
73
67
  def status_code
74
68
  @response.to_h['status_code']
75
69
  end
76
-
77
- def to_h
78
- @response.to_h
79
- end
80
70
  end
81
71
  end
@@ -1,5 +1,7 @@
1
1
  module CodewarsApi
2
2
  class FinalizeSolution
3
+ include Common
4
+
3
5
  def initialize(options)
4
6
  api_key = options.delete!(:api_key)
5
7
  project_id = options.delete!(:project_id)
@@ -14,13 +16,5 @@ module CodewarsApi
14
16
  request_options
15
17
  )
16
18
  end
17
-
18
- def success
19
- @response.to_h['success']
20
- end
21
-
22
- def to_h
23
- @response.to_h
24
- end
25
19
  end
26
20
  end
@@ -1,5 +1,7 @@
1
1
  module CodewarsApi
2
2
  class KataInfo
3
+ include Common
4
+
3
5
  def initialize(id)
4
6
  @response = RequestHelper.get("#{CodewarsApi::API_URL}/code-challenges/#{id}")
5
7
  end
@@ -95,9 +97,5 @@ module CodewarsApi
95
97
  def unresolved_suggestions
96
98
  @response.to_h['unresolved'].andand['suggestions']
97
99
  end
98
-
99
- def to_h
100
- @response.to_h
101
- end
102
100
  end
103
101
  end
@@ -1,5 +1,7 @@
1
1
  module CodewarsApi
2
2
  class TrainNextKata
3
+ include Common
4
+
3
5
  def initialize(options)
4
6
  api_key = options.delete!(:api_key)
5
7
  language = options.delete!(:language)
@@ -14,10 +16,6 @@ module CodewarsApi
14
16
  )
15
17
  end
16
18
 
17
- def success
18
- @response.to_h['success']
19
- end
20
-
21
19
  def name
22
20
  @response.to_h['name']
23
21
  end
@@ -69,9 +67,5 @@ module CodewarsApi
69
67
  def code
70
68
  @response.to_h['session'].andand['code']
71
69
  end
72
-
73
- def to_h
74
- @response.to_h
75
- end
76
70
  end
77
71
  end
@@ -1,5 +1,7 @@
1
1
  module CodewarsApi
2
2
  class TrainSpecificKata
3
+ include Common
4
+
3
5
  def initialize(options)
4
6
  api_key = options.delete!(:api_key)
5
7
  language = options.delete!(:language)
@@ -14,10 +16,6 @@ module CodewarsApi
14
16
  )
15
17
  end
16
18
 
17
- def success
18
- @response.to_h['success']
19
- end
20
-
21
19
  def name
22
20
  @response.to_h['name']
23
21
  end
@@ -69,9 +67,5 @@ module CodewarsApi
69
67
  def recently_attempted
70
68
  @response.to_h['session'].andand['recentlyAttempted']
71
69
  end
72
-
73
- def to_h
74
- @response.to_h
75
- end
76
70
  end
77
71
  end
@@ -1,8 +1,10 @@
1
1
  module CodewarsApi
2
2
  class User
3
- def initialize(username)
4
- fail 'Username is not set' unless username
5
- @response = RequestHelper.get("#{CodewarsApi::API_URL}/users/#{username}")
3
+ include Common
4
+
5
+ def initialize(id_or_username)
6
+ fail 'Username or id is not set' unless id_or_username
7
+ @response = RequestHelper.get("#{CodewarsApi::API_URL}/users/#{id_or_username}")
6
8
  end
7
9
 
8
10
  def username
@@ -44,9 +46,5 @@ module CodewarsApi
44
46
  def katas_completed
45
47
  @response.to_h['codeChallenges'].andand['totalCompleted']
46
48
  end
47
-
48
- def to_h
49
- @response.to_h
50
- end
51
49
  end
52
50
  end
@@ -1,3 +1,3 @@
1
1
  module CodewarsApi
2
- VERSION = '0.1.1'
2
+ VERSION = '0.2.1'
3
3
  end
data/lib/codewars_api.rb CHANGED
@@ -17,6 +17,7 @@ class Hash
17
17
  end
18
18
 
19
19
  require 'andand'
20
+ require 'codewars_api/common'
20
21
  require 'codewars_api/request_helper'
21
22
  require 'codewars_api/version'
22
23
  require 'codewars_api/client'
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.1.1
4
+ version: 0.2.1
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-11-08 00:00:00.000000000 Z
11
+ date: 2015-11-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -198,6 +198,7 @@ files:
198
198
  - lib/codewars_api.rb
199
199
  - lib/codewars_api/attempt_solution.rb
200
200
  - lib/codewars_api/client.rb
201
+ - lib/codewars_api/common.rb
201
202
  - lib/codewars_api/deferred_response.rb
202
203
  - lib/codewars_api/finalize_solution.rb
203
204
  - lib/codewars_api/kata_info.rb