ocean-rails 4.0.3 → 4.0.4
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.
- checksums.yaml +4 -4
- data/lib/ocean/api.rb +4 -5
- data/lib/ocean/api_remote_resource.rb +31 -13
- data/lib/ocean/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9e13cc2480ac989b37242e14182c41931b25b5ff
|
4
|
+
data.tar.gz: e84d495747487e35a951cc80eb1c53508d742351
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c75d7190f2c20ada7c2349e625523fb2bf5161bd7e805d680d5bd4b2872605850fa3e65cd067022aad9f2ad3b18be0e0203c4b9215839df3d1c716562594a2ae
|
7
|
+
data.tar.gz: 17e85cd0ce7257bbedac4b231e4222f62e563bc21089ee43a29c448f68314ea94f41e82a175d04417f3065953b4295f8c36958bd4d469df8ea9b8050b3596925
|
data/lib/ocean/api.rb
CHANGED
@@ -349,7 +349,7 @@ class Api
|
|
349
349
|
# If not successful, +nil+ is returned.
|
350
350
|
#
|
351
351
|
def self.authenticate(username=API_USER, password=API_PASSWORD)
|
352
|
-
response = Api.request "
|
352
|
+
response = Api.request "/v1/authentications", :post,
|
353
353
|
headers: {'X-API-Authenticate' => credentials(username, password)}
|
354
354
|
case response.status
|
355
355
|
when 201
|
@@ -423,8 +423,7 @@ class Api
|
|
423
423
|
#
|
424
424
|
def self.permitted?(token, args={})
|
425
425
|
raise unless token
|
426
|
-
Api.request "
|
427
|
-
args: args
|
426
|
+
Api.request "/v1/authentications/#{token}", :get, args: args
|
428
427
|
end
|
429
428
|
|
430
429
|
|
@@ -480,7 +479,7 @@ class Api
|
|
480
479
|
subject: nil,
|
481
480
|
plaintext: nil, html: nil,
|
482
481
|
plaintext_url: nil, html_url: nil, substitutions: nil)
|
483
|
-
Api.request "
|
482
|
+
Api.request "/v1/mails", :post,
|
484
483
|
x_api_token: Api.service_token, credentials: Api.credentials,
|
485
484
|
body: {
|
486
485
|
from: from, to: to, subject: subject,
|
@@ -555,7 +554,7 @@ class Api
|
|
555
554
|
#
|
556
555
|
def self.run_async_job(href=nil, method=nil, job: nil, **keywords, &block)
|
557
556
|
job ||= async_job_body(href, method, **keywords)
|
558
|
-
Api.request "
|
557
|
+
Api.request "/v1/async_jobs", :post,
|
559
558
|
body: job.to_json, x_api_token: Api.service_token
|
560
559
|
rescue TimeoutError, NoResponseError => e
|
561
560
|
raise e unless block
|
@@ -107,6 +107,11 @@ class Api
|
|
107
107
|
# The above is a Thing resource, wrapped with its type. Attributes should appear in the inner
|
108
108
|
# hash, which must have at least a +_links+ hyperlink attribute with a href and a content type.
|
109
109
|
#
|
110
|
+
# If any of the four getters (.get!, .get, #get!, and #get) receive an Ocean collection,
|
111
|
+
# the instance method +#collection+ will return an array of RemoteResources. NB: the getters
|
112
|
+
# will still, in all cases, return the RemoteResource itself. The collection is always made
|
113
|
+
# available as the value of +#collection+ on the RemoteResource which was used to obtain it.
|
114
|
+
#
|
110
115
|
# To refresh a resource using a conditional GET:
|
111
116
|
#
|
112
117
|
# thing.refresh
|
@@ -126,13 +131,11 @@ class Api
|
|
126
131
|
# +nil+, you can always chack +#status+, +#status_message+, and/or +#headers+ to determine what
|
127
132
|
# went wrong. After fetching non-resource data, +#present?+ will always be false.
|
128
133
|
#
|
129
|
-
# TODO: If .get or .get! retrieve an Ocean collection, let them return an array of RemoteResources.
|
130
|
-
#
|
131
134
|
class RemoteResource
|
132
135
|
|
133
136
|
attr_reader :uri, :args, :content_type, :retries, :backoff_time, :backoff_rate, :backoff_max
|
134
137
|
attr_reader :raw, :resource, :resource_type, :status, :headers, :credentials, :x_api_token
|
135
|
-
attr_reader :status_message, :response, :etag
|
138
|
+
attr_reader :status_message, :response, :etag, :collection
|
136
139
|
|
137
140
|
#
|
138
141
|
# The credentials and the x_api_token, if both are left unspecified, will default to
|
@@ -435,7 +438,7 @@ class Api
|
|
435
438
|
|
436
439
|
attr_accessor :present
|
437
440
|
attr_writer :raw, :resource, :resource_type, :status, :headers, :status_message, :response
|
438
|
-
attr_writer :etag
|
441
|
+
attr_writer :etag, :collection
|
439
442
|
|
440
443
|
|
441
444
|
def _credentials(rr)
|
@@ -491,11 +494,16 @@ class Api
|
|
491
494
|
end
|
492
495
|
|
493
496
|
|
494
|
-
def _setup(
|
495
|
-
self.raw =
|
496
|
-
|
497
|
-
|
498
|
-
|
497
|
+
def _setup(wrapped, response)
|
498
|
+
self.raw = wrapped
|
499
|
+
if raw && raw.is_a?(Hash) && raw['_collection']
|
500
|
+
self.collection = raw['_collection']['resources'].map { |wrapped| _make wrapped, response }
|
501
|
+
self.resource_type = '_collection'
|
502
|
+
else
|
503
|
+
type, resource = verify_resource wrapped
|
504
|
+
self.resource = resource
|
505
|
+
self.resource_type = type
|
506
|
+
end
|
499
507
|
self.response = response
|
500
508
|
self.status = response.status
|
501
509
|
self.status_message = response.message
|
@@ -505,10 +513,20 @@ class Api
|
|
505
513
|
end
|
506
514
|
|
507
515
|
|
508
|
-
def
|
509
|
-
|
510
|
-
|
511
|
-
|
516
|
+
def _make(wrapped, response)
|
517
|
+
resource_type, attributes = wrapped.to_a.first
|
518
|
+
r = Api::RemoteResource.new attributes['_links']['self']['href'],
|
519
|
+
retries: retries, backoff_time: backoff_time,
|
520
|
+
backoff_rate: backoff_rate, backoff_max: backoff_max
|
521
|
+
r.send :_setup, wrapped, response
|
522
|
+
r
|
523
|
+
end
|
524
|
+
|
525
|
+
|
526
|
+
def verify_resource(wrapped)
|
527
|
+
raise JsonIsNoResource unless wrapped.is_a? Hash
|
528
|
+
raise JsonIsNoResource unless wrapped.size == 1
|
529
|
+
resource_type, attributes = wrapped.to_a.first
|
512
530
|
raise JsonIsNoResource unless attributes.is_a? Hash
|
513
531
|
raise JsonIsNoResource unless attributes['_links'].is_a? Hash
|
514
532
|
raise JsonIsNoResource unless attributes['_links']['self'].is_a? Hash
|
data/lib/ocean/version.rb
CHANGED