springnote_client 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/History.txt +3 -0
- data/lib/springnote_client/base.rb +34 -7
- data/lib/springnote_client/version.rb +1 -1
- data/lib/springnote_client.rb +26 -7
- metadata +14 -5
data/History.txt
CHANGED
@@ -23,8 +23,8 @@ module Springnote
|
|
23
23
|
class << self
|
24
24
|
def build(hsh, holder)
|
25
25
|
new_resource(collection_url(holder), holder, hsh)
|
26
|
-
end
|
27
|
-
|
26
|
+
end
|
27
|
+
|
28
28
|
def new_resource(url, holder, hash = nil)
|
29
29
|
ret = new(url, holder.username, holder.password)
|
30
30
|
ret.holder = holder
|
@@ -32,18 +32,20 @@ module Springnote
|
|
32
32
|
if block_given?
|
33
33
|
ret.hash = yield(ret)
|
34
34
|
elsif hash
|
35
|
+
identifier = hash.delete('identifier')
|
35
36
|
ret.hash = hash
|
37
|
+
ret.identifier = identifier if identifier
|
36
38
|
end
|
37
39
|
|
38
40
|
ret
|
39
41
|
end
|
40
42
|
|
41
43
|
def element_url(holder, id, params = {})
|
42
|
-
holder.
|
44
|
+
holder.make_url("/#{collection_name}/#{id}", params)
|
43
45
|
end
|
44
46
|
|
45
47
|
def collection_url(holder, params = {})
|
46
|
-
holder.
|
48
|
+
holder.make_url("/#{collection_name}", params)
|
47
49
|
end
|
48
50
|
|
49
51
|
def find(*args)
|
@@ -59,20 +61,34 @@ module Springnote
|
|
59
61
|
Hash.from_xml(ret.get(:accept => XML))[ret.singular_name]
|
60
62
|
end
|
61
63
|
end
|
64
|
+
|
65
|
+
def find_all(holder)
|
66
|
+
find_multi(holder)
|
67
|
+
end
|
62
68
|
|
63
69
|
def find_some(ids, holder)
|
64
|
-
|
70
|
+
find_multi(holder, :identifiers => ids.join(','), :detail => true)
|
71
|
+
end
|
72
|
+
|
73
|
+
def find_multi(holder, params = {})
|
74
|
+
target = collection_url(holder, params)
|
75
|
+
ret = new_resource(target, holder).get(:accept => 'application/xml')
|
76
|
+
|
65
77
|
Hash.from_xml(ret)[collection_name].map do |item|
|
66
78
|
new_resource(element_url(holder, item['identifier']), holder, item)
|
67
79
|
end
|
68
80
|
rescue RuntimeError
|
69
81
|
[]
|
70
82
|
end
|
83
|
+
|
84
|
+
def search(query, holder)
|
85
|
+
find_multi(holder, :q => query)
|
86
|
+
end
|
71
87
|
end
|
72
|
-
|
88
|
+
|
73
89
|
def method_missing(method, *args)
|
74
90
|
str = method.to_s
|
75
|
-
str[-1] ==
|
91
|
+
(str[-1].to_s == "=") ?
|
76
92
|
@hash[str[0..-2]] = args[0] :
|
77
93
|
@hash[str]
|
78
94
|
end
|
@@ -91,6 +107,17 @@ module Springnote
|
|
91
107
|
self
|
92
108
|
end
|
93
109
|
|
110
|
+
def delete
|
111
|
+
super
|
112
|
+
self.identifier = nil
|
113
|
+
end
|
114
|
+
|
115
|
+
def identifier=(newval)
|
116
|
+
@hash['identifier'] = newval
|
117
|
+
self.url = element_url
|
118
|
+
newval
|
119
|
+
end
|
120
|
+
|
94
121
|
def element_url
|
95
122
|
self.class.element_url(holder, @hash['identifier'])
|
96
123
|
end
|
data/lib/springnote_client.rb
CHANGED
@@ -12,11 +12,12 @@ module Springnote
|
|
12
12
|
attr_accessor :name, :config
|
13
13
|
|
14
14
|
# config should have app_key, user_openid, user_key
|
15
|
-
def initialize(name, config)
|
15
|
+
def initialize(name, config = {})
|
16
16
|
@name, @config = name, config
|
17
17
|
end
|
18
18
|
|
19
19
|
def pages
|
20
|
+
raise ConfigurationMissing unless @config[:app_key]
|
20
21
|
CallProxy.new(Page, self)
|
21
22
|
end
|
22
23
|
|
@@ -28,7 +29,7 @@ module Springnote
|
|
28
29
|
@config[:user_key] ? "#{@config[:user_key]}.#{@config[:app_key]}" : @config[:app_key]
|
29
30
|
end
|
30
31
|
|
31
|
-
def
|
32
|
+
def make_url(path = '/', params = {})
|
32
33
|
query = params.map{|k,v| "#{k}=#{CGI.escape(v.to_s)}"}.join('&')
|
33
34
|
"http://api.springnote.com#{path}?domain=#{@name}&#{query}"
|
34
35
|
end
|
@@ -36,12 +37,30 @@ module Springnote
|
|
36
37
|
|
37
38
|
|
38
39
|
class Page < Resource
|
39
|
-
def self.singular_name
|
40
|
-
|
40
|
+
def self.singular_name; 'page' end
|
41
|
+
def self.collection_name; 'pages' end
|
42
|
+
|
43
|
+
def attachments
|
44
|
+
CallProxy.new(Attachment, self)
|
41
45
|
end
|
42
46
|
|
43
|
-
def
|
44
|
-
|
45
|
-
|
47
|
+
def make_url(path = '/', params = {})
|
48
|
+
if self.hash
|
49
|
+
holder.make_url("/pages/#{self.hash['identifier']}#{path}", params)
|
50
|
+
else
|
51
|
+
holder.make_url(path, params)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
class Attachment < Resource
|
57
|
+
def self.singular_name; 'attachment' end
|
58
|
+
def self.collection_name; 'attachments' end
|
46
59
|
end
|
60
|
+
|
61
|
+
def make_url(path = '/', params = {})
|
62
|
+
holder.make_url(path, params)
|
63
|
+
end
|
64
|
+
|
65
|
+
class ConfigurationMissing < RuntimeError; end
|
47
66
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: springnote_client
|
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
|
- Bryan Kang
|
@@ -9,10 +9,19 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-
|
12
|
+
date: 2008-10-08 00:00:00 +09:00
|
13
13
|
default_executable:
|
14
|
-
dependencies:
|
15
|
-
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: hoe
|
17
|
+
type: :development
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 1.7.0
|
24
|
+
version:
|
16
25
|
description: Springnote Client
|
17
26
|
email:
|
18
27
|
- byblue@gmail.com
|
@@ -56,7 +65,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
56
65
|
requirements: []
|
57
66
|
|
58
67
|
rubyforge_project: springnote
|
59
|
-
rubygems_version: 1.
|
68
|
+
rubygems_version: 1.2.0
|
60
69
|
signing_key:
|
61
70
|
specification_version: 2
|
62
71
|
summary: Springnote Client
|