pyr 0.3.5 → 0.3.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +15 -0
- data/lib/pyr.rb +55 -24
- data/lib/pyr/resource.rb +2 -0
- data/lib/pyr/response.rb +2 -2
- data/lib/pyr/response_object.rb +12 -3
- data/lib/pyr/version.rb +1 -1
- metadata +4 -4
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 3cd5d4b0396c09ef15ce17149ddc2630c0a7be0b
         | 
| 4 | 
            +
              data.tar.gz: 23862f7073f6ce87b2d4b7dd499ba69484c55eba
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 9ed8f194ac9d6a9f7da98603875a19a4a96adb6107b3e7b04954f1289fb28e0f0691507bfd3f43a2cbe3dd6f4bc94ea432c13ae7f859a0ca4a43b04b8ac79093
         | 
| 7 | 
            +
              data.tar.gz: ccca4b7c35d5995d5d888418f204b5bbbd9392ce350b18d45ce4e5ef914e3fb0124ae767d647f4e82c65395d1b0c4cdc99fe7b7b63517c855e856ce5b2eb964a
         | 
    
        data/README.md
    CHANGED
    
    | @@ -1,5 +1,9 @@ | |
| 1 1 | 
             
            # PYR
         | 
| 2 | 
            +
            [](https://badge.fury.io/rb/pyr)
         | 
| 2 3 | 
             
            [](https://codeclimate.com/github/msimonborg/pyr)
         | 
| 4 | 
            +
            [](https://coveralls.io/github/msimonborg/pyr?branch=master)
         | 
| 5 | 
            +
            [](https://travis-ci.org/msimonborg/pyr)
         | 
| 6 | 
            +
            [](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 | 
            -
              #  | 
| 116 | 
            -
              # with are returned by this method.
         | 
| 115 | 
            +
              # Main interface to the API, specify a resource, optional ID, and params
         | 
| 117 116 | 
             
              #
         | 
| 118 | 
            -
              #  | 
| 117 | 
            +
              # @param resource [Symbol, String]
         | 
| 118 | 
            +
              # @param id [String]
         | 
| 119 119 | 
             
              #
         | 
| 120 | 
            -
              #  | 
| 121 | 
            -
              #
         | 
| 122 | 
            -
              # * a valid Phone Your Rep URI beginning with the API_BASE_URI string value;
         | 
| 120 | 
            +
              # @return [PYR::Response]
         | 
| 123 121 | 
             
              #
         | 
| 124 | 
            -
              #  | 
| 125 | 
            -
              #   optional ID(String).
         | 
| 122 | 
            +
              # @api public
         | 
| 126 123 | 
             
              #
         | 
| 127 | 
            -
              # @ | 
| 124 | 
            +
              # @example
         | 
| 125 | 
            +
              #   PYR.call(:zctas, '90026') { |req| req.reps = true }
         | 
| 128 126 | 
             
              def self.call(resource, id = nil, &config_block)
         | 
| 129 | 
            -
                 | 
| 130 | 
            -
             | 
| 131 | 
            -
                 | 
| 132 | 
            -
             | 
| 133 | 
            -
             | 
| 134 | 
            -
             | 
| 135 | 
            -
             | 
| 136 | 
            -
             | 
| 137 | 
            -
             | 
| 138 | 
            -
             | 
| 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
    
    
    
        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 | 
            -
                    @ | 
| 53 | 
            -
                    @ | 
| 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, '')
         | 
    
        data/lib/pyr/response_object.rb
    CHANGED
    
    | @@ -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. | 
| 42 | 
            +
                  PYR.object self
         | 
| 34 43 | 
             
                end
         | 
| 35 44 |  | 
| 36 45 | 
             
                private
         | 
    
        data/lib/pyr/version.rb
    CHANGED
    
    
    
        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. | 
| 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- | 
| 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. | 
| 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. | 
| 54 | 
            +
                    version: 0.6.2
         | 
| 55 55 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 56 56 | 
             
              name: bundler
         | 
| 57 57 | 
             
              requirement: !ruby/object:Gem::Requirement
         |