ocean-rails 3.3.1 → 3.3.2
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_remote_resource.rb +15 -20
- 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: 2438ccfdaf98ac780b68714372b10bbb7182372c
|
4
|
+
data.tar.gz: 8f080fdec12373dc8cc8d9c0802f3260913e0389
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c51f0ec1983312a743c9ae9d5ec8988f3c2eb0be46f76d5575f4f14428a524c734ad60b2079d1e1fcb3b4a7331bfe8b88827bbd82c5a6fd780886d568940c1be
|
7
|
+
data.tar.gz: 4fb09674fa65c1dc3aeb97be98f3a52255cfebecd853f891e4288ed31db5e9a1007adb82c5f9bec9e8008a5472c545b826742ef76d4ea419bad03023fda6f71f
|
@@ -13,7 +13,7 @@ class Api
|
|
13
13
|
#
|
14
14
|
# thing.resource_type => 'thing'
|
15
15
|
# thing.status => 200
|
16
|
-
# thing.
|
16
|
+
# thing.status_message => "OK"
|
17
17
|
#
|
18
18
|
# The last raw body can be read:
|
19
19
|
#
|
@@ -41,25 +41,25 @@ class Api
|
|
41
41
|
#
|
42
42
|
# The following two are equivalent:
|
43
43
|
#
|
44
|
-
# Api::RemoteResource.
|
45
|
-
# Api::RemoteResource.
|
44
|
+
# Api::RemoteResource.get("foo") always returns a new RemoteResource
|
45
|
+
# Api::RemoteResource.new("foo").get always returns the RemoteResource
|
46
46
|
#
|
47
47
|
# as are:
|
48
48
|
#
|
49
|
-
# Api::RemoteResource.
|
50
|
-
# Api::RemoteResource.
|
49
|
+
# Api::RemoteResource.get!("foo") returns a new RemoteResource or raises an error
|
50
|
+
# Api::RemoteResource.new("foo").get! returns the RemoteResource or raises an error
|
51
51
|
#
|
52
52
|
# #post, #post!, #put, #put!, #delete, and #delete! are also available.
|
53
53
|
#
|
54
54
|
# If get or get! retrieve an Ocean collection, they will return an array of RemoteResources.
|
55
55
|
#
|
56
|
-
# <tt>thing.get!</tt> returns
|
57
|
-
# <tt>thing.get</tt> does the same, but returns
|
56
|
+
# <tt>thing.get!</tt> returns the Api::RemoteResource if successful. If not, raises an exception.
|
57
|
+
# <tt>thing.get</tt> does the same, but always returns the Api::RemoteResource. The remote resource
|
58
|
+
# can be examined to see its status.
|
58
59
|
#
|
59
60
|
# Exceptions:
|
60
61
|
#
|
61
62
|
# GetFailed raised when the GET to obtain the remote resource has failed.
|
62
|
-
# WrongContentType raised when the Content-Type doesn't match :content_type.
|
63
63
|
# UnparseableJson raised when the response body doesn't parse as JSON.
|
64
64
|
# JsonIsNoResource raised when the structure of the parsed JSON body is not a resource.
|
65
65
|
#
|
@@ -119,19 +119,14 @@ class Api
|
|
119
119
|
end
|
120
120
|
|
121
121
|
def self.get(*args)
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
nil
|
126
|
-
end
|
122
|
+
rr = new(*args)
|
123
|
+
rr.get! rescue nil
|
124
|
+
rr
|
127
125
|
end
|
128
126
|
|
129
127
|
def get
|
130
|
-
|
131
|
-
|
132
|
-
rescue
|
133
|
-
nil
|
134
|
-
end
|
128
|
+
get! rescue nil
|
129
|
+
self
|
135
130
|
end
|
136
131
|
|
137
132
|
def [](key)
|
@@ -157,7 +152,6 @@ class Api
|
|
157
152
|
|
158
153
|
|
159
154
|
class GetFailed < StandardError; end
|
160
|
-
class WrongContentType < StandardError; end
|
161
155
|
class UnparseableJson < StandardError; end
|
162
156
|
class JsonIsNoResource < StandardError; end
|
163
157
|
|
@@ -179,8 +173,8 @@ class Api
|
|
179
173
|
response = Api.request rr.uri, :get, headers: {}, credentials: credentials, x_api_token: token
|
180
174
|
rr.send :status=, response.status
|
181
175
|
rr.send :status_message=, response.message
|
176
|
+
rr.send :headers=, response.headers
|
182
177
|
raise GetFailed unless response.success?
|
183
|
-
#raise WrongContentType unless response.headers['Content-Type'] == rr.content_type
|
184
178
|
begin
|
185
179
|
raw = response.body
|
186
180
|
rescue JSON::ParserError
|
@@ -204,6 +198,7 @@ class Api
|
|
204
198
|
self.resource = value
|
205
199
|
self.resource_type = resource_type
|
206
200
|
self.status = response.status
|
201
|
+
self.status_message = response.message
|
207
202
|
self.headers = response.headers
|
208
203
|
self.present = true
|
209
204
|
end
|
data/lib/ocean/version.rb
CHANGED