ocean-rails 3.3.1 → 3.3.2

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: 31b1b38b3c165623d55d20c2c50a4e8d0dfcf3af
4
- data.tar.gz: 4953f5131a176fe9e62d5026170756069546cad0
3
+ metadata.gz: 2438ccfdaf98ac780b68714372b10bbb7182372c
4
+ data.tar.gz: 8f080fdec12373dc8cc8d9c0802f3260913e0389
5
5
  SHA512:
6
- metadata.gz: 449a836b690b3246421c3a821469cd5ccd9bc2926803db306e58c0c875a6cb7b859938d08f724053d3a09b9262005b83c53f8206d11c946d17186a859aeae306
7
- data.tar.gz: c29371feb920c6ae52c51617fc3c82db1684864d219bcf3c8a07af611145bd7a35187756afbb0207664b18117ea61fa2bd277bd9139f000a401c70c9508119ae
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.success? => true
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.new("foo").get
45
- # Api::RemoteResource.get("foo")
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.new("foo").get!
50
- # Api::RemoteResource.get!("foo")
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 an Api::RemoteResource if successful. If not, raises an exception.
57
- # <tt>thing.get</tt> does the same, but returns nil if unsuccessful.
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
- begin
123
- get!(*args)
124
- rescue
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
- begin
131
- get!
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
@@ -1,3 +1,3 @@
1
1
  module Ocean
2
- VERSION = "3.3.1"
2
+ VERSION = "3.3.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ocean-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.3.1
4
+ version: 3.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Bengtson