lingq 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of lingq might be problematic. Click here for more details.

@@ -0,0 +1,2 @@
1
+ ---
2
+ BUNDLE_WITHOUT: ""
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ source "http://rubygems.org"
2
+ source "http://gems.github.com/"
3
+
4
+ gem "httparty"
5
+
6
+ group(:test){
7
+ gem "test-unit"
8
+ gem "thoughtbot-shoulda"
9
+ gem "webmock"
10
+ }
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Ethan Vizitei
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,37 @@
1
+ = lingq
2
+
3
+ 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
4
+
5
+ == Getting Started
6
+
7
+ You need the API key for your account. Usage is as follows:
8
+
9
+ require 'lingq'
10
+ client = Lingq::Client.new("apikey")
11
+
12
+ #must be one of the languages available for this user, check client.languages array
13
+ client.change_language!("ru")
14
+
15
+ #load all lessons for the user
16
+ lessons = client.lessons
17
+
18
+ #load all lingq flashcards for the user
19
+ words = client.words
20
+
21
+ == Current Status
22
+
23
+ Right now just data pulling is done. Will add soon the ability to update lingqs and load lingqs by lesson.
24
+
25
+ == Note on Patches/Pull Requests
26
+
27
+ * Fork the project.
28
+ * Make your feature addition or bug fix.
29
+ * Add tests for it. This is important so I don't break it in a
30
+ future version unintentionally.
31
+ * Commit, do not mess with rakefile, version, or history.
32
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
33
+ * Send me a pull request. Bonus points for topic branches.
34
+
35
+ == Copyright
36
+
37
+ Copyright (c) 2010 Ethan Vizitei. See LICENSE for details.
@@ -0,0 +1,53 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "lingq"
8
+ gem.summary = %Q{API Wrapper for Lingq.com}
9
+ gem.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}
10
+ gem.email = "ethan.vizitei@gmail.com"
11
+ gem.homepage = "http://github.com/evizitei/lingq"
12
+ gem.authors = ["Ethan Vizitei"]
13
+ gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
14
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
15
+ end
16
+ Jeweler::GemcutterTasks.new
17
+ rescue LoadError
18
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
19
+ end
20
+
21
+ require 'rake/testtask'
22
+ Rake::TestTask.new(:test) do |test|
23
+ test.libs << 'lib' << 'test'
24
+ test.pattern = 'test/**/test_*.rb'
25
+ test.verbose = true
26
+ end
27
+
28
+ begin
29
+ require 'rcov/rcovtask'
30
+ Rcov::RcovTask.new do |test|
31
+ test.libs << 'test'
32
+ test.pattern = 'test/**/test_*.rb'
33
+ test.verbose = true
34
+ end
35
+ rescue LoadError
36
+ task :rcov do
37
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
38
+ end
39
+ end
40
+
41
+ task :test => :check_dependencies
42
+
43
+ task :default => :test
44
+
45
+ require 'rake/rdoctask'
46
+ Rake::RDocTask.new do |rdoc|
47
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
48
+
49
+ rdoc.rdoc_dir = 'rdoc'
50
+ rdoc.title = "lingq #{version}"
51
+ rdoc.rdoc_files.include('README*')
52
+ rdoc.rdoc_files.include('lib/**/*.rb')
53
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.1
@@ -0,0 +1,5 @@
1
+ Bundler.setup(:default)
2
+
3
+ require 'lingq/lesson'
4
+ require 'lingq/word'
5
+ require 'lingq/client'
@@ -0,0 +1,46 @@
1
+ require 'httparty'
2
+
3
+ module Lingq
4
+ class Client
5
+ include HTTParty
6
+ base_uri 'lingq.com/api_v2'
7
+
8
+ attr_reader :target_language
9
+ attr_reader :languages
10
+
11
+ def initialize(api_key)
12
+ @apikey = api_key
13
+ load_languages!
14
+ end
15
+
16
+ def learning_language?(language_code)
17
+ @languages.index(language_code)
18
+ end
19
+
20
+ def load_languages!
21
+ @languages = get_with_key('/languages/').parsed_response
22
+ @target_language = @languages.first
23
+ end
24
+
25
+ def change_language!(language_code)
26
+ @target_language = language_code if learning_language?(language_code)
27
+ end
28
+
29
+ def lessons
30
+ get_with_language("lessons/").map{|hash| Lingq::Lesson.new(@target_language,hash)}
31
+ end
32
+
33
+ def words
34
+ get_with_language("lingqs/").map{|hash| Lingq::Word.new(@target_language,hash)}
35
+ end
36
+
37
+ private
38
+ def get_with_key(path,params={})
39
+ self.class.get(path,{:query=>params.merge({:apikey=>@apikey})})
40
+ end
41
+
42
+ def get_with_language(path,params={})
43
+ get_with_key("/#{@target_language}/#{path}",params)
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,13 @@
1
+ module Lingq
2
+ class Lesson
3
+ attr_reader :audio_url,:image_url,:id,:cards_count,:title,:language
4
+ def initialize(language_code,json)
5
+ @language = language_code
6
+ @audio_url = json["audio_url"]
7
+ @image_url = json["image_url"]
8
+ @id = json["id"]
9
+ @cards_count = json["cards_count"]
10
+ @title = json["title"]
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ module Lingq
2
+ class Word
3
+ attr_reader :hint,:term,:id,:fragment,:status,:language
4
+ def initialize(language_code,json)
5
+ @language = language_code
6
+ @hint = json["hint"]
7
+ @term = json["term"]
8
+ @id = json["id"]
9
+ @fragment = json["fragment"]
10
+ @status = json["status"]
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,63 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{lingq}
8
+ s.version = "0.1.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Ethan Vizitei"]
12
+ s.date = %q{2010-06-19}
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
+ s.email = %q{ethan.vizitei@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".bundle/config",
21
+ ".document",
22
+ ".gitignore",
23
+ "Gemfile",
24
+ "LICENSE",
25
+ "README.rdoc",
26
+ "Rakefile",
27
+ "VERSION",
28
+ "lib/lingq.rb",
29
+ "lib/lingq/client.rb",
30
+ "lib/lingq/lesson.rb",
31
+ "lib/lingq/word.rb",
32
+ "lingq.gemspec",
33
+ "test/helper.rb",
34
+ "test/test_client.rb",
35
+ "test/test_lesson.rb",
36
+ "test/test_word.rb"
37
+ ]
38
+ s.homepage = %q{http://github.com/evizitei/lingq}
39
+ s.rdoc_options = ["--charset=UTF-8"]
40
+ s.require_paths = ["lib"]
41
+ s.rubygems_version = %q{1.3.7}
42
+ s.summary = %q{API Wrapper for Lingq.com}
43
+ s.test_files = [
44
+ "test/helper.rb",
45
+ "test/test_client.rb",
46
+ "test/test_lesson.rb",
47
+ "test/test_word.rb"
48
+ ]
49
+
50
+ if s.respond_to? :specification_version then
51
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
52
+ s.specification_version = 3
53
+
54
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
55
+ s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
56
+ else
57
+ s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
58
+ end
59
+ else
60
+ s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
61
+ end
62
+ end
63
+
@@ -0,0 +1,14 @@
1
+ require 'rubygems'
2
+ require "bundler"
3
+ Bundler.setup(:default,:test)
4
+ require 'test/unit'
5
+ require 'shoulda'
6
+ require 'webmock/test_unit'
7
+
8
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
9
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
10
+ require 'lingq'
11
+
12
+ class Test::Unit::TestCase
13
+ include WebMock
14
+ end
@@ -0,0 +1,76 @@
1
+ require 'helper'
2
+
3
+ class TestClient < Test::Unit::TestCase
4
+ context "" do
5
+ setup do
6
+ language_body = %Q{["ru","fr"]}
7
+ stub_api("languages",language_body)
8
+ @client = Lingq::Client.new("api-key")
9
+ end
10
+
11
+ context "new client" do
12
+
13
+ should "cache languages being learned at creation" do
14
+ assert_equal ["ru","fr"],@client.languages
15
+ assert @client.learning_language?("ru")
16
+ assert @client.learning_language?("fr")
17
+ end
18
+
19
+ should "exclude languages not being learned" do
20
+ assert !@client.learning_language?("en")
21
+ end
22
+
23
+ should "pick first in list as current language" do
24
+ assert_equal "ru",@client.target_language
25
+ end
26
+
27
+ should "be able to change to another valid language" do
28
+ @client.change_language!("fr")
29
+ assert_equal "fr",@client.target_language
30
+ end
31
+
32
+ end
33
+
34
+ context "prebuilt client for lesson call" do
35
+ setup do
36
+ body = %Q{[ { "audio_url": "http://m.lingq.com/media/_28/resources/contents/audio/2007/06/21/eating-out-3.mp3", "image_url": "http://m.lingq.com/media/_28/resources/contents/images/2008/08/26/Eating_Out_______.jpg", "id": 21730, "cards_count": 31, "title": "Part 3" },
37
+ { "audio_url": "http://m.lingq.com/media/_28/resources/contents/audio/2007/06/21/eating-out-2.mp3", "image_url": "http://m.lingq.com/media/_28/resources/contents/images/2008/08/26/Eating_Out________.jpg", "id": 21729, "cards_count": 5, "title": "Part 2" },
38
+ { "audio_url": "http://m.lingq.com/media/_28/resources/contents/audio/2007/06/21/eating-out-1.mp3", "image_url": "http://m.lingq.com/media/_28/resources/contents/images/2008/07/04/restaurant-120.jpg", "id": 21727, "cards_count": 19, "title": "Part 1" } ]}
39
+ stub_api("ru/lessons",body)
40
+ @lessons = @client.lessons
41
+ end
42
+
43
+ should "load an array of lessons" do
44
+ assert_equal Lingq::Lesson,@lessons.first.class
45
+ end
46
+
47
+ should "load one lesson for each json hash" do
48
+ assert_equal 3,@lessons.size
49
+ end
50
+ end
51
+
52
+ context "prebuilt client for words call" do
53
+ setup do
54
+ body = %Q{[ { "status": 0, "fragment": "вперед и вы найдете его .", "term": "Его", "id": 4259928, "hint": "him" },
55
+ { "status": 0, "fragment": "Официант, принесите нам счет , пожалуйста", "term": "Счет", "id": 4259923, "hint": "check " },
56
+ { "status": 0, "fragment": "Легко сказать да трудно сделать.", "term": "трудно", "id": 4259919, "hint": "difficult" },
57
+ { "status": 0, "fragment": "Легко сказать да трудно сделать.", "term": "Легко", "id": 4259916, "hint": "easily" },
58
+ { "status": 0, "fragment": "стараться делать это с радостью .", "term": "радостью", "id": 4259915, "hint": "joy" }]}
59
+ stub_api("ru/lingqs",body)
60
+ @words = @client.words
61
+ end
62
+
63
+ should "load an array of lessons" do
64
+ assert_equal Lingq::Word,@words.first.class
65
+ end
66
+
67
+ should "load one lesson for each json hash" do
68
+ assert_equal 5,@words.size
69
+ end
70
+ end
71
+ end
72
+
73
+ def stub_api(path,body)
74
+ stub_request(:any, "http://lingq.com/api_v2/#{path}/?apikey=api-key").to_return(:body => body, :status => 200, :headers => { 'Content-Type' => "application/json; charset=utf-8" } )
75
+ end
76
+ end
@@ -0,0 +1,35 @@
1
+ require 'helper'
2
+
3
+ class TestLesson < Test::Unit::TestCase
4
+ context "lesson" do
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",
7
+ "image_url"=>"http://m.lingq.com/media/_28/resources/contents/images/2008/08/26/Eating_Out_______.jpg",
8
+ "id"=> 21730, "cards_count"=> 31, "title"=> "Part 3" })
9
+ end
10
+
11
+ should "cache audio url" do
12
+ assert @lesson.audio_url =~ /eating-out-3\.mp3/
13
+ end
14
+
15
+ should "cache image url" do
16
+ assert @lesson.image_url =~ /Eating_Out_______\.jpg/
17
+ end
18
+
19
+ should "cache id" do
20
+ assert_equal 21730,@lesson.id
21
+ end
22
+
23
+ should "cache card count" do
24
+ assert_equal 31,@lesson.cards_count
25
+ end
26
+
27
+ should "cache title" do
28
+ assert_equal "Part 3",@lesson.title
29
+ end
30
+
31
+ should "cache language" do
32
+ assert_equal "ru",@lesson.language
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,37 @@
1
+ require 'helper'
2
+
3
+ class TestWord < Test::Unit::TestCase
4
+ context "word" do
5
+ setup do
6
+ @word = Lingq::Word.new("ru",{ "status"=> 0,
7
+ "fragment"=> "вперед и вы найдете его .",
8
+ "term"=> "Его",
9
+ "id"=> 4259928,
10
+ "hint"=> "him" })
11
+ end
12
+
13
+ should "cache status" do
14
+ assert_equal 0,@word.status
15
+ end
16
+
17
+ should "cache fragment" do
18
+ assert_equal "вперед и вы найдете его .",@word.fragment
19
+ end
20
+
21
+ should "cache id" do
22
+ assert_equal 4259928,@word.id
23
+ end
24
+
25
+ should "cache term" do
26
+ assert_equal "Его",@word.term
27
+ end
28
+
29
+ should "cache hint" do
30
+ assert_equal "him",@word.hint
31
+ end
32
+
33
+ should "cache language" do
34
+ assert_equal "ru",@word.language
35
+ end
36
+ end
37
+ end
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lingq
3
+ version: !ruby/object:Gem::Version
4
+ hash: 25
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 1
10
+ version: 0.1.1
11
+ platform: ruby
12
+ authors:
13
+ - Ethan Vizitei
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-06-19 00:00:00 -05:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: thoughtbot-shoulda
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
33
+ type: :development
34
+ version_requirements: *id001
35
+ description: 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
36
+ email: ethan.vizitei@gmail.com
37
+ executables: []
38
+
39
+ extensions: []
40
+
41
+ extra_rdoc_files:
42
+ - LICENSE
43
+ - README.rdoc
44
+ files:
45
+ - .bundle/config
46
+ - .document
47
+ - .gitignore
48
+ - Gemfile
49
+ - LICENSE
50
+ - README.rdoc
51
+ - Rakefile
52
+ - VERSION
53
+ - lib/lingq.rb
54
+ - lib/lingq/client.rb
55
+ - lib/lingq/lesson.rb
56
+ - lib/lingq/word.rb
57
+ - lingq.gemspec
58
+ - test/helper.rb
59
+ - test/test_client.rb
60
+ - test/test_lesson.rb
61
+ - test/test_word.rb
62
+ has_rdoc: true
63
+ homepage: http://github.com/evizitei/lingq
64
+ licenses: []
65
+
66
+ post_install_message:
67
+ rdoc_options:
68
+ - --charset=UTF-8
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ hash: 3
77
+ segments:
78
+ - 0
79
+ version: "0"
80
+ required_rubygems_version: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ hash: 3
86
+ segments:
87
+ - 0
88
+ version: "0"
89
+ requirements: []
90
+
91
+ rubyforge_project:
92
+ rubygems_version: 1.3.7
93
+ signing_key:
94
+ specification_version: 3
95
+ summary: API Wrapper for Lingq.com
96
+ test_files:
97
+ - test/helper.rb
98
+ - test/test_client.rb
99
+ - test/test_lesson.rb
100
+ - test/test_word.rb