lingq 0.2.1 → 0.3.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/VERSION +1 -1
- data/lib/lingq/client.rb +29 -2
- data/lib/lingq/word.rb +12 -2
- data/lingq.gemspec +2 -2
- data/test/test_client.rb +21 -2
- data/test/test_lesson.rb +1 -1
- data/test/test_word.rb +9 -1
- metadata +5 -5
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.3.0
|
data/lib/lingq/client.rb
CHANGED
@@ -31,15 +31,26 @@ module Lingq
|
|
31
31
|
end
|
32
32
|
|
33
33
|
def words
|
34
|
-
get_with_language("lingqs/").map{|hash| Lingq::Word.new(
|
34
|
+
get_with_language("lingqs/").map{|hash| Lingq::Word.new(self,@target_language,hash)}
|
35
35
|
end
|
36
36
|
|
37
37
|
def words_for_lesson(lesson)
|
38
38
|
change_language!(lesson.language)
|
39
|
-
get_with_language("#{lesson.id}/lingqs/").map{|hash| Lingq::Word.new(
|
39
|
+
get_with_language("#{lesson.id}/lingqs/").map{|hash| Lingq::Word.new(self,@target_language,hash)}
|
40
|
+
end
|
41
|
+
|
42
|
+
def update_word!(word)
|
43
|
+
#put_with_language("lingqs/",word.params)
|
44
|
+
|
45
|
+
##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
|
46
|
+
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}")
|
40
47
|
end
|
41
48
|
|
42
49
|
private
|
50
|
+
def system_call(call)
|
51
|
+
system(call)
|
52
|
+
end
|
53
|
+
|
43
54
|
def get_with_key(path,params={})
|
44
55
|
self.class.get(path,{:query=>params.merge({:apikey=>@apikey})})
|
45
56
|
end
|
@@ -47,5 +58,21 @@ module Lingq
|
|
47
58
|
def get_with_language(path,params={})
|
48
59
|
get_with_key("/#{@target_language}/#{path}",params)
|
49
60
|
end
|
61
|
+
|
62
|
+
def post_with_key(path,params={})
|
63
|
+
self.class.post(path,{:body=>params,:query=>{:apikey=>@apikey}})
|
64
|
+
end
|
65
|
+
|
66
|
+
def post_with_language(path,params={})
|
67
|
+
post_with_key("/#{@target_language}/#{path}",params)
|
68
|
+
end
|
69
|
+
|
70
|
+
def put_with_key(path,params={})
|
71
|
+
self.class.put(path,{:body=>params,:query=>{:apikey=>@apikey}})
|
72
|
+
end
|
73
|
+
|
74
|
+
def put_with_language(path,params={})
|
75
|
+
put_with_key("/#{@target_language}/#{path}",params)
|
76
|
+
end
|
50
77
|
end
|
51
78
|
end
|
data/lib/lingq/word.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
module Lingq
|
2
2
|
class Word
|
3
|
-
|
4
|
-
def initialize(language_code,json)
|
3
|
+
attr_accessor :hint,:term,:id,:fragment,:status,:language
|
4
|
+
def initialize(client,language_code,json)
|
5
|
+
@lingq_client = client
|
5
6
|
@language = language_code
|
6
7
|
@hint = json["hint"]
|
7
8
|
@term = json["term"]
|
@@ -9,5 +10,14 @@ module Lingq
|
|
9
10
|
@fragment = json["fragment"]
|
10
11
|
@status = json["status"]
|
11
12
|
end
|
13
|
+
|
14
|
+
def params
|
15
|
+
{:id=>@id,:hint=>@hint,:fragment=>@fragment,:status=>@status}
|
16
|
+
end
|
17
|
+
|
18
|
+
def increment_status!
|
19
|
+
@status += 1
|
20
|
+
@lingq_client.update_word!(self)
|
21
|
+
end
|
12
22
|
end
|
13
23
|
end
|
data/lingq.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{lingq}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.3.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Ethan Vizitei"]
|
12
|
-
s.date = %q{2010-06-
|
12
|
+
s.date = %q{2010-06-21}
|
13
13
|
s.description = %q{Gem for interacting with the API of lingq.com. It's a language learning website, and it's pretty useful, but I want to be able to work on my flashcards offline. This gem is being written to be included in a desktop client (and maybe eventually a mobile client), but will certainly still be useful as a standalone api wrapper for other projects that want to interact with Lingq.com}
|
14
14
|
s.email = %q{ethan.vizitei@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
data/test/test_client.rb
CHANGED
@@ -89,9 +89,28 @@ class TestClient < Test::Unit::TestCase
|
|
89
89
|
assert_equal 5,@words.size
|
90
90
|
end
|
91
91
|
end
|
92
|
+
|
93
|
+
context "prebuilt client for updating a word" do
|
94
|
+
setup do
|
95
|
+
stub_regex_api(/ru\/lingqs/,"",:put)
|
96
|
+
@word = Lingq::Word.new(@client,"ru",{ "status"=> 0, "fragment"=> "fragment", "term"=> "Его", "id"=> 4259928, "hint"=> "him" })
|
97
|
+
@word.status = 1
|
98
|
+
@client.expects(:system_call).with("curl -X PUT -d 'id=4259928;status=1;hint=him;fragment=fragment' http://www.lingq.com/api_v2/ru/lingqs/?apikey=api-key")
|
99
|
+
@client.update_word!(@word)
|
100
|
+
end
|
101
|
+
|
102
|
+
should "not bomb" do
|
103
|
+
assert true
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
|
109
|
+
def stub_api(path,body,method = :any)
|
110
|
+
stub_request(method, "http://lingq.com/api_v2/#{path}/?apikey=api-key").to_return(:body => body, :status => 200, :headers => { 'Content-Type' => "application/json; charset=utf-8" } )
|
92
111
|
end
|
93
112
|
|
94
|
-
def
|
95
|
-
stub_request(
|
113
|
+
def stub_regex_api(regex,body,method = :any)
|
114
|
+
stub_request(method, regex).to_return(:body => body, :status => 200, :headers => { 'Content-Type' => "application/json; charset=utf-8" } )
|
96
115
|
end
|
97
116
|
end
|
data/test/test_lesson.rb
CHANGED
@@ -40,7 +40,7 @@ class TestLesson < Test::Unit::TestCase
|
|
40
40
|
|
41
41
|
context "loading words" do
|
42
42
|
setup do
|
43
|
-
@client.expects(:words_for_lesson).with(@lesson).returns([Lingq::Word.new("ru",{})])
|
43
|
+
@client.expects(:words_for_lesson).with(@lesson).returns([Lingq::Word.new(@client,"ru",{})])
|
44
44
|
@words = @lesson.words
|
45
45
|
end
|
46
46
|
|
data/test/test_word.rb
CHANGED
@@ -3,7 +3,9 @@ require 'helper'
|
|
3
3
|
class TestWord < Test::Unit::TestCase
|
4
4
|
context "word" do
|
5
5
|
setup do
|
6
|
-
|
6
|
+
Lingq::Client.any_instance.stubs(:load_languages!)
|
7
|
+
@client = Lingq::Client.new("apikey")
|
8
|
+
@word = Lingq::Word.new(@client,"ru",{ "status"=> 0,
|
7
9
|
"fragment"=> "вперед и вы найдете его .",
|
8
10
|
"term"=> "Его",
|
9
11
|
"id"=> 4259928,
|
@@ -33,5 +35,11 @@ class TestWord < Test::Unit::TestCase
|
|
33
35
|
should "cache language" do
|
34
36
|
assert_equal "ru",@word.language
|
35
37
|
end
|
38
|
+
|
39
|
+
should "be able to update status with builtin client" do
|
40
|
+
@client.expects(:update_word!).with(@word)
|
41
|
+
@word.increment_status!
|
42
|
+
assert_equal 1,@word.status
|
43
|
+
end
|
36
44
|
end
|
37
45
|
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: 19
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 3
|
9
|
+
- 0
|
10
|
+
version: 0.3.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Ethan Vizitei
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-06-
|
18
|
+
date: 2010-06-21 00:00:00 -05:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|