nov-iknow 0.2.0 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +13 -1
- data/README +2 -2
- data/Rakefile +3 -4
- data/examples/pure_ruby.rb +2 -0
- data/lib/iknow/core/auth.rb +4 -4
- data/lib/iknow/core/config.rb +16 -9
- data/lib/iknow/core/version.rb +1 -1
- data/lib/iknow/model/item.rb +38 -7
- data/lib/iknow/model/list.rb +2 -1
- data/lib/iknow/model/sentence.rb +34 -7
- data/lib/iknow.rb +3 -1
- data/test/iknow_test.rb +3 -0
- metadata +4 -13
data/ChangeLog
CHANGED
data/README
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
= iknow
|
2
2
|
|
3
|
-
by nov <
|
3
|
+
by nov <developer@iknow.co.jp>
|
4
4
|
|
5
5
|
== Description
|
6
6
|
|
@@ -40,6 +40,6 @@
|
|
40
40
|
|
41
41
|
== Copyright
|
42
42
|
|
43
|
-
Author:: nov <
|
43
|
+
Author:: nov <developer@iknow.co.jp>
|
44
44
|
Copyright:: Copyright (c) 2008 nov
|
45
45
|
License:: MIT License
|
data/Rakefile
CHANGED
@@ -14,7 +14,7 @@ NAME = "iknow"
|
|
14
14
|
AUTHOR = "nov"
|
15
15
|
EMAIL = "developer@iknow.co.jp"
|
16
16
|
DESCRIPTION = "A rubygem for iKnow! APIs"
|
17
|
-
RUBYFORGE_PROJECT =
|
17
|
+
RUBYFORGE_PROJECT = NAME
|
18
18
|
HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
|
19
19
|
BIN_FILES = %w( )
|
20
20
|
|
@@ -60,10 +60,9 @@ spec = Gem::Specification.new do |s|
|
|
60
60
|
#s.autorequire = ""
|
61
61
|
s.test_files = Dir["test/*_test.rb"]
|
62
62
|
|
63
|
-
s.add_dependency('rails', '>=2.1.0')
|
64
63
|
s.add_dependency('json')
|
65
|
-
s.add_dependency('oauth'
|
66
|
-
|
64
|
+
s.add_dependency('oauth')
|
65
|
+
# s.required_ruby_version = '>= 1.8.6'
|
67
66
|
|
68
67
|
s.files = %w(README ChangeLog Rakefile) +
|
69
68
|
Dir.glob("{bin,doc,test,lib,templates,extras,website,script}/**/*") +
|
data/examples/pure_ruby.rb
CHANGED
@@ -7,6 +7,8 @@ Iknow::Config.init do |conf|
|
|
7
7
|
conf.api_key = '' # 'SET_YOUR_API_KEY'
|
8
8
|
conf.oauth_consumer_key = '' # 'SET_YOUR_OAUTH_CONSUMER_KEY'
|
9
9
|
conf.oauth_consumer_secret = '' # 'SET_YOUR_OAUTH_CONSUMER_SECRET'
|
10
|
+
conf.oauth_http_method = :post
|
11
|
+
conf.oauth_scheme = :header
|
10
12
|
conf.timeout = 15
|
11
13
|
end
|
12
14
|
|
data/lib/iknow/core/auth.rb
CHANGED
@@ -28,10 +28,10 @@ class Iknow::Auth
|
|
28
28
|
@@consumer ||= OAuth::Consumer.new(
|
29
29
|
Iknow::Config.oauth_consumer_key,
|
30
30
|
Iknow::Config.oauth_consumer_secret,
|
31
|
-
:http_method =>
|
32
|
-
:
|
33
|
-
:site => Iknow::Config.
|
34
|
-
:authorize_url => "#{Iknow::Config.
|
31
|
+
:http_method => Iknow::Config.oauth_http_method,
|
32
|
+
:scheme => Iknow::Config.oauth_scheme,
|
33
|
+
:site => Iknow::Config.api_base_url,
|
34
|
+
:authorize_url => "#{Iknow::Config.base_url}/oauth/authorize"
|
35
35
|
)
|
36
36
|
end
|
37
37
|
|
data/lib/iknow/core/config.rb
CHANGED
@@ -2,9 +2,10 @@ require 'singleton'
|
|
2
2
|
|
3
3
|
class Iknow::Config
|
4
4
|
include Singleton
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
ATTRIBUTES = [ :protocol, :host, :port, :api_protocol, :api_host, :api_port, :api_key, :timeout,
|
6
|
+
:oauth_consumer_key, :oauth_consumer_secret, :oauth_http_method, :oauth_scheme,
|
7
|
+
:user_agent, :application_name, :application_version, :application_url ]
|
8
|
+
attr_accessor *ATTRIBUTES
|
8
9
|
|
9
10
|
def self.init(&block)
|
10
11
|
conf = Iknow::Config.instance
|
@@ -14,10 +15,12 @@ class Iknow::Config
|
|
14
15
|
:api_protocol => 'http',
|
15
16
|
:api_host => 'api.iknow.co.jp',
|
16
17
|
:api_port => 80,
|
17
|
-
:timeout => 30,
|
18
18
|
:api_key => '',
|
19
|
+
:timeout => 30,
|
19
20
|
:oauth_consumer_key => '',
|
20
21
|
:oauth_consumer_secret => '',
|
22
|
+
:oauth_http_method => :post,
|
23
|
+
:oauth_scheme => :header,
|
21
24
|
:user_agent => 'default',
|
22
25
|
:application_name => 'iKnow! Gem',
|
23
26
|
:application_version => Iknow::Version.to_version,
|
@@ -27,18 +30,22 @@ class Iknow::Config
|
|
27
30
|
conf
|
28
31
|
end
|
29
32
|
|
30
|
-
def
|
33
|
+
def base_url
|
31
34
|
port = self.port==80 ? nil : ":#{self.port}"
|
32
35
|
"#{self.protocol}://#{self.host}#{port}"
|
33
36
|
end
|
34
37
|
|
35
|
-
def
|
38
|
+
def api_base_url
|
36
39
|
port = self.api_port==80 ? nil : ":#{self.api_port}"
|
37
40
|
"#{self.api_protocol}://#{self.api_host}#{port}"
|
38
41
|
end
|
39
42
|
|
40
|
-
|
41
|
-
|
43
|
+
# hack: Object.timeout is already defined..
|
44
|
+
def self.timeout
|
45
|
+
instance.timeout
|
42
46
|
end
|
43
47
|
|
44
|
-
|
48
|
+
def self.method_missing(method, *args)
|
49
|
+
Iknow::Config.instance.send(method, *args)
|
50
|
+
end
|
51
|
+
end
|
data/lib/iknow/core/version.rb
CHANGED
data/lib/iknow/model/item.rb
CHANGED
@@ -78,20 +78,46 @@ class Iknow::Item < Iknow::Base
|
|
78
78
|
|
79
79
|
def add_image(iknow_auth, params)
|
80
80
|
post_params = if params.is_a?(String)
|
81
|
-
{'image[url]' => params
|
81
|
+
{ 'image[url]' => params }
|
82
82
|
else
|
83
|
-
{
|
84
|
-
|
83
|
+
image_params = {
|
84
|
+
'image[url]' => params[:url],
|
85
|
+
'image[list_id]' => params[:list_id]
|
86
|
+
}
|
87
|
+
if params[:attribution]
|
88
|
+
attribution_params = {
|
89
|
+
'attribution[media_entity]' => params[:attribution][:media_entity],
|
90
|
+
'attribution[author]' => params[:attribution][:media_entity],
|
91
|
+
'attribution[author_url]' => params[:attribution][:media_entity],
|
92
|
+
'attribution[attribution_license_id]' => params[:attribution][:media_entity]
|
93
|
+
}
|
94
|
+
image_params.merge(attribution_params)
|
95
|
+
else
|
96
|
+
image_params
|
97
|
+
end
|
85
98
|
end
|
86
99
|
Iknow::RestClient::Item.add_image(iknow_auth, post_params.merge(:id => self.id))
|
87
100
|
end
|
88
101
|
|
89
102
|
def add_sound(iknow_auth, params)
|
90
103
|
post_params = if params.is_a?(String)
|
91
|
-
{'sound[url]' => params
|
104
|
+
{ 'sound[url]' => params }
|
92
105
|
else
|
93
|
-
|
94
|
-
|
106
|
+
sound_params = {
|
107
|
+
'sound[url]' => params[:url],
|
108
|
+
'sound[list_id]' => params[:list_id]
|
109
|
+
}
|
110
|
+
if params[:attribution]
|
111
|
+
attribution_params = {
|
112
|
+
'attribution[media_entity]' => params[:attribution][:media_entity],
|
113
|
+
'attribution[author]' => params[:attribution][:media_entity],
|
114
|
+
'attribution[author_url]' => params[:attribution][:media_entity],
|
115
|
+
'attribution[attribution_license_id]' => params[:attribution][:media_entity]
|
116
|
+
}
|
117
|
+
sound_params.merge(attribution_params)
|
118
|
+
else
|
119
|
+
sound_params
|
120
|
+
end
|
95
121
|
end
|
96
122
|
Iknow::RestClient::Item.add_sound(iknow_auth, post_params.merge(:id => self.id))
|
97
123
|
end
|
@@ -99,7 +125,12 @@ class Iknow::Item < Iknow::Base
|
|
99
125
|
def add_tags(iknow_auth, *tags)
|
100
126
|
post_params = {}
|
101
127
|
tags.each_with_index do |tag, idx|
|
102
|
-
|
128
|
+
if tag.is_a?(String)
|
129
|
+
post_params["semantic_tags[#{idx}][name]"] = tag
|
130
|
+
else
|
131
|
+
post_params["semantic_tags[#{idx}][name]"] = tag[:name]
|
132
|
+
post_params["semantic_tags[#{idx}][disambiguation]"] = tag[:disambiguation]
|
133
|
+
end
|
103
134
|
end
|
104
135
|
Iknow::RestClient::Item.add_tags(iknow_auth, post_params.merge(:id => self.id))
|
105
136
|
end
|
data/lib/iknow/model/list.rb
CHANGED
@@ -14,7 +14,7 @@
|
|
14
14
|
# "author_url": "http://www.iknow.co.jp/user/Cerego"
|
15
15
|
|
16
16
|
class Iknow::List < Iknow::Base
|
17
|
-
ATTRIBUTES = [:id, :title, :description, :icon, :item_count, :user_count, :iknow, :dictation, :brainspeed,
|
17
|
+
ATTRIBUTES = [:id, :title, :description, :icon, :square_icon, :item_count, :user_count, :iknow, :dictation, :brainspeed,
|
18
18
|
:language, :translation_language, :list_type, :transcript, :embed,
|
19
19
|
:tags, :media_entry, :author, :author_id, :author_url, :attribution_license_id,
|
20
20
|
:items, :sentences]
|
@@ -64,6 +64,7 @@ class Iknow::List < Iknow::Base
|
|
64
64
|
@title = params[:title]
|
65
65
|
@description = params[:description]
|
66
66
|
@icon = params[:icon]
|
67
|
+
@square_icon = params[:square_icon]
|
67
68
|
@item_count = (params[:item_count].to_i rescue nil)
|
68
69
|
@user_count = (params[:user_count].to_i rescue nil)
|
69
70
|
@language = params[:language]
|
data/lib/iknow/model/sentence.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
class Iknow::Sentence < Iknow::Base
|
2
|
-
ATTRIBUTES = [:sound, :image, :text, :language, :id, :transliterations, :translations, :item, :list]
|
2
|
+
ATTRIBUTES = [:sound, :image, :square_image, :text, :language, :id, :transliterations, :translations, :item, :list]
|
3
3
|
READONLY_ATTRIBUTES = [:id]
|
4
4
|
attr_accessor *(ATTRIBUTES - READONLY_ATTRIBUTES)
|
5
5
|
attr_reader *READONLY_ATTRIBUTES
|
@@ -33,6 +33,7 @@ class Iknow::Sentence < Iknow::Base
|
|
33
33
|
@list = params[:list]
|
34
34
|
@sound = params[:sound]
|
35
35
|
@image = params[:image]
|
36
|
+
@square_image = params[:square_image]
|
36
37
|
@text = params[:text]
|
37
38
|
@language = params[:language]
|
38
39
|
@transliterations = params[:transliterations]
|
@@ -50,20 +51,46 @@ class Iknow::Sentence < Iknow::Base
|
|
50
51
|
|
51
52
|
def add_image(iknow_auth, params)
|
52
53
|
post_params = if params.is_a?(String)
|
53
|
-
{'image[url]' => params
|
54
|
+
{ 'image[url]' => params }
|
54
55
|
else
|
55
|
-
{
|
56
|
-
|
56
|
+
image_params = {
|
57
|
+
'image[url]' => params[:url],
|
58
|
+
'image[list_id]' => params[:list_id]
|
59
|
+
}
|
60
|
+
if params[:attribution]
|
61
|
+
attribution_params = {
|
62
|
+
'attribution[media_entity]' => params[:attribution][:media_entity],
|
63
|
+
'attribution[author]' => params[:attribution][:media_entity],
|
64
|
+
'attribution[author_url]' => params[:attribution][:media_entity],
|
65
|
+
'attribution[attribution_license_id]' => params[:attribution][:media_entity]
|
66
|
+
}
|
67
|
+
image_params.merge(attribution_params)
|
68
|
+
else
|
69
|
+
image_params
|
70
|
+
end
|
57
71
|
end
|
58
72
|
Iknow::RestClient::Sentence.add_image(iknow_auth, post_params.merge(:id => self.id))
|
59
73
|
end
|
60
74
|
|
61
75
|
def add_sound(iknow_auth, params)
|
62
76
|
post_params = if params.is_a?(String)
|
63
|
-
{'sound[url]' => params
|
77
|
+
{ 'sound[url]' => params }
|
64
78
|
else
|
65
|
-
|
66
|
-
|
79
|
+
sound_params = {
|
80
|
+
'sound[url]' => params[:url],
|
81
|
+
'sound[list_id]' => params[:list_id]
|
82
|
+
}
|
83
|
+
if params[:attribution]
|
84
|
+
attribution_params = {
|
85
|
+
'attribution[media_entity]' => params[:attribution][:media_entity],
|
86
|
+
'attribution[author]' => params[:attribution][:media_entity],
|
87
|
+
'attribution[author_url]' => params[:attribution][:media_entity],
|
88
|
+
'attribution[attribution_license_id]' => params[:attribution][:media_entity]
|
89
|
+
}
|
90
|
+
sound_params.merge(attribution_params)
|
91
|
+
else
|
92
|
+
sound_params
|
93
|
+
end
|
67
94
|
end
|
68
95
|
Iknow::RestClient::Sentence.add_sound(iknow_auth, post_params.merge(:id => self.id))
|
69
96
|
end
|
data/lib/iknow.rb
CHANGED
data/test/iknow_test.rb
CHANGED
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.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- nov
|
@@ -9,18 +9,9 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-12-
|
12
|
+
date: 2008-12-24 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
|
-
- !ruby/object:Gem::Dependency
|
16
|
-
name: rails
|
17
|
-
version_requirement:
|
18
|
-
version_requirements: !ruby/object:Gem::Requirement
|
19
|
-
requirements:
|
20
|
-
- - ">="
|
21
|
-
- !ruby/object:Gem::Version
|
22
|
-
version: 2.1.0
|
23
|
-
version:
|
24
15
|
- !ruby/object:Gem::Dependency
|
25
16
|
name: json
|
26
17
|
version_requirement:
|
@@ -37,7 +28,7 @@ dependencies:
|
|
37
28
|
requirements:
|
38
29
|
- - ">="
|
39
30
|
- !ruby/object:Gem::Version
|
40
|
-
version: 0
|
31
|
+
version: "0"
|
41
32
|
version:
|
42
33
|
description: A rubygem for iKnow! APIs
|
43
34
|
email: developer@iknow.co.jp
|
@@ -100,7 +91,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
100
91
|
requirements:
|
101
92
|
- - ">="
|
102
93
|
- !ruby/object:Gem::Version
|
103
|
-
version:
|
94
|
+
version: "0"
|
104
95
|
version:
|
105
96
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
106
97
|
requirements:
|