iknow 0.0.4 → 0.1.0
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 +4 -23
- data/Rakefile +5 -2
- data/examples/pure_ruby.rb +77 -35
- data/lib/ext/hash.rb +29 -0
- data/lib/iknow/core/auth.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 +14 -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
@@ -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 IknowOauthGenerator < 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
|