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 CHANGED
@@ -5,6 +5,7 @@ gem "httparty"
5
5
 
6
6
  group(:test){
7
7
  gem "test-unit"
8
+ gem "mocha"
8
9
  gem "thoughtbot-shoulda"
9
10
  gem "webmock"
10
11
  }
@@ -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 and load lingqs by lesson.
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
@@ -43,7 +43,8 @@ rescue LoadError
43
43
  end
44
44
  end
45
45
 
46
- task :test => :check_dependencies
46
+ #dont need this, we're using bundler
47
+ #task :test => :check_dependencies
47
48
 
48
49
  task :default => :test
49
50
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.4
1
+ 0.2.0
@@ -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(@target_language,hash)}
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})})
@@ -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
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{lingq}
8
- s.version = "0.1.4"
8
+ s.version = "0.2.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"]
@@ -4,6 +4,7 @@ Bundler.setup(:default,:test)
4
4
  require 'test/unit'
5
5
  require 'shoulda'
6
6
  require 'webmock/test_unit'
7
+ require 'mocha'
7
8
 
8
9
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
9
10
  $LOAD_PATH.unshift(File.dirname(__FILE__))
@@ -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)
@@ -3,7 +3,9 @@ require 'helper'
3
3
  class TestLesson < Test::Unit::TestCase
4
4
  context "lesson" do
5
5
  setup do
6
- @lesson = Lingq::Lesson.new("ru",{"audio_url"=>"http://m.lingq.com/media/_28/resources/contents/audio/2007/06/21/eating-out-3.mp3",
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: 19
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 1
9
- - 4
10
- version: 0.1.4
8
+ - 2
9
+ - 0
10
+ version: 0.2.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Ethan Vizitei