pyr 0.2.6 → 0.2.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/pyr.rb +1 -1
- data/lib/pyr/response.rb +42 -9
- data/lib/pyr/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: 914f50257dbe7dc3ae66aaf21f42ad22a55e5159
|
4
|
+
data.tar.gz: 06f70f5b276a4255fb2447bde72b7a93908fddaf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 379d5b802899fa9bf3d6e1005cc4088229903650a1fe8c655a302f6ee21736cc2c1a2709adb36df912b7a5b9675bf6a8c0ec8491bdae3db584986e7975d5e80b
|
7
|
+
data.tar.gz: 30a81749f5c73352238d337a3861cc70def6da50420e3f02ac1b77fc92dafcf1d8e4f5c443c5570a33069fa8aa873cf2845fed68f548755b11cb688adccd2378
|
data/lib/pyr.rb
CHANGED
@@ -155,7 +155,7 @@ module PYR
|
|
155
155
|
if resource.is_a?(ResponseObject)
|
156
156
|
request_object = { response_object: resource }
|
157
157
|
elsif resource.to_s.include? API_BASE_URI
|
158
|
-
request_object = {
|
158
|
+
request_object = { uri: resource }
|
159
159
|
else
|
160
160
|
resource = Request.build(resource, id)
|
161
161
|
yield resource if block_given?
|
data/lib/pyr/response.rb
CHANGED
@@ -2,25 +2,58 @@
|
|
2
2
|
|
3
3
|
module PYR
|
4
4
|
# The object returned by a request call to the API.
|
5
|
+
# == Example
|
6
|
+
# response = PYR.call :reps, 'S000033'
|
7
|
+
# # => #<PYR::Response:0x007fe8f90829f8 ... >
|
5
8
|
class Response
|
6
|
-
|
9
|
+
# Returns a hash of the Raw JSON response
|
10
|
+
# == Example
|
11
|
+
# response.body # => { ... }
|
12
|
+
attr_reader :body
|
13
|
+
# Returns a string of the URI path
|
14
|
+
# == Example
|
15
|
+
# response.path # => 'reps/S000033'
|
16
|
+
attr_reader :path
|
17
|
+
# Returns an integer of the HTTP status code
|
18
|
+
# == Example
|
19
|
+
# response.code # => 200
|
20
|
+
attr_reader :code
|
21
|
+
# Returns a string of the response HTTP reason phrase
|
22
|
+
# == Example
|
23
|
+
# response.reason_phrase # => "OK"
|
24
|
+
attr_reader :reason_phrase
|
25
|
+
# Returns a hash of the response HTTP headers
|
26
|
+
# == Example
|
27
|
+
# response.headers # => {"server"=>"Cowboy", "connection"=>"close", ... }
|
28
|
+
attr_reader :headers
|
29
|
+
# Returns a collection of PYR::ResponseObjects representing API objects
|
30
|
+
# == Example
|
31
|
+
# response.objects
|
32
|
+
# # => #<PYR::RepRelation [#<PYR::Rep ... >]>
|
33
|
+
# response.objects.first.office_locations
|
34
|
+
# # => #<PYR::OfficeLocationRelation [#<PYR::OfficeLocation ... >]>
|
35
|
+
attr_reader :objects
|
36
|
+
# Returns a symbol representing the Responding API controller
|
37
|
+
# == Example
|
38
|
+
# response.controller # => :reps
|
39
|
+
attr_reader :controller
|
7
40
|
|
8
|
-
def initialize(
|
9
|
-
assign_url_and_controller(
|
41
|
+
def initialize(uri: nil, resource: nil, response_object: nil)
|
42
|
+
assign_url_and_controller(uri, resource, response_object)
|
10
43
|
fetch_and_parse_payload
|
11
44
|
parse_objects
|
12
45
|
end
|
13
46
|
|
14
|
-
def assign_url_and_controller(
|
47
|
+
def assign_url_and_controller(uri, resource, response_object)
|
15
48
|
if resource
|
16
49
|
@controller = resource.controller
|
17
|
-
@path
|
18
|
-
elsif
|
19
|
-
@controller =
|
20
|
-
@path
|
50
|
+
@path = resource.to_s
|
51
|
+
elsif uri
|
52
|
+
@controller = uri.sub!(API_BASE_URI, '').split('/').first
|
53
|
+
@path = uri
|
21
54
|
elsif response_object
|
22
55
|
@controller = response_object.controller
|
23
|
-
@path
|
56
|
+
@path = response_object.self.sub(API_BASE_URI, '')
|
24
57
|
end
|
25
58
|
end
|
26
59
|
|
data/lib/pyr/version.rb
CHANGED