wanikani 1.3 → 1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/wanikani.rb +16 -10
- data/lib/wanikani/version.rb +1 -1
- metadata +10 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c80fe4a266a176e7b3e9ef72398a2cfef11d16df
|
4
|
+
data.tar.gz: b523b20cf4098bb327ae0587f554df26088ff4da
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d6fe284b27ac4398c138973336d604296a7e2f13792ac06eb65b1095a8e1b1aef46e1bb79ca804afea4a0931e308085e6047b1268b19736805e17307b288f519
|
7
|
+
data.tar.gz: b4addf8432b0d277b4a4d16cd452d349975f3b828b421fbe6cf8fe300860fee281dce7188acabba713d9884ac82fb66d840f20b47ff0e8710b512e3fe31cc3f7
|
data/lib/wanikani.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# -*- encoding : utf-8 -*-
|
2
|
-
require '
|
3
|
-
require '
|
2
|
+
require 'faraday'
|
3
|
+
require 'faraday_middleware'
|
4
4
|
|
5
5
|
require 'wanikani/user'
|
6
6
|
require 'wanikani/study_queue'
|
@@ -14,7 +14,7 @@ Encoding.default_external = Encoding::UTF_8
|
|
14
14
|
Encoding.default_internal = Encoding::UTF_8
|
15
15
|
|
16
16
|
module Wanikani
|
17
|
-
API_ENDPOINT = "https://www.wanikani.com
|
17
|
+
API_ENDPOINT = "https://www.wanikani.com"
|
18
18
|
DEFAULT_API_VERSION = "v1.4"
|
19
19
|
VALID_API_VERSIONS = %w(v1 v1.1 v1.2 v1.3 v1.4)
|
20
20
|
|
@@ -40,13 +40,12 @@ module Wanikani
|
|
40
40
|
raise ArgumentError, "You must set your Wanikani API key before querying the API" if Wanikani.api_key.nil? || Wanikani.api_key.empty?
|
41
41
|
|
42
42
|
begin
|
43
|
-
|
44
|
-
parsed_response = MultiJson.load(response)
|
43
|
+
res = client.get("/api/#{Wanikani.api_version}/user/#{Wanikani.api_key}/#{resource}/#{optional_arg}")
|
45
44
|
|
46
|
-
if
|
47
|
-
self.raise_exception(
|
45
|
+
if res.body.has_key?("error")
|
46
|
+
self.raise_exception(res.body["error"]["message"])
|
48
47
|
else
|
49
|
-
return
|
48
|
+
return res.body
|
50
49
|
end
|
51
50
|
rescue => error
|
52
51
|
self.raise_exception(error.message)
|
@@ -57,12 +56,19 @@ module Wanikani
|
|
57
56
|
api_key ||= Wanikani.api_key
|
58
57
|
return false if api_key.nil? || api_key.empty?
|
59
58
|
|
60
|
-
|
61
|
-
!
|
59
|
+
res = client.get("/api/#{Wanikani.api_version}/user/#{api_key}/user-information")
|
60
|
+
!res.body.has_key?("error")
|
62
61
|
end
|
63
62
|
|
64
63
|
private
|
65
64
|
|
65
|
+
def self.client
|
66
|
+
Faraday.new(url: Wanikani::API_ENDPOINT) do |conn|
|
67
|
+
conn.response :json, :content_type => /\bjson$/
|
68
|
+
conn.adapter Faraday.default_adapter
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
66
72
|
def self.raise_exception(message)
|
67
73
|
raise Wanikani::Exception, "There was an error fetching the data from Wanikani (#{message})"
|
68
74
|
end
|
data/lib/wanikani/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wanikani
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '1.
|
4
|
+
version: '1.4'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dennis Martinez
|
@@ -11,47 +11,47 @@ cert_chain: []
|
|
11
11
|
date: 2015-02-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: faraday
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '0.9'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '0.9'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: faraday_middleware
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '0.10'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '0.10'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '3.
|
47
|
+
version: '3.4'
|
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.
|
54
|
+
version: '3.4'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: webmock
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -101,7 +101,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
101
101
|
version: '0'
|
102
102
|
requirements: []
|
103
103
|
rubyforge_project:
|
104
|
-
rubygems_version: 2.
|
104
|
+
rubygems_version: 2.5.1
|
105
105
|
signing_key:
|
106
106
|
specification_version: 4
|
107
107
|
summary: Add Japanese Kanji learning goodness to your Ruby projects!
|