springnote_resources 0.5.1 → 0.6.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/History.txt +3 -0
- data/Manifest.txt +1 -0
- data/README.korean.txt +8 -7
- data/README.txt +12 -10
- data/Rakefile +1 -0
- data/lib/exts/request_with_oauth.rb +35 -0
- data/lib/springnote/base.rb +1 -1
- data/lib/springnote/configuration.rb +29 -14
- data/lib/springnote_resources.rb +7 -1
- metadata +32 -4
data/History.txt
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
== 0.6.0 / 2008-5-6
|
2
|
+
* Support OAuth protocol. Old authententication method will be removed very soon. You should set access_token, access_token_secret, consumer_token, consumer_secret instead of app_key, user_openid, user_key
|
3
|
+
|
1
4
|
== 0.5.1 / 2008-4-8
|
2
5
|
* protocol configuration added.
|
3
6
|
|
data/Manifest.txt
CHANGED
data/README.korean.txt
CHANGED
@@ -13,6 +13,8 @@
|
|
13
13
|
|
14
14
|
* activesupport
|
15
15
|
* activeresource
|
16
|
+
* oauth
|
17
|
+
* ruby-hmac
|
16
18
|
|
17
19
|
== 설치:
|
18
20
|
|
@@ -20,17 +22,16 @@
|
|
20
22
|
|
21
23
|
== 개발자키와 사용자키 발급 및 설정:
|
22
24
|
|
23
|
-
1. 스프링노트 매시업을 작성하기 위해서는 먼저
|
24
|
-
자세한 내용은 http://dev.springnote.com/pages/
|
25
|
+
1. 스프링노트 매시업을 작성하기 위해서는 먼저 컨슈머 토큰이 필요하다. 이 키는 오픈마루 API 센터(https://api.openmaru.com/oauth/new)에서 발급받을 수 있다.
|
26
|
+
자세한 내용은 http://dev.springnote.com/pages/1083036 에서 얻을 수 있다.
|
25
27
|
|
26
|
-
2. 그리고
|
27
|
-
자세한 내용은 http://dev.springnote.com/pages/372761에서 얻을 수 있다.
|
28
|
+
2. 그리고 액세스 토큰을 발급받아야 한다.자세한 방법은 OAuth 튜토리얼을 참고하기 바란다. http://myruby.net/pages/1154148
|
28
29
|
|
29
30
|
3. 이렇게 받은 키를 스프링노트 리소스에서 사용하려면 아래처럼 설정한다.
|
30
31
|
|
31
|
-
Springnote::Base.configuration.set :
|
32
|
-
:
|
33
|
-
:
|
32
|
+
Springnote::Base.configuration.set :consumer_token => 'CK', :consumer_secret => 'CS',
|
33
|
+
:access_token => 'AK', :access_secret => 'AS',
|
34
|
+
:domain => 'notename'
|
34
35
|
|
35
36
|
== 사용법:
|
36
37
|
|
data/README.txt
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
= Springnote Resources
|
2
2
|
|
3
3
|
* Homepage: http://myruby.net/pages/391111
|
4
|
-
* Author:
|
4
|
+
* Author: deepblue (http://myruby.net) and Changshin Lee (http://www.iasandcb.pe.kr)
|
5
5
|
|
6
6
|
== DESCRIPTIONS:
|
7
7
|
|
@@ -11,6 +11,8 @@ ActiveResource wrapper library for Springnote.com's REST API
|
|
11
11
|
|
12
12
|
* activesupport
|
13
13
|
* activeresource
|
14
|
+
* oauth
|
15
|
+
* ruby-hmac
|
14
16
|
|
15
17
|
== INSTALL:
|
16
18
|
|
@@ -18,19 +20,19 @@ ActiveResource wrapper library for Springnote.com's REST API
|
|
18
20
|
|
19
21
|
== How to get keys
|
20
22
|
|
21
|
-
1. You need to register your application on Openmaru API Center and
|
22
|
-
get the
|
23
|
+
1. You need to register your application on Openmaru API Center(https://api.openmaru.com/oauth/new) and
|
24
|
+
get the consumer token. Read http://dev.springnote.com/pages/438963
|
23
25
|
for more details.
|
24
26
|
|
25
|
-
2. Now you need to get the
|
26
|
-
Read
|
27
|
+
2. Now you need to get the access token for the application you registered.
|
28
|
+
Read the OAuth tutorial for more details.
|
27
29
|
|
28
|
-
3. You have
|
29
|
-
|
30
|
+
3. You have two tokens. Configure SpringnoteResources with the information
|
31
|
+
like following code:
|
30
32
|
|
31
|
-
Springnote::Base.configuration.set :
|
32
|
-
:
|
33
|
-
:
|
33
|
+
Springnote::Base.configuration.set :consumer_token => 'CK', :consumer_secret => 'CS',
|
34
|
+
:access_token => 'AK', :access_secret => 'AS',
|
35
|
+
:domain => 'notename'
|
34
36
|
|
35
37
|
== USAGE:
|
36
38
|
|
data/Rakefile
CHANGED
@@ -11,6 +11,7 @@ Hoe.new("springnote_resources", Springnote::VERSION) do |p|
|
|
11
11
|
p.email = 'byblue@gmail.com'
|
12
12
|
p.changes = p.paragraphs_of('History.txt', 0..1).join("\n\n")
|
13
13
|
p.need_zip = true
|
14
|
+
p.extra_deps = %w(activeresource ruby-hmac oauth)
|
14
15
|
end
|
15
16
|
|
16
17
|
task :update_manifest do
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module RequestWithOauth
|
2
|
+
def self.included(mod)
|
3
|
+
mod.alias_method_chain :request, :oauth
|
4
|
+
mod.send :cattr_accessor, :oauth_configuration
|
5
|
+
end
|
6
|
+
|
7
|
+
delegate :oauth_configuration, :to => "self.class"
|
8
|
+
|
9
|
+
def request_with_oauth(method, path, *arguments)
|
10
|
+
logger.info "#{method.to_s.upcase} #{site.scheme}://#{site.host}:#{site.port}#{path}" if logger
|
11
|
+
result = nil
|
12
|
+
time = Benchmark.realtime { result = http_request(method, path, arguments) }
|
13
|
+
logger.info "--> #{result.code} #{result.message} (#{result.body ? result.body : 0}b %.2fs)" % time if logger
|
14
|
+
handle_response(result)
|
15
|
+
end
|
16
|
+
|
17
|
+
def http_request(method, path, arguments)
|
18
|
+
# old way
|
19
|
+
return http.send(method, path, *arguments) unless oauth?
|
20
|
+
|
21
|
+
# new way
|
22
|
+
logger.debug "(request with oauth)" if logger
|
23
|
+
@http = http
|
24
|
+
req = "Net::HTTP::#{method.to_s.capitalize}".constantize.new(path, *arguments)
|
25
|
+
req.oauth! @http, oauth_configuration.consumer, oauth_configuration.token, :signature_method => 'HMAC-SHA1'
|
26
|
+
|
27
|
+
@http.request(req)
|
28
|
+
end
|
29
|
+
|
30
|
+
def oauth?
|
31
|
+
oauth_configuration && oauth_configuration.consumer && oauth_configuration.token
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
ActiveResource::Connection.send :include, RequestWithOauth
|
data/lib/springnote/base.rb
CHANGED
@@ -4,18 +4,15 @@ module Springnote
|
|
4
4
|
class MissingConfiguration < RuntimeError; end
|
5
5
|
|
6
6
|
class Configuration
|
7
|
-
|
8
|
-
|
7
|
+
attr_accessor :consumer_token, :consumer_secret
|
8
|
+
attr_accessor :access_token, :access_secret
|
9
|
+
attr_accessor :protocol, :domain
|
9
10
|
|
10
11
|
SERVER_URL = "api.springnote.com"
|
11
12
|
|
12
13
|
def protocol
|
13
|
-
@protocol || '
|
14
|
-
end
|
15
|
-
|
16
|
-
def site
|
17
|
-
"#{protocol}://#{username}:#{password}@#{SERVER_URL}/"
|
18
|
-
end
|
14
|
+
@protocol || 'http'
|
15
|
+
end
|
19
16
|
|
20
17
|
def load(file)
|
21
18
|
set YAML.load(File.read(file))
|
@@ -26,6 +23,28 @@ module Springnote
|
|
26
23
|
Springnote::Base.site = self.site
|
27
24
|
self
|
28
25
|
end
|
26
|
+
|
27
|
+
def domain=(name = nil)
|
28
|
+
ActiveResource::Connection.common_params[:domain] = name
|
29
|
+
end
|
30
|
+
|
31
|
+
def site
|
32
|
+
@app_key ?
|
33
|
+
"#{protocol}://#{username}:#{password}@#{SERVER_URL}/" :
|
34
|
+
"#{protocol}://#{SERVER_URL}/"
|
35
|
+
end
|
36
|
+
|
37
|
+
def token
|
38
|
+
@token ||= OAuth::Token.new @access_token, @access_secret if @access_token && @access_secret
|
39
|
+
end
|
40
|
+
|
41
|
+
def consumer
|
42
|
+
@consumer ||= OAuth::Consumer.new @consumer_token, @consumer_secret, :site => "https://api.openmaru.com" if @consumer_token && @consumer_secret
|
43
|
+
end
|
44
|
+
|
45
|
+
# deprecated
|
46
|
+
attr_writer :app_key, :user_key
|
47
|
+
attr_writer :user_openid
|
29
48
|
|
30
49
|
def username
|
31
50
|
CGI.escape(@user_openid || 'anonymous')
|
@@ -36,11 +55,7 @@ module Springnote
|
|
36
55
|
end
|
37
56
|
|
38
57
|
def app_key
|
39
|
-
@app_key
|
40
|
-
end
|
41
|
-
|
42
|
-
def domain=(name = nil)
|
43
|
-
ActiveResource::Connection.common_params[:domain] = name
|
44
|
-
end
|
58
|
+
@app_key
|
59
|
+
end
|
45
60
|
end
|
46
61
|
end # module Springnote
|
data/lib/springnote_resources.rb
CHANGED
@@ -1,17 +1,21 @@
|
|
1
1
|
$:.unshift(File.dirname(__FILE__)) unless
|
2
2
|
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
3
3
|
|
4
|
+
require 'rubygems'
|
5
|
+
require 'oauth'
|
6
|
+
require 'oauth/consumer'
|
7
|
+
|
4
8
|
unless defined?(ActiveResource)
|
5
9
|
begin
|
6
10
|
$:.unshift(File.dirname(__FILE__) + "/../vendor/activeresource/lib")
|
7
11
|
require 'active_resource'
|
8
12
|
rescue LoadError
|
9
|
-
require 'rubygems'
|
10
13
|
require 'activeresource'
|
11
14
|
end
|
12
15
|
end
|
13
16
|
|
14
17
|
# extend activeresource
|
18
|
+
require 'exts/request_with_oauth'
|
15
19
|
require 'exts/common_parameters'
|
16
20
|
require 'exts/active_resource_extension'
|
17
21
|
|
@@ -24,3 +28,5 @@ require 'springnote/page'
|
|
24
28
|
require 'springnote/attachment'
|
25
29
|
require 'springnote/lock'
|
26
30
|
require 'springnote/revision'
|
31
|
+
|
32
|
+
ActiveResource::Connection.oauth_configuration = Springnote::Base.configuration
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: springnote_resources
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bryan Kang
|
@@ -9,9 +9,36 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-
|
12
|
+
date: 2008-05-06 00:00:00 +09:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: activeresource
|
17
|
+
version_requirement:
|
18
|
+
version_requirements: !ruby/object:Gem::Requirement
|
19
|
+
requirements:
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: "0"
|
23
|
+
version:
|
24
|
+
- !ruby/object:Gem::Dependency
|
25
|
+
name: ruby-hmac
|
26
|
+
version_requirement:
|
27
|
+
version_requirements: !ruby/object:Gem::Requirement
|
28
|
+
requirements:
|
29
|
+
- - ">="
|
30
|
+
- !ruby/object:Gem::Version
|
31
|
+
version: "0"
|
32
|
+
version:
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: oauth
|
35
|
+
version_requirement:
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: "0"
|
41
|
+
version:
|
15
42
|
- !ruby/object:Gem::Dependency
|
16
43
|
name: hoe
|
17
44
|
version_requirement:
|
@@ -21,7 +48,7 @@ dependencies:
|
|
21
48
|
- !ruby/object:Gem::Version
|
22
49
|
version: 1.5.1
|
23
50
|
version:
|
24
|
-
description: "== DESCRIPTIONS: ActiveResource wrapper library for Springnote.com's REST API == REQUIREMENTS: * activesupport * activeresource"
|
51
|
+
description: "== DESCRIPTIONS: ActiveResource wrapper library for Springnote.com's REST API == REQUIREMENTS: * activesupport * activeresource * oauth * ruby-hmac"
|
25
52
|
email: byblue@gmail.com
|
26
53
|
executables: []
|
27
54
|
|
@@ -51,6 +78,7 @@ files:
|
|
51
78
|
- lib/springnote/revision.rb
|
52
79
|
- lib/exts/active_resource_extension.rb
|
53
80
|
- lib/exts/common_parameters.rb
|
81
|
+
- lib/exts/request_with_oauth.rb
|
54
82
|
- spec/base_spec.rb
|
55
83
|
- spec/configuration_spec.rb
|
56
84
|
has_rdoc: true
|
@@ -76,7 +104,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
76
104
|
requirements: []
|
77
105
|
|
78
106
|
rubyforge_project: springnote
|
79
|
-
rubygems_version: 1.0
|
107
|
+
rubygems_version: 1.1.0
|
80
108
|
signing_key:
|
81
109
|
specification_version: 2
|
82
110
|
summary: ActiveResource wrapper library for Springnote.com's REST API
|