duracloud-client 0.0.3 → 0.1.0

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.
@@ -2,20 +2,8 @@ require "date"
2
2
 
3
3
  module Duracloud
4
4
  class SpaceProperties < Properties
5
-
6
5
  def self.property?(prop)
7
6
  space_property?(prop)
8
7
  end
9
-
10
- def count
11
- space_count.to_i
12
- end
13
-
14
- def created
15
- DateTime.parse(space_created)
16
- rescue ArgumentError
17
- space_created
18
- end
19
-
20
8
  end
21
9
  end
@@ -1,16 +1,28 @@
1
1
  require "nokogiri"
2
2
 
3
3
  module Duracloud
4
+ #
5
+ # A Duracloud storage provider account.
6
+ #
4
7
  class Store
5
8
 
9
+ # @return [Array<Duracloud::Store>] the list of available storage provider accounts.
6
10
  def self.all
7
11
  response = Client.get_stores
8
12
  doc = Nokogiri::XML(response.body)
9
13
  doc.css('storageAcct').map { |acct| new(acct) }
10
14
  end
11
15
 
16
+ # @return [Duracloud::Store] the primary storage provider account.
17
+ def self.primary
18
+ all.detect { |store| store.primary? }
19
+ end
20
+
21
+ private_class_method :new
22
+
12
23
  attr_reader :id, :owner_id, :primary, :provider_type
13
24
 
25
+ # @api private
14
26
  def initialize(xml_node)
15
27
  @owner_id = xml_node['ownerId']
16
28
  @primary = xml_node['isPrimary']
@@ -1,3 +1,3 @@
1
1
  module Duracloud
2
- VERSION = "0.0.3"
2
+ VERSION = "0.1.0"
3
3
  end
data/lib/duracloud.rb CHANGED
@@ -2,12 +2,14 @@ require "duracloud/version"
2
2
  require "duracloud/error"
3
3
 
4
4
  module Duracloud
5
+ autoload :AuditLog, "duracloud/audit_log"
5
6
  autoload :BitIntegrityReport, "duracloud/bit_integrity_report"
6
7
  autoload :Client, "duracloud/client"
7
8
  autoload :Configuration, "duracloud/configuration"
8
9
  autoload :Connection, "duracloud/connection"
9
10
  autoload :Content, "duracloud/content"
10
11
  autoload :ContentProperties, "duracloud/content_properties"
12
+ autoload :CSVReader, "duracloud/csv_reader"
11
13
  autoload :DurastoreRequest, "duracloud/durastore_request"
12
14
  autoload :ErrorHandler, "duracloud/error_handler"
13
15
  autoload :HasProperties, "duracloud/has_properties"
data/spec/spec_helper.rb CHANGED
@@ -1,23 +1,16 @@
1
1
  require "duracloud"
2
2
  require "rspec/its"
3
- # This file was generated by the `rspec --init` command. Conventionally, all
4
- # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
5
- # The generated `.rspec` file contains `--require spec_helper` which will cause
6
- # this file to always be loaded, without a need to explicitly require it in any
7
- # files.
8
- #
9
- # Given that it is always loaded, you are encouraged to keep this file as
10
- # light-weight as possible. Requiring heavyweight dependencies from this file
11
- # will add to the boot time of your test suite on EVERY test run, even for an
12
- # individual file that may not need all of that loaded. Instead, consider making
13
- # a separate helper file that requires the additional dependencies and performs
14
- # the additional setup, and require it from the spec files that actually need
15
- # it.
16
- #
17
- # The `.rspec` file also contains a few flags that are not defaults but that
18
- # users commonly want.
19
- #
20
- # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
3
+ require "webmock/rspec"
4
+
5
+ WebMock.disable_net_connect!(allow_localhost: true)
6
+
7
+ Duracloud::Client.configure do |config|
8
+ config.host = "example.com"
9
+ config.user = "testuser"
10
+ config.password = "testpass"
11
+ config.silence_logging!
12
+ end
13
+
21
14
  RSpec.configure do |config|
22
15
  # rspec-expectations config goes here. You can use an alternate
23
16
  # assertion/expectation library such as wrong or the stdlib/minitest
@@ -72,13 +65,13 @@ RSpec.configure do |config|
72
65
  # Use the documentation formatter for detailed output,
73
66
  # unless a formatter has already been configured
74
67
  # (e.g. via a command-line flag).
75
- config.default_formatter = 'doc'
68
+ # config.default_formatter = 'doc'
76
69
  end
77
70
 
78
71
  # Print the 10 slowest examples and example groups at the
79
72
  # end of the spec run, to help surface which specs are running
80
73
  # particularly slow.
81
- config.profile_examples = 10
74
+ # config.profile_examples = 10
82
75
 
83
76
  # Run specs in random order to surface order dependencies. If you find an
84
77
  # order dependency and want to debug it, you can fix the order by providing
@@ -0,0 +1,5 @@
1
+ module Duracloud
2
+ RSpec.describe AuditLog do
3
+
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ module Duracloud
2
+ RSpec.describe BitIntegrityReport do
3
+
4
+ end
5
+ end
@@ -1,9 +1,280 @@
1
1
  module Duracloud
2
2
  RSpec.describe Client do
3
- describe "#get_content"
4
- describe "#get_content_properties"
5
- describe "#set_content_properties"
6
- describe "#store_content"
7
- describe "#delete_content"
3
+ describe "get_stores" do
4
+ specify {
5
+ stub = stub_request(:get, "https://example.com/durastore/stores")
6
+ subject.get_stores
7
+ expect(stub).to have_been_requested
8
+ }
9
+ end
10
+
11
+ describe "get_spaces" do
12
+ specify {
13
+ stub = stub_request(:get, "https://example.com/durastore/spaces")
14
+ subject.get_spaces
15
+ expect(stub).to have_been_requested
16
+ }
17
+ specify {
18
+ stub = stub_request(:get, "https://example.com/durastore/spaces")
19
+ .with(query: {storeID: 1})
20
+ subject.get_spaces(storeID: 1)
21
+ expect(stub).to have_been_requested
22
+ }
23
+ end
24
+
25
+ describe "get_space" do
26
+ specify {
27
+ stub = stub_request(:get, "https://example.com/durastore/foo")
28
+ subject.get_space("foo")
29
+ expect(stub).to have_been_requested
30
+ }
31
+ specify {
32
+ stub = stub_request(:get, "https://example.com/durastore/foo")
33
+ .with(query: {storeID: 1, prefix: "bar", maxResults: 50, marker: "item1"})
34
+ subject.get_space("foo", storeID: 1, prefix: "bar", maxResults: 50, marker: "item1")
35
+ expect(stub).to have_been_requested
36
+ }
37
+ end
38
+
39
+ describe "create_space" do
40
+ specify {
41
+ stub = stub_request(:put, "https://example.com/durastore/foo")
42
+ subject.create_space("foo")
43
+ expect(stub).to have_been_requested
44
+ }
45
+ specify {
46
+ stub = stub_request(:put, "https://example.com/durastore/foo")
47
+ .with(query: {storeID: 1})
48
+ subject.create_space("foo", storeID: 1)
49
+ expect(stub).to have_been_requested
50
+ }
51
+ end
52
+
53
+ describe "delete_space" do
54
+ specify {
55
+ stub = stub_request(:delete, "https://example.com/durastore/foo")
56
+ subject.delete_space("foo")
57
+ expect(stub).to have_been_requested
58
+ }
59
+ specify {
60
+ stub = stub_request(:delete, "https://example.com/durastore/foo")
61
+ .with(query: {storeID: 1})
62
+ subject.delete_space("foo", storeID: 1)
63
+ expect(stub).to have_been_requested
64
+ }
65
+ end
66
+
67
+ describe "get_space_acls" do
68
+ specify {
69
+ stub = stub_request(:head, "https://example.com/durastore/acl/foo")
70
+ subject.get_space_acls("foo")
71
+ expect(stub).to have_been_requested
72
+ }
73
+ specify {
74
+ stub = stub_request(:head, "https://example.com/durastore/acl/foo")
75
+ .with(query: {storeID: 1})
76
+ subject.get_space_acls("foo", storeID: 1)
77
+ expect(stub).to have_been_requested
78
+ }
79
+ end
80
+
81
+ describe "set_space_acls" do
82
+ specify {
83
+ stub = stub_request(:post, "https://example.com/durastore/acl/foo")
84
+ .with(headers: {'x-dura-meta-acl-user0'=>'WRITE',
85
+ 'x-dura-meta-acl-user1'=>'WRITE',
86
+ 'x-dura-meta-acl-group-curators'=>'READ'})
87
+ subject.set_space_acls("foo",
88
+ headers: {'x-dura-meta-acl-user0'=>'WRITE',
89
+ 'x-dura-meta-acl-user1'=>'WRITE',
90
+ 'x-dura-meta-acl-group-curators'=>'READ'})
91
+ expect(stub).to have_been_requested
92
+ }
93
+ specify {
94
+ stub = stub_request(:post, "https://example.com/durastore/acl/foo")
95
+ .with(headers: {'x-dura-meta-acl-user0'=>'WRITE',
96
+ 'x-dura-meta-acl-user1'=>'WRITE',
97
+ 'x-dura-meta-acl-group-curators'=>'READ'},
98
+ query: {storeID: 1})
99
+ subject.set_space_acls("foo",
100
+ storeID: 1,
101
+ headers: {'x-dura-meta-acl-user0'=>'WRITE',
102
+ 'x-dura-meta-acl-user1'=>'WRITE',
103
+ 'x-dura-meta-acl-group-curators'=>'READ'})
104
+ expect(stub).to have_been_requested
105
+ }
106
+ end
107
+
108
+ describe "get_content" do
109
+ specify {
110
+ stub = stub_request(:get, "https://example.com/durastore/foo/bar")
111
+ subject.get_content("foo", "bar")
112
+ expect(stub).to have_been_requested
113
+ }
114
+ specify {
115
+ stub = stub_request(:get, "https://example.com/durastore/foo/bar")
116
+ .with(query: {storeID: 1})
117
+ subject.get_content("foo", "bar", storeID: 1)
118
+ expect(stub).to have_been_requested
119
+ }
120
+ end
121
+
122
+ describe "get_content_properties" do
123
+ specify {
124
+ stub = stub_request(:head, "https://example.com/durastore/foo/bar")
125
+ subject.get_content_properties("foo", "bar")
126
+ expect(stub).to have_been_requested
127
+ }
128
+ specify {
129
+ stub = stub_request(:head, "https://example.com/durastore/foo/bar")
130
+ .with(query: {storeID: 1})
131
+ subject.get_content_properties("foo", "bar", storeID: 1)
132
+ expect(stub).to have_been_requested
133
+ }
134
+ end
135
+
136
+ describe "set_content_properties" do
137
+ specify {
138
+ stub = stub_request(:post, "https://example.com/durastore/foo/bar")
139
+ .with(headers: {'x-dura-meta-owner'=>'testuser'})
140
+ subject.set_content_properties("foo", "bar",
141
+ headers: {'x-dura-meta-owner'=>'testuser'})
142
+ expect(stub).to have_been_requested
143
+ }
144
+ specify {
145
+ stub = stub_request(:post, "https://example.com/durastore/foo/bar")
146
+ .with(headers: {'x-dura-meta-owner'=>'testuser'},
147
+ query: {storeID: 1})
148
+ subject.set_content_properties("foo", "bar",
149
+ headers: {'x-dura-meta-owner'=>'testuser'},
150
+ storeID: 1)
151
+ expect(stub).to have_been_requested
152
+ }
153
+ end
154
+
155
+ describe "store_content" do
156
+ specify {
157
+ stub = stub_request(:put, "https://example.com/durastore/foo/bar")
158
+ .with(body: "File content",
159
+ headers: {
160
+ 'Content-Type'=>'text/plain',
161
+ 'Content-MD5'=>'8bb2564936980e92ceec8a5759ec34a8'
162
+ })
163
+ subject.store_content("foo", "bar",
164
+ body: "File content",
165
+ headers: {
166
+ 'Content-Type'=>'text/plain',
167
+ 'Content-MD5'=>'8bb2564936980e92ceec8a5759ec34a8'
168
+ })
169
+ expect(stub).to have_been_requested
170
+ }
171
+ specify {
172
+ stub = stub_request(:put, "https://example.com/durastore/foo/bar")
173
+ .with(body: "File content",
174
+ headers: {
175
+ 'Content-Type'=>'text/plain',
176
+ 'Content-MD5'=>'8bb2564936980e92ceec8a5759ec34a8'
177
+ },
178
+ query: {storeID: 1})
179
+ subject.store_content("foo", "bar",
180
+ body: "File content",
181
+ headers: {
182
+ 'Content-Type'=>'text/plain',
183
+ 'Content-MD5'=>'8bb2564936980e92ceec8a5759ec34a8'
184
+ },
185
+ storeID: 1)
186
+ expect(stub).to have_been_requested
187
+ }
188
+ end
189
+
190
+ describe "delete_content" do
191
+ specify {
192
+ stub = stub_request(:delete, "https://example.com/durastore/foo/bar")
193
+ subject.delete_content("foo", "bar")
194
+ expect(stub).to have_been_requested
195
+ }
196
+ specify {
197
+ stub = stub_request(:delete, "https://example.com/durastore/foo/bar")
198
+ .with(query: {storeID: 1})
199
+ subject.delete_content("foo", "bar", storeID: 1)
200
+ expect(stub).to have_been_requested
201
+ }
202
+ end
203
+
204
+ describe "copy_content" do
205
+ specify {
206
+ expect { subject.copy_content("foo", "bar", headers: {'x-dura-meta-copy-source'=>'space-id/content-id'}) }
207
+ .to raise_error(NotImplementedError)
208
+ }
209
+ end
210
+
211
+ describe "get_audit_log" do
212
+ specify {
213
+ stub = stub_request(:get, "https://example.com/durastore/audit/foo")
214
+ subject.get_audit_log("foo")
215
+ expect(stub).to have_been_requested
216
+ }
217
+ specify {
218
+ stub = stub_request(:get, "https://example.com/durastore/audit/foo")
219
+ .with(query: {storeID: 1})
220
+ subject.get_audit_log("foo", storeID: 1)
221
+ expect(stub).to have_been_requested
222
+ }
223
+ end
224
+
225
+ describe "get_manifest" do
226
+ specify {
227
+ stub = stub_request(:get, "https://example.com/durastore/manifest/foo")
228
+ subject.get_manifest("foo")
229
+ expect(stub).to have_been_requested
230
+ }
231
+ specify {
232
+ stub = stub_request(:get, "https://example.com/durastore/manifest/foo")
233
+ .with(query: {format: "BAGIT", storeID: 1})
234
+ subject.get_manifest("foo", format: "BAGIT", storeID: 1)
235
+ expect(stub).to have_been_requested
236
+ }
237
+ end
238
+
239
+ describe "get_bit_integrity_report" do
240
+ specify {
241
+ stub = stub_request(:get, "https://example.com/durastore/bit-integrity/foo")
242
+ subject.get_bit_integrity_report("foo")
243
+ expect(stub).to have_been_requested
244
+ }
245
+ specify {
246
+ stub = stub_request(:get, "https://example.com/durastore/bit-integrity/foo")
247
+ .with(query: {storeID: 1})
248
+ subject.get_bit_integrity_report("foo", storeID: 1)
249
+ expect(stub).to have_been_requested
250
+ }
251
+ end
252
+
253
+ describe "get_bit_integrity_report_properties" do
254
+ specify {
255
+ stub = stub_request(:head, "https://example.com/durastore/bit-integrity/foo")
256
+ subject.get_bit_integrity_report_properties("foo")
257
+ expect(stub).to have_been_requested
258
+ }
259
+ specify {
260
+ stub = stub_request(:head, "https://example.com/durastore/bit-integrity/foo")
261
+ .with(query: {storeID: 1})
262
+ subject.get_bit_integrity_report_properties("foo", storeID: 1)
263
+ expect(stub).to have_been_requested
264
+ }
265
+ end
266
+
267
+ describe "get_tasks" do
268
+ specify {
269
+ expect { subject.get_tasks }.to raise_error(NotImplementedError)
270
+ }
271
+ end
272
+
273
+ describe "perform_task" do
274
+ specify {
275
+ expect { subject.perform_task("enable-streaming") }
276
+ .to raise_error(NotImplementedError)
277
+ }
278
+ end
8
279
  end
9
280
  end
@@ -1,29 +1,122 @@
1
1
  module Duracloud
2
2
  RSpec.describe Content do
3
3
 
4
+ let(:url) { "https://example.com/durastore/foo/bar" }
5
+
4
6
  describe ".find" do
5
- subject { Content.find(space_id: "foo", id: "bar") }
6
- before {
7
- allow_any_instance_of(Content).to receive(:load_properties) { nil }
8
- }
9
- it { is_expected.to be_a(Content) }
10
- its(:url) { is_expected.to eq("foo/bar") }
7
+ describe "when it exists" do
8
+ before { stub_request(:head, url) }
9
+ specify {
10
+ expect(Content.find("foo", "bar")).to be_a(Content)
11
+ }
12
+ end
13
+ describe "when it does not exist" do
14
+ before { stub_request(:head, url).to_return(status: 404) }
15
+ specify {
16
+ expect { Content.find("foo", "bar") }.to raise_error(NotFoundError)
17
+ }
18
+ end
11
19
  end
12
20
 
13
- describe ".create" do
14
- let(:body) { "Contents of the file" }
15
- subject { Content.create(space_id: "foo", id: "bar", body: body) }
16
- before {
17
- allow_any_instance_of(Content).to receive(:save) { nil }
18
- }
19
- it { is_expected.to be_a(Content) }
20
- its(:url) { is_expected.to eq("foo/bar") }
21
+ describe ".exist?" do
22
+ subject { Content.exist?("foo", "bar") }
23
+ describe "when it exists" do
24
+ before { stub_request(:head, url) }
25
+ it { is_expected.to be true }
26
+ end
27
+ describe "when it does not exist" do
28
+ before { stub_request(:head, url).to_return(status: 404) }
29
+ it { is_expected.to be false }
30
+ end
21
31
  end
22
32
 
23
33
  describe "#save" do
34
+ subject { Content.new("foo", "bar") }
35
+ describe "when not persisted" do
36
+ describe "when empty" do
37
+ it "raises an exception" do
38
+ expect { subject.save }.to raise_error(Error)
39
+ end
40
+ end
41
+ describe "when not empty" do
42
+ before { subject.body = "Some file content" }
43
+ describe "and the space does not exist" do
44
+ before {
45
+ stub_request(:put, url).with(body: "Some file content")
46
+ .to_return(status: 404)
47
+ }
48
+ it "raises an exception" do
49
+ expect { subject.save }.to raise_error(NotFoundError)
50
+ end
51
+ end
52
+ describe "and the space exists" do
53
+ before {
54
+ stub_request(:put, url).with(body: "Some file content")
55
+ .to_return(status: 201)
56
+ }
57
+ it "stores the content" do
58
+ subject.save
59
+ expect(subject).to be_persisted
60
+ end
61
+ end
62
+ end
63
+ end
64
+ describe "when persisted" do
65
+ before {
66
+ allow(subject).to receive(:persisted?) { true }
67
+ stub_request(:head, url)
68
+ }
69
+ describe "and the body has changed" do
70
+ before {
71
+ stub_request(:put, url).with(body: "Some file content")
72
+ .to_return(status: 201)
73
+ }
74
+ it "stores the content" do
75
+ subject.body = "Some file content"
76
+ subject.save
77
+ end
78
+ end
79
+ describe "and the body has not changed" do
80
+ before {
81
+ allow(subject).to receive(:body_changed?) { false }
82
+ stub_request(:post, url)
83
+ .with(headers: {'x-dura-meta-creator'=>'testuser'})
84
+ }
85
+ it "updates the properties" do
86
+ subject.properties.creator = "testuser"
87
+ subject.save
88
+ end
89
+ end
90
+ end
24
91
  end
25
92
 
26
93
  describe "#delete" do
94
+ subject { Content.new("foo", "bar") }
95
+ describe "when not found" do
96
+ before { stub_request(:delete, url).to_return(status: 404) }
97
+ it "raises an exception" do
98
+ expect { subject.delete }.to raise_error(NotFoundError)
99
+ end
100
+ end
101
+ describe "when found" do
102
+ before { stub_request(:delete, url) }
103
+ it "deletes the content" do
104
+ subject.delete
105
+ expect(subject).to be_deleted
106
+ end
107
+ end
108
+ end
109
+
110
+ describe "#properties" do
111
+ before {
112
+ stub_request(:head, url)
113
+ .to_return(status: 200, headers: {'x-dura-meta-creator'=>'testuser'})
114
+ }
115
+ specify {
116
+ pending "A problem with Webmock / HTTPClient?"
117
+ content = Content.find("foo", "bar")
118
+ expect(content.properties.x_dura_meta_creator).to eq('testuser')
119
+ }
27
120
  end
28
121
 
29
122
  end
@@ -1,3 +1,12 @@
1
+ module Duracloud
2
+ RSpec.describe Manifest do
3
+
4
+ let(:body) { <<-EOS
1
5
  space-id content-id MD5
2
6
  auditlogs localhost/51/auditlogs/localhost_51_auditlogs-2014-09-10-15-56-07.tsv 6992f8e57dafb17335f766aa2acf5942
3
7
  auditlogs localhost/51/photos/localhost_51_photos-2014-09-10-15-55-01.tsv 820e786633fb495db447dc5d5cf0b2bd
8
+ EOS
9
+ }
10
+
11
+ end
12
+ end