Class: Lingq::Client
Instance Attribute Summary collapse
-
#languages ⇒ Object
readonly
Returns the value of attribute languages.
-
#target_language ⇒ Object
readonly
Returns the value of attribute target_language.
Instance Method Summary collapse
- #change_language!(language_code) ⇒ Object
-
#initialize(api_key) ⇒ Client
constructor
A new instance of Client.
- #learning_language?(language_code) ⇒ Boolean
- #lessons ⇒ Object
- #load_languages! ⇒ Object
- #update_word!(word) ⇒ Object
- #words ⇒ Object
- #words_for_lesson(lesson) ⇒ Object
Constructor Details
#initialize(api_key) ⇒ Client
Returns a new instance of Client.
11 12 13 14 |
# File 'lib/lingq/client.rb', line 11 def initialize(api_key) @apikey = api_key load_languages! end |
Instance Attribute Details
#languages ⇒ Object (readonly)
Returns the value of attribute languages.
9 10 11 |
# File 'lib/lingq/client.rb', line 9 def languages @languages end |
#target_language ⇒ Object (readonly)
Returns the value of attribute target_language.
8 9 10 |
# File 'lib/lingq/client.rb', line 8 def target_language @target_language end |
Instance Method Details
#change_language!(language_code) ⇒ Object
25 26 27 |
# File 'lib/lingq/client.rb', line 25 def change_language!(language_code) @target_language = language_code if learning_language?(language_code) end |
#learning_language?(language_code) ⇒ Boolean
16 17 18 |
# File 'lib/lingq/client.rb', line 16 def learning_language?(language_code) @languages.index(language_code) end |
#lessons ⇒ Object
29 30 31 |
# File 'lib/lingq/client.rb', line 29 def lessons get_with_language("lessons/").map{|hash| Lingq::Lesson.new(self,@target_language,hash)} end |
#load_languages! ⇒ Object
20 21 22 23 |
# File 'lib/lingq/client.rb', line 20 def load_languages! @languages = get_with_key('/languages/').parsed_response @target_language = @languages.first end |
#update_word!(word) ⇒ Object
42 43 44 45 46 47 |
# File 'lib/lingq/client.rb', line 42 def update_word!(word) #put_with_language("lingqs/",word.params) ##TODO: This is a horrible awful hack, but until I can figure out how to get httparty to PUT this data properly, it will function system_call("curl -X PUT -d 'id=#{word.id};status=#{word.status};hint=#{word.hint};fragment=#{word.fragment}' http://www.lingq.com/api_v2/#{@target_language}/lingqs/?apikey=#{@apikey}") end |