nov-iknow 0.0.2 → 0.0.3
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.
- data/README +24 -0
- data/examples/pure_ruby.rb +4 -4
- data/lib/iknow/model/base.rb +1 -1
- data/lib/iknow/rest_client/base.rb +2 -2
- metadata +2 -14
- data/generators/iknow/USAGE +0 -12
- data/generators/iknow/iknow_generator.rb +0 -22
- data/generators/iknow/templates/iknow_oauth_controller.rb +0 -24
- data/generators/iknow/templates/iknow_oauth_controller_test.rb +0 -7
- data/generators/iknow/templates/iknow_oauth_helper.rb +0 -3
- data/generators/iknow/templates/iknow_oauth_system.rb +0 -26
- data/generators/iknow/templates/iknow_oauth_token.rb +0 -37
- data/generators/iknow/templates/iknow_oauth_token_test.rb +0 -7
- data/generators/iknow/templates/iknow_oauth_tokens_migration.rb +0 -15
- data/generators/iknow/templates/index.rhtml +0 -4
data/README
CHANGED
@@ -27,9 +27,33 @@
|
|
27
27
|
|
28
28
|
Create/Add/Delete APIs are not implemented.
|
29
29
|
They will be implemented in a few weeks.
|
30
|
+
|
31
|
+
iKnow! OAuth is still pre-alpha.
|
32
|
+
Wait a few weeks to use it, please.
|
30
33
|
|
31
34
|
== Synopsis
|
32
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
|
+
|
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
|
33
57
|
See examples and iKnow! Developers, please.
|
34
58
|
iKnow! Developers (http://developer.iknow.co.jp)
|
35
59
|
|
data/examples/pure_ruby.rb
CHANGED
@@ -2,7 +2,7 @@ require 'rubygems'
|
|
2
2
|
require 'iknow'
|
3
3
|
|
4
4
|
Iknow::Config.init do |conf|
|
5
|
-
conf.api_key = '
|
5
|
+
conf.api_key = ''
|
6
6
|
conf.oauth_consumer_key = ''
|
7
7
|
conf.oauth_consumer_secret = ''
|
8
8
|
end
|
@@ -28,14 +28,14 @@ end
|
|
28
28
|
@user.items
|
29
29
|
@user.lists
|
30
30
|
@user.friends
|
31
|
-
@user.
|
31
|
+
@user.study.results
|
32
32
|
@matchied_users = Iknow::User.matching('matake')
|
33
33
|
|
34
34
|
# ## List API
|
35
35
|
@recent_lists = Iknow::List.recent
|
36
36
|
@matchied_lists = Iknow::List.matching("遺伝的アルゴリズム")
|
37
|
-
@
|
38
|
-
@
|
37
|
+
@matchied_lists.first.items
|
38
|
+
@matchied_lists.first.sentences
|
39
39
|
|
40
40
|
# ## Item API
|
41
41
|
@recent_items = Iknow::Item.recent
|
data/lib/iknow/model/base.rb
CHANGED
@@ -86,7 +86,7 @@ class Iknow::RestClient::Base
|
|
86
86
|
end
|
87
87
|
|
88
88
|
def self.http_get_request(uri, params = {})
|
89
|
-
unless self.config.api_key
|
89
|
+
unless self.config.api_key == ''
|
90
90
|
params.merge!(:api_key => self.config.api_key)
|
91
91
|
end
|
92
92
|
path = (params.size > 0) ? "#{uri}?#{params.to_http_str}" : uri
|
@@ -101,7 +101,7 @@ class Iknow::RestClient::Base
|
|
101
101
|
end
|
102
102
|
|
103
103
|
def self.http_delete_request(uri, params = {})
|
104
|
-
unless self.config.api_key
|
104
|
+
unless self.config.api_key == ''
|
105
105
|
params.merge!(:api_key => self.config.api_key)
|
106
106
|
end
|
107
107
|
path = (params.size > 0) ? "#{uri}?#{params.to_http_str}" : uri
|
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.3
|
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-10-
|
12
|
+
date: 2008-10-18 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -76,18 +76,6 @@ files:
|
|
76
76
|
- lib/iknow/rest_client/user.rb
|
77
77
|
- lib/iknow/rest_client.rb
|
78
78
|
- lib/iknow.rb
|
79
|
-
- generators/iknow
|
80
|
-
- generators/iknow/iknow_generator.rb
|
81
|
-
- generators/iknow/templates
|
82
|
-
- generators/iknow/templates/iknow_oauth_controller.rb
|
83
|
-
- generators/iknow/templates/iknow_oauth_controller_test.rb
|
84
|
-
- generators/iknow/templates/iknow_oauth_helper.rb
|
85
|
-
- generators/iknow/templates/iknow_oauth_system.rb
|
86
|
-
- generators/iknow/templates/iknow_oauth_token.rb
|
87
|
-
- generators/iknow/templates/iknow_oauth_token_test.rb
|
88
|
-
- generators/iknow/templates/iknow_oauth_tokens_migration.rb
|
89
|
-
- generators/iknow/templates/index.rhtml
|
90
|
-
- generators/iknow/USAGE
|
91
79
|
- generators/iknow_oauth
|
92
80
|
- generators/iknow_oauth/iknow_oauth_generator.rb
|
93
81
|
- generators/iknow_oauth/templates
|
data/generators/iknow/USAGE
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
NAME
|
2
|
-
iknow_oauth - creates a functional iknow oauth consumer
|
3
|
-
|
4
|
-
SYNOPSIS
|
5
|
-
nothing
|
6
|
-
|
7
|
-
Description:
|
8
|
-
Generates a model, controller, helper, view and library for making a OAuth consumer of iKnow! API.
|
9
|
-
No arguments are needed.
|
10
|
-
|
11
|
-
Example:
|
12
|
-
./script/generate iknow_oauth
|
@@ -1,22 +0,0 @@
|
|
1
|
-
require 'rails_generator/base'
|
2
|
-
|
3
|
-
class IknowGenerator < Rails::Generator::Base
|
4
|
-
def manifest
|
5
|
-
record do |m|
|
6
|
-
m.class_collisions 'IknowOauthController', 'IknowOauthControllerTest', 'IknowOauthHelper',
|
7
|
-
'IknowOauthSystem', 'IknowOauthToken', 'IknowOauthTokenTest'
|
8
|
-
|
9
|
-
m.migration_template 'iknow_oauth_tokens_migration.rb', 'db/migrate', :migration_file_name => 'create_iknow_oauth_tokens'
|
10
|
-
|
11
|
-
m.template 'iknow_oauth_controller.rb', File.join('app/controllers', 'iknow_oauth_controller.rb' )
|
12
|
-
m.template 'iknow_oauth_controller_test.rb', File.join('test/functional', 'iknow_oauth_controller_test.rb')
|
13
|
-
m.template 'iknow_oauth_helper.rb', File.join('app/helpers', 'iknow_oauth_helper.rb' )
|
14
|
-
m.template 'iknow_oauth_system.rb', File.join('lib', 'iknow_oauth_system.rb' )
|
15
|
-
m.template 'iknow_oauth_token.rb', File.join('app/models', 'iknow_oauth_token.rb' )
|
16
|
-
m.template 'iknow_oauth_token_test.rb', File.join('test/unit', 'iknow_oauth_token_test.rb' )
|
17
|
-
|
18
|
-
m.directory File.join('app/views', 'iknow_oauth')
|
19
|
-
m.template 'index.rhtml', File.join('app/views', 'iknow_oauth', 'index.rhtml')
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
@@ -1,24 +0,0 @@
|
|
1
|
-
class IknowOauthController < ApplicationController
|
2
|
-
|
3
|
-
def index; end
|
4
|
-
|
5
|
-
def new_request
|
6
|
-
request_token = IknowOauthToken.new_request_token
|
7
|
-
|
8
|
-
session[:iknow_username] = params[:iknow_username]
|
9
|
-
session[:request_token] = request_token
|
10
|
-
session[:redirect_url_after_auth] = params[:redirect_url_after_auth] || request.referer
|
11
|
-
|
12
|
-
if request_token
|
13
|
-
redirect_to(request_token.authorize_url)
|
14
|
-
else
|
15
|
-
raise RuntimeError.new("Failed to get a iKnow! Request Token")
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
def callback
|
20
|
-
AuthToken.establish_auth_token(session[:iknow_username], session[:request_token])
|
21
|
-
redirect_to(session[:redirect_url_after_auth])
|
22
|
-
end
|
23
|
-
|
24
|
-
end
|
@@ -1,26 +0,0 @@
|
|
1
|
-
module IknowOauthSystem
|
2
|
-
|
3
|
-
protected
|
4
|
-
|
5
|
-
def require_iknow_oauth
|
6
|
-
unless iknow_username_exists?
|
7
|
-
redirect_to(:controller => 'iknow_oauth', :action => 'index')
|
8
|
-
return false
|
9
|
-
end
|
10
|
-
|
11
|
-
iknow_oauth_token = IknowOauthToken.find_by_username(session[:iknow_username])
|
12
|
-
unless iknow_oauth_token
|
13
|
-
redirect_to(:controller => 'iknow_oauth', :action => 'new_request')
|
14
|
-
return false
|
15
|
-
end
|
16
|
-
|
17
|
-
true
|
18
|
-
end
|
19
|
-
|
20
|
-
private
|
21
|
-
|
22
|
-
def iknow_username_exists?
|
23
|
-
!session[:iknow_username].blank?
|
24
|
-
end
|
25
|
-
|
26
|
-
end
|
@@ -1,37 +0,0 @@
|
|
1
|
-
require 'oauth/consumer'
|
2
|
-
|
3
|
-
class IknowOauthToken < ActiveRecord::Base
|
4
|
-
|
5
|
-
def self.consumer
|
6
|
-
@@consumer ||= OAuth::Consumer.new(
|
7
|
-
Iknow::Config.oauth_consumer_key,
|
8
|
-
Iknow::Config.oauth_consumer_secret,
|
9
|
-
:site => Iknow::Config.iknow_api_base_url,
|
10
|
-
:authorize_url => "#{Iknow::Config.iknow_base_url}/oauth/authorize"
|
11
|
-
)
|
12
|
-
end
|
13
|
-
|
14
|
-
def self.new_request_token
|
15
|
-
begin
|
16
|
-
self.consumer.get_request_token
|
17
|
-
rescue Exception => e
|
18
|
-
nil
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
def self.establish_auth_token(iknow_username, request_token)
|
23
|
-
access_token = request_token.get_access_token
|
24
|
-
|
25
|
-
auth_token = IknowAuthToken.new
|
26
|
-
auth_token.username = iknow_username
|
27
|
-
auth_token.token = access_token.token
|
28
|
-
auth_token.secret = access_token.secret
|
29
|
-
auth_token.save!
|
30
|
-
end
|
31
|
-
|
32
|
-
def to_access_token
|
33
|
-
OAuth::AccessToken.new(self.class.consumer, self.token, self.secret)
|
34
|
-
end
|
35
|
-
|
36
|
-
end
|
37
|
-
|
@@ -1,15 +0,0 @@
|
|
1
|
-
class CreateIknowOauthTokens < ActiveRecord::Migration
|
2
|
-
def self.up
|
3
|
-
create_table :iknow_oauth_tokens do |t|
|
4
|
-
t.column :iknow_username, :string, :null => false
|
5
|
-
t.column :token, :string, :unique => true
|
6
|
-
t.column :secret, :string
|
7
|
-
end
|
8
|
-
add_index :iknow_oauth_tokens, :token, :unique => true
|
9
|
-
add_index :iknow_oauth_tokens, :iknow_username
|
10
|
-
end
|
11
|
-
|
12
|
-
def self.down
|
13
|
-
drop_table :iknow_oauth_tokens
|
14
|
-
end
|
15
|
-
end
|