worochi 0.0.17 → 0.0.18

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ba19eba17277fa5f087571933bc694748ab1d5bc
4
- data.tar.gz: caf94af71f2b4604cdca507712ec0d7021733496
3
+ metadata.gz: a2a18845c1adcadfe7c424ac39bf2d9d8a66ae5e
4
+ data.tar.gz: ea90cb0fb85aa177b54226862af3cd56f9b80487
5
5
  SHA512:
6
- metadata.gz: 53d259f34d1d476bc244e7fe6be7da7f8fe2b9f768795e9b47d58a1d75677e05b9ef4106c415985a959764ca96424fc50fa410bab9a92a78c8b3ccfa78ae2bea
7
- data.tar.gz: 5ae4f9391864dd60cf2f3cd00ecdf9238ac3ef5b027f0ed1b2be3eb2dc0fc27686a9739264c8543ce134045c6288f7c1521716b5b401aea39285531d500b552e
6
+ metadata.gz: dcf3004c8fe46c9ed7df05d05bcea8d312eb0109f4fff883fd54f7640abb0118163b189df4892d0f73196443beb9b52d78780631cb3d98f60e5bd1260d39b2d2
7
+ data.tar.gz: 227612326f57102371ee6e94a4ffdfd53c50ff063f61440cdd98e050f4cc4c82a0280b3ad6b18a46cc2515a1bb7bbcbfa11745edf8c26191e705612d335a831d
data/README.md CHANGED
@@ -156,10 +156,6 @@ Tokens are hashes and `refresh` expects a hash containing the field
156
156
 
157
157
  Currently these services are fully supported:
158
158
 
159
- **Google Drive**
160
- - Service name `:google_drive`
161
- - Env variables `GOOGLE_ID` `GOOGLE_SECRET` `GOOGLE_TEST_TOKEN`
162
-
163
159
  **Dropbox**
164
160
  - Service name `:dropbox`
165
161
  - Env variables `DROPBOX_ID` `DROPBOX_SECRET` `DROPBOX_TEST_TOKEN`
@@ -168,6 +164,14 @@ Currently these services are fully supported:
168
164
  - Service name `:github`
169
165
  - Env variables `GITHUB_ID` `GITHUB_SECRET` `GITHUB_TEST_TOKEN`
170
166
 
167
+ **Google Drive**
168
+ - Service name `:google_drive`
169
+ - Env variables `GOOGLE_ID` `GOOGLE_SECRET` `GOOGLE_TEST_TOKEN`
170
+
171
+ **Box**
172
+ - Service name `:box`
173
+ - Env variables `BOX_ID` `BOX_SECRET` `BOX_TEST_TOKEN`
174
+
171
175
  ### Environmental Variables
172
176
 
173
177
  `ID` and `SECRET` variables are only needed for retrieving access tokens and
data/circle.yml CHANGED
@@ -8,12 +8,13 @@ machine:
8
8
  AWS_SECRET_ACCESS_KEY: abc
9
9
  BOX_ID: abc
10
10
  BOX_SECRET: abc
11
- GOOGLE_ID: abc
12
- GOOGLE_SECRET: abc
13
- GITHUB_ID: abc
14
- GITHUB_SECRET: abc
11
+ BOX_TEST_TOKEN: abc
15
12
  DROPBOX_ID: abc
16
13
  DROPBOX_SECRET: abc
17
- GITHUB_TEST_TOKEN: abc
18
14
  DROPBOX_TEST_TOKEN: abc
15
+ GITHUB_ID: abc
16
+ GITHUB_SECRET: abc
17
+ GITHUB_TEST_TOKEN: abc
18
+ GOOGLE_ID: abc
19
+ GOOGLE_SECRET: abc
19
20
  GOOGLE_TEST_TOKEN: abc
@@ -246,7 +246,6 @@ end
246
246
  Worochi::Config.services.each do |service|
247
247
  begin
248
248
  require "worochi/agent/#{service}"
249
- rescue LoadError
250
- Worochi::Log.warn "Found #{service}.yml but not #{service}.rb"
249
+ rescue LoadError # yml is defined but not the agent
251
250
  end
252
251
  end
@@ -41,7 +41,7 @@ class Worochi
41
41
  # @see Agent#folders
42
42
  # @see Agent#files
43
43
  def list(path=nil)
44
- remote_path = path || options[:dir]
44
+ remote_path = list_path(path)
45
45
  result = @client.get_file_list(remote_path)
46
46
  result.map do |elem|
47
47
  {
@@ -0,0 +1,78 @@
1
+ require 'ruby-box'
2
+
3
+ class Worochi
4
+ # The {Agent} for Box API.
5
+ # @see https://github.com/attachmentsme/ruby-box
6
+ class Agent::Box < Agent
7
+ # Initializes ruby-box client.
8
+ #
9
+ # @return [RubyBox::Client]
10
+ def init_client
11
+ session = RubyBox::Session.new(
12
+ client_id: 'dummy_id',
13
+ access_token: options[:token])
14
+ @client = RubyBox::Client.new(session)
15
+ end
16
+
17
+ # Returns a list of files and subdirectories at the remote path specified
18
+ # by `options[:dir]`.
19
+ #
20
+ # @param path [String] path to list instead of the current directory
21
+ # @return [Array<Hash>] list of files and subdirectories
22
+ def list(path=nil)
23
+ remote_path = list_path(path)
24
+ begin
25
+ folder = @client.folder(remote_path)
26
+ raise Error if folder.nil?
27
+ folder.items.map do |elem|
28
+ {
29
+ name: elem.name,
30
+ path: "#{remote_path}/#{elem.name}",
31
+ type: elem.type
32
+ }
33
+ end
34
+ rescue RubyBox::AuthError
35
+ box_error
36
+ end
37
+ end
38
+
39
+ # Push a single {Item} to Box.
40
+ #
41
+ # @param item [Item]
42
+ def push_item(item)
43
+ abs_path = full_path(item.path)
44
+ begin
45
+ folder = @client.create_folder(File.dirname(abs_path))
46
+ raise Error if folder.nil?
47
+ folder.upload_file(item.filename, item.content, true)
48
+ rescue RubyBox::AuthError
49
+ box_error
50
+ end
51
+ nil
52
+ end
53
+
54
+ # Deletes the file at `path` from Box.
55
+ #
56
+ # @param path [String] path relative to current directory
57
+ # @return [Boolean] `true` if a file was actually deleted
58
+ def delete(path)
59
+ abs_path = full_path(path)
60
+ begin
61
+ file = @client.file(abs_path)
62
+ return false if file.nil?
63
+ file.delete
64
+ rescue RubyBox::AuthError
65
+ box_error
66
+ end
67
+ true
68
+ end
69
+
70
+ private
71
+
72
+ # Box tokens can expire so the user should check for this error to and
73
+ # refresh the access token when necessary.
74
+ def box_error
75
+ raise Error, 'Box access token is valid or has expired'
76
+ end
77
+ end
78
+ end
@@ -1,4 +1,4 @@
1
1
  class Worochi
2
2
  # Current version of the gem
3
- VERSION = '0.0.17'
3
+ VERSION = '0.0.18'
4
4
  end
@@ -29,7 +29,8 @@ end
29
29
  test_token_prefix = {
30
30
  google_drive: 'GOOGLE',
31
31
  dropbox: 'DROPBOX',
32
- github: 'GITHUB'
32
+ github: 'GITHUB',
33
+ box: 'BOX'
33
34
  }
34
35
 
35
36
  # Removes sensitive keys from recordings
@@ -69,7 +70,7 @@ RSpec.configure do |c|
69
70
  if ENV["#{prefix}_TEST_TOKEN"].nil?
70
71
  c.filter_run_excluding service
71
72
  service_name = Worochi::Config.service_display_name(service)
72
- puts "#{prefix}_TEST_TOKEN not found. Skipping Google Drive tests."
73
+ puts "#{prefix}_TEST_TOKEN not found. Skipping #{service_name} tests."
73
74
  end
74
75
  end
75
- end
76
+ end
@@ -0,0 +1,34 @@
1
+ require 'spec_helper'
2
+
3
+ describe Worochi::Agent::Box, :box do
4
+ let(:required_keys) { [] }
5
+ let(:client_class) { RubyBox::Client }
6
+
7
+ let(:agent) do
8
+ Worochi::Agent::Box.new(
9
+ token: ENV['BOX_TEST_TOKEN'],
10
+ dir: '/worochi/test')
11
+ end
12
+
13
+ it_should_behave_like 'a service agent'
14
+
15
+ describe '#push_item', :vcr do
16
+ it 'pushes a single item' do
17
+ item = Worochi::Item.open_single(local.source)
18
+ agent.push_item(item)
19
+ expect(agent.files).to include(local.name)
20
+ agent.delete(local.name)
21
+ expect(agent.files).not_to include(local.name)
22
+ end
23
+ end
24
+
25
+ describe '#box_error', :vcr do
26
+ it 'raises an error on expired/invalid tokens' do
27
+ bad_agent = Worochi::Agent::Box.new(token: 'badtoken')
28
+ expect{bad_agent.files}.to raise_error(Worochi::Error)
29
+ item = Worochi::Item.open_single(local.source)
30
+ expect{bad_agent.push_item(item)}.to raise_error(Worochi::Error)
31
+ expect{bad_agent.delete(local.name)}.to raise_error(Worochi::Error)
32
+ end
33
+ end
34
+ end
@@ -32,6 +32,7 @@ Gem::Specification.new do |s|
32
32
  s.add_runtime_dependency('dropbox-sdk') # Dropbox
33
33
  s.add_runtime_dependency('google-api-client') # Google
34
34
  s.add_runtime_dependency('octokit', ['1.25.0']) # GitHub
35
+ s.add_runtime_dependency('ruby-box') # Box
35
36
 
36
37
  s.add_development_dependency('ruby-filemagic')
37
38
  s.add_development_dependency('rspec', ['~> 2.14.1'])
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: worochi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.17
4
+ version: 0.0.18
5
5
  platform: ruby
6
6
  authors:
7
7
  - Raven Jiang
@@ -108,6 +108,20 @@ dependencies:
108
108
  - - '='
109
109
  - !ruby/object:Gem::Version
110
110
  version: 1.25.0
111
+ - !ruby/object:Gem::Dependency
112
+ name: ruby-box
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
111
125
  - !ruby/object:Gem::Dependency
112
126
  name: ruby-filemagic
113
127
  requirement: !ruby/object:Gem::Requirement
@@ -253,6 +267,7 @@ files:
253
267
  - lib/worochi/agent/github.rb
254
268
  - lib/worochi/agent/#example.rb
255
269
  - lib/worochi/agent/google_drive.rb
270
+ - lib/worochi/agent/box.rb
256
271
  - lib/worochi/agent/dropbox.rb
257
272
  - lib/worochi/helper.rb
258
273
  - lib/worochi/item.rb
@@ -274,6 +289,7 @@ files:
274
289
  - spec/worochi/helper/github_helper_spec.rb
275
290
  - spec/worochi/agent/dropbox_spec.rb
276
291
  - spec/worochi/agent/github_spec.rb
292
+ - spec/worochi/agent/box_spec.rb
277
293
  - spec/worochi/agent/google_drive_spec.rb
278
294
  - spec/worochi/config_spec.rb
279
295
  - spec/worochi/agent_spec.rb
@@ -317,6 +333,7 @@ test_files:
317
333
  - spec/worochi/helper/github_helper_spec.rb
318
334
  - spec/worochi/agent/dropbox_spec.rb
319
335
  - spec/worochi/agent/github_spec.rb
336
+ - spec/worochi/agent/box_spec.rb
320
337
  - spec/worochi/agent/google_drive_spec.rb
321
338
  - spec/worochi/config_spec.rb
322
339
  - spec/worochi/agent_spec.rb