springnote_resources 0.2.1 → 0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +13 -0
- data/Manifest.txt +7 -1
- data/README.korean.txt +75 -0
- data/README.txt +36 -3
- data/init.rb +1 -0
- data/lib/exts/active_resource_extension.rb +25 -0
- data/lib/exts/common_parameters.rb +21 -0
- data/lib/springnote/attachment.rb +13 -0
- data/lib/springnote/base.rb +3 -1
- data/lib/springnote/configuration.rb +9 -2
- data/lib/springnote/lock.rb +2 -2
- data/lib/springnote/page.rb +15 -5
- data/lib/springnote/page_import.rb +59 -0
- data/lib/springnote/revision.rb +2 -2
- data/lib/springnote_resources.rb +8 -1
- metadata +59 -45
data/History.txt
CHANGED
@@ -1,3 +1,16 @@
|
|
1
|
+
== 0.4
|
2
|
+
* ActiveResourceExtension added.
|
3
|
+
* query pages with multiple identifiers.
|
4
|
+
* CommonParameters added. Now you can configure domain.
|
5
|
+
with CommonParametersExtension.
|
6
|
+
* Attachment has source method.
|
7
|
+
|
8
|
+
== 0.3 / 2007-12-10
|
9
|
+
* Page get search, with_tags methods.
|
10
|
+
* protocol can be changed.
|
11
|
+
* Attachment resource added
|
12
|
+
* PageImport added
|
13
|
+
|
1
14
|
== 0.2.1 / 2007-8-6
|
2
15
|
* tiny naming fix for rubygems
|
3
16
|
|
data/Manifest.txt
CHANGED
@@ -1,13 +1,19 @@
|
|
1
1
|
History.txt
|
2
2
|
Manifest.txt
|
3
3
|
README.txt
|
4
|
+
README.korean.txt
|
4
5
|
Rakefile
|
5
6
|
Todo.txt
|
7
|
+
init.rb
|
6
8
|
lib/springnote_resources.rb
|
9
|
+
lib/springnote/attachment.rb
|
7
10
|
lib/springnote/base.rb
|
8
11
|
lib/springnote/configuration.rb
|
9
12
|
lib/springnote/lock.rb
|
10
13
|
lib/springnote/page.rb
|
14
|
+
lib/springnote/page_import.rb
|
11
15
|
lib/springnote/revision.rb
|
16
|
+
lib/exts/active_resource_extension.rb
|
17
|
+
lib/exts/common_parameters.rb
|
12
18
|
spec/base_spec.rb
|
13
|
-
spec/configuration_spec.rb
|
19
|
+
spec/configuration_spec.rb
|
data/README.korean.txt
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
= Springnote Resources
|
2
|
+
|
3
|
+
* 홈페이지: http://myruby.net/pages/391111
|
4
|
+
* 제작자: deepblue (http://myruby.net), Changshin Lee (http://www.iasandcb.pe.kr)
|
5
|
+
|
6
|
+
== 설명:
|
7
|
+
|
8
|
+
스프링노트는 REST API를 제공하며, 레일스 프로젝트의 일부인 REST 클라이언트 '액티브리소스(ActiveResource)'를 통해
|
9
|
+
매우 쉽게 접근할 수 있다. 이를 활용하면, 자신의 데이터베이스에서 ORM인 액티브레코드를 이용해 데이터를 읽고 쓰는 것처럼, 액티브리소스를
|
10
|
+
이용해 스프링노트에 있는 데이터를 쉽게 다룰 수 있다.
|
11
|
+
|
12
|
+
== 요구사항:
|
13
|
+
|
14
|
+
* activesupport
|
15
|
+
* activeresource
|
16
|
+
|
17
|
+
== 설치:
|
18
|
+
|
19
|
+
* sudo gem install springnote_resources
|
20
|
+
|
21
|
+
== 개발자키와 사용자키 발급 및 설정:
|
22
|
+
|
23
|
+
1. 스프링노트 매시업을 작성하기 위해서는 먼저 개발자키가 필요하다. 이 키는 오픈마루 API 센터에서 발급받을 수 있다.
|
24
|
+
자세한 내용은 http://dev.springnote.com/pages/372760 에서 얻을 수 있다.
|
25
|
+
|
26
|
+
2. 그리고 해당 개발자키에 대한 스프링노트 사용자키를 발급받아야 한다. 이 키 또한 API 센터에서 얻을 수 있다.
|
27
|
+
자세한 내용은 http://dev.springnote.com/pages/372761에서 얻을 수 있다.
|
28
|
+
|
29
|
+
3. 이렇게 받은 키를 스프링노트 리소스에서 사용하려면 아래처럼 설정한다.
|
30
|
+
|
31
|
+
Springnote::Base.configuration.set :app_key => '__개발자키__',
|
32
|
+
:user_openid => 'http://user-open-id-url/',
|
33
|
+
:user_key => '__사용자키__'
|
34
|
+
|
35
|
+
== 사용법:
|
36
|
+
|
37
|
+
# 페이지 불러오기
|
38
|
+
page = Springnote::Page.find(144)
|
39
|
+
puts page.source
|
40
|
+
|
41
|
+
# 페이지 수정하기
|
42
|
+
page = Springnote::Page.find(144)
|
43
|
+
page.source = '<p>New Contents</p>'
|
44
|
+
page.save
|
45
|
+
|
46
|
+
# 페이지 만들기
|
47
|
+
page = Springnote::Page.create :title => 'NewName', :source => 'NewContents'
|
48
|
+
|
49
|
+
# 페이지 지우기
|
50
|
+
Springnote::Page.find(144).destroy
|
51
|
+
|
52
|
+
== LICENSE:
|
53
|
+
|
54
|
+
(The MIT License)
|
55
|
+
|
56
|
+
Copyright (c) 2007 Bryan Kang and Changshin Lee
|
57
|
+
|
58
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
59
|
+
a copy of this software and associated documentation files (the
|
60
|
+
"Software"), to deal in the Software without restriction, including
|
61
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
62
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
63
|
+
permit persons to whom the Software is furnished to do so, subject to
|
64
|
+
the following conditions:
|
65
|
+
|
66
|
+
The above copyright notice and this permission notice shall be
|
67
|
+
included in all copies or substantial portions of the Software.
|
68
|
+
|
69
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
70
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
71
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
72
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
73
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
74
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
75
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.txt
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
= Springnote Resources
|
2
2
|
|
3
|
-
* Homepage: http://
|
4
|
-
* Author: Bryan Kang (http://myruby.net)
|
3
|
+
* Homepage: http://myruby.net/pages/391111
|
4
|
+
* Author: Bryan Kang (http://myruby.net), Changshin Lee (http://www.iasandcb.pe.kr)
|
5
5
|
|
6
6
|
== DESCRIPTIONS:
|
7
7
|
|
@@ -16,11 +16,44 @@ ActiveResource wrapper library for Springnote.com's REST API
|
|
16
16
|
|
17
17
|
* sudo gem install springnote_resources
|
18
18
|
|
19
|
+
== How to get keys
|
20
|
+
|
21
|
+
1. You need to register your application on Openmaru API Center and
|
22
|
+
get the application key. Read http://dev.springnote.com/pages/438963
|
23
|
+
for more details.
|
24
|
+
|
25
|
+
2. Now you need to get the user key for the application you registered.
|
26
|
+
Read http://dev.springnote.com/pages/438944 for more details.
|
27
|
+
|
28
|
+
3. You have user OpenID, user key, and application key. Configure SpringnoteResources
|
29
|
+
with the information like following code:
|
30
|
+
|
31
|
+
Springnote::Base.configuration.set :app_key => '__ApplicationKey_Here__',
|
32
|
+
:user_openid => 'http://user-open-id-url/',
|
33
|
+
:user_key => '__UserKey_Here__'
|
34
|
+
|
35
|
+
== USAGE:
|
36
|
+
|
37
|
+
# Load a page
|
38
|
+
page = Springnote::Page.find(144)
|
39
|
+
puts page.source
|
40
|
+
|
41
|
+
# Update the page
|
42
|
+
page = Springnote::Page.find(144)
|
43
|
+
page.source = '<p>New Contents</p>'
|
44
|
+
page.save
|
45
|
+
|
46
|
+
# Create a new page
|
47
|
+
page = Springnote::Page.create :title => 'NewName', :source => 'NewContents'
|
48
|
+
|
49
|
+
# Destroy the page
|
50
|
+
Springnote::Page.find(144).destroy
|
51
|
+
|
19
52
|
== LICENSE:
|
20
53
|
|
21
54
|
(The MIT License)
|
22
55
|
|
23
|
-
Copyright (c) 2007 Bryan Kang
|
56
|
+
Copyright (c) 2007 Bryan Kang and Changshin Lee
|
24
57
|
|
25
58
|
Permission is hereby granted, free of charge, to any person obtaining
|
26
59
|
a copy of this software and associated documentation files (the
|
data/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'springnote_resources'
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module ActiveResourceExtension
|
2
|
+
def find(*args)
|
3
|
+
if multiple_query?(args)
|
4
|
+
return super(:all, :params => { :identifiers => args.join(','), :detail => true })
|
5
|
+
end
|
6
|
+
|
7
|
+
scope = args.slice!(0)
|
8
|
+
options = convert_options(args.slice!(0) || {})
|
9
|
+
super(scope, options)
|
10
|
+
|
11
|
+
# empty elements result causes error in typecast_xml_value because of xmlns of springnote
|
12
|
+
rescue RuntimeError
|
13
|
+
[]
|
14
|
+
end
|
15
|
+
|
16
|
+
protected
|
17
|
+
def multiple_query?(args)
|
18
|
+
args.size > 1 && args[0].respond_to?(:to_int) && args[1].respond_to?(:to_int)
|
19
|
+
end
|
20
|
+
|
21
|
+
def convert_options(args)
|
22
|
+
return args if args.empty? || args.include?(:from) || args.include?(:params)
|
23
|
+
{:params => args}
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module CommonParameters
|
2
|
+
def self.included(mod)
|
3
|
+
mod.alias_method_chain :request, :commons
|
4
|
+
mod.send :cattr_accessor, :common_params
|
5
|
+
mod.common_params = {}
|
6
|
+
end
|
7
|
+
|
8
|
+
def request_with_commons(method, path, *arguments)
|
9
|
+
unless common_params.empty?
|
10
|
+
path += path.include?('?') ? '&' : '?'
|
11
|
+
path += common_params.to_query
|
12
|
+
end
|
13
|
+
request_without_commons(method, path, *arguments)
|
14
|
+
end
|
15
|
+
|
16
|
+
def common_params
|
17
|
+
self.class.common_params
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
ActiveResource::Connection.send :include, CommonParameters
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Springnote
|
2
|
+
class Attachment < Base
|
3
|
+
set_prefix '/pages/:relation_is_part_of/'
|
4
|
+
|
5
|
+
def source
|
6
|
+
http = Net::HTTP.new(Springnote::Configuration::SERVER_URL, 80)
|
7
|
+
req = Net::HTTP::Get.new(element_path[0..-5])
|
8
|
+
req.basic_auth(Springnote::Base.site.user, Springnote::Base.site.password)
|
9
|
+
response = http.request(req)
|
10
|
+
response.body
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end # module Springnote
|
data/lib/springnote/base.rb
CHANGED
@@ -5,17 +5,20 @@ module Springnote
|
|
5
5
|
|
6
6
|
class Configuration
|
7
7
|
attr_writer :app_key, :user_key, :user_openid
|
8
|
+
attr_reader :domain
|
9
|
+
|
10
|
+
SERVER_PROTOCOL = 'https'
|
8
11
|
SERVER_URL = "api.springnote.com"
|
9
12
|
|
10
13
|
def site
|
11
|
-
"
|
14
|
+
"#{SERVER_PROTOCOL}://#{username}:#{password}@#{SERVER_URL}/"
|
12
15
|
end
|
13
16
|
|
14
17
|
def load(file)
|
15
18
|
set YAML.load(File.read(file))
|
16
19
|
end
|
17
20
|
|
18
|
-
def set(options)
|
21
|
+
def set(options = {})
|
19
22
|
options.each{|k,v| self.send("#{k}=", v)}
|
20
23
|
Springnote::Base.site = self.site
|
21
24
|
self
|
@@ -32,5 +35,9 @@ module Springnote
|
|
32
35
|
def app_key
|
33
36
|
@app_key or raise MissingConfiguration
|
34
37
|
end
|
38
|
+
|
39
|
+
def domain=(name = nil)
|
40
|
+
ActiveResource::Connection.common_params[:_domain] = name
|
41
|
+
end
|
35
42
|
end
|
36
43
|
end # module Springnote
|
data/lib/springnote/lock.rb
CHANGED
data/lib/springnote/page.rb
CHANGED
@@ -1,7 +1,17 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
1
|
+
class Springnote::Page < Springnote::Base
|
2
|
+
def self.with_tags(tags, params = {})
|
3
|
+
find(:all, :params => prarams.reverse_merge(:tags => tags))
|
4
|
+
end
|
5
|
+
|
6
|
+
def self.search(query, params = {})
|
7
|
+
find(:all, :params => params.reverse_merge(:q => query))
|
8
|
+
end
|
9
|
+
|
10
|
+
def lock
|
11
|
+
@lock ||= Lock.find(:relation_is_part_of => self.id)
|
12
|
+
end
|
13
|
+
|
14
|
+
def attachments
|
15
|
+
@attachments ||= Attachment.find(:all, :params => {:relation_is_part_of => self.id})
|
6
16
|
end
|
7
17
|
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
module Springnote::PageImport
|
2
|
+
BOUNDARY = 'AaB03x'
|
3
|
+
|
4
|
+
module ClassMethod
|
5
|
+
def import_file(path)
|
6
|
+
new.import_file(path)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def import_file(path)
|
11
|
+
body = File.open(path) do |f|
|
12
|
+
create_query_multipart_str({:Filedata => f}, BOUNDARY)
|
13
|
+
end
|
14
|
+
headers = self.class.headers.merge 'Content-Transfer-Encoding' => 'binary',
|
15
|
+
'Content-Length' => body.length.to_s,
|
16
|
+
'Content-Type' => "multipart/form-data; boundary=#{BOUNDARY}"
|
17
|
+
|
18
|
+
returning connection.post(collection_path, body, headers) do |response|
|
19
|
+
self.id = id_from_response(response)
|
20
|
+
load_attributes_from_response(response)
|
21
|
+
end
|
22
|
+
self
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.included(base)
|
26
|
+
base.extend(ClassMethod)
|
27
|
+
end
|
28
|
+
|
29
|
+
|
30
|
+
protected
|
31
|
+
# COPY from ruby/facets 1.8.54
|
32
|
+
def create_query_multipart_str(query, boundary)
|
33
|
+
query.collect { |attr, value|
|
34
|
+
value ||= ''
|
35
|
+
if value.is_a? File
|
36
|
+
params = {
|
37
|
+
'filename' => value.path,
|
38
|
+
# Creation time is not available from File::Stat
|
39
|
+
# 'creation-date' => value.ctime.rfc822,
|
40
|
+
'modification-date' => value.mtime.rfc822,
|
41
|
+
'read-date' => value.atime.rfc822,
|
42
|
+
}
|
43
|
+
param_str = params.to_a.collect { |k, v|
|
44
|
+
"#{k}=\"#{v}\""
|
45
|
+
}.join("; ")
|
46
|
+
"--#{boundary}\r\n" +
|
47
|
+
%{Content-Disposition: form-data; name="#{attr.to_s}"; #{param_str}\r\n} +
|
48
|
+
"Content-Transfer-Encoding: binary\r\n" +
|
49
|
+
"Content-Type: application/octet-stream\r\n\r\n#{value.read}\r\n"
|
50
|
+
else
|
51
|
+
"--#{boundary}\r\n" +
|
52
|
+
%{Content-Disposition: form-data; name="#{attr.to_s}"\r\n} +
|
53
|
+
"\r\n#{value.to_s}\r\n"
|
54
|
+
end
|
55
|
+
}.join('') + "--#{boundary}--\r\n"
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
Springnote::Page.send :include, Springnote::PageImport
|
data/lib/springnote/revision.rb
CHANGED
data/lib/springnote_resources.rb
CHANGED
@@ -7,12 +7,19 @@ unless defined?(ActiveResource)
|
|
7
7
|
require 'active_resource'
|
8
8
|
rescue LoadError
|
9
9
|
require 'rubygems'
|
10
|
-
|
10
|
+
require 'activeresource'
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
|
+
# extend activeresource
|
15
|
+
require 'exts/common_parameters'
|
16
|
+
require 'exts/active_resource_extension'
|
17
|
+
|
18
|
+
# Springnote's resources
|
14
19
|
require 'springnote/configuration'
|
15
20
|
require 'springnote/base'
|
16
21
|
require 'springnote/page'
|
22
|
+
require 'springnote/attachment'
|
17
23
|
require 'springnote/lock'
|
18
24
|
require 'springnote/revision'
|
25
|
+
|
metadata
CHANGED
@@ -1,70 +1,84 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
-
rubygems_version: 0.9.4
|
3
|
-
specification_version: 1
|
4
2
|
name: springnote_resources
|
5
3
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.
|
7
|
-
date: 2007-08-06 00:00:00 +09:00
|
8
|
-
summary: ActiveResource wrapper library for Springnote.com's REST API
|
9
|
-
require_paths:
|
10
|
-
- lib
|
11
|
-
email: byblue@gmail.com
|
12
|
-
homepage: http://deepblue.springnote.com/pages/391111
|
13
|
-
rubyforge_project: springnote
|
14
|
-
description: "== DESCRIPTIONS: ActiveResource wrapper library for Springnote.com's REST API == REQUIREMENTS: * activesupport * activeresource"
|
15
|
-
autorequire:
|
16
|
-
default_executable:
|
17
|
-
bindir: bin
|
18
|
-
has_rdoc: true
|
19
|
-
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
|
-
requirements:
|
21
|
-
- - ">"
|
22
|
-
- !ruby/object:Gem::Version
|
23
|
-
version: 0.0.0
|
24
|
-
version:
|
4
|
+
version: "0.4"
|
25
5
|
platform: ruby
|
26
|
-
signing_key:
|
27
|
-
cert_chain:
|
28
|
-
post_install_message:
|
29
6
|
authors:
|
30
7
|
- Bryan Kang
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-01-17 00:00:00 +09:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: hoe
|
17
|
+
version_requirement:
|
18
|
+
version_requirements: !ruby/object:Gem::Requirement
|
19
|
+
requirements:
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 1.4.0
|
23
|
+
version:
|
24
|
+
description: "== DESCRIPTIONS: ActiveResource wrapper library for Springnote.com's REST API == REQUIREMENTS: * activesupport * activeresource"
|
25
|
+
email: byblue@gmail.com
|
26
|
+
executables: []
|
27
|
+
|
28
|
+
extensions: []
|
29
|
+
|
30
|
+
extra_rdoc_files:
|
31
|
+
- History.txt
|
32
|
+
- Manifest.txt
|
33
|
+
- README.txt
|
34
|
+
- README.korean.txt
|
35
|
+
- Todo.txt
|
31
36
|
files:
|
32
37
|
- History.txt
|
33
38
|
- Manifest.txt
|
34
39
|
- README.txt
|
40
|
+
- README.korean.txt
|
35
41
|
- Rakefile
|
36
42
|
- Todo.txt
|
43
|
+
- init.rb
|
37
44
|
- lib/springnote_resources.rb
|
45
|
+
- lib/springnote/attachment.rb
|
38
46
|
- lib/springnote/base.rb
|
39
47
|
- lib/springnote/configuration.rb
|
40
48
|
- lib/springnote/lock.rb
|
41
49
|
- lib/springnote/page.rb
|
50
|
+
- lib/springnote/page_import.rb
|
42
51
|
- lib/springnote/revision.rb
|
52
|
+
- lib/exts/active_resource_extension.rb
|
53
|
+
- lib/exts/common_parameters.rb
|
43
54
|
- spec/base_spec.rb
|
44
55
|
- spec/configuration_spec.rb
|
45
|
-
|
46
|
-
|
56
|
+
has_rdoc: true
|
57
|
+
homepage: http://myruby.net/pages/391111
|
58
|
+
post_install_message:
|
47
59
|
rdoc_options:
|
48
60
|
- --main
|
49
61
|
- README.txt
|
50
|
-
|
51
|
-
-
|
52
|
-
|
53
|
-
|
54
|
-
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
62
|
+
require_paths:
|
63
|
+
- lib
|
64
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: "0"
|
69
|
+
version:
|
70
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: "0"
|
75
|
+
version:
|
59
76
|
requirements: []
|
60
77
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
- !ruby/object:Gem::Version
|
69
|
-
version: 1.2.2
|
70
|
-
version:
|
78
|
+
rubyforge_project: springnote
|
79
|
+
rubygems_version: 1.0.1
|
80
|
+
signing_key:
|
81
|
+
specification_version: 2
|
82
|
+
summary: ActiveResource wrapper library for Springnote.com's REST API
|
83
|
+
test_files: []
|
84
|
+
|