Class: Lingq::Client

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/lingq/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#languagesObject (readonly)

Returns the value of attribute languages.



9
10
11
# File 'lib/lingq/client.rb', line 9

def languages
  @languages
end

#target_languageObject (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

Returns:

  • (Boolean)


16
17
18
# File 'lib/lingq/client.rb', line 16

def learning_language?(language_code)
  @languages.index(language_code)
end

#lessonsObject



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

#wordsObject



33
34
35
# File 'lib/lingq/client.rb', line 33

def words
  get_with_language("lingqs/").map{|hash| Lingq::Word.new(self,@target_language,hash)}
end

#words_for_lesson(lesson) ⇒ Object



37
38
39
40
# File 'lib/lingq/client.rb', line 37

def words_for_lesson(lesson)
  change_language!(lesson.language)
  get_with_language("#{lesson.id}/lingqs/").map{|hash| Lingq::Word.new(self,@target_language,hash)}
end