pyr 0.3.5 → 0.3.6

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: 06dabb456b098d36fcdd56f8e2ca411081cdb6d9
4
- data.tar.gz: e09dc5d6924736a814728202502dcfb7914b069f
3
+ metadata.gz: 3cd5d4b0396c09ef15ce17149ddc2630c0a7be0b
4
+ data.tar.gz: 23862f7073f6ce87b2d4b7dd499ba69484c55eba
5
5
  SHA512:
6
- metadata.gz: 97b7a826450b221c83eee3695bc9d942a9b1930b21f3ac751e872305ca246ecf9a546b3761adf3d941a9cf401a4e837ba6a49e26f0059befce4625e27d8a4692
7
- data.tar.gz: 14f9b4d09aaf1c2b260db07c54684e590f076ab7337da24d6183d011481653c539a84a747d2c9508938638b5bb458bd5d0825c264bbe1dda517623055b9df3ff
6
+ metadata.gz: 9ed8f194ac9d6a9f7da98603875a19a4a96adb6107b3e7b04954f1289fb28e0f0691507bfd3f43a2cbe3dd6f4bc94ea432c13ae7f859a0ca4a43b04b8ac79093
7
+ data.tar.gz: ccca4b7c35d5995d5d888418f204b5bbbd9392ce350b18d45ce4e5ef914e3fb0124ae767d647f4e82c65395d1b0c4cdc99fe7b7b63517c855e856ce5b2eb964a
data/README.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # PYR
2
+ [![Gem Version](https://badge.fury.io/rb/pyr.svg)](https://badge.fury.io/rb/pyr)
2
3
  [![Code Climate](https://codeclimate.com/github/msimonborg/pyr/badges/gpa.svg)](https://codeclimate.com/github/msimonborg/pyr)
4
+ [![Coverage Status](https://coveralls.io/repos/github/msimonborg/pyr/badge.svg?branch=master)](https://coveralls.io/github/msimonborg/pyr?branch=master)
5
+ [![Build Status](https://travis-ci.org/msimonborg/pyr.svg?branch=master)](https://travis-ci.org/msimonborg/pyr)
6
+ [![Inline docs](http://inch-ci.org/github/msimonborg/pyr.svg?branch=master)](http://inch-ci.org/github/msimonborg/pyr)
3
7
 
4
8
  PYR makes integrating data from the [Phone Your Rep API](https://www.github.com/phoneyourrep/phone-your-rep-api) into your Ruby project as easy as pie.
5
9
 
@@ -122,6 +126,17 @@ district = PYR.call(uri).objects.first
122
126
  => #<PYR::District self: "https://phone-your-rep.herokuapp.com/api/beta/districts/5000", full_code: "5000", code: "00", state_code: "50">
123
127
  ```
124
128
 
129
+ ## Platform support
130
+
131
+ Tested against:
132
+ * MRI 2.3.0
133
+ * MRI 2.3.4
134
+ * MRI 2.4.1
135
+ * JRuby 9.1.6.0
136
+ * Rubinius 3.74
137
+ * JRuby HEAD
138
+ * MRI HEAD
139
+
125
140
  ## Development
126
141
 
127
142
  After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
data/lib/pyr.rb CHANGED
@@ -112,43 +112,66 @@ module PYR
112
112
  inflect.irregular 'zcta', 'zctas'
113
113
  end
114
114
 
115
- # The main API interface. All the objects you will need to work
116
- # with are returned by this method.
115
+ # Main interface to the API, specify a resource, optional ID, and params
117
116
  #
118
- # Arguments can be:
117
+ # @param resource [Symbol, String]
118
+ # @param id [String]
119
119
  #
120
- # * a particular PYR::ResponseObject itself to query that object's 'self' url;
121
- #
122
- # * a valid Phone Your Rep URI beginning with the API_BASE_URI string value;
120
+ # @return [PYR::Response]
123
121
  #
124
- # * or, perhaps most commonly, a resource name (String or Symbol) with
125
- # optional ID(String).
122
+ # @api public
126
123
  #
127
- # @return [Response]
124
+ # @example
125
+ # PYR.call(:zctas, '90026') { |req| req.reps = true }
128
126
  def self.call(resource, id = nil, &config_block)
129
- if resource.is_a?(ResponseObject)
130
- request_object = { response_object: resource }
131
- elsif resource.to_s.include? API_BASE_URI
132
- request_object = { uri: resource }
133
- else
134
- resource = Request.build(resource, id)
135
- config_block.call resource if block_given?
136
- request_object = { resource: resource }
137
- end
138
- Response.new request_object
127
+ resource = Request.build(resource, id)
128
+ config_block.call resource if block_given?
129
+ Response.new(resource: resource)
130
+ end
131
+
132
+ # Query the API by a valid Phone Your Rep URI
133
+ #
134
+ # @example
135
+ # PYR.uri("#{PYR::BASE_URI.dup}reps/S000033") # => #<PYR::Response ... >
136
+ #
137
+ # @return [PYR::Response]
138
+ #
139
+ # @param uri [String]
140
+ #
141
+ # @api public
142
+ def self.uri(uri)
143
+ Response.new(uri: uri)
144
+ end
145
+
146
+ # Query the API by passing a PYR::ResponseObject
147
+ #
148
+ # @example
149
+ # object = PYR.call(:reps, 'S000033').objects.first # => #<PYR::Rep ... >
150
+ # other_object = PYR.object(object).objects.first # => #<PYR::Rep ... >
151
+ # object == other_object # => true
152
+ #
153
+ # @return [PYR::Response]
154
+ #
155
+ # @param object [PYR::ResponseObject]
156
+ #
157
+ # @api public
158
+ def self.object(object)
159
+ Response.new(response_object: object)
139
160
  end
140
161
 
141
- # Call the :reps resource.
162
+ # Call the :reps resource
142
163
  #
143
164
  # @example
144
165
  # PYR.reps { |r| r.address = '123 Main St, USA 12345' }
145
166
  #
167
+ # @api public
168
+ #
146
169
  # @return [PYR::Response]
147
170
  def self.reps(id = nil, &config_block)
148
171
  call(:reps, id, &config_block)
149
172
  end
150
173
 
151
- # Call the :office_locations resource.
174
+ # Call the :office_locations resource
152
175
  #
153
176
  # @example
154
177
  # PYR.office_locations do |r|
@@ -156,36 +179,44 @@ module PYR
156
179
  # r.radius = 50
157
180
  # end
158
181
  #
182
+ # @api public
183
+ #
159
184
  # @return [PYR::Response]
160
185
  def self.office_locations(id = nil, &config_block)
161
186
  call(:office_locations, id, &config_block)
162
187
  end
163
188
 
164
- # Call the :zctas resource.
189
+ # Call the :zctas resource
165
190
  #
166
191
  # @example
167
192
  # PYR.zctas('90026') { |r| r.reps = true }
168
193
  #
194
+ # @api public
195
+ #
169
196
  # @return [PYR::Response]
170
197
  def self.zctas(id = nil, &config_block)
171
198
  call(:zctas, id, &config_block)
172
199
  end
173
200
 
174
- # Call the :states resource.
201
+ # Call the :states resource
175
202
  #
176
203
  # @example
177
204
  # PYR.states '50'
178
205
  #
206
+ # @api public
207
+ #
179
208
  # @return [PYR::Response]
180
209
  def self.states(id = nil, &config_block)
181
210
  call(:states, id, &config_block)
182
211
  end
183
212
 
184
- # Call the :districts resource.
213
+ # Call the :districts resource
185
214
  #
186
215
  # @example
187
216
  # PYR.districts '5000'
188
217
  #
218
+ # @api public
219
+ #
189
220
  # @return [PYR::Response]
190
221
  def self.districts(id = nil, &config_block)
191
222
  call(:districts, id, &config_block)
data/lib/pyr/resource.rb CHANGED
@@ -33,6 +33,8 @@ module PYR
33
33
  "#{controller}#{id}?#{params.map(&:to_s).join('&')}"
34
34
  end
35
35
 
36
+ private
37
+
36
38
  def params
37
39
  @params ||= []
38
40
  end
data/lib/pyr/response.rb CHANGED
@@ -49,8 +49,8 @@ module PYR
49
49
  @controller = resource.controller
50
50
  @path = resource.to_s
51
51
  elsif uri
52
- @controller = uri.sub!(API_BASE_URI, '').split('/').first
53
- @path = uri
52
+ @path = uri.sub(API_BASE_URI, '')
53
+ @controller = @path.split('/').first
54
54
  elsif response_object
55
55
  @controller = response_object.controller
56
56
  @path = response_object.self.sub(API_BASE_URI, '')
@@ -23,14 +23,23 @@ module PYR
23
23
  super(new_opts, &block)
24
24
  end
25
25
 
26
- # The controller name, based on the object's class name.
26
+ # The controller name, based on the object's class name
27
27
  def controller
28
28
  @controller ||= self.class.to_s.split('::').last.tableize
29
29
  end
30
30
 
31
- # Send a request to the API for the object.
31
+ # Send a request to the API for the object
32
+ #
33
+ # @example
34
+ # object = PYR.call(:reps, 'S000033').objects.first # => #<PYR::Rep ... >
35
+ # res = object.call # => #<PYR::Response ... >
36
+ # object == res.objects.first # => true
37
+ #
38
+ # @return [PYR::Response]
39
+ #
40
+ # @api public
32
41
  def call
33
- PYR.call self
42
+ PYR.object self
34
43
  end
35
44
 
36
45
  private
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.3.5' # :nodoc:
4
+ VERSION = '0.3.6' # :nodoc:
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pyr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.5
4
+ version: 0.3.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - M. Simon Borg
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-04-18 00:00:00.000000000 Z
11
+ date: 2017-04-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 0.6.0
47
+ version: 0.6.2
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 0.6.0
54
+ version: 0.6.2
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: bundler
57
57
  requirement: !ruby/object:Gem::Requirement