marvelite 0.1.1 → 0.1.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: 7fa3e96bed80844b8f93bc232ba7870c72a8ed65
4
- data.tar.gz: 09185929b654a41aef73e2f5c21022bbd625e0ac
3
+ metadata.gz: faa7a107bdb9bf78772cbfeeb23682c7a31571bd
4
+ data.tar.gz: 2c183a0ee440da0e4f9a5ea0a97a2aa386c2a94d
5
5
  SHA512:
6
- metadata.gz: b27af76180a1d2d99216e47f2c421faa28f7bdb79b117bd409ec0c94de72bc20f249e8b5ed9587dc7e4c4f7dfa978d5ee8c8359bcb35211cde45344acc6ecd50
7
- data.tar.gz: 953135e4e303d34fe230d643043952501cb75fc32c039644387a674f9497d7ea6b5ef818e11be47cd70ed6e1505383c5ba947e10986033cd7007d828b0f630e5
6
+ metadata.gz: ce9f5eae4795d770a9106443fa38bcf24a26a3a46f8ed2075ddfe1325cab8fdc6c3689fd87bc94723b846ca8e59a6e265a4a80c44f51e6693a77aecb78aa972d
7
+ data.tar.gz: e740a5008b0b3867a2c5987c5ca153f4ff065fe749854d3179a97a4938064f13025b097054ba3b7b3d0d78133e7bcb40c729f24220cb02c5864a4baa19596584
@@ -1,5 +1,9 @@
1
1
  ## Changelog
2
2
 
3
+ ### 0.1.2
4
+ * Adds `#raw_response` to store the original response from the API inside
5
+ a `Marvelite::API::Response` instance. Author: [Jon Allured](https://github.com/jonallured)
6
+
3
7
  ### 0.1.1
4
8
  * Gzipped responses are enabled by default.
5
9
  * All API requests include `{ 'Accept-Encoding' = 'gzip' }` which translates
data/README.md CHANGED
@@ -128,6 +128,22 @@ response.data
128
128
  response.data[:results]
129
129
  ```
130
130
 
131
+ You can always access the raw response returned by the API by calling the
132
+ `#raw_response` attribute of the response. Example:
133
+
134
+ ```ruby
135
+ hero = client.character(1009610)
136
+ hero.raw_response
137
+ #=> { "code"=>200, "status"=>"Ok", "copyright"=>"© 2014 MARVEL", ... }
138
+ ```
139
+ Difference between `response` and `raw_reponse`, is that `raw_response` does
140
+ not include `Hashie` helpers, and thus you need to navigate it as a plain old
141
+ Hash.
142
+ ```ruby
143
+ hero.raw_response['data'][0]['name']
144
+ #=> "Spider-Man"
145
+ ```
146
+
131
147
  ## Etags and Gzip support
132
148
 
133
149
  Support for Etags is built into every endpoint:
@@ -40,14 +40,7 @@ module Marvelite
40
40
  end
41
41
 
42
42
  def build_response_object(response)
43
- case response.code
44
- when 200
45
- Response.new(response)
46
- when 304
47
- NotModifiedResponse.new(response)
48
- else
49
- ErrorResponse.new(response)
50
- end
43
+ Response.make(response)
51
44
  end
52
45
 
53
46
  def find_by_name_or_title(endpoint, column, value)
@@ -5,6 +5,24 @@ module Marvelite
5
5
  include Hashie::Extensions::KeyConversion
6
6
  include Hashie::Extensions::MethodAccess
7
7
  include Hashie::Extensions::IndifferentAccess
8
+
9
+ attr_reader :raw_response
10
+
11
+ def self.make(response)
12
+ case response.code
13
+ when 200
14
+ Response.new(response)
15
+ when 304
16
+ NotModifiedResponse.new(response)
17
+ else
18
+ ErrorResponse.new(response)
19
+ end
20
+ end
21
+
22
+ def initialize(raw)
23
+ @raw_response = raw
24
+ super(raw)
25
+ end
8
26
  end
9
27
 
10
28
  class ErrorResponse < Response; end
@@ -1,3 +1,3 @@
1
1
  module Marvelite
2
- VERSION = '0.1.1'
2
+ VERSION = '0.1.2'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: marvelite
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Antonio Antillon
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-19 00:00:00.000000000 Z
11
+ date: 2014-05-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty