nov-iknow 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +8 -0
- data/Rakefile +1 -1
- data/examples/pure_ruby.rb +20 -14
- data/lib/ext/hash.rb +13 -0
- data/lib/iknow/core/version.rb +1 -1
- data/lib/iknow/model/base.rb +13 -5
- data/lib/iknow/model/item.rb +19 -13
- data/lib/iknow/model/list.rb +62 -7
- data/lib/iknow/model/sentence.rb +14 -4
- data/lib/iknow/model/user.rb +38 -23
- data/lib/iknow/rest_client/item.rb +1 -0
- data/lib/iknow/rest_client/list.rb +1 -0
- data/lib/iknow/rest_client/sentence.rb +1 -0
- metadata +3 -3
data/ChangeLog
CHANGED
data/Rakefile
CHANGED
@@ -62,7 +62,7 @@ spec = Gem::Specification.new do |s|
|
|
62
62
|
|
63
63
|
s.add_dependency('rails', '>=2.1.0')
|
64
64
|
s.add_dependency('json')
|
65
|
-
s.add_dependency('oauth', '
|
65
|
+
s.add_dependency('oauth', '>=0.2.4')
|
66
66
|
s.required_ruby_version = '>= 1.8.6'
|
67
67
|
|
68
68
|
s.files = %w(README ChangeLog Rakefile) +
|
data/examples/pure_ruby.rb
CHANGED
@@ -2,9 +2,9 @@ require 'rubygems'
|
|
2
2
|
require 'iknow'
|
3
3
|
|
4
4
|
Iknow::Config.init do |conf|
|
5
|
-
conf.api_key = ''
|
6
|
-
conf.oauth_consumer_key = ''
|
7
|
-
conf.oauth_consumer_secret = ''
|
5
|
+
conf.api_key = 'SET_YOUR_API_KEY'
|
6
|
+
conf.oauth_consumer_key = 'SET_YOUR_OAUTH_CONSUMER_KEY'
|
7
|
+
conf.oauth_consumer_secret = 'SET_YOUR_OAUTH_CONSUMER_SECRET'
|
8
8
|
end
|
9
9
|
|
10
10
|
please_get_api_key =<<EOS
|
@@ -24,25 +24,31 @@ if Iknow::Config.api_key == ''# or
|
|
24
24
|
end
|
25
25
|
|
26
26
|
## User API
|
27
|
-
@user = Iknow::User.find('
|
28
|
-
@user.items
|
27
|
+
@user = Iknow::User.find('kirk')
|
28
|
+
@user.items(:include_sentences => true)
|
29
29
|
@user.lists
|
30
30
|
@user.friends
|
31
31
|
@user.study.results
|
32
|
-
@
|
32
|
+
@user.study.total_results
|
33
|
+
@matched_users = Iknow::User.matching('matake')
|
33
34
|
|
34
|
-
|
35
|
+
## List API
|
35
36
|
@recent_lists = Iknow::List.recent
|
36
|
-
@
|
37
|
-
@
|
38
|
-
@
|
37
|
+
@list = Iknow::List.find(31509, :include_sentences => true, :include_items => true)
|
38
|
+
@list.items
|
39
|
+
@list.sentences
|
40
|
+
@matched_lists = Iknow::List.matching("イタリア語であいさつ")
|
39
41
|
|
40
|
-
#
|
41
|
-
|
42
|
-
|
42
|
+
# puts Iknow::List.find(31509, :include_sentences => true, :include_items => true).inspect
|
43
|
+
|
44
|
+
## Item API
|
45
|
+
@recent_items = Iknow::Item.recent(:include_sentences => true)
|
46
|
+
@item = Iknow::Item.find(437525)
|
47
|
+
@matched_items = Iknow::Item.matching('record', :include_sentences => true)
|
43
48
|
@items = Iknow::Item.extract("sometimes, often, electrical")
|
44
49
|
@items.first.sentences
|
45
50
|
|
46
51
|
## Sentence API
|
47
52
|
@recent_sentences = Iknow::Sentence.recent
|
48
|
-
@
|
53
|
+
@sentence = Iknow::Sentence.find(312271)
|
54
|
+
@matched_sentences = Iknow::Sentence.matching('record')
|
data/lib/ext/hash.rb
CHANGED
@@ -7,4 +7,17 @@ class Hash
|
|
7
7
|
end
|
8
8
|
result.chop
|
9
9
|
end
|
10
|
+
def symbolize_keys!
|
11
|
+
self.each do |key, value|
|
12
|
+
unless self.delete(key.to_s).nil?
|
13
|
+
if value.is_a?(Hash)
|
14
|
+
value.symbolize_keys!
|
15
|
+
elsif value.is_a?(Array)
|
16
|
+
value.map!{ |v| v.symbolize_keys! if v.is_a?(Hash) }
|
17
|
+
end
|
18
|
+
self[key.to_sym] = value
|
19
|
+
end
|
20
|
+
end
|
21
|
+
self
|
22
|
+
end
|
10
23
|
end
|
data/lib/iknow/core/version.rb
CHANGED
data/lib/iknow/model/base.rb
CHANGED
@@ -5,13 +5,21 @@ class Iknow::Base
|
|
5
5
|
def attributes; self.class.attributes end
|
6
6
|
|
7
7
|
def self.deserialize(response, params = {})
|
8
|
-
return nil if response.
|
8
|
+
return nil if response.nil? or
|
9
|
+
(response.is_a?(Hash) and
|
9
10
|
!response['error'].nil? and
|
10
|
-
response['error']['code'].to_i == 404
|
11
|
+
response['error']['code'].to_i == 404)
|
11
12
|
|
12
|
-
klass = params[:as]
|
13
|
-
response.is_a?(Array)
|
14
|
-
|
13
|
+
klass = params[:as] ? params[:as] : self
|
14
|
+
if response.is_a?(Array)
|
15
|
+
response.inject([]) { |results, hash|
|
16
|
+
hash.symbolize_keys!
|
17
|
+
results << klass.new(hash)
|
18
|
+
}
|
19
|
+
else
|
20
|
+
response.symbolize_keys!
|
21
|
+
klass.new(response)
|
22
|
+
end
|
15
23
|
end
|
16
24
|
|
17
25
|
def deserialize(response, params = {})
|
data/lib/iknow/model/item.rb
CHANGED
@@ -3,24 +3,27 @@ class Iknow::Item < Iknow::Base
|
|
3
3
|
attr_reader *ATTRIBUTES
|
4
4
|
|
5
5
|
class Response
|
6
|
-
ATTRIBUTES = [:text]
|
6
|
+
ATTRIBUTES = [:text, :type, :language]
|
7
7
|
attr_reader *ATTRIBUTES
|
8
8
|
|
9
9
|
def initialize(params = {})
|
10
|
-
@text
|
10
|
+
@text = params[:text]
|
11
|
+
@type = params[:type]
|
12
|
+
@language = params[:language]
|
11
13
|
end
|
12
14
|
end
|
13
15
|
|
14
16
|
class Cue
|
15
|
-
ATTRIBUTES = [:sound, :part_of_speech, :
|
17
|
+
ATTRIBUTES = [:text, :sound, :part_of_speech, :language]
|
16
18
|
NOT_WRITABLE_ATTRIBUTES = [:text]
|
17
19
|
attr_accessor *(ATTRIBUTES - NOT_WRITABLE_ATTRIBUTES)
|
18
20
|
attr_reader *NOT_WRITABLE_ATTRIBUTES
|
19
21
|
|
20
22
|
def initialize(params = {})
|
21
|
-
@text
|
22
|
-
@sound
|
23
|
-
@
|
23
|
+
@text = params[:text]
|
24
|
+
@sound = params[:sound]
|
25
|
+
@part_of_speech = params[:part_of_speech]
|
26
|
+
@language = params[:language]
|
24
27
|
end
|
25
28
|
end
|
26
29
|
|
@@ -29,6 +32,12 @@ class Iknow::Item < Iknow::Base
|
|
29
32
|
self.deserialize(response) || []
|
30
33
|
end
|
31
34
|
|
35
|
+
def self.find(item_id, params = {})
|
36
|
+
params[:id] = item_id
|
37
|
+
response = Iknow::RestClient::Item.find(params)
|
38
|
+
self.deserialize(response)
|
39
|
+
end
|
40
|
+
|
32
41
|
def self.matching(keyword, params = {})
|
33
42
|
params[:keyword] = keyword
|
34
43
|
response = Iknow::RestClient::Item.matching(params)
|
@@ -42,13 +51,10 @@ class Iknow::Item < Iknow::Base
|
|
42
51
|
end
|
43
52
|
|
44
53
|
def initialize(params = {})
|
45
|
-
@id
|
46
|
-
@
|
47
|
-
params[
|
48
|
-
|
49
|
-
end
|
50
|
-
@response = params['response'] ? Iknow::Item::Response.new(params['response']) : nil
|
51
|
-
@cue = Iknow::Item::Cue.new(params['cue'])
|
54
|
+
@id = params[:id].to_i
|
55
|
+
@cue = self.deserialize(params[:cue], :as => Iknow::Item::Cue)
|
56
|
+
@responses = self.deserialize(params[:responses], :as => Iknow::Item::Response)
|
57
|
+
@sentences = self.deserialize(params[:sentences], :as => Iknow::Sentence)
|
52
58
|
end
|
53
59
|
|
54
60
|
end
|
data/lib/iknow/model/list.rb
CHANGED
@@ -1,16 +1,50 @@
|
|
1
|
+
# "iknow": true,
|
2
|
+
# "description": "hogehoge",
|
3
|
+
# "translation_language": "ja",
|
4
|
+
# "dictation": true,
|
5
|
+
# "icon": "http://www.iknow.co.jp/assets/courses/m4.jpg",
|
6
|
+
# "brainspeed": true,
|
7
|
+
# "language": "en",
|
8
|
+
# "item_count": 117,
|
9
|
+
# "author_id": "Cerego",
|
10
|
+
# "user_count": 45056,
|
11
|
+
# "author": "Team iKnow!",
|
12
|
+
# "title": "\u65c5\u306b\u51fa\u3088\u3046\uff01\uff08\u51fa\u56fd\uff06\u8857\u3092\u6b69\u304f\uff09",
|
13
|
+
# "id": 708,
|
14
|
+
# "author_url": "http://www.iknow.co.jp/user/Cerego"
|
15
|
+
|
1
16
|
class Iknow::List < Iknow::Base
|
2
|
-
ATTRIBUTES = [:list_id, :title, :description, :
|
17
|
+
ATTRIBUTES = [:list_id, :title, :description, :icon, :item_count, :user_count, :iknow, :dictation, :brainspeed,
|
3
18
|
:language, :translation_language, :list_type, :transcript, :embed,
|
4
|
-
:tags, :media_entry, :author, :author_url, :attribution_license_id
|
5
|
-
|
19
|
+
:tags, :media_entry, :author, :author_id, :author_url, :attribution_license_id,
|
20
|
+
:items, :sentences]
|
21
|
+
NOT_WRITABLE_ATTRIBUTES = [:list_id, :icon, :item_count, :user_count, :iknow, :dictation, :brainspeed]
|
6
22
|
attr_accessor *(ATTRIBUTES - NOT_WRITABLE_ATTRIBUTES)
|
7
23
|
attr_reader *NOT_WRITABLE_ATTRIBUTES
|
8
24
|
|
25
|
+
class Application
|
26
|
+
attr_reader :application, :list_id, :lang
|
27
|
+
def initialize(params = {})
|
28
|
+
@application = params[:application]
|
29
|
+
@list_id = params[:list_id]
|
30
|
+
@lang = params[:lang]
|
31
|
+
end
|
32
|
+
def url
|
33
|
+
"http://www.iknow.co.jp/flash?swf=#{self.name}&course_id=#{self.list_id}&lang=#{self.lang}"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
9
37
|
def self.recent(params = {})
|
10
38
|
response = Iknow::RestClient::List.recent(params)
|
11
39
|
self.deserialize(response) || []
|
12
40
|
end
|
13
41
|
|
42
|
+
def self.find(list_id, params = {})
|
43
|
+
params[:id] = list_id
|
44
|
+
response = Iknow::RestClient::List.find(params)
|
45
|
+
self.deserialize(response)
|
46
|
+
end
|
47
|
+
|
14
48
|
def self.matching(keyword, params = {})
|
15
49
|
params[:keyword] = keyword
|
16
50
|
response = Iknow::RestClient::List.matching(params)
|
@@ -23,10 +57,31 @@ class Iknow::List < Iknow::Base
|
|
23
57
|
end
|
24
58
|
|
25
59
|
def initialize(params = {})
|
26
|
-
@list_id = params[
|
27
|
-
@title = params[:title]
|
28
|
-
@description = params[:description]
|
29
|
-
@
|
60
|
+
@list_id = (params[:id].to_i rescue nil)
|
61
|
+
@title = params[:title]
|
62
|
+
@description = params[:description]
|
63
|
+
@icon = params[:icon]
|
64
|
+
@item_count = (params[:item_count].to_i rescue nil)
|
65
|
+
@user_count = (params[:user_count].to_i rescue nil)
|
66
|
+
@language = params[:language]
|
67
|
+
@translation_language = params[:translation_language]
|
68
|
+
if @list_id and @translation_language
|
69
|
+
common_settings = {:list_id => @list_id, :lang => @translation_language}
|
70
|
+
@iknow = Application.new(common_settings.merge(:application => 'iknow')) if params[:iknow]
|
71
|
+
@dictation = Application.new(common_settings.merge(:application => 'dictation')) if params[:dictation]
|
72
|
+
@brainspeed = Application.new(common_settings.merge(:application => 'brainspeed')) if params[:brainspeed]
|
73
|
+
end
|
74
|
+
@author = params[:author] # display_name or username
|
75
|
+
@author_id = params[:author_id] # username
|
76
|
+
@author_url = params[:author_url]
|
77
|
+
@list_type = params[:list_type] # for list creation
|
78
|
+
@transcript = params[:transcript] # for list creation
|
79
|
+
@embed = params[:embed] # for list creation
|
80
|
+
@tags = params[:tags] # for list creation
|
81
|
+
@media_entry = params[:media_entry] # for list creation
|
82
|
+
@attribution_license_id = params[:attribution_license_id] # for list creation
|
83
|
+
@items = self.deserialize(params[:items], :as => Iknow::Item)
|
84
|
+
@sentences = self.deserialize(params[:sentences], :as => Iknow::Sentence)
|
30
85
|
end
|
31
86
|
|
32
87
|
def items(params = {})
|
data/lib/iknow/model/sentence.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
class Iknow::Sentence < Iknow::Base
|
2
|
-
ATTRIBUTES = [:sound, :image, :text]
|
2
|
+
ATTRIBUTES = [:sound, :image, :text, :language, :id, :transliterations, :translations]
|
3
3
|
WRITABLE_ATTRIBUTES = [:sound, :image]
|
4
4
|
attr_accessor *WRITABLE_ATTRIBUTES
|
5
5
|
attr_reader *(ATTRIBUTES - WRITABLE_ATTRIBUTES)
|
@@ -9,6 +9,12 @@ class Iknow::Sentence < Iknow::Base
|
|
9
9
|
self.deserialize(response) || []
|
10
10
|
end
|
11
11
|
|
12
|
+
def self.find(sentence_id, params = {})
|
13
|
+
params[:id] = sentence_id
|
14
|
+
response = Iknow::RestClient::Sentence.find(params)
|
15
|
+
self.deserialize(response)
|
16
|
+
end
|
17
|
+
|
12
18
|
def self.matching(keyword, params = {})
|
13
19
|
params[:keyword] = keyword
|
14
20
|
response = Iknow::RestClient::Sentence.matching(params)
|
@@ -16,9 +22,13 @@ class Iknow::Sentence < Iknow::Base
|
|
16
22
|
end
|
17
23
|
|
18
24
|
def initialize(params = {})
|
19
|
-
@
|
20
|
-
@
|
21
|
-
@
|
25
|
+
@id = params[:id]
|
26
|
+
@sound = params[:sound]
|
27
|
+
@image = params[:image]
|
28
|
+
@text = params[:text]
|
29
|
+
@language = params[:language]
|
30
|
+
@transliterations = params[:transliterations]
|
31
|
+
@translations = self.deserialize(params[:translations], :as => Iknow::Sentence)
|
22
32
|
end
|
23
33
|
|
24
34
|
end
|
data/lib/iknow/model/user.rb
CHANGED
@@ -7,19 +7,19 @@ class Iknow::User < Iknow::Base
|
|
7
7
|
attr_reader *ATTRIBUTES
|
8
8
|
|
9
9
|
def initialize(params = {})
|
10
|
-
@name = params[
|
11
|
-
@gender = params[
|
12
|
-
@birthday = (Date.parse(params[
|
13
|
-
@description = params[
|
14
|
-
@blog_url = params[
|
15
|
-
@profile_url = params[
|
16
|
-
@foaf_url = params[
|
17
|
-
@icon_url = params[
|
10
|
+
@name = params[:name]
|
11
|
+
@gender = params[:gender]
|
12
|
+
@birthday = (Date.parse(params[:birthday]) rescue nil)
|
13
|
+
@description = params[:description]
|
14
|
+
@blog_url = params[:blog_url]
|
15
|
+
@profile_url = params[:profile_url]
|
16
|
+
@foaf_url = params[:foaf_url]
|
17
|
+
@icon_url = params[:icon_url]
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
21
|
class Study < Iknow::Base
|
22
|
-
ATTRIBUTES = [:today, :results]
|
22
|
+
ATTRIBUTES = [:today, :results, :total_summary]
|
23
23
|
attr_reader *ATTRIBUTES
|
24
24
|
|
25
25
|
class Result < Iknow::Base
|
@@ -27,28 +27,43 @@ class Iknow::User < Iknow::Base
|
|
27
27
|
attr_reader *ATTRIBUTES
|
28
28
|
|
29
29
|
def initialize(params = {})
|
30
|
-
@timestamp = (params[
|
31
|
-
@seconds = (params[
|
30
|
+
@timestamp = (params[:timestamp].to_i rescue nil)
|
31
|
+
@seconds = (params[:seconds].to_i rescue nil)
|
32
32
|
@totals = {
|
33
|
-
:seconds => (params[
|
34
|
-
:seen => (params[
|
35
|
-
:completed => (params[
|
33
|
+
:seconds => (params[:totals][:seconds].to_i rescue nil),
|
34
|
+
:seen => (params[:totals][:seen].to_i rescue nil),
|
35
|
+
:completed => (params[:totals][:completed].to_i rescue nil)
|
36
36
|
}
|
37
|
-
@seen = (params[
|
38
|
-
@completed = (params[
|
39
|
-
@date = (Date.parse(params[
|
37
|
+
@seen = (params[:seen].to_i rescue nil)
|
38
|
+
@completed = (params[:completed].to_i rescue nil)
|
39
|
+
@date = (Date.parse(params[:date]) rescue nil)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
class TotalSummary < Iknow::Base
|
44
|
+
ATTRIBUTES = [:studied, :completed, :performance, :best_speed, :best_score]
|
45
|
+
attr_reader *ATTRIBUTES
|
46
|
+
|
47
|
+
def initialize(params = {})
|
48
|
+
@studied = params[:studied]
|
49
|
+
@completed = params[:completed]
|
50
|
+
@performance = params[:performance]
|
51
|
+
@best_speed = params[:best_speed]
|
52
|
+
@best_score = params[:best_score]
|
40
53
|
end
|
41
54
|
end
|
42
55
|
|
43
56
|
def initialize(params = {})
|
44
|
-
@today
|
45
|
-
@results
|
57
|
+
@today = (Date.parse(params[:today]) rescue nil)
|
58
|
+
@results = self.deserialize(params[:study_results], :as => Iknow::User::Study::Result)
|
59
|
+
@total_summary = self.deserialize(params[:total_summary], :as => Iknow::User::Study::TotalSummary)
|
46
60
|
end
|
47
61
|
|
48
62
|
end
|
49
63
|
|
50
|
-
def self.find(username)
|
51
|
-
|
64
|
+
def self.find(username, params = {})
|
65
|
+
params[:username] = username
|
66
|
+
response = Iknow::RestClient::User.find(params)
|
52
67
|
self.deserialize(response)
|
53
68
|
end
|
54
69
|
|
@@ -59,8 +74,8 @@ class Iknow::User < Iknow::Base
|
|
59
74
|
end
|
60
75
|
|
61
76
|
def initialize(params)
|
62
|
-
@profile = Profile.new(params[
|
63
|
-
@username = params[
|
77
|
+
@profile = Profile.new(params[:profile])
|
78
|
+
@username = params[:username]
|
64
79
|
end
|
65
80
|
|
66
81
|
def items(params = {})
|
@@ -2,6 +2,7 @@ class Iknow::RestClient::Item < Iknow::RestClient::Base
|
|
2
2
|
|
3
3
|
ACTIONS = {
|
4
4
|
:recent => { :path => '/items' },
|
5
|
+
:find => { :path => '/items/__id__' },
|
5
6
|
:matching => { :path => '/items/matching/__keyword__' },
|
6
7
|
:add_image => { :path => '/items/__id__/images', :http_method => :post },
|
7
8
|
:add_sound => { :path => '/items/__id__/sounds', :http_method => :post },
|
@@ -2,6 +2,7 @@ class Iknow::RestClient::List < Iknow::RestClient::Base
|
|
2
2
|
|
3
3
|
ACTIONS = {
|
4
4
|
:recent => { :path => '/lists' },
|
5
|
+
:find => { :path => '/lists/__id__' },
|
5
6
|
:items => { :path => '/lists/__id__/items' },
|
6
7
|
:sentences => { :path => '/lists/__id__/sentences' },
|
7
8
|
:matching => { :path => '/lists/matching/__keyword__' },
|
@@ -2,6 +2,7 @@ class Iknow::RestClient::Sentence < Iknow::RestClient::Base
|
|
2
2
|
|
3
3
|
ACTIONS = {
|
4
4
|
:recent => { :path => '/sentences' },
|
5
|
+
:find => { :path => '/sentences/__id__' },
|
5
6
|
:matching => { :path => '/sentences/matching/__keyword__' },
|
6
7
|
:create => { :path => '/sentences', :http_method => :post },
|
7
8
|
:add_image => { :path => '/sentences/__id__/images', :http_method => :post },
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nov-iknow
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- nov
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-
|
12
|
+
date: 2008-11-29 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -35,7 +35,7 @@ dependencies:
|
|
35
35
|
version_requirement:
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: 0.2.4
|
41
41
|
version:
|