nov-iknow 0.0.4 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README +4 -23
- data/Rakefile +5 -2
- data/examples/pure_ruby.rb +52 -10
- data/lib/ext/hash.rb +29 -0
- data/lib/iknow/core/config.rb +1 -1
- data/lib/iknow/core/version.rb +2 -2
- data/lib/iknow/core.rb +2 -1
- data/lib/iknow/model/list.rb +31 -18
- data/lib/iknow/rest_client/base.rb +66 -49
- data/lib/iknow/rest_client/item.rb +5 -5
- data/lib/iknow/rest_client/list.rb +9 -7
- metadata +13 -39
- data/examples/iknow_on_rails/app/controllers/application.rb +0 -15
- data/examples/iknow_on_rails/app/controllers/iknow_oauth_controller.rb +0 -24
- data/examples/iknow_on_rails/app/controllers/users_controller.rb +0 -10
- data/examples/iknow_on_rails/app/helpers/application_helper.rb +0 -3
- data/examples/iknow_on_rails/app/helpers/iknow_oauth_helper.rb +0 -3
- data/examples/iknow_on_rails/app/helpers/users_helper.rb +0 -2
- data/examples/iknow_on_rails/app/models/iknow_oauth_token.rb +0 -37
- data/examples/iknow_on_rails/config/boot.rb +0 -109
- data/examples/iknow_on_rails/config/environment.rb +0 -76
- data/examples/iknow_on_rails/config/environments/development.rb +0 -17
- data/examples/iknow_on_rails/config/environments/production.rb +0 -22
- data/examples/iknow_on_rails/config/environments/test.rb +0 -22
- data/examples/iknow_on_rails/config/initializers/inflections.rb +0 -10
- data/examples/iknow_on_rails/config/initializers/mime_types.rb +0 -5
- data/examples/iknow_on_rails/config/initializers/new_rails_defaults.rb +0 -17
- data/examples/iknow_on_rails/config/routes.rb +0 -44
- data/examples/iknow_on_rails/db/migrate/20081017012212_create_iknow_oauth_tokens.rb +0 -15
- data/examples/iknow_on_rails/db/schema.rb +0 -23
- data/examples/iknow_on_rails/lib/iknow_oauth_system.rb +0 -26
- data/examples/iknow_on_rails/public/dispatch.rb +0 -10
- data/examples/iknow_on_rails/test/functional/iknow_oauth_controller_test.rb +0 -7
- data/examples/iknow_on_rails/test/functional/users_controller_test.rb +0 -8
- data/examples/iknow_on_rails/test/test_helper.rb +0 -38
- data/examples/iknow_on_rails/test/unit/iknow_oauth_token_test.rb +0 -7
- data/generators/iknow_oauth/USAGE +0 -12
- data/generators/iknow_oauth/iknow_oauth_generator.rb +0 -22
- data/generators/iknow_oauth/templates/iknow_oauth_controller.rb +0 -24
- data/generators/iknow_oauth/templates/iknow_oauth_controller_test.rb +0 -7
- data/generators/iknow_oauth/templates/iknow_oauth_helper.rb +0 -3
- data/generators/iknow_oauth/templates/iknow_oauth_system.rb +0 -26
- data/generators/iknow_oauth/templates/iknow_oauth_token.rb +0 -37
- data/generators/iknow_oauth/templates/iknow_oauth_token_test.rb +0 -7
- data/generators/iknow_oauth/templates/iknow_oauth_tokens_migration.rb +0 -15
- data/generators/iknow_oauth/templates/index.rhtml +0 -4
data/README
CHANGED
@@ -6,6 +6,9 @@
|
|
6
6
|
|
7
7
|
This rubygem is a wrapper of iKnow! API.
|
8
8
|
You can get pure-ruby example at examples/pure_ruby.rb.
|
9
|
+
http://github.com/nov/iknow/tree/master/examples/pure_ruby.rb
|
10
|
+
|
11
|
+
It shows all API calls you can use with this gem.
|
9
12
|
|
10
13
|
== Installation
|
11
14
|
|
@@ -19,7 +22,7 @@
|
|
19
22
|
|
20
23
|
=== Gem Installation
|
21
24
|
|
22
|
-
gem install
|
25
|
+
gem install iknow
|
23
26
|
|
24
27
|
== Features/Problems
|
25
28
|
|
@@ -29,31 +32,9 @@
|
|
29
32
|
They will be implemented in a few weeks.
|
30
33
|
|
31
34
|
iKnow! OAuth is still pre-alpha.
|
32
|
-
Wait a few weeks to use it, please.
|
33
35
|
|
34
36
|
== Synopsis
|
35
|
-
|
36
|
-
% rails iknow_on_rails
|
37
|
-
% cd iknow_on_rails
|
38
|
-
% ./script/generate iknow_oauth
|
39
|
-
% rake db:create
|
40
|
-
% rake db:migrate
|
41
|
-
|
42
|
-
and edit environment.rb like examples/iknow_on_rails
|
43
|
-
and add some controllers and views like examples/iknow_on_rails
|
44
|
-
and go http://localhost:3000/
|
45
37
|
|
46
|
-
You can run examples/iknow_on_rails
|
47
|
-
|
48
|
-
1. DOWNLOAD THIS GEM
|
49
|
-
|
50
|
-
2. Run the example
|
51
|
-
% cd iknow/examples/iknow_on_rails (cd nov-iknow/examples/iknow_on_rails ??)
|
52
|
-
% rake db:create
|
53
|
-
% rake db:migrate
|
54
|
-
% ./script/server
|
55
|
-
|
56
|
-
About Another things
|
57
38
|
See examples and iKnow! Developers, please.
|
58
39
|
iKnow! Developers (http://developer.iknow.co.jp)
|
59
40
|
|
data/Rakefile
CHANGED
@@ -62,11 +62,12 @@ 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('
|
65
|
+
s.add_dependency('mechanize')
|
66
|
+
s.add_dependency('oauth', '>=0.2.7')
|
66
67
|
s.required_ruby_version = '>= 1.8.6'
|
67
68
|
|
68
69
|
s.files = %w(README ChangeLog Rakefile) +
|
69
|
-
Dir.glob("{bin,doc,test,lib,templates,
|
70
|
+
Dir.glob("{bin,doc,test,lib,templates,extras,website,script}/**/*") +
|
70
71
|
Dir.glob("ext/**/*.{h,c,rb}") +
|
71
72
|
Dir.glob("examples/**/*.rb") +
|
72
73
|
Dir.glob("tools/*.rb") +
|
@@ -80,12 +81,14 @@ Rake::GemPackageTask.new(spec) do |p|
|
|
80
81
|
p.gem_spec = spec
|
81
82
|
end
|
82
83
|
|
84
|
+
desc "Install"
|
83
85
|
task :install do
|
84
86
|
name = "#{NAME}-#{VERS}.gem"
|
85
87
|
sh %{rake package}
|
86
88
|
sh %{sudo gem install pkg/#{name}}
|
87
89
|
end
|
88
90
|
|
91
|
+
desc "Uninstall"
|
89
92
|
task :uninstall => [:clean] do
|
90
93
|
sh %{sudo gem uninstall #{NAME}}
|
91
94
|
end
|
data/examples/pure_ruby.rb
CHANGED
@@ -1,12 +1,22 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'iknow'
|
3
|
+
require 'oauth/consumer'
|
3
4
|
|
4
5
|
Iknow::Config.init do |conf|
|
5
|
-
conf.
|
6
|
-
conf.
|
7
|
-
conf.
|
6
|
+
conf.api_host = 'api.iknow.co.jp'
|
7
|
+
conf.api_key = '' # 'SET_YOUR_API_KEY'
|
8
|
+
conf.oauth_consumer_key = '' # 'SET_YOUR_OAUTH_CONSUMER_KEY'
|
9
|
+
conf.oauth_consumer_secret = '' # 'SET_YOUR_OAUTH_CONSUMER_SECRET'
|
8
10
|
end
|
9
11
|
|
12
|
+
# Edit here
|
13
|
+
OAUTH_ACCESS_TOKEN = ''
|
14
|
+
OAUTH_ACCESS_TOKEN_SECRET = ''
|
15
|
+
|
16
|
+
# Edit here
|
17
|
+
IKNOW_USERNAME = ''
|
18
|
+
IKNOW_PASSWORD = ''
|
19
|
+
|
10
20
|
please_get_api_key =<<EOS
|
11
21
|
This example needs your own iKnow! API key.
|
12
22
|
(for only Iknow::Item.extract example)
|
@@ -17,19 +27,22 @@ iKnow! Developers (http://developer.iknow.co.jp/)
|
|
17
27
|
Thanks!
|
18
28
|
EOS
|
19
29
|
|
20
|
-
if Iknow::Config.api_key == ''
|
21
|
-
# Iknow::Config.oauth_consumer_key == '' or
|
22
|
-
# Iknow::Config.oauth_consumer_secret == ''
|
30
|
+
if Iknow::Config.api_key == ''
|
23
31
|
raise ArgumentError.new(please_get_api_key)
|
24
32
|
end
|
25
33
|
|
34
|
+
|
35
|
+
###########################
|
36
|
+
## WITHOUT AUTHORIZATION ##
|
37
|
+
###########################
|
38
|
+
|
26
39
|
## User API
|
27
40
|
@user = Iknow::User.find('kirk')
|
28
41
|
@user.items(:include_sentences => true)
|
29
42
|
@user.lists
|
30
43
|
@user.friends
|
31
44
|
@user.study.results
|
32
|
-
@user.study.
|
45
|
+
@user.study.total_summary
|
33
46
|
@matched_users = Iknow::User.matching('matake')
|
34
47
|
|
35
48
|
## List API
|
@@ -39,8 +52,6 @@ end
|
|
39
52
|
@list.sentences
|
40
53
|
@matched_lists = Iknow::List.matching("イタリア語であいさつ")
|
41
54
|
|
42
|
-
# puts Iknow::List.find(31509, :include_sentences => true, :include_items => true).inspect
|
43
|
-
|
44
55
|
## Item API
|
45
56
|
@recent_items = Iknow::Item.recent(:include_sentences => true)
|
46
57
|
@item = Iknow::Item.find(437525)
|
@@ -51,4 +62,35 @@ end
|
|
51
62
|
## Sentence API
|
52
63
|
@recent_sentences = Iknow::Sentence.recent
|
53
64
|
@sentence = Iknow::Sentence.find(312271)
|
54
|
-
@matched_sentences = Iknow::Sentence.matching('record')
|
65
|
+
@matched_sentences = Iknow::Sentence.matching('record')
|
66
|
+
|
67
|
+
|
68
|
+
########################
|
69
|
+
## WITH AUTHORIZATION ##
|
70
|
+
########################
|
71
|
+
|
72
|
+
iknow_auth = case
|
73
|
+
when OAUTH_ACCESS_TOKEN != ''
|
74
|
+
if Iknow::Config.oauth_consumer_key == '' or Iknow::Config.oauth_consumer_secret == ''
|
75
|
+
raise ArgumentError.new("oauth_consumer_key and oauth_consumer_secret are required")
|
76
|
+
end
|
77
|
+
Iknow::Auth.new(:token => OAUTH_ACCESS_TOKEN, :secret => OAUTH_ACCESS_TOKEN_SECRET)
|
78
|
+
when IKNOW_USERNAME != ''
|
79
|
+
Iknow::Auth.new(:username => IKNOW_USERNAME, :password => IKNOW_PASSWORD)
|
80
|
+
else
|
81
|
+
nil
|
82
|
+
end
|
83
|
+
unless iknow_auth
|
84
|
+
puts "Skip calls which require authentication"
|
85
|
+
exit
|
86
|
+
end
|
87
|
+
|
88
|
+
## List API
|
89
|
+
|
90
|
+
@list = Iknow::List.create(iknow_auth, :title => 'iKnow! gem test', :description => 'A list for iKnow! gem test')
|
91
|
+
@list.add_item(iknow_auth, Iknow::Item.find(437525))
|
92
|
+
unless OAUTH_ACCESS_TOKEN.empty?
|
93
|
+
# A kind of weird, only with basic auth...
|
94
|
+
@list.delete_item(iknow_auth, @list.items.first)
|
95
|
+
end
|
96
|
+
@list.delete(iknow_auth)
|
data/lib/ext/hash.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
class Hash
|
2
|
+
|
2
3
|
def to_http_str
|
3
4
|
result = ''
|
4
5
|
return result if self.empty?
|
@@ -7,6 +8,7 @@ class Hash
|
|
7
8
|
end
|
8
9
|
result.chop
|
9
10
|
end
|
11
|
+
|
10
12
|
def symbolize_keys!
|
11
13
|
self.each do |key, value|
|
12
14
|
unless self.delete(key.to_s).nil?
|
@@ -20,4 +22,31 @@ class Hash
|
|
20
22
|
end
|
21
23
|
self
|
22
24
|
end
|
25
|
+
|
26
|
+
def stringfy_keys!
|
27
|
+
self.each do |key, value|
|
28
|
+
unless self.delete(key.to_sym).nil?
|
29
|
+
if value.is_a?(Hash)
|
30
|
+
value.stringfy_keys!
|
31
|
+
elsif value.is_a?(Array)
|
32
|
+
value.map!{ |v| v.stringfy_keys! if v.is_a?(Hash) }
|
33
|
+
end
|
34
|
+
self[key.to_s] = value
|
35
|
+
end
|
36
|
+
end
|
37
|
+
self
|
38
|
+
end
|
39
|
+
|
40
|
+
def stringfy_values!
|
41
|
+
self.each do |key, value|
|
42
|
+
if value.is_a?(Hash)
|
43
|
+
value.stringfy_values!
|
44
|
+
elsif value.is_a?(Array)
|
45
|
+
value.map!{ |v| v.stringfy_values! if v.is_a?(Hash) }
|
46
|
+
end
|
47
|
+
self[key] = value.to_s
|
48
|
+
end
|
49
|
+
self
|
50
|
+
end
|
51
|
+
|
23
52
|
end
|
data/lib/iknow/core/config.rb
CHANGED
@@ -20,7 +20,7 @@ class Iknow::Config
|
|
20
20
|
:user_agent => 'default',
|
21
21
|
:application_name => 'A rubygem for iKnow! API',
|
22
22
|
:application_version => Iknow::Version.to_version,
|
23
|
-
:application_url => 'http://github.com/nov/
|
23
|
+
:application_url => 'http://github.com/nov/iknow',
|
24
24
|
:source => 'iknow'
|
25
25
|
}.each do |key, value| conf.send("#{key}=", value) end
|
26
26
|
yield conf if block_given?
|
data/lib/iknow/core/version.rb
CHANGED
data/lib/iknow/core.rb
CHANGED
data/lib/iknow/model/list.rb
CHANGED
@@ -14,11 +14,11 @@
|
|
14
14
|
# "author_url": "http://www.iknow.co.jp/user/Cerego"
|
15
15
|
|
16
16
|
class Iknow::List < Iknow::Base
|
17
|
-
ATTRIBUTES = [:
|
17
|
+
ATTRIBUTES = [:id, :title, :description, :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]
|
21
|
-
NOT_WRITABLE_ATTRIBUTES = [:
|
21
|
+
NOT_WRITABLE_ATTRIBUTES = [:id, :icon, :item_count, :user_count, :iknow, :dictation, :brainspeed]
|
22
22
|
attr_accessor *(ATTRIBUTES - NOT_WRITABLE_ATTRIBUTES)
|
23
23
|
attr_reader *NOT_WRITABLE_ATTRIBUTES
|
24
24
|
|
@@ -51,13 +51,16 @@ class Iknow::List < Iknow::Base
|
|
51
51
|
self.deserialize(response) || []
|
52
52
|
end
|
53
53
|
|
54
|
-
def self.create(params = {})
|
55
|
-
|
56
|
-
|
54
|
+
def self.create(iknow_auth, params = {})
|
55
|
+
self.new(params).save(iknow_auth)
|
56
|
+
end
|
57
|
+
|
58
|
+
def self.delete(list_id)
|
59
|
+
self.find(list_id).delete
|
57
60
|
end
|
58
61
|
|
59
62
|
def initialize(params = {})
|
60
|
-
@
|
63
|
+
@id = (params[:id].to_i rescue nil)
|
61
64
|
@title = params[:title]
|
62
65
|
@description = params[:description]
|
63
66
|
@icon = params[:icon]
|
@@ -66,7 +69,7 @@ class Iknow::List < Iknow::Base
|
|
66
69
|
@language = params[:language]
|
67
70
|
@translation_language = params[:translation_language]
|
68
71
|
if @list_id and @translation_language
|
69
|
-
common_settings = {:list_id => @
|
72
|
+
common_settings = {:list_id => @id, :lang => @translation_language}
|
70
73
|
@iknow = Application.new(common_settings.merge(:application => 'iknow')) if params[:iknow]
|
71
74
|
@dictation = Application.new(common_settings.merge(:application => 'dictation')) if params[:dictation]
|
72
75
|
@brainspeed = Application.new(common_settings.merge(:application => 'brainspeed')) if params[:brainspeed]
|
@@ -85,24 +88,35 @@ class Iknow::List < Iknow::Base
|
|
85
88
|
end
|
86
89
|
|
87
90
|
def items(params = {})
|
88
|
-
response = Iknow::RestClient::List.items(params.merge(:id => self.
|
91
|
+
response = Iknow::RestClient::List.items(params.merge(:id => self.id))
|
89
92
|
self.deserialize(response, :as => Iknow::Item) || []
|
90
93
|
end
|
91
94
|
|
92
95
|
def sentences(params = {})
|
93
|
-
response = Iknow::RestClient::List.sentences(params.merge(:id => self.
|
96
|
+
response = Iknow::RestClient::List.sentences(params.merge(:id => self.id))
|
94
97
|
self.deserialize(response, :as => Iknow::Sentence) || []
|
95
98
|
end
|
96
99
|
|
97
|
-
def save
|
98
|
-
|
100
|
+
def save(iknow_auth)
|
101
|
+
begin
|
102
|
+
list_id = Iknow::RestClient::List.create(iknow_auth, self.to_post_data)
|
103
|
+
rescue
|
104
|
+
return false
|
105
|
+
end
|
106
|
+
Iknow::List.find(list_id)
|
107
|
+
end
|
108
|
+
|
109
|
+
def delete(iknow_auth)
|
110
|
+
Iknow::RestClient::List.delete(iknow_auth, :id => self.id)
|
99
111
|
end
|
112
|
+
alias_method :destroy, :delete
|
100
113
|
|
101
|
-
def
|
102
|
-
self.
|
103
|
-
|
104
|
-
|
105
|
-
|
114
|
+
def add_item(iknow_auth, item)
|
115
|
+
Iknow::RestClient::List.add_item(iknow_auth, {:list_id => self.id, :id => item.id})
|
116
|
+
end
|
117
|
+
|
118
|
+
def delete_item(iknow_auth, item)
|
119
|
+
Iknow::RestClient::List.delete_item(iknow_auth, {:list_id => self.id, :id => item.id})
|
106
120
|
end
|
107
121
|
|
108
122
|
protected
|
@@ -116,11 +130,10 @@ class Iknow::List < Iknow::Base
|
|
116
130
|
'list[language]' => self.language || 'en',
|
117
131
|
'list[translation_language]' => self.translation_language || 'ja'
|
118
132
|
}
|
119
|
-
#
|
133
|
+
# Optional attributes
|
120
134
|
if self.list_type
|
121
135
|
post_data['list[type]'] = self.list_type
|
122
136
|
end
|
123
|
-
# Optional attributes
|
124
137
|
[ :transcript, :embed, :tags, :media_entry,
|
125
138
|
:author, :author_url, :attribution_license_id ].each do |key|
|
126
139
|
if self.send("#{key}")
|
@@ -1,16 +1,15 @@
|
|
1
1
|
class Iknow::RestClient::Base
|
2
2
|
|
3
3
|
class RESTError < Exception
|
4
|
-
attr_accessor :code, :message
|
4
|
+
attr_accessor :code, :message
|
5
5
|
|
6
6
|
def initialize(params = {})
|
7
7
|
self.code = params[:code]
|
8
8
|
self.message = params[:message]
|
9
|
-
self.uri = params[:uri]
|
10
9
|
end
|
11
10
|
|
12
11
|
def to_s
|
13
|
-
"HTTP #{@code}: #{@message}
|
12
|
+
"HTTP #{@code}: #{@message}"
|
14
13
|
end
|
15
14
|
end
|
16
15
|
|
@@ -22,43 +21,41 @@ class Iknow::RestClient::Base
|
|
22
21
|
# GET methods are handled here
|
23
22
|
# POST and DELETE methods should be implemented in each class
|
24
23
|
super unless self.valid_action?(action)
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
24
|
+
case self.http_method(action)
|
25
|
+
when :get
|
26
|
+
path, params = path_with_params(self.path(action), args[0])
|
27
|
+
http_get_request(path, params)
|
28
|
+
when :post
|
29
|
+
path, params = path_with_params(self.path(action), args[1])
|
30
|
+
http_post_request(iknow_auth(args[0]), path, params)
|
31
|
+
when :delete
|
32
|
+
path, params = path_with_params(self.path(action), args[1])
|
33
|
+
http_delete_request(iknow_auth(args[0]), path, params)
|
35
34
|
end
|
36
35
|
end
|
37
36
|
|
38
37
|
private
|
39
38
|
|
40
39
|
def self.config; Iknow::Config end
|
40
|
+
|
41
|
+
def self.iknow_auth(iknow_auth)
|
42
|
+
if iknow_auth.is_a?(Iknow::Auth)
|
43
|
+
iknow_auth
|
44
|
+
else
|
45
|
+
raise ArgumentError.new("Authorized Iknow::Auth instance is required")
|
46
|
+
end
|
47
|
+
end
|
41
48
|
|
42
49
|
def self.api_key_required
|
43
50
|
raise ArgumentError.new("iKnow! API key is required") if self.config.api_key == ''
|
44
51
|
end
|
45
52
|
|
46
|
-
def self.
|
47
|
-
|
48
|
-
connection.start do |conn|
|
49
|
-
request = yield connection
|
50
|
-
response = conn.request(request)
|
51
|
-
handle_rest_response(response)
|
52
|
-
JSON.parse(response.body)
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
def self.raise_rest_error(response, uri = nil)
|
57
|
-
raise RESTError.new(:code => response.code, :message => response.message, :uri => uri)
|
53
|
+
def self.raise_rest_error(response)
|
54
|
+
raise RESTError.new(:code => response.code, :message => response.message)
|
58
55
|
end
|
59
56
|
|
60
|
-
def self.handle_rest_response(response
|
61
|
-
raise_rest_error(response
|
57
|
+
def self.handle_rest_response(response)
|
58
|
+
raise_rest_error(response) unless response.is_a?(Net::HTTPSuccess)
|
62
59
|
end
|
63
60
|
|
64
61
|
def self.http_header
|
@@ -72,43 +69,63 @@ class Iknow::RestClient::Base
|
|
72
69
|
@@http_header
|
73
70
|
end
|
74
71
|
|
75
|
-
def self.
|
76
|
-
|
72
|
+
def self.path_with_params(path, params = {})
|
73
|
+
path_with_params = path.clone
|
77
74
|
unless params.empty?
|
78
75
|
params.each do |key, value|
|
79
|
-
if
|
80
|
-
|
76
|
+
if path_with_params=~/__#{key}__/
|
77
|
+
path_with_params.sub!(/__#{key}__/, value.to_s)
|
81
78
|
params.delete(key)
|
82
79
|
end
|
83
80
|
end
|
84
81
|
end
|
85
|
-
return
|
82
|
+
return path_with_params, params
|
86
83
|
end
|
87
84
|
|
88
|
-
def self.http_get_request(
|
89
|
-
unless self.config.api_key == ''
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
85
|
+
def self.http_get_request(path, params = {})
|
86
|
+
params.merge!(:api_key => self.config.api_key) unless self.config.api_key == ''
|
87
|
+
path = (params.size > 0) ? "#{path}?#{params.to_http_str}" : path
|
88
|
+
http = Net::HTTP.new(self.config.api_host, self.config.api_port)
|
89
|
+
response = http.get(path, http_header)
|
90
|
+
handle_rest_response(response)
|
91
|
+
JSON.parse(response.body)
|
94
92
|
end
|
95
93
|
|
96
|
-
def self.http_post_request(
|
94
|
+
def self.http_post_request(iknow_auth, path, params = {})
|
97
95
|
self.api_key_required
|
98
|
-
|
99
|
-
|
100
|
-
|
96
|
+
params.merge!(:api_key => self.config.api_key)
|
97
|
+
case iknow_auth.mode
|
98
|
+
when :oauth
|
99
|
+
response = iknow_auth.auth_token.post(path, params, http_header)
|
100
|
+
handle_rest_response(response)
|
101
|
+
response.body
|
102
|
+
when :basic_auth
|
103
|
+
begin
|
104
|
+
response = iknow_auth.auth_token.post(self.config.iknow_api_base_url + path, params)
|
105
|
+
response.body
|
106
|
+
rescue WWW::Mechanize::ResponseCodeError => e
|
107
|
+
raise RESTError.new(:code => e.response_code, :message => e.to_s)
|
108
|
+
end
|
109
|
+
end
|
101
110
|
end
|
102
111
|
|
103
|
-
def self.http_delete_request(
|
104
|
-
|
105
|
-
|
112
|
+
def self.http_delete_request(iknow_auth, path, params = {})
|
113
|
+
self.api_key_required
|
114
|
+
params.merge!(:api_key => self.config.api_key)
|
115
|
+
case iknow_auth.mode
|
116
|
+
when :oauth
|
117
|
+
response = iknow_auth.auth_token.delete(path, params.stringfy_keys!.stringfy_values!)
|
118
|
+
handle_rest_response(response)
|
119
|
+
when :basic_auth
|
120
|
+
begin
|
121
|
+
iknow_auth.auth_token.delete(self.config.iknow_api_base_url + path, params.stringfy_keys!)
|
122
|
+
rescue WWW::Mechanize::ResponseCodeError => e
|
123
|
+
raise RESTError.new(:code => e.response_code, :message => e.to_s)
|
124
|
+
end
|
106
125
|
end
|
107
|
-
path = (params.size > 0) ? "#{uri}?#{params.to_http_str}" : uri
|
108
|
-
Net::HTTP::Delete.new(path, http_header)
|
109
126
|
end
|
110
127
|
|
111
|
-
private_class_method :
|
112
|
-
:
|
128
|
+
private_class_method :raise_rest_error, :handle_rest_response, :http_header,
|
129
|
+
:path_with_params, :http_get_request, :http_post_request, :http_delete_request
|
113
130
|
|
114
131
|
end
|
@@ -1,12 +1,12 @@
|
|
1
1
|
class Iknow::RestClient::Item < Iknow::RestClient::Base
|
2
2
|
|
3
3
|
ACTIONS = {
|
4
|
-
:recent => { :path => '/items'
|
5
|
-
:find => { :path => '/items/__id__'
|
6
|
-
:matching => { :path => '/items/matching/__keyword__'
|
4
|
+
:recent => { :path => '/items' },
|
5
|
+
:find => { :path => '/items/__id__' },
|
6
|
+
:matching => { :path => '/items/matching/__keyword__' },
|
7
|
+
:extract => { :path => '/items/extract', },
|
7
8
|
:add_image => { :path => '/items/__id__/images', :http_method => :post },
|
8
|
-
:add_sound => { :path => '/items/__id__/sounds', :http_method => :post }
|
9
|
-
:extract => { :path => '/items/extract', :http_method => :post }
|
9
|
+
:add_sound => { :path => '/items/__id__/sounds', :http_method => :post }
|
10
10
|
}
|
11
11
|
|
12
12
|
end
|
@@ -1,13 +1,15 @@
|
|
1
1
|
class Iknow::RestClient::List < Iknow::RestClient::Base
|
2
2
|
|
3
3
|
ACTIONS = {
|
4
|
-
:recent
|
5
|
-
:find
|
6
|
-
:items
|
7
|
-
:sentences
|
8
|
-
:matching
|
9
|
-
:create
|
10
|
-
:delete
|
4
|
+
:recent => { :path => '/lists' },
|
5
|
+
:find => { :path => '/lists/__id__' },
|
6
|
+
:items => { :path => '/lists/__id__/items' },
|
7
|
+
:sentences => { :path => '/lists/__id__/sentences' },
|
8
|
+
:matching => { :path => '/lists/matching/__keyword__' },
|
9
|
+
:create => { :path => '/lists', :http_method => :post },
|
10
|
+
:delete => { :path => '/lists/__id__', :http_method => :delete },
|
11
|
+
:add_item => { :path => '/lists/__list_id__/items', :http_method => :post },
|
12
|
+
:delete_item => { :path => '/lists/__list_id__/items/__id__', :http_method => :delete }
|
11
13
|
}
|
12
14
|
|
13
15
|
end
|
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.1.0
|
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-12-19 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -30,6 +30,15 @@ dependencies:
|
|
30
30
|
- !ruby/object:Gem::Version
|
31
31
|
version: "0"
|
32
32
|
version:
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: mechanize
|
35
|
+
version_requirement:
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: "0"
|
41
|
+
version:
|
33
42
|
- !ruby/object:Gem::Dependency
|
34
43
|
name: oauth
|
35
44
|
version_requirement:
|
@@ -37,7 +46,7 @@ dependencies:
|
|
37
46
|
requirements:
|
38
47
|
- - ">="
|
39
48
|
- !ruby/object:Gem::Version
|
40
|
-
version: 0.2.
|
49
|
+
version: 0.2.7
|
41
50
|
version:
|
42
51
|
description: A rubygem for iKnow! APIs
|
43
52
|
email: developer@iknow.co.jp
|
@@ -58,6 +67,7 @@ files:
|
|
58
67
|
- lib/ext/hash.rb
|
59
68
|
- lib/iknow
|
60
69
|
- lib/iknow/core
|
70
|
+
- lib/iknow/core/auth.rb
|
61
71
|
- lib/iknow/core/config.rb
|
62
72
|
- lib/iknow/core/version.rb
|
63
73
|
- lib/iknow/core.rb
|
@@ -76,42 +86,6 @@ files:
|
|
76
86
|
- lib/iknow/rest_client/user.rb
|
77
87
|
- lib/iknow/rest_client.rb
|
78
88
|
- lib/iknow.rb
|
79
|
-
- generators/iknow_oauth
|
80
|
-
- generators/iknow_oauth/iknow_oauth_generator.rb
|
81
|
-
- generators/iknow_oauth/templates
|
82
|
-
- generators/iknow_oauth/templates/iknow_oauth_controller.rb
|
83
|
-
- generators/iknow_oauth/templates/iknow_oauth_controller_test.rb
|
84
|
-
- generators/iknow_oauth/templates/iknow_oauth_helper.rb
|
85
|
-
- generators/iknow_oauth/templates/iknow_oauth_system.rb
|
86
|
-
- generators/iknow_oauth/templates/iknow_oauth_token.rb
|
87
|
-
- generators/iknow_oauth/templates/iknow_oauth_token_test.rb
|
88
|
-
- generators/iknow_oauth/templates/iknow_oauth_tokens_migration.rb
|
89
|
-
- generators/iknow_oauth/templates/index.rhtml
|
90
|
-
- generators/iknow_oauth/USAGE
|
91
|
-
- examples/iknow_on_rails/app/controllers/application.rb
|
92
|
-
- examples/iknow_on_rails/app/controllers/iknow_oauth_controller.rb
|
93
|
-
- examples/iknow_on_rails/app/controllers/users_controller.rb
|
94
|
-
- examples/iknow_on_rails/app/helpers/application_helper.rb
|
95
|
-
- examples/iknow_on_rails/app/helpers/iknow_oauth_helper.rb
|
96
|
-
- examples/iknow_on_rails/app/helpers/users_helper.rb
|
97
|
-
- examples/iknow_on_rails/app/models/iknow_oauth_token.rb
|
98
|
-
- examples/iknow_on_rails/config/boot.rb
|
99
|
-
- examples/iknow_on_rails/config/environment.rb
|
100
|
-
- examples/iknow_on_rails/config/environments/development.rb
|
101
|
-
- examples/iknow_on_rails/config/environments/production.rb
|
102
|
-
- examples/iknow_on_rails/config/environments/test.rb
|
103
|
-
- examples/iknow_on_rails/config/initializers/inflections.rb
|
104
|
-
- examples/iknow_on_rails/config/initializers/mime_types.rb
|
105
|
-
- examples/iknow_on_rails/config/initializers/new_rails_defaults.rb
|
106
|
-
- examples/iknow_on_rails/config/routes.rb
|
107
|
-
- examples/iknow_on_rails/db/migrate/20081017012212_create_iknow_oauth_tokens.rb
|
108
|
-
- examples/iknow_on_rails/db/schema.rb
|
109
|
-
- examples/iknow_on_rails/lib/iknow_oauth_system.rb
|
110
|
-
- examples/iknow_on_rails/public/dispatch.rb
|
111
|
-
- examples/iknow_on_rails/test/functional/iknow_oauth_controller_test.rb
|
112
|
-
- examples/iknow_on_rails/test/functional/users_controller_test.rb
|
113
|
-
- examples/iknow_on_rails/test/test_helper.rb
|
114
|
-
- examples/iknow_on_rails/test/unit/iknow_oauth_token_test.rb
|
115
89
|
- examples/pure_ruby.rb
|
116
90
|
has_rdoc: true
|
117
91
|
homepage: http://iknow.rubyforge.org
|
@@ -1,15 +0,0 @@
|
|
1
|
-
# Filters added to this controller apply to all controllers in the application.
|
2
|
-
# Likewise, all the methods added will be available for all controllers.
|
3
|
-
|
4
|
-
class ApplicationController < ActionController::Base
|
5
|
-
helper :all # include all helpers, all the time
|
6
|
-
|
7
|
-
# See ActionController::RequestForgeryProtection for details
|
8
|
-
# Uncomment the :secret if you're not using the cookie session store
|
9
|
-
protect_from_forgery # :secret => 'e1ab9cfeba306b3feb0b9156d59c3e15'
|
10
|
-
|
11
|
-
# See ActionController::Base for details
|
12
|
-
# Uncomment this to filter the contents of submitted sensitive data parameters
|
13
|
-
# from your application log (in this case, all fields with names like "password").
|
14
|
-
# filter_parameter_logging :password
|
15
|
-
end
|