lingq 0.1.4 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of lingq might be problematic. Click here for more details.
- data/Gemfile +1 -0
- data/README.rdoc +4 -1
- data/Rakefile +2 -1
- data/VERSION +1 -1
- data/lib/lingq/client.rb +6 -1
- data/lib/lingq/lesson.rb +8 -2
- data/lingq.gemspec +1 -1
- data/test/helper.rb +1 -0
- data/test/test_client.rb +21 -0
- data/test/test_lesson.rb +20 -1
- metadata +4 -4
data/Gemfile
CHANGED
data/README.rdoc
CHANGED
@@ -17,10 +17,13 @@ You need the API key for your account. Usage is as follows:
|
|
17
17
|
|
18
18
|
#load all lingq flashcards for the user
|
19
19
|
words = client.words
|
20
|
+
|
21
|
+
#load only the flashcards for a single lesson
|
22
|
+
words = lessons.first.words
|
20
23
|
|
21
24
|
== Current Status
|
22
25
|
|
23
|
-
Right now just data pulling is done. Will add soon the ability to update lingqs
|
26
|
+
Right now just data pulling is done. Will add soon the ability to update lingqs.
|
24
27
|
|
25
28
|
== Note on Patches/Pull Requests
|
26
29
|
|
data/Rakefile
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
data/lib/lingq/client.rb
CHANGED
@@ -27,13 +27,18 @@ module Lingq
|
|
27
27
|
end
|
28
28
|
|
29
29
|
def lessons
|
30
|
-
get_with_language("lessons/").map{|hash| Lingq::Lesson.new(
|
30
|
+
get_with_language("lessons/").map{|hash| Lingq::Lesson.new(self,@target_language,hash)}
|
31
31
|
end
|
32
32
|
|
33
33
|
def words
|
34
34
|
get_with_language("lingqs/").map{|hash| Lingq::Word.new(@target_language,hash)}
|
35
35
|
end
|
36
36
|
|
37
|
+
def words_for_lesson(lesson)
|
38
|
+
change_language!(lesson.language)
|
39
|
+
get_with_language("#{lesson.id}/lingqs/").map{|hash| Lingq::Word.new(@target_language,hash)}
|
40
|
+
end
|
41
|
+
|
37
42
|
private
|
38
43
|
def get_with_key(path,params={})
|
39
44
|
self.class.get(path,{:query=>params.merge({:apikey=>@apikey})})
|
data/lib/lingq/lesson.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
module Lingq
|
2
2
|
class Lesson
|
3
|
-
attr_reader :audio_url,:image_url,:id,:cards_count,:title,:language
|
4
|
-
def initialize(language_code,json)
|
3
|
+
attr_reader :audio_url,:image_url,:id,:cards_count,:title,:language,:lingq_client
|
4
|
+
def initialize(client,language_code,json)
|
5
|
+
@lingq_client = client
|
5
6
|
@language = language_code
|
6
7
|
@audio_url = json["audio_url"]
|
7
8
|
@image_url = json["image_url"]
|
@@ -9,5 +10,10 @@ module Lingq
|
|
9
10
|
@cards_count = json["cards_count"]
|
10
11
|
@title = json["title"]
|
11
12
|
end
|
13
|
+
|
14
|
+
def words
|
15
|
+
return @words if @words
|
16
|
+
@words = @lingq_client.words_for_lesson(self)
|
17
|
+
end
|
12
18
|
end
|
13
19
|
end
|
data/lingq.gemspec
CHANGED
data/test/helper.rb
CHANGED
data/test/test_client.rb
CHANGED
@@ -68,6 +68,27 @@ class TestClient < Test::Unit::TestCase
|
|
68
68
|
assert_equal 5,@words.size
|
69
69
|
end
|
70
70
|
end
|
71
|
+
|
72
|
+
context "prebuilt client for words from lesson call" do
|
73
|
+
setup do
|
74
|
+
body = %Q{[ { "status": 0, "fragment": "вперед и вы найдете его .", "term": "Его", "id": 4259928, "hint": "him" },
|
75
|
+
{ "status": 0, "fragment": "Официант, принесите нам счет , пожалуйста", "term": "Счет", "id": 4259923, "hint": "check " },
|
76
|
+
{ "status": 0, "fragment": "Легко сказать да трудно сделать.", "term": "трудно", "id": 4259919, "hint": "difficult" },
|
77
|
+
{ "status": 0, "fragment": "Легко сказать да трудно сделать.", "term": "Легко", "id": 4259916, "hint": "easily" },
|
78
|
+
{ "status": 0, "fragment": "стараться делать это с радостью .", "term": "радостью", "id": 4259915, "hint": "joy" }]}
|
79
|
+
@lesson = Lingq::Lesson.new(@client,"ru",{"id"=> 123})
|
80
|
+
stub_api("ru/123/lingqs",body)
|
81
|
+
@words = @client.words_for_lesson(@lesson)
|
82
|
+
end
|
83
|
+
|
84
|
+
should "load an array of lessons" do
|
85
|
+
assert_equal Lingq::Word,@words.first.class
|
86
|
+
end
|
87
|
+
|
88
|
+
should "load one lesson for each json hash" do
|
89
|
+
assert_equal 5,@words.size
|
90
|
+
end
|
91
|
+
end
|
71
92
|
end
|
72
93
|
|
73
94
|
def stub_api(path,body)
|
data/test/test_lesson.rb
CHANGED
@@ -3,7 +3,9 @@ require 'helper'
|
|
3
3
|
class TestLesson < Test::Unit::TestCase
|
4
4
|
context "lesson" do
|
5
5
|
setup do
|
6
|
-
|
6
|
+
Lingq::Client.any_instance.stubs(:load_languages!)
|
7
|
+
@client = Lingq::Client.new("apikey")
|
8
|
+
@lesson = Lingq::Lesson.new(@client,"ru",{"audio_url"=>"http://m.lingq.com/media/_28/resources/contents/audio/2007/06/21/eating-out-3.mp3",
|
7
9
|
"image_url"=>"http://m.lingq.com/media/_28/resources/contents/images/2008/08/26/Eating_Out_______.jpg",
|
8
10
|
"id"=> 21730, "cards_count"=> 31, "title"=> "Part 3" })
|
9
11
|
end
|
@@ -31,5 +33,22 @@ class TestLesson < Test::Unit::TestCase
|
|
31
33
|
should "cache language" do
|
32
34
|
assert_equal "ru",@lesson.language
|
33
35
|
end
|
36
|
+
|
37
|
+
should "cache the client that created it" do
|
38
|
+
assert_equal @client,@lesson.lingq_client
|
39
|
+
end
|
40
|
+
|
41
|
+
context "loading words" do
|
42
|
+
setup do
|
43
|
+
@client.expects(:words_for_lesson).with(@lesson).returns([Lingq::Word.new("ru",{})])
|
44
|
+
@words = @lesson.words
|
45
|
+
end
|
46
|
+
|
47
|
+
should "load words from client" do
|
48
|
+
assert_equal Lingq::Word,@words.first.class
|
49
|
+
assert_equal @lesson.language,@words.first.language
|
50
|
+
assert_equal 1,@words.size
|
51
|
+
end
|
52
|
+
end
|
34
53
|
end
|
35
54
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lingq
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 2
|
9
|
+
- 0
|
10
|
+
version: 0.2.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Ethan Vizitei
|