Module: Wanikani
- Defined in:
- lib/wanikani.rb,
lib/wanikani/srs.rb,
lib/wanikani/user.rb,
lib/wanikani/level.rb,
lib/wanikani/study_queue.rb,
lib/wanikani/critical_items.rb,
lib/wanikani/recent_unlocks.rb
Defined Under Namespace
Classes: CriticalItems, Level, RecentUnlocks, SRS, StudyQueue, User
Constant Summary
collapse
- API_ENDPOINT =
"http://www.wanikani.com/api/user"
Class Method Summary
collapse
Class Method Details
.api_key ⇒ Object
22
23
24
|
# File 'lib/wanikani.rb', line 22
def self.api_key
@api_key
end
|
.api_key=(api_key) ⇒ Object
18
19
20
|
# File 'lib/wanikani.rb', line 18
def self.api_key=(api_key)
@api_key = api_key
end
|
.api_response(resource, optional_arg = nil) ⇒ Object
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/wanikani.rb', line 26
def self.api_response(resource, optional_arg = nil)
raise ArgumentError, "You must define a resource to query Wanikani" if resource.nil? || resource.empty?
raise ArgumentError, "You must set your Wanikani API key before querying the API" if Wanikani.api_key.nil? || Wanikani.api_key.empty?
begin
response = RestClient.get("#{Wanikani::API_ENDPOINT}/#{Wanikani.api_key}/#{resource}/#{optional_arg}")
parsed_response = MultiJson.load(response)
if parsed_response.has_key?("error")
self.raise_exception(parsed_response["error"]["message"])
else
return parsed_response
end
rescue => error
self.raise_exception(error.message)
end
end
|