worochi 0.0.7 → 0.0.10

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.
Files changed (60) hide show
  1. checksums.yaml +4 -4
  2. data/lib/worochi/agent/{sample.rb → #example.rb} +2 -14
  3. data/lib/worochi/agent/dropbox.rb +3 -13
  4. data/lib/worochi/agent/github.rb +8 -23
  5. data/lib/worochi/agent.rb +46 -18
  6. data/lib/worochi/config/#example.yml +35 -0
  7. data/lib/worochi/config/dropbox.yml +14 -0
  8. data/lib/worochi/config/github.yml +17 -0
  9. data/lib/worochi/config.rb +9 -84
  10. data/lib/worochi/configurator.rb +120 -0
  11. data/lib/worochi/helper/github_helper.rb +111 -0
  12. data/lib/worochi/helper.rb +28 -7
  13. data/lib/worochi/item.rb +5 -3
  14. data/lib/worochi/log.rb +8 -14
  15. data/lib/worochi/oauth.rb +69 -0
  16. data/lib/worochi/version.rb +1 -1
  17. data/lib/worochi.rb +20 -3
  18. data/spec/cassettes/Worochi/_push/pushes_with_agents.yml +512 -0
  19. data/spec/cassettes/Worochi_Agent_Dropbox/_push_item/pushes_it_chunked_if_size_exceeds_limit.yml +1049 -0
  20. data/spec/cassettes/Worochi_Agent_Dropbox/_push_item_chunked/raises_an_error.yml +44 -0
  21. data/spec/cassettes/Worochi_Agent_Dropbox/_push_items/pushes_multiple_items.yml +165 -0
  22. data/spec/cassettes/Worochi_Agent_Dropbox/it_should_behave_like_a_service_agent/_files/raises_error_on_invalid_path.yml +38 -0
  23. data/spec/cassettes/Worochi_Agent_Dropbox/it_should_behave_like_a_service_agent/_files_and_folders/shows_detailed_listing.yml +79 -0
  24. data/spec/cassettes/Worochi_Agent_Dropbox/it_should_behave_like_a_service_agent/_files_and_folders/shows_detailed_listing_including_the_required_fields.yml +79 -0
  25. data/spec/cassettes/Worochi_Agent_Github/_list/works_with_absolute_paths.yml +12 -12
  26. data/spec/cassettes/Worochi_Agent_Github/_repos/lists_the_repos.yml +207 -0
  27. data/spec/cassettes/Worochi_Agent_Github/_source_branch/retrieves_the_master_branch_correctly.yml +6 -6
  28. data/spec/cassettes/Worochi_Agent_Github/it_should_behave_like_a_service_agent/_files/accepts_a_different_relative_path.yml +12 -12
  29. data/spec/cassettes/Worochi_Agent_Github/it_should_behave_like_a_service_agent/_files/contains_file1.yml +12 -12
  30. data/spec/cassettes/Worochi_Agent_Github/it_should_behave_like_a_service_agent/_files/does_not_contain_folder1.yml +12 -12
  31. data/spec/cassettes/Worochi_Agent_Github/it_should_behave_like_a_service_agent/_files/raises_error_on_invalid_path.yml +133 -0
  32. data/spec/cassettes/Worochi_Agent_Github/it_should_behave_like_a_service_agent/_files_and_folders/contains_folder1_and_file1.yml +24 -24
  33. data/spec/cassettes/Worochi_Agent_Github/it_should_behave_like_a_service_agent/_files_and_folders/shows_detailed_listing_including_the_required_fields.yml +133 -0
  34. data/spec/cassettes/Worochi_Agent_Github/it_should_behave_like_a_service_agent/_folders/accepts_a_different_relative_path.yml +12 -12
  35. data/spec/cassettes/Worochi_Agent_Github/it_should_behave_like_a_service_agent/_folders/contains_folder1.yml +12 -12
  36. data/spec/cassettes/Worochi_Agent_Github/it_should_behave_like_a_service_agent/_folders/does_not_contain_file1.yml +12 -12
  37. data/spec/cassettes/Worochi_Agent_Github/{_push_all → modifies_the_repo/_push_all}/pushes_a_list_of_items_to_create_a_new_commit.yml +80 -80
  38. data/spec/cassettes/Worochi_Agent_Github/{_push_all → modifies_the_repo/_push_all}/pushes_the_file_to_the_right_place.yml +60 -60
  39. data/spec/cassettes/Worochi_Agent_Github/modifies_the_repo/_push_blob/pushes_the_blob_even_when_it_is_larger_than_block_size.yml +181 -0
  40. data/spec/cassettes/Worochi_Agent_Github/modifies_the_repo/_push_item/pushes_a_single_item_and_makes_a_commit.yml +687 -0
  41. data/spec/cassettes/Worochi_Agent_Github/modifies_the_repo/_stream_blob/streams_the_file_as_an_Base64_JSON_field.yml +181 -0
  42. data/spec/cassettes/Worochi_OAuth/_flow_end/rejects_bad_code.yml +56 -0
  43. data/spec/{helper.rb → spec_helper.rb} +14 -1
  44. data/spec/support/aws_uri_matcher.rb +1 -1
  45. data/spec/support/shared_exampes_for_agents.rb +13 -2
  46. data/spec/support/test_files.rb +4 -4
  47. data/spec/worochi/agent/dropbox_spec.rb +29 -3
  48. data/spec/worochi/agent/github_spec.rb +54 -26
  49. data/spec/worochi/agent_spec.rb +34 -1
  50. data/spec/worochi/config_spec.rb +46 -30
  51. data/spec/worochi/helper/github_helper_spec.rb +94 -0
  52. data/spec/worochi/helper_spec.rb +15 -3
  53. data/spec/worochi/item_spec.rb +9 -6
  54. data/spec/worochi/log_spec.rb +30 -0
  55. data/spec/worochi/oauth_spec.rb +33 -0
  56. data/spec/worochi_spec.rb +25 -1
  57. data/worochi.gemspec +5 -1
  58. metadata +104 -11
  59. data/lib/worochi/helper/github.rb +0 -100
  60. data/spec/worochi/helper/github_spec.rb +0 -57
@@ -0,0 +1,94 @@
1
+ require 'spec_helper'
2
+
3
+ class Worochi::Agent::Github
4
+ describe Helper do
5
+ describe Helper::StreamIO do
6
+
7
+ let(:size) { 114 }
8
+ let(:checksum) { '0bda09766257c6e8d33557cf4d1e1718e82540d46b53d288fc13198e7126f2bc' }
9
+ let(:stream) do
10
+ item = Worochi::Item.open_single(local.source)
11
+ Helper::StreamIO.new(item)
12
+ end
13
+
14
+ after do
15
+ stream.rewind
16
+ end
17
+
18
+ describe '.new' do
19
+ it 'initializes' do
20
+ item = Worochi::Item.open_single(local.source)
21
+ s = Helper::StreamIO.new(item)
22
+ expect(s.class).to be(Helper::StreamIO)
23
+ end
24
+ end
25
+
26
+ describe '#size' do
27
+ it 'returns the encoded size' do
28
+ expect(stream.size).to eq(size)
29
+ end
30
+ end
31
+
32
+ describe '#read' do
33
+ def verify(content)
34
+ expect(Digest::SHA2.hexdigest(content)).to eq(checksum)
35
+ expect(content.size).to eq(size)
36
+ end
37
+
38
+ it 'encodes a file correctly' do
39
+ content = stream.read
40
+ verify(content)
41
+ end
42
+
43
+ it 'reads partial lengths' do
44
+ part = stream.read(6)
45
+ expect(part).to eq('{"cont')
46
+ expect(part.size).to eq(6)
47
+
48
+ part = stream.read(15)
49
+ expect(part).to eq('ent":"VGhpcyBpc')
50
+ expect(part.size).to eq(15)
51
+ end
52
+
53
+ it 'tracks file positions correctly' do
54
+ content = stream.read(stream.size)
55
+ verify(content)
56
+ stream.rewind
57
+ content = stream.read(stream.size + 100)
58
+ verify(content)
59
+ stream.rewind
60
+ content = stream.read(stream.size - 10)
61
+ content += stream.read(10)
62
+ verify(content)
63
+ end
64
+
65
+ it 'accepts an output buffer' do
66
+ outbuf = ''
67
+ stream.read(5, outbuf)
68
+ expect(outbuf.size).to eq(5)
69
+ expect(outbuf).to eq('{"con')
70
+ stream.read
71
+ expect(stream.read(5, outbuf)).to be(nil)
72
+ expect(outbuf).to eq('')
73
+ end
74
+
75
+ it 'terminates correctly' do
76
+ stream.read(stream.size)
77
+ expect(stream.read(10)).to be(nil)
78
+ expect(stream.read).to eq('')
79
+ end
80
+ end
81
+
82
+ describe '#rewind' do
83
+ it 'rewinds the stream' do
84
+ expect(stream.read(20)).to eq('{"content":"VGhpcyBp')
85
+ stream.rewind
86
+ expect(stream.read(20)).to eq('{"content":"VGhpcyBp')
87
+ stream.read
88
+ stream.rewind
89
+ expect(stream.read(20)).to eq('{"content":"VGhpcyBp')
90
+ end
91
+ end
92
+ end
93
+ end
94
+ end
@@ -1,4 +1,4 @@
1
- require 'helper'
1
+ require 'spec_helper'
2
2
 
3
3
  describe Worochi::Helper do
4
4
 
@@ -16,8 +16,20 @@ describe Worochi::Helper do
16
16
 
17
17
  describe '.s3_url', :aws do
18
18
  it 'returns the right S3 URL' do
19
- url = Worochi::Helper.s3_url('s3:test/path')
20
- expect(url.to_s).to match(/^https.+s3\.amazonaws\.com\/test\/path.*/)
19
+ Worochi::Config.s3_bucket = 'rspec-test'
20
+ uri = Worochi::Helper.s3_url('s3:test/path')
21
+ expect(uri.path).to eq('/test/path')
22
+ expect(uri.host).to include('rspec-test')
23
+ end
24
+
25
+ it 'parses bucket names' do
26
+ uri = Worochi::Helper.s3_url('s3:bucket-name:test/path')
27
+ expect(uri.path).to eq('/test/path')
28
+ expect(uri.host).to include('bucket-name')
29
+ end
30
+
31
+ it 'rejects invalid URLs' do
32
+ expect{Worochi::Helper.s3_url('a/b')}.to raise_error(Worochi::Error)
21
33
  end
22
34
  end
23
35
  end
@@ -1,4 +1,4 @@
1
- require 'helper'
1
+ require 'spec_helper'
2
2
 
3
3
  describe Worochi::Item do
4
4
  describe '.open', :vcr do
@@ -58,21 +58,24 @@ describe Worochi::Item do
58
58
  it 'accepts a String' do
59
59
  item = Worochi::Item.open_single(remote.source)
60
60
  expect(item.class).to be(Worochi::Item)
61
- expect(item.size).to eq(remote.size)
61
+ expect(item.size).to eq(remote.file_size)
62
62
  end
63
63
 
64
64
  it 'accepts a Hash' do
65
65
  hash = { path: local.path, source: local.source }
66
66
  item = Worochi::Item.open_single(hash)
67
67
  expect(item.class).to be(Worochi::Item)
68
- expect(item.size).to eq(local.size)
68
+ expect(item.size).to eq(local.file_size)
69
69
  end
70
70
 
71
71
  it 'works with AWS S3 paths', :aws do
72
+ Worochi::Config.s3_bucket = 'data-pixelapse'
72
73
  item = Worochi::Item.open_single(s3.source)
73
74
  expect(item.class).to be(Worochi::Item)
74
- checksum = Digest::SHA2.hexdigest(item.content.read)
75
+ content = item.content.read
76
+ checksum = Digest::SHA2.hexdigest(content)
75
77
  expect(checksum).to eq(s3.checksum)
78
+ expect(content.size).to eq(s3.file_size)
76
79
  end
77
80
  end
78
81
 
@@ -82,7 +85,7 @@ describe Worochi::Item do
82
85
  first_word = item.read(4)
83
86
  expect(first_word).to eq('This')
84
87
  rest = item.read
85
- expect(rest.size).to eq(local.size - 4)
88
+ expect(rest.size).to eq(local.file_size - 4)
86
89
  end
87
90
  end
88
91
 
@@ -92,7 +95,7 @@ describe Worochi::Item do
92
95
  item.read
93
96
  expect(item.read.size).to eq(0)
94
97
  expect(item.rewind).to eq(0)
95
- expect(item.read.size).to eq(local.size)
98
+ expect(item.read.size).to eq(local.file_size)
96
99
  end
97
100
  end
98
101
  end
@@ -0,0 +1,30 @@
1
+ require 'spec_helper'
2
+
3
+ class Worochi
4
+ describe Log do
5
+ before do
6
+ Config.silent = false
7
+ @output = StringIO.new
8
+ Log.init(@output)
9
+ end
10
+
11
+ after do
12
+ Config.silent = true
13
+ Log.init
14
+ end
15
+
16
+ describe '.warn' do
17
+ it 'logs warning' do
18
+ Log.warn 'test warn'
19
+ expect(@output.string).to include('test warn')
20
+ end
21
+ end
22
+
23
+ describe '.error' do
24
+ it 'logs error' do
25
+ Log.error 'test error'
26
+ expect(@output.string).to include('test error')
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,33 @@
1
+ require 'spec_helper'
2
+
3
+ describe Worochi::OAuth do
4
+ let(:redirect_uri) { 'http://127.0.0.1:3000' }
5
+ let(:auth) { Worochi::OAuth.new(:github, redirect_uri) }
6
+ describe '.new' do
7
+ it 'initializes the options correctly' do
8
+ expect(auth.options.site).to eq('https://github.com')
9
+ expect(auth.client.class).to be(OAuth2::Client)
10
+ end
11
+ end
12
+
13
+ describe '#flow_start' do
14
+ it 'returns the URL to begin authorization' do
15
+ url = auth.flow_start
16
+ expect(url).to include("scope=#{auth.send(:scope)}")
17
+ expect(url).to include(auth.options.site)
18
+ expect(url).to include(auth.options.authorize_url)
19
+ end
20
+
21
+ it 'supports state' do
22
+ state = SecureRandom.hex
23
+ url = auth.flow_start(state)
24
+ expect(url).to include("state=#{state}")
25
+ end
26
+ end
27
+
28
+ describe '#flow_end', :vcr do
29
+ it 'rejects bad code' do
30
+ expect{auth.flow_end('abc')}.to raise_error(OAuth2::Error)
31
+ end
32
+ end
33
+ end
data/spec/worochi_spec.rb CHANGED
@@ -1,4 +1,4 @@
1
- require 'helper'
1
+ require 'spec_helper'
2
2
 
3
3
  describe Worochi do
4
4
  let(:token) { 'service token' }
@@ -69,6 +69,15 @@ describe Worochi do
69
69
  end
70
70
  end
71
71
 
72
+ describe '.remove' do
73
+ it 'removes a single agent' do
74
+ a = create_dropbox_agent
75
+ expect(Worochi.agents).to include(a)
76
+ Worochi.remove(a)
77
+ expect(Worochi.agents).not_to include(a)
78
+ end
79
+ end
80
+
72
81
  describe '.remove_service' do
73
82
  it 'removes multiple agents by service' do
74
83
  create_dropbox_agent
@@ -112,4 +121,19 @@ describe Worochi do
112
121
  expect(Worochi.agents).to include(a)
113
122
  end
114
123
  end
124
+
125
+ describe '.push', :vcr do
126
+ it 'pushes with agents' do
127
+ a = Worochi.create(:github, ENV['GITHUB_TEST_TOKEN'], {
128
+ repo: 'darkmirage/test',
129
+ source: 'master',
130
+ target: 'rspec',
131
+ commit_msg: "RSpec Test"
132
+ })
133
+ expect(Worochi.push(path: local.path, source: local.source)).to be(true)
134
+ end
135
+ it 'requires at least one active agent' do
136
+ expect(Worochi.push(local.source)).to be(false)
137
+ end
138
+ end
115
139
  end
data/worochi.gemspec CHANGED
@@ -16,11 +16,13 @@ Gem::Specification.new do |s|
16
16
  s.license = 'MIT'
17
17
 
18
18
  s.files = %w(README.md LICENSE worochi.gemspec)
19
- s.files += Dir.glob('lib/**/*.rb')
19
+ s.files += Dir.glob('lib/**/*.{rb,yml}')
20
20
  s.test_files = Dir.glob('spec/**/*')
21
21
 
22
22
  s.require_paths = ['lib']
23
23
 
24
+ s.add_runtime_dependency('hashie')
25
+ s.add_runtime_dependency('oauth2')
24
26
  s.add_runtime_dependency('aws-sdk')
25
27
  s.add_runtime_dependency('dropbox-sdk') # Dropbox
26
28
  s.add_runtime_dependency('octokit') # GitHub
@@ -30,6 +32,8 @@ Gem::Specification.new do |s|
30
32
  s.add_development_dependency('webmock', ['~> 1.9.3'])
31
33
  s.add_development_dependency('awesome_print')
32
34
  s.add_development_dependency('yard')
35
+ s.add_development_dependency('simplecov')
36
+ s.add_development_dependency('coveralls')
33
37
 
34
38
  s.post_install_message = <<-MESSAGE
35
39
  Worochi says, "RAWRRRRR!!!"
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.7
4
+ version: 0.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Raven Jiang
@@ -10,6 +10,34 @@ bindir: bin
10
10
  cert_chain: []
11
11
  date: 2013-08-02 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: hashie
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: oauth2
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
13
41
  - !ruby/object:Gem::Dependency
14
42
  name: aws-sdk
15
43
  requirement: !ruby/object:Gem::Requirement
@@ -122,6 +150,34 @@ dependencies:
122
150
  - - '>='
123
151
  - !ruby/object:Gem::Version
124
152
  version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: simplecov
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - '>='
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - '>='
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: coveralls
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - '>='
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - '>='
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
125
181
  description: Provides a standard way to interface with Ruby API wrappers provided
126
182
  by various cloud storage services such as Dropbox and Google Drive.
127
183
  email:
@@ -136,41 +192,60 @@ files:
136
192
  - lib/worochi/error.rb
137
193
  - lib/worochi/log.rb
138
194
  - lib/worochi/agent.rb
139
- - lib/worochi/helper/github.rb
195
+ - lib/worochi/helper/github_helper.rb
140
196
  - lib/worochi/config.rb
141
- - lib/worochi/agent/sample.rb
142
197
  - lib/worochi/agent/github.rb
198
+ - lib/worochi/agent/#example.rb
143
199
  - lib/worochi/agent/dropbox.rb
144
200
  - lib/worochi/helper.rb
145
201
  - lib/worochi/item.rb
202
+ - lib/worochi/oauth.rb
146
203
  - lib/worochi/version.rb
204
+ - lib/worochi/configurator.rb
147
205
  - lib/worochi.rb
206
+ - lib/worochi/config/github.yml
207
+ - lib/worochi/config/dropbox.yml
208
+ - lib/worochi/config/#example.yml
209
+ - spec/spec_helper.rb
148
210
  - spec/worochi/helper_spec.rb
211
+ - spec/worochi/log_spec.rb
149
212
  - spec/worochi/item_spec.rb
150
- - spec/worochi/helper/github_spec.rb
213
+ - spec/worochi/helper/github_helper_spec.rb
151
214
  - spec/worochi/agent/dropbox_spec.rb
152
215
  - spec/worochi/agent/github_spec.rb
153
216
  - spec/worochi/config_spec.rb
154
217
  - spec/worochi/agent_spec.rb
218
+ - spec/worochi/oauth_spec.rb
155
219
  - spec/worochi_spec.rb
156
220
  - spec/support/aws_uri_matcher.rb
157
221
  - spec/support/shared_exampes_for_agents.rb
158
222
  - spec/support/test_files.rb
159
223
  - spec/support/test_file
224
+ - spec/cassettes/Worochi_Agent_Dropbox/_push_item_chunked/raises_an_error.yml
160
225
  - spec/cassettes/Worochi_Agent_Dropbox/_push_item_chunked/pushes_a_single_item_in_chunks.yml
161
226
  - spec/cassettes/Worochi_Agent_Dropbox/_list/works_with_absolute_paths.yml
227
+ - spec/cassettes/Worochi_Agent_Dropbox/it_should_behave_like_a_service_agent/_files_and_folders/shows_detailed_listing.yml
228
+ - spec/cassettes/Worochi_Agent_Dropbox/it_should_behave_like_a_service_agent/_files_and_folders/shows_detailed_listing_including_the_required_fields.yml
162
229
  - spec/cassettes/Worochi_Agent_Dropbox/it_should_behave_like_a_service_agent/_files_and_folders/contains_folder1_and_file1.yml
230
+ - spec/cassettes/Worochi_Agent_Dropbox/it_should_behave_like_a_service_agent/_files/raises_error_on_invalid_path.yml
163
231
  - spec/cassettes/Worochi_Agent_Dropbox/it_should_behave_like_a_service_agent/_files/does_not_contain_folder1.yml
164
232
  - spec/cassettes/Worochi_Agent_Dropbox/it_should_behave_like_a_service_agent/_files/contains_file1.yml
165
233
  - spec/cassettes/Worochi_Agent_Dropbox/it_should_behave_like_a_service_agent/_files/accepts_a_different_relative_path.yml
166
234
  - spec/cassettes/Worochi_Agent_Dropbox/it_should_behave_like_a_service_agent/_folders/contains_folder1.yml
167
235
  - spec/cassettes/Worochi_Agent_Dropbox/it_should_behave_like_a_service_agent/_folders/does_not_contain_file1.yml
168
236
  - spec/cassettes/Worochi_Agent_Dropbox/it_should_behave_like_a_service_agent/_folders/accepts_a_different_relative_path.yml
237
+ - spec/cassettes/Worochi_Agent_Dropbox/_push_items/pushes_multiple_items.yml
169
238
  - spec/cassettes/Worochi_Agent_Dropbox/_push_item/pushes_a_single_item.yml
170
- - spec/cassettes/Worochi_Agent_Github/_push_all/pushes_the_file_to_the_right_place.yml
171
- - spec/cassettes/Worochi_Agent_Github/_push_all/pushes_a_list_of_items_to_create_a_new_commit.yml
239
+ - spec/cassettes/Worochi_Agent_Dropbox/_push_item/pushes_it_chunked_if_size_exceeds_limit.yml
240
+ - spec/cassettes/Worochi_Agent_Github/modifies_the_repo/_push_all/pushes_the_file_to_the_right_place.yml
241
+ - spec/cassettes/Worochi_Agent_Github/modifies_the_repo/_push_all/pushes_a_list_of_items_to_create_a_new_commit.yml
242
+ - spec/cassettes/Worochi_Agent_Github/modifies_the_repo/_stream_blob/streams_the_file_as_an_Base64_JSON_field.yml
243
+ - spec/cassettes/Worochi_Agent_Github/modifies_the_repo/_push_blob/pushes_the_blob_even_when_it_is_larger_than_block_size.yml
244
+ - spec/cassettes/Worochi_Agent_Github/modifies_the_repo/_push_item/pushes_a_single_item_and_makes_a_commit.yml
172
245
  - spec/cassettes/Worochi_Agent_Github/_list/works_with_absolute_paths.yml
246
+ - spec/cassettes/Worochi_Agent_Github/it_should_behave_like_a_service_agent/_files_and_folders/shows_detailed_listing_including_the_required_fields.yml
173
247
  - spec/cassettes/Worochi_Agent_Github/it_should_behave_like_a_service_agent/_files_and_folders/contains_folder1_and_file1.yml
248
+ - spec/cassettes/Worochi_Agent_Github/it_should_behave_like_a_service_agent/_files/raises_error_on_invalid_path.yml
174
249
  - spec/cassettes/Worochi_Agent_Github/it_should_behave_like_a_service_agent/_files/does_not_contain_folder1.yml
175
250
  - spec/cassettes/Worochi_Agent_Github/it_should_behave_like_a_service_agent/_files/contains_file1.yml
176
251
  - spec/cassettes/Worochi_Agent_Github/it_should_behave_like_a_service_agent/_files/accepts_a_different_relative_path.yml
@@ -178,6 +253,8 @@ files:
178
253
  - spec/cassettes/Worochi_Agent_Github/it_should_behave_like_a_service_agent/_folders/does_not_contain_file1.yml
179
254
  - spec/cassettes/Worochi_Agent_Github/it_should_behave_like_a_service_agent/_folders/accepts_a_different_relative_path.yml
180
255
  - spec/cassettes/Worochi_Agent_Github/_source_branch/retrieves_the_master_branch_correctly.yml
256
+ - spec/cassettes/Worochi_Agent_Github/_repos/lists_the_repos.yml
257
+ - spec/cassettes/Worochi/_push/pushes_with_agents.yml
181
258
  - spec/cassettes/Worochi_Item/_open_single/accepts_a_String.yml
182
259
  - spec/cassettes/Worochi_Item/_open_single/works_with_AWS_S3_paths.yml
183
260
  - spec/cassettes/Worochi_Item/_open/opens_multiple_files/with_String_parameters.yml
@@ -188,7 +265,7 @@ files:
188
265
  - spec/cassettes/Worochi_Item/_open/with_multiple_files/accepts_Hash_parameters.yml
189
266
  - spec/cassettes/Worochi_Item/_open/opens_a_single_file/with_String_parameter.yml
190
267
  - spec/cassettes/Worochi_Item/_open/opens_a_single_file/with_Hash_parameter.yml
191
- - spec/helper.rb
268
+ - spec/cassettes/Worochi_OAuth/_flow_end/rejects_bad_code.yml
192
269
  homepage: http://rubygems.org/gems/worochi
193
270
  licenses:
194
271
  - MIT
@@ -215,32 +292,46 @@ signing_key:
215
292
  specification_version: 4
216
293
  summary: Worochi
217
294
  test_files:
295
+ - spec/spec_helper.rb
218
296
  - spec/worochi/helper_spec.rb
297
+ - spec/worochi/log_spec.rb
219
298
  - spec/worochi/item_spec.rb
220
- - spec/worochi/helper/github_spec.rb
299
+ - spec/worochi/helper/github_helper_spec.rb
221
300
  - spec/worochi/agent/dropbox_spec.rb
222
301
  - spec/worochi/agent/github_spec.rb
223
302
  - spec/worochi/config_spec.rb
224
303
  - spec/worochi/agent_spec.rb
304
+ - spec/worochi/oauth_spec.rb
225
305
  - spec/worochi_spec.rb
226
306
  - spec/support/aws_uri_matcher.rb
227
307
  - spec/support/shared_exampes_for_agents.rb
228
308
  - spec/support/test_files.rb
229
309
  - spec/support/test_file
310
+ - spec/cassettes/Worochi_Agent_Dropbox/_push_item_chunked/raises_an_error.yml
230
311
  - spec/cassettes/Worochi_Agent_Dropbox/_push_item_chunked/pushes_a_single_item_in_chunks.yml
231
312
  - spec/cassettes/Worochi_Agent_Dropbox/_list/works_with_absolute_paths.yml
313
+ - spec/cassettes/Worochi_Agent_Dropbox/it_should_behave_like_a_service_agent/_files_and_folders/shows_detailed_listing.yml
314
+ - spec/cassettes/Worochi_Agent_Dropbox/it_should_behave_like_a_service_agent/_files_and_folders/shows_detailed_listing_including_the_required_fields.yml
232
315
  - spec/cassettes/Worochi_Agent_Dropbox/it_should_behave_like_a_service_agent/_files_and_folders/contains_folder1_and_file1.yml
316
+ - spec/cassettes/Worochi_Agent_Dropbox/it_should_behave_like_a_service_agent/_files/raises_error_on_invalid_path.yml
233
317
  - spec/cassettes/Worochi_Agent_Dropbox/it_should_behave_like_a_service_agent/_files/does_not_contain_folder1.yml
234
318
  - spec/cassettes/Worochi_Agent_Dropbox/it_should_behave_like_a_service_agent/_files/contains_file1.yml
235
319
  - spec/cassettes/Worochi_Agent_Dropbox/it_should_behave_like_a_service_agent/_files/accepts_a_different_relative_path.yml
236
320
  - spec/cassettes/Worochi_Agent_Dropbox/it_should_behave_like_a_service_agent/_folders/contains_folder1.yml
237
321
  - spec/cassettes/Worochi_Agent_Dropbox/it_should_behave_like_a_service_agent/_folders/does_not_contain_file1.yml
238
322
  - spec/cassettes/Worochi_Agent_Dropbox/it_should_behave_like_a_service_agent/_folders/accepts_a_different_relative_path.yml
323
+ - spec/cassettes/Worochi_Agent_Dropbox/_push_items/pushes_multiple_items.yml
239
324
  - spec/cassettes/Worochi_Agent_Dropbox/_push_item/pushes_a_single_item.yml
240
- - spec/cassettes/Worochi_Agent_Github/_push_all/pushes_the_file_to_the_right_place.yml
241
- - spec/cassettes/Worochi_Agent_Github/_push_all/pushes_a_list_of_items_to_create_a_new_commit.yml
325
+ - spec/cassettes/Worochi_Agent_Dropbox/_push_item/pushes_it_chunked_if_size_exceeds_limit.yml
326
+ - spec/cassettes/Worochi_Agent_Github/modifies_the_repo/_push_all/pushes_the_file_to_the_right_place.yml
327
+ - spec/cassettes/Worochi_Agent_Github/modifies_the_repo/_push_all/pushes_a_list_of_items_to_create_a_new_commit.yml
328
+ - spec/cassettes/Worochi_Agent_Github/modifies_the_repo/_stream_blob/streams_the_file_as_an_Base64_JSON_field.yml
329
+ - spec/cassettes/Worochi_Agent_Github/modifies_the_repo/_push_blob/pushes_the_blob_even_when_it_is_larger_than_block_size.yml
330
+ - spec/cassettes/Worochi_Agent_Github/modifies_the_repo/_push_item/pushes_a_single_item_and_makes_a_commit.yml
242
331
  - spec/cassettes/Worochi_Agent_Github/_list/works_with_absolute_paths.yml
332
+ - spec/cassettes/Worochi_Agent_Github/it_should_behave_like_a_service_agent/_files_and_folders/shows_detailed_listing_including_the_required_fields.yml
243
333
  - spec/cassettes/Worochi_Agent_Github/it_should_behave_like_a_service_agent/_files_and_folders/contains_folder1_and_file1.yml
334
+ - spec/cassettes/Worochi_Agent_Github/it_should_behave_like_a_service_agent/_files/raises_error_on_invalid_path.yml
244
335
  - spec/cassettes/Worochi_Agent_Github/it_should_behave_like_a_service_agent/_files/does_not_contain_folder1.yml
245
336
  - spec/cassettes/Worochi_Agent_Github/it_should_behave_like_a_service_agent/_files/contains_file1.yml
246
337
  - spec/cassettes/Worochi_Agent_Github/it_should_behave_like_a_service_agent/_files/accepts_a_different_relative_path.yml
@@ -248,6 +339,8 @@ test_files:
248
339
  - spec/cassettes/Worochi_Agent_Github/it_should_behave_like_a_service_agent/_folders/does_not_contain_file1.yml
249
340
  - spec/cassettes/Worochi_Agent_Github/it_should_behave_like_a_service_agent/_folders/accepts_a_different_relative_path.yml
250
341
  - spec/cassettes/Worochi_Agent_Github/_source_branch/retrieves_the_master_branch_correctly.yml
342
+ - spec/cassettes/Worochi_Agent_Github/_repos/lists_the_repos.yml
343
+ - spec/cassettes/Worochi/_push/pushes_with_agents.yml
251
344
  - spec/cassettes/Worochi_Item/_open_single/accepts_a_String.yml
252
345
  - spec/cassettes/Worochi_Item/_open_single/works_with_AWS_S3_paths.yml
253
346
  - spec/cassettes/Worochi_Item/_open/opens_multiple_files/with_String_parameters.yml
@@ -258,5 +351,5 @@ test_files:
258
351
  - spec/cassettes/Worochi_Item/_open/with_multiple_files/accepts_Hash_parameters.yml
259
352
  - spec/cassettes/Worochi_Item/_open/opens_a_single_file/with_String_parameter.yml
260
353
  - spec/cassettes/Worochi_Item/_open/opens_a_single_file/with_Hash_parameter.yml
261
- - spec/helper.rb
354
+ - spec/cassettes/Worochi_OAuth/_flow_end/rejects_bad_code.yml
262
355
  has_rdoc:
@@ -1,100 +0,0 @@
1
- require 'base64'
2
-
3
- class Worochi
4
- # Helper classes for GitHub JSON streaming.
5
- module Helper::Github
6
-
7
- # Size to read in. Must be a multiple of 3 for Base64 streaming.
8
- BLOCK_SIZE = 12288
9
-
10
- # This is a wrapper that produces a JSON stream that works with
11
- # {Net::HTTP::Post#body_stream}.
12
- class StreamIO
13
-
14
- def initialize(item)
15
- item.content.rewind
16
- @parts = [
17
- StringIO.new('{"content":"'),
18
- Base64IO.new(item.content),
19
- StringIO.new('","encoding":"base64"}')
20
- ]
21
- @part_no = 0
22
- @size = @parts.inject(0) {|sum, p| sum + p.size}
23
- end
24
-
25
- # @return [Integer] size of the JSON
26
- def size
27
- @size
28
- end
29
-
30
- # Rewind each component of the stream.
31
- #
32
- # @return [nil]
33
- def rewind
34
- @parts.each { |part| part.rewind }
35
- @part_no = 0
36
- nil
37
- end
38
-
39
- # @param length [Integer]
40
- # @param outbuf [IO]
41
- # @return [String]
42
- def read(length=nil, outbuf=nil)
43
- return length.nil? ? '' : nil if @part_no >= @parts.size
44
-
45
- length = length || size
46
- output = @parts[@part_no].read(length).to_s
47
-
48
- if output.nil?
49
- return nil if @part_no >= @parts.size
50
- output = ''
51
- end
52
-
53
- while output.length < length
54
- @part_no += 1
55
- break if @part_no == @parts.size
56
- output += @parts[@part_no].read(length - output.length).to_s
57
- end
58
- if not outbuf.nil?
59
- outbuf.clear
60
- outbuf.insert(0, output)
61
- end
62
-
63
- output
64
- end
65
- end
66
-
67
- # This is a wrapper around the file content that streams the file as a
68
- # Base64 encoded string.
69
- class Base64IO
70
- def initialize(file)
71
- file.rewind
72
- @file = file
73
- @encoded_size = (@file.size / 3.0).ceil * 4
74
- @buffer = ''
75
- end
76
-
77
- # @return [Integer] size of the JSON
78
- def size
79
- @encoded_size
80
- end
81
-
82
- # Rewind the stream.
83
- def rewind
84
- @file.rewind
85
- @buffer = ''
86
- nil
87
- end
88
-
89
- # @param length [Integer]
90
- # @param outbuf [IO]
91
- # @return [String]
92
- def read(length=size, outbuf=nil)
93
- while @buffer.length < length and not @file.eof?
94
- @buffer += Base64.strict_encode64 @file.read(BLOCK_SIZE)
95
- end
96
- @buffer.empty? ? nil : @buffer.slice!(0, length)
97
- end
98
- end
99
- end
100
- end