cloud_file 0.0.1
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/.document +5 -0
- data/.lre +1 -0
- data/.rspec +2 -0
- data/Gemfile +39 -0
- data/Gemfile.lock +128 -0
- data/Guardfile +11 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +19 -0
- data/Rakefile +49 -0
- data/VERSION +1 -0
- data/cloud_file.gemspec +117 -0
- data/lib/cloud_file.rb +108 -0
- data/lib/cloud_file/address.rb +43 -0
- data/lib/cloud_file/cloud_uri.rb +10 -0
- data/lib/cloud_file/cloud_uri/dsl.rb +80 -0
- data/lib/cloud_file/convertors.rb +76 -0
- data/lib/cloud_file/copy.rb +15 -0
- data/lib/cloud_file/file.rb +28 -0
- data/lib/cloud_file/outer_service.rb +22 -0
- data/lib/cloud_file/providers/dropbox.rb +25 -0
- data/lib/cloud_file/providers/evernote.rb +78 -0
- data/lib/cloud_file/providers/gdrive.rb +39 -0
- data/lib/cloud_file/providers/local.rb +19 -0
- data/lib/cloud_file/providers/memory.rb +25 -0
- data/lib/cloud_file/service.rb +82 -0
- data/lib/cloud_file/services.rb +25 -0
- data/spec/cassettes/most.yml +307 -0
- data/spec/cloud_file_spec.rb +20 -0
- data/spec/cloud_uri_spec.rb +66 -0
- data/spec/providers/memory_spec.rb +24 -0
- data/spec/spec_helper.rb +104 -0
- data/vol/copy_test.rb +3 -0
- data/vol/gsub_test.rb +1 -0
- metadata +339 -0
@@ -0,0 +1,25 @@
|
|
1
|
+
module CloudFile
|
2
|
+
class Memory < Service
|
3
|
+
register :provider => "memory"
|
4
|
+
uri_format ":key"
|
5
|
+
|
6
|
+
def read(key)
|
7
|
+
world[key.to_s]
|
8
|
+
end
|
9
|
+
def write(key,val)
|
10
|
+
world[key.to_s] = val
|
11
|
+
end
|
12
|
+
fattr(:world) { {} }
|
13
|
+
|
14
|
+
class << self
|
15
|
+
fattr(:instance) { new }
|
16
|
+
def method_missing(sym,*args,&b)
|
17
|
+
instance.send(sym,*args,&b)
|
18
|
+
end
|
19
|
+
|
20
|
+
def for_user(user)
|
21
|
+
instance
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
module CloudFile
|
2
|
+
class Service
|
3
|
+
include FromHash
|
4
|
+
fattr(:auth_hash) { {} }
|
5
|
+
class << self
|
6
|
+
def auth_value(*args)
|
7
|
+
args.flatten.each do |meth|
|
8
|
+
define_method(meth) do
|
9
|
+
auth_hash[meth.to_s]
|
10
|
+
end
|
11
|
+
define_method("#{meth}=") do |val|
|
12
|
+
auth_hash[meth.to_s] = val
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
auth_value :access_token, :access_secret
|
19
|
+
|
20
|
+
def read(ops)
|
21
|
+
raise NotImplementedError.new("read")
|
22
|
+
end
|
23
|
+
def write(ops,val)
|
24
|
+
raise NotImplementedError.new("write")
|
25
|
+
end
|
26
|
+
|
27
|
+
def read_format(target_format,ops)
|
28
|
+
::CloudFile::Convertors.convert(self.class.format,target_format,read(ops))
|
29
|
+
end
|
30
|
+
|
31
|
+
def files(*args)
|
32
|
+
list(*args).map do |f|
|
33
|
+
CloudFile::File.new(:service => self, :loc => f)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
def open(ops)
|
40
|
+
file = CloudFile::File.new(:loc => ops, :service => self)
|
41
|
+
if block_given?
|
42
|
+
yield(file)
|
43
|
+
end
|
44
|
+
file
|
45
|
+
end
|
46
|
+
|
47
|
+
class << self
|
48
|
+
def for_user(user)
|
49
|
+
#puts user.identities.map { |x| x.provider }.inspect
|
50
|
+
#puts name
|
51
|
+
ident = user.identities.find { |x| x.provider == provider }
|
52
|
+
new(:access_token => ident.access_token, :access_secret => ident.access_secret)
|
53
|
+
end
|
54
|
+
|
55
|
+
attr_accessor :provider, :format, :location_params
|
56
|
+
def register(ops)
|
57
|
+
::CloudFile::Services << self
|
58
|
+
ops.each do |k,v|
|
59
|
+
send("#{k}=",v)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
def register_converter(ops,&b)
|
63
|
+
::CloudFile::Convertors.register(ops,&b)
|
64
|
+
end
|
65
|
+
|
66
|
+
def location_params(*args)
|
67
|
+
if args.empty?
|
68
|
+
instance_variable_get("@location_params")
|
69
|
+
else
|
70
|
+
self.location_params = args.flatten
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
attr_accessor :uri_parser
|
75
|
+
def uri_format(str)
|
76
|
+
CloudUri::Dsl.new(:service_class => self, :format => str).run!
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
|
81
|
+
end
|
82
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module CloudFile
|
2
|
+
class Services
|
3
|
+
include FromHash
|
4
|
+
|
5
|
+
fattr(:list) { [] }
|
6
|
+
def <<(s)
|
7
|
+
self.list << s
|
8
|
+
end
|
9
|
+
|
10
|
+
def service_class(provider)
|
11
|
+
res = list.find { |x| x.provider.to_s == provider.to_s }
|
12
|
+
if !res
|
13
|
+
raise "no class found for #{provider}, ops are " + list.map { |x| x.provider }.inspect
|
14
|
+
end
|
15
|
+
res
|
16
|
+
end
|
17
|
+
|
18
|
+
class << self
|
19
|
+
fattr(:instance) { new }
|
20
|
+
def method_missing(sym,*args,&b)
|
21
|
+
instance.send(sym,*args,&b)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,307 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: https://api.dropbox.com/1/metadata/dropbox/test/abc.txt?
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers:
|
10
|
+
Accept:
|
11
|
+
- ! '*/*'
|
12
|
+
User-Agent:
|
13
|
+
- OAuth gem v0.4.7
|
14
|
+
Authorization:
|
15
|
+
- OAuth oauth_consumer_key="wncno17ygixgpy2", oauth_nonce="OFBcHhkkrDGXmi49aG7iOuqD2KmFRgPZ5yVXM2s",
|
16
|
+
oauth_signature="jAg%2FJcHyWvEazZFL5tKPZc7fFHQ%3D", oauth_signature_method="HMAC-SHA1",
|
17
|
+
oauth_timestamp="1360086259", oauth_token="930fjrsep84llr7", oauth_version="1.0"
|
18
|
+
response:
|
19
|
+
status:
|
20
|
+
code: 200
|
21
|
+
message: OK
|
22
|
+
headers:
|
23
|
+
Server:
|
24
|
+
- nginx
|
25
|
+
Date:
|
26
|
+
- Tue, 05 Feb 2013 17:44:18 GMT
|
27
|
+
Content-Type:
|
28
|
+
- text/javascript
|
29
|
+
Transfer-Encoding:
|
30
|
+
- chunked
|
31
|
+
Connection:
|
32
|
+
- keep-alive
|
33
|
+
Access-Control-Expose-Headers:
|
34
|
+
- X-Dropbox-Metadata, Accept-Ranges, Content-Range
|
35
|
+
Pragma:
|
36
|
+
- no-cache
|
37
|
+
Cache-Control:
|
38
|
+
- no-cache
|
39
|
+
X-Frame-Options:
|
40
|
+
- SAMEORIGIN
|
41
|
+
Access-Control-Allow-Origin:
|
42
|
+
- ! '*'
|
43
|
+
body:
|
44
|
+
encoding: US-ASCII
|
45
|
+
string: ! '{"revision": 201705, "rev": "313e900a671c6", "thumb_exists": false,
|
46
|
+
"bytes": 3, "modified": "Fri, 01 Feb 2013 22:13:52 +0000", "client_mtime":
|
47
|
+
"Fri, 01 Feb 2013 22:13:50 +0000", "path": "/test/abc.txt", "is_dir": false,
|
48
|
+
"icon": "page_white_text", "root": "dropbox", "mime_type": "text/plain", "size":
|
49
|
+
"3 bytes"}'
|
50
|
+
http_version:
|
51
|
+
recorded_at: Tue, 05 Feb 2013 17:44:21 GMT
|
52
|
+
- request:
|
53
|
+
method: post
|
54
|
+
uri: https://api.dropbox.com/1/media/dropbox/test/abc.txt
|
55
|
+
body:
|
56
|
+
encoding: US-ASCII
|
57
|
+
string: ''
|
58
|
+
headers:
|
59
|
+
Accept:
|
60
|
+
- ! '*/*'
|
61
|
+
User-Agent:
|
62
|
+
- OAuth gem v0.4.7
|
63
|
+
Content-Length:
|
64
|
+
- '0'
|
65
|
+
Content-Type:
|
66
|
+
- application/x-www-form-urlencoded
|
67
|
+
Authorization:
|
68
|
+
- OAuth oauth_consumer_key="wncno17ygixgpy2", oauth_nonce="wb890glIMOOXH3lAtaO2rdnh43QK6gs03dpzABc",
|
69
|
+
oauth_signature="0%2Fyjb%2B4xn7PXeMCjjTCnlHfoYXo%3D", oauth_signature_method="HMAC-SHA1",
|
70
|
+
oauth_timestamp="1360086261", oauth_token="930fjrsep84llr7", oauth_version="1.0"
|
71
|
+
response:
|
72
|
+
status:
|
73
|
+
code: 200
|
74
|
+
message: OK
|
75
|
+
headers:
|
76
|
+
Server:
|
77
|
+
- nginx
|
78
|
+
Date:
|
79
|
+
- Tue, 05 Feb 2013 17:44:19 GMT
|
80
|
+
Content-Type:
|
81
|
+
- text/javascript
|
82
|
+
Transfer-Encoding:
|
83
|
+
- chunked
|
84
|
+
Connection:
|
85
|
+
- keep-alive
|
86
|
+
Access-Control-Expose-Headers:
|
87
|
+
- X-Dropbox-Metadata, Accept-Ranges, Content-Range
|
88
|
+
Pragma:
|
89
|
+
- no-cache
|
90
|
+
Cache-Control:
|
91
|
+
- no-cache
|
92
|
+
X-Frame-Options:
|
93
|
+
- SAMEORIGIN
|
94
|
+
Access-Control-Allow-Origin:
|
95
|
+
- ! '*'
|
96
|
+
body:
|
97
|
+
encoding: US-ASCII
|
98
|
+
string: ! '{"url": "https://dl.dropbox.com/0/view/x8dwszaqm0c1cj1/test/abc.txt",
|
99
|
+
"expires": "Tue, 05 Feb 2013 21:44:19 +0000"}'
|
100
|
+
http_version:
|
101
|
+
recorded_at: Tue, 05 Feb 2013 17:44:21 GMT
|
102
|
+
- request:
|
103
|
+
method: get
|
104
|
+
uri: https://api-content.dropbox.com/1/files/dropbox/test/abc.txt?
|
105
|
+
body:
|
106
|
+
encoding: US-ASCII
|
107
|
+
string: ''
|
108
|
+
headers:
|
109
|
+
Accept:
|
110
|
+
- ! '*/*'
|
111
|
+
User-Agent:
|
112
|
+
- OAuth gem v0.4.7
|
113
|
+
Authorization:
|
114
|
+
- OAuth oauth_consumer_key="wncno17ygixgpy2", oauth_nonce="hH6vd44NRY2f9bOL7vks1LpWgojhJCMPTMsdHZ5eqAc",
|
115
|
+
oauth_signature="CmTtznFChhVA6xwPv0f9UnLyOeI%3D", oauth_signature_method="HMAC-SHA1",
|
116
|
+
oauth_timestamp="1360086261", oauth_token="930fjrsep84llr7", oauth_version="1.0"
|
117
|
+
response:
|
118
|
+
status:
|
119
|
+
code: 200
|
120
|
+
message: OK
|
121
|
+
headers:
|
122
|
+
Server:
|
123
|
+
- nginx/1.2.6
|
124
|
+
Date:
|
125
|
+
- Tue, 05 Feb 2013 17:44:20 GMT
|
126
|
+
Content-Type:
|
127
|
+
- text/plain; charset=ascii
|
128
|
+
Content-Length:
|
129
|
+
- '3'
|
130
|
+
Connection:
|
131
|
+
- keep-alive
|
132
|
+
Access-Control-Expose-Headers:
|
133
|
+
- X-Dropbox-Metadata, Accept-Ranges, Content-Range
|
134
|
+
Accept-Ranges:
|
135
|
+
- bytes
|
136
|
+
X-Dropbox-Metadata:
|
137
|
+
- ! '{"revision": 201705, "rev": "313e900a671c6", "thumb_exists": false, "bytes":
|
138
|
+
3, "modified": "Fri, 01 Feb 2013 22:13:52 +0000", "client_mtime": "Fri, 01
|
139
|
+
Feb 2013 22:13:50 +0000", "path": "/test/abc.txt", "is_dir": false, "icon":
|
140
|
+
"page_white_text", "root": "dropbox", "mime_type": "text/plain", "size": "3
|
141
|
+
bytes"}'
|
142
|
+
Etag:
|
143
|
+
- 201705n
|
144
|
+
Pragma:
|
145
|
+
- public
|
146
|
+
Cache-Control:
|
147
|
+
- max-age=0
|
148
|
+
Access-Control-Allow-Origin:
|
149
|
+
- ! '*'
|
150
|
+
body:
|
151
|
+
encoding: US-ASCII
|
152
|
+
string: foo
|
153
|
+
http_version:
|
154
|
+
recorded_at: Tue, 05 Feb 2013 17:44:22 GMT
|
155
|
+
- request:
|
156
|
+
method: get
|
157
|
+
uri: https://api.dropbox.com/1/metadata/dropbox/test/abc.txt?
|
158
|
+
body:
|
159
|
+
encoding: US-ASCII
|
160
|
+
string: ''
|
161
|
+
headers:
|
162
|
+
Accept:
|
163
|
+
- ! '*/*'
|
164
|
+
User-Agent:
|
165
|
+
- OAuth gem v0.4.7
|
166
|
+
Authorization:
|
167
|
+
- OAuth oauth_consumer_key="wncno17ygixgpy2", oauth_nonce="gOyj2ZrbU1FU7hy8MQP4GgWCvAHjLJEE92bD2CfCdA",
|
168
|
+
oauth_signature="%2FWtNT8lawrMTu7AUSY65xrM4XC0%3D", oauth_signature_method="HMAC-SHA1",
|
169
|
+
oauth_timestamp="1360086262", oauth_token="930fjrsep84llr7", oauth_version="1.0"
|
170
|
+
response:
|
171
|
+
status:
|
172
|
+
code: 200
|
173
|
+
message: OK
|
174
|
+
headers:
|
175
|
+
Server:
|
176
|
+
- nginx
|
177
|
+
Date:
|
178
|
+
- Tue, 05 Feb 2013 17:44:20 GMT
|
179
|
+
Content-Type:
|
180
|
+
- text/javascript
|
181
|
+
Transfer-Encoding:
|
182
|
+
- chunked
|
183
|
+
Connection:
|
184
|
+
- keep-alive
|
185
|
+
Access-Control-Expose-Headers:
|
186
|
+
- X-Dropbox-Metadata, Accept-Ranges, Content-Range
|
187
|
+
Pragma:
|
188
|
+
- no-cache
|
189
|
+
Cache-Control:
|
190
|
+
- no-cache
|
191
|
+
X-Frame-Options:
|
192
|
+
- SAMEORIGIN
|
193
|
+
Access-Control-Allow-Origin:
|
194
|
+
- ! '*'
|
195
|
+
body:
|
196
|
+
encoding: US-ASCII
|
197
|
+
string: ! '{"revision": 201705, "rev": "313e900a671c6", "thumb_exists": false,
|
198
|
+
"bytes": 3, "modified": "Fri, 01 Feb 2013 22:13:52 +0000", "client_mtime":
|
199
|
+
"Fri, 01 Feb 2013 22:13:50 +0000", "path": "/test/abc.txt", "is_dir": false,
|
200
|
+
"icon": "page_white_text", "root": "dropbox", "mime_type": "text/plain", "size":
|
201
|
+
"3 bytes"}'
|
202
|
+
http_version:
|
203
|
+
recorded_at: Tue, 05 Feb 2013 17:44:23 GMT
|
204
|
+
- request:
|
205
|
+
method: post
|
206
|
+
uri: https://api.dropbox.com/1/media/dropbox/test/abc.txt
|
207
|
+
body:
|
208
|
+
encoding: US-ASCII
|
209
|
+
string: ''
|
210
|
+
headers:
|
211
|
+
Accept:
|
212
|
+
- ! '*/*'
|
213
|
+
User-Agent:
|
214
|
+
- OAuth gem v0.4.7
|
215
|
+
Content-Length:
|
216
|
+
- '0'
|
217
|
+
Content-Type:
|
218
|
+
- application/x-www-form-urlencoded
|
219
|
+
Authorization:
|
220
|
+
- OAuth oauth_consumer_key="wncno17ygixgpy2", oauth_nonce="0eKNduMT7Xu78n8q43IiWdTNNXsjqRKDmZO1KKWg",
|
221
|
+
oauth_signature="cEpuY4muU5cvuJDeWzXKDWUgXSs%3D", oauth_signature_method="HMAC-SHA1",
|
222
|
+
oauth_timestamp="1360086263", oauth_token="930fjrsep84llr7", oauth_version="1.0"
|
223
|
+
response:
|
224
|
+
status:
|
225
|
+
code: 200
|
226
|
+
message: OK
|
227
|
+
headers:
|
228
|
+
Server:
|
229
|
+
- nginx
|
230
|
+
Date:
|
231
|
+
- Tue, 05 Feb 2013 17:44:21 GMT
|
232
|
+
Content-Type:
|
233
|
+
- text/javascript
|
234
|
+
Transfer-Encoding:
|
235
|
+
- chunked
|
236
|
+
Connection:
|
237
|
+
- keep-alive
|
238
|
+
Access-Control-Expose-Headers:
|
239
|
+
- X-Dropbox-Metadata, Accept-Ranges, Content-Range
|
240
|
+
Pragma:
|
241
|
+
- no-cache
|
242
|
+
Cache-Control:
|
243
|
+
- no-cache
|
244
|
+
X-Frame-Options:
|
245
|
+
- SAMEORIGIN
|
246
|
+
Access-Control-Allow-Origin:
|
247
|
+
- ! '*'
|
248
|
+
body:
|
249
|
+
encoding: US-ASCII
|
250
|
+
string: ! '{"url": "https://dl.dropbox.com/0/view/x8dwszaqm0c1cj1/test/abc.txt",
|
251
|
+
"expires": "Tue, 05 Feb 2013 21:44:21 +0000"}'
|
252
|
+
http_version:
|
253
|
+
recorded_at: Tue, 05 Feb 2013 17:44:23 GMT
|
254
|
+
- request:
|
255
|
+
method: get
|
256
|
+
uri: https://api-content.dropbox.com/1/files/dropbox/test/abc.txt?
|
257
|
+
body:
|
258
|
+
encoding: US-ASCII
|
259
|
+
string: ''
|
260
|
+
headers:
|
261
|
+
Accept:
|
262
|
+
- ! '*/*'
|
263
|
+
User-Agent:
|
264
|
+
- OAuth gem v0.4.7
|
265
|
+
Authorization:
|
266
|
+
- OAuth oauth_consumer_key="wncno17ygixgpy2", oauth_nonce="UvkwvYx6u9vLuBJtzfoRihIg3HtOzhF3q1w7Xg3TL0",
|
267
|
+
oauth_signature="%2FRj%2F5myxRyNlEezFrmfnFrRGjdQ%3D", oauth_signature_method="HMAC-SHA1",
|
268
|
+
oauth_timestamp="1360086263", oauth_token="930fjrsep84llr7", oauth_version="1.0"
|
269
|
+
response:
|
270
|
+
status:
|
271
|
+
code: 200
|
272
|
+
message: OK
|
273
|
+
headers:
|
274
|
+
Server:
|
275
|
+
- nginx/1.2.6
|
276
|
+
Date:
|
277
|
+
- Tue, 05 Feb 2013 17:44:21 GMT
|
278
|
+
Content-Type:
|
279
|
+
- text/plain; charset=ascii
|
280
|
+
Content-Length:
|
281
|
+
- '3'
|
282
|
+
Connection:
|
283
|
+
- keep-alive
|
284
|
+
Access-Control-Expose-Headers:
|
285
|
+
- X-Dropbox-Metadata, Accept-Ranges, Content-Range
|
286
|
+
Accept-Ranges:
|
287
|
+
- bytes
|
288
|
+
X-Dropbox-Metadata:
|
289
|
+
- ! '{"revision": 201705, "rev": "313e900a671c6", "thumb_exists": false, "bytes":
|
290
|
+
3, "modified": "Fri, 01 Feb 2013 22:13:52 +0000", "client_mtime": "Fri, 01
|
291
|
+
Feb 2013 22:13:50 +0000", "path": "/test/abc.txt", "is_dir": false, "icon":
|
292
|
+
"page_white_text", "root": "dropbox", "mime_type": "text/plain", "size": "3
|
293
|
+
bytes"}'
|
294
|
+
Etag:
|
295
|
+
- 201705n
|
296
|
+
Pragma:
|
297
|
+
- public
|
298
|
+
Cache-Control:
|
299
|
+
- max-age=0
|
300
|
+
Access-Control-Allow-Origin:
|
301
|
+
- ! '*'
|
302
|
+
body:
|
303
|
+
encoding: US-ASCII
|
304
|
+
string: foo
|
305
|
+
http_version:
|
306
|
+
recorded_at: Tue, 05 Feb 2013 17:44:24 GMT
|
307
|
+
recorded_with: VCR 2.4.0
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
vcr_options = { :cassette_name => "most", :record => :new_episodes }
|
4
|
+
describe "CloudFile", :vcr => vcr_options do
|
5
|
+
it "smoke" do
|
6
|
+
2.should == 2
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'dropbox read' do
|
10
|
+
CloudFile.open(:user => Tokens.user, :provider => "dropbox", :loc => {:path => "test/abc.txt"}) do |f|
|
11
|
+
str = f.read
|
12
|
+
#puts f.read
|
13
|
+
f.read.should == 'foo'
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'dropbox 2' do
|
18
|
+
CloudFile.read("dropbox://test/abc.txt").should == 'foo'
|
19
|
+
end
|
20
|
+
end
|