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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ea77ac4b5fe041319a0edff8e173cb200ea4f4f0
4
- data.tar.gz: 8a988b40f80559222bce3a60697c96c5272b770f
3
+ metadata.gz: 914f50257dbe7dc3ae66aaf21f42ad22a55e5159
4
+ data.tar.gz: 06f70f5b276a4255fb2447bde72b7a93908fddaf
5
5
  SHA512:
6
- metadata.gz: 1f74b966917b39d84d78d4bfa85f0019aafab98d8bac66eb558687fca72ad6ce68ed23b20de280178a83611839b5e3dec29ad726adcb211772f1acc1c2c48917
7
- data.tar.gz: 3dbb8631337eb18f10010626a9e788961d62c22f64c1926857b0f05652f14a942cf2a6eeba7414cc4c3c18d03b5e349626801c04aabca9279cc1be595311dbbc
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 = { base_url: resource }
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
- attr_reader :body, :path, :code, :reason_phrase, :headers, :objects, :controller
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(base_url: nil, resource: nil, response_object: nil)
9
- assign_url_and_controller(base_url, resource, response_object)
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(base_url, resource, response_object)
47
+ def assign_url_and_controller(uri, resource, response_object)
15
48
  if resource
16
49
  @controller = resource.controller
17
- @path = resource.to_s
18
- elsif base_url
19
- @controller = base_url.sub!(API_BASE_URI, '').split('/').first
20
- @path = base_url
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 = response_object.self.sub(API_BASE_URI, '')
56
+ @path = response_object.self.sub(API_BASE_URI, '')
24
57
  end
25
58
  end
26
59
 
data/lib/pyr/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PYR
4
- VERSION = '0.2.6' # :nodoc:
4
+ VERSION = '0.2.7' # :nodoc:
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pyr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.6
4
+ version: 0.2.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - M. Simon Borg