geocodio 2.1.0 → 3.0.0
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/lib/geocodio/address.rb +5 -5
- data/lib/geocodio/address_set.rb +7 -3
- data/lib/geocodio/client.rb +4 -4
- data/lib/geocodio/congressional_district.rb +9 -0
- data/lib/geocodio/legislator.rb +69 -0
- data/lib/geocodio/state_legislative_district.rb +2 -1
- data/lib/geocodio/utils.rb +5 -3
- data/lib/geocodio/version.rb +2 -2
- data/spec/address_spec.rb +17 -15
- data/spec/client_spec.rb +9 -3
- data/spec/congressional_district_spec.rb +16 -3
- data/spec/legislator_spec.rb +116 -0
- data/spec/spec_helper.rb +2 -0
- data/spec/vcr_cassettes/alaska_geocode_with_fields.yml +21 -7
- data/spec/vcr_cassettes/batch_geocode.yml +32 -23
- data/spec/vcr_cassettes/batch_geocode_with_bad_address.yml +20 -10
- data/spec/vcr_cassettes/batch_geocode_with_fields.yml +107 -40
- data/spec/vcr_cassettes/batch_reverse.yml +66 -35
- data/spec/vcr_cassettes/batch_reverse_with_fields.yml +298 -70
- data/spec/vcr_cassettes/geocode.yml +24 -14
- data/spec/vcr_cassettes/geocode_bad_address.yml +11 -5
- data/spec/vcr_cassettes/geocode_with_fields.yml +53 -21
- data/spec/vcr_cassettes/geocode_with_postdirectional.yml +13 -9
- data/spec/vcr_cassettes/invalid_key.yml +12 -6
- data/spec/vcr_cassettes/parse.yml +17 -7
- data/spec/vcr_cassettes/reverse.yml +33 -17
- data/spec/vcr_cassettes/reverse_with_fields.yml +108 -28
- data/spec/vcr_cassettes/reverse_with_fields_no_house_info.yml +62 -0
- metadata +6 -1
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 4cfd3cac7a1ad430766ac95a5e2c62f19f00f5da4154a80c33f1ecfa6992509f
         | 
| 4 | 
            +
              data.tar.gz: 2a1fe5eb2f4471f841e0a5e0f4653099b10a1fa2a8ba342376b7ddff18929e1d
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 5f3c3158f187ea4ba28cef389881978aaf7e69b003a9a262023bfee02b43f7b31f1b4264a6f7a079e6762c482400ac6e848ef48ec5aed2561e3bac99719bb76f
         | 
| 7 | 
            +
              data.tar.gz: ba9774ac73a69bce566fea407415b3f42201f058292090e9142659c960e9d2471995e5dd056c6a1f9a8d5afc96328573f55ff68799c5fefa717720197736aca0
         | 
    
        data/lib/geocodio/address.rb
    CHANGED
    
    | @@ -12,7 +12,7 @@ module Geocodio | |
| 12 12 | 
             
                alias :lat :latitude
         | 
| 13 13 | 
             
                alias :lng :longitude
         | 
| 14 14 |  | 
| 15 | 
            -
                attr_reader : | 
| 15 | 
            +
                attr_reader :congressional_districts, :house_district, :senate_district,
         | 
| 16 16 | 
             
                            :unified_school_district, :elementary_school_district,
         | 
| 17 17 | 
             
                            :secondary_school_district
         | 
| 18 18 |  | 
| @@ -60,16 +60,16 @@ module Geocodio | |
| 60 60 | 
             
                end
         | 
| 61 61 |  | 
| 62 62 | 
             
                def set_additional_fields(fields)
         | 
| 63 | 
            -
                   | 
| 63 | 
            +
                  set_congressional_districts(fields['congressional_districts'])   if fields['congressional_districts']
         | 
| 64 64 | 
             
                  set_legislative_districts(fields['state_legislative_districts']) if fields['state_legislative_districts']
         | 
| 65 65 | 
             
                  set_school_districts(fields['school_districts'])                 if fields['school_districts']
         | 
| 66 66 | 
             
                  set_timezone(fields['timezone'])                                 if fields['timezone']
         | 
| 67 67 | 
             
                end
         | 
| 68 68 |  | 
| 69 | 
            -
                def  | 
| 70 | 
            -
                  return if  | 
| 69 | 
            +
                def set_congressional_districts(districts)
         | 
| 70 | 
            +
                  return if districts.empty?
         | 
| 71 71 |  | 
| 72 | 
            -
                  @ | 
| 72 | 
            +
                  @congressional_districts = districts.map { |district| CongressionalDistrict.new(district) }
         | 
| 73 73 | 
             
                end
         | 
| 74 74 |  | 
| 75 75 | 
             
                def set_legislative_districts(districts)
         | 
    
        data/lib/geocodio/address_set.rb
    CHANGED
    
    | @@ -11,9 +11,10 @@ module Geocodio | |
| 11 11 | 
             
                # @return [String] the original query
         | 
| 12 12 | 
             
                attr_reader :query
         | 
| 13 13 |  | 
| 14 | 
            -
                def initialize(query, *addresses)
         | 
| 15 | 
            -
                  @query | 
| 16 | 
            -
                  @addresses | 
| 14 | 
            +
                def initialize(query, *addresses, input: nil)
         | 
| 15 | 
            +
                  @query           = query
         | 
| 16 | 
            +
                  @addresses       = addresses
         | 
| 17 | 
            +
                  @formatted_input = input
         | 
| 17 18 | 
             
                end
         | 
| 18 19 |  | 
| 19 20 | 
             
                def each(&block)
         | 
| @@ -24,6 +25,9 @@ module Geocodio | |
| 24 25 | 
             
                #
         | 
| 25 26 | 
             
                # @return [Geocodio::Address] the most accurate address
         | 
| 26 27 | 
             
                def best
         | 
| 28 | 
            +
                  best = @addresses.find { |address| address.to_s == @formatted_input }
         | 
| 29 | 
            +
                  return best if best
         | 
| 30 | 
            +
             | 
| 27 31 | 
             
                  max_by(&:accuracy)
         | 
| 28 32 | 
             
                end
         | 
| 29 33 |  | 
    
        data/lib/geocodio/client.rb
    CHANGED
    
    | @@ -92,9 +92,9 @@ module Geocodio | |
| 92 92 | 
             
                    params[:q] = address
         | 
| 93 93 |  | 
| 94 94 | 
             
                    response  = get '/geocode', params, options
         | 
| 95 | 
            -
                    addresses = parse_results(response)
         | 
| 95 | 
            +
                    addresses, input = parse_results(response)
         | 
| 96 96 |  | 
| 97 | 
            -
                    AddressSet.new(address, *addresses)
         | 
| 97 | 
            +
                    AddressSet.new(address, *addresses, input: input)
         | 
| 98 98 | 
             
                  end
         | 
| 99 99 |  | 
| 100 100 | 
             
                  def reverse_geocode_single(pair, options = {})
         | 
| @@ -103,9 +103,9 @@ module Geocodio | |
| 103 103 | 
             
                    params[:q] = pair
         | 
| 104 104 |  | 
| 105 105 | 
             
                    response  = get '/reverse', params, options
         | 
| 106 | 
            -
                    addresses = parse_results(response)
         | 
| 106 | 
            +
                    addresses, input = parse_results(response)
         | 
| 107 107 |  | 
| 108 | 
            -
                    AddressSet.new(pair, *addresses)
         | 
| 108 | 
            +
                    AddressSet.new(pair, *addresses, input: input)
         | 
| 109 109 | 
             
                  end
         | 
| 110 110 |  | 
| 111 111 | 
             
                  def geocode_batch(addresses, options = {})
         | 
| @@ -1,14 +1,23 @@ | |
| 1 | 
            +
            require 'geocodio/legislator'
         | 
| 2 | 
            +
             | 
| 1 3 | 
             
            module Geocodio
         | 
| 2 4 | 
             
              class CongressionalDistrict
         | 
| 3 5 | 
             
                attr_reader :name
         | 
| 4 6 | 
             
                attr_reader :district_number
         | 
| 5 7 | 
             
                attr_reader :congress_number
         | 
| 8 | 
            +
                attr_reader :proportion
         | 
| 9 | 
            +
                attr_reader :current_legislators
         | 
| 6 10 |  | 
| 7 11 | 
             
                def initialize(payload = {})
         | 
| 8 12 | 
             
                  @name            = payload['name']
         | 
| 9 13 | 
             
                  @district_number = payload['district_number'].to_i
         | 
| 10 14 | 
             
                  @congress_number = payload['congress_number'].to_i
         | 
| 11 15 | 
             
                  @congress_years  = payload['congress_years']
         | 
| 16 | 
            +
                  @proportion      = payload['proportion'].to_i
         | 
| 17 | 
            +
             | 
| 18 | 
            +
                  @current_legislators = payload['current_legislators'].map do |legislator|
         | 
| 19 | 
            +
                    Legislator.new(legislator)
         | 
| 20 | 
            +
                  end
         | 
| 12 21 | 
             
                end
         | 
| 13 22 |  | 
| 14 23 | 
             
                def congress_years
         | 
| @@ -0,0 +1,69 @@ | |
| 1 | 
            +
            module Geocodio
         | 
| 2 | 
            +
              class Legislator
         | 
| 3 | 
            +
                attr_reader :type
         | 
| 4 | 
            +
                attr_reader :name
         | 
| 5 | 
            +
                attr_reader :birthday
         | 
| 6 | 
            +
                attr_reader :gender
         | 
| 7 | 
            +
                attr_reader :party
         | 
| 8 | 
            +
                attr_reader :url
         | 
| 9 | 
            +
                attr_reader :address
         | 
| 10 | 
            +
                attr_reader :phone
         | 
| 11 | 
            +
                attr_reader :contact_form
         | 
| 12 | 
            +
                attr_reader :rss_url
         | 
| 13 | 
            +
                attr_reader :twitter
         | 
| 14 | 
            +
                attr_reader :facebook
         | 
| 15 | 
            +
                attr_reader :youtube
         | 
| 16 | 
            +
                attr_reader :youtube_id
         | 
| 17 | 
            +
                attr_reader :bioguide_id
         | 
| 18 | 
            +
                attr_reader :thomas_id
         | 
| 19 | 
            +
                attr_reader :opensecrets_id
         | 
| 20 | 
            +
                attr_reader :lis_id
         | 
| 21 | 
            +
                attr_reader :cspan_id
         | 
| 22 | 
            +
                attr_reader :govtrack_id
         | 
| 23 | 
            +
                attr_reader :votesmart_id
         | 
| 24 | 
            +
                attr_reader :ballotpedia_id
         | 
| 25 | 
            +
                attr_reader :washington_post_id
         | 
| 26 | 
            +
                attr_reader :icpsr_id
         | 
| 27 | 
            +
                attr_reader :wikipedia_id
         | 
| 28 | 
            +
             | 
| 29 | 
            +
                def initialize(payload = {})
         | 
| 30 | 
            +
                  @type = payload['type']
         | 
| 31 | 
            +
             | 
| 32 | 
            +
                  if payload['bio']
         | 
| 33 | 
            +
                    @name = "#{payload['bio']['first_name']} #{payload['bio']['last_name']}"
         | 
| 34 | 
            +
                    @birthday = Date.new(*payload['bio']['birthday'].split('-').map(&:to_i))
         | 
| 35 | 
            +
                    @gender = payload['bio']['gender']
         | 
| 36 | 
            +
                    @party = payload['bio']['party']
         | 
| 37 | 
            +
                  end
         | 
| 38 | 
            +
             | 
| 39 | 
            +
                  if payload['contact']
         | 
| 40 | 
            +
                    @url          = payload['contact']['url']
         | 
| 41 | 
            +
                    @address      = payload['contact']['address']
         | 
| 42 | 
            +
                    @phone        = payload['contact']['phone']
         | 
| 43 | 
            +
                    @contact_form = payload['contact']['contact_form']
         | 
| 44 | 
            +
                  end
         | 
| 45 | 
            +
             | 
| 46 | 
            +
                  if payload['social']
         | 
| 47 | 
            +
                    @rss_url    = payload['social']['rss_url']
         | 
| 48 | 
            +
                    @twitter    = payload['social']['twitter']
         | 
| 49 | 
            +
                    @facebook   = payload['social']['facebook']
         | 
| 50 | 
            +
                    @youtube    = payload['social']['youtube']
         | 
| 51 | 
            +
                    @youtube_id = payload['social']['youtube_id']
         | 
| 52 | 
            +
                  end
         | 
| 53 | 
            +
             | 
| 54 | 
            +
                  if payload['references']
         | 
| 55 | 
            +
                    @bioguide_id        = payload['references']['bioguide_id']
         | 
| 56 | 
            +
                    @thomas_id          = payload['references']['thomas_id']
         | 
| 57 | 
            +
                    @opensecrets_id     = payload['references']['opensecrets_id']
         | 
| 58 | 
            +
                    @lis_id             = payload['references']['lis_id']
         | 
| 59 | 
            +
                    @cspan_id           = payload['references']['cspan_id']
         | 
| 60 | 
            +
                    @govtrack_id        = payload['references']['govtrack_id']
         | 
| 61 | 
            +
                    @votesmart_id       = payload['references']['votesmart_id']
         | 
| 62 | 
            +
                    @ballotpedia_id     = payload['references']['ballotpedia_id']
         | 
| 63 | 
            +
                    @washington_post_id = payload['references']['washington_post_id']
         | 
| 64 | 
            +
                    @icpsr_id           = payload['references']['icpsr_id']
         | 
| 65 | 
            +
                    @wikipedia_id       = payload['references']['wikipedia_id']
         | 
| 66 | 
            +
                  end
         | 
| 67 | 
            +
                end
         | 
| 68 | 
            +
              end
         | 
| 69 | 
            +
            end
         | 
| @@ -5,7 +5,8 @@ module Geocodio | |
| 5 5 |  | 
| 6 6 | 
             
                def initialize(payload = {})
         | 
| 7 7 | 
             
                  @name            = payload['name']
         | 
| 8 | 
            -
                  @district_number = payload['district_number']
         | 
| 8 | 
            +
                  @district_number = payload['district_number'].to_i
         | 
| 9 | 
            +
                  @district_number = payload['district_number'] if @district_number == 0
         | 
| 9 10 | 
             
                end
         | 
| 10 11 | 
             
              end
         | 
| 11 12 | 
             
            end
         | 
    
        data/lib/geocodio/utils.rb
    CHANGED
    
    | @@ -2,19 +2,21 @@ module Geocodio | |
| 2 2 | 
             
              module Utils
         | 
| 3 3 | 
             
                def parse_results(response)
         | 
| 4 4 | 
             
                  results   = response.body['results']
         | 
| 5 | 
            -
                   | 
| 5 | 
            +
                  input     = response.body['input']['formatted_address'] if response.body['input']
         | 
| 6 | 
            +
                  [results.map { |result| Address.new(result) }, input]
         | 
| 6 7 | 
             
                end
         | 
| 7 8 |  | 
| 8 9 | 
             
                def parse_nested_results(response)
         | 
| 9 10 | 
             
                  results = response.body['results']
         | 
| 10 11 |  | 
| 11 | 
            -
                  results.map do |result_set|
         | 
| 12 | 
            +
                  results = results.map do |result_set|
         | 
| 12 13 | 
             
                    addresses = Array(result_set['response']['results'])
         | 
| 13 14 | 
             
                    addresses.map! { |result| Address.new(result) }
         | 
| 14 15 |  | 
| 15 16 | 
             
                    query = result_set['query']
         | 
| 17 | 
            +
                    input = result_set['response']['input']['formatted_address'] if result_set['response']['input']
         | 
| 16 18 |  | 
| 17 | 
            -
                    AddressSet.new(query, *addresses)
         | 
| 19 | 
            +
                    AddressSet.new(query, *addresses, input: input)
         | 
| 18 20 | 
             
                  end
         | 
| 19 21 | 
             
                end
         | 
| 20 22 |  | 
    
        data/lib/geocodio/version.rb
    CHANGED
    
    
    
        data/spec/address_spec.rb
    CHANGED
    
    | @@ -21,7 +21,7 @@ describe Geocodio::Address do | |
| 21 21 | 
             
                it 'has a street' do
         | 
| 22 22 | 
             
                  expect(address.street).to eq('Colorado')
         | 
| 23 23 | 
             
                end
         | 
| 24 | 
            -
             | 
| 24 | 
            +
             | 
| 25 25 | 
             
                it 'has a formatted_street' do
         | 
| 26 26 | 
             
                  expect(address.formatted_street).to eq('W Colorado Blvd')
         | 
| 27 27 | 
             
                end
         | 
| @@ -76,7 +76,7 @@ describe Geocodio::Address do | |
| 76 76 | 
             
                  it 'has a street' do
         | 
| 77 77 | 
             
                    expect(address.street).to eq('Colorado')
         | 
| 78 78 | 
             
                  end
         | 
| 79 | 
            -
             | 
| 79 | 
            +
             | 
| 80 80 | 
             
                  it 'has a formatted_street' do
         | 
| 81 81 | 
             
                    expect(address.formatted_street).to eq('W Colorado Blvd')
         | 
| 82 82 | 
             
                  end
         | 
| @@ -102,20 +102,20 @@ describe Geocodio::Address do | |
| 102 102 | 
             
                  end
         | 
| 103 103 |  | 
| 104 104 | 
             
                  it 'has a latitude' do
         | 
| 105 | 
            -
                    expect(address.latitude).to eq(34. | 
| 106 | 
            -
                    expect(address.lat).to      eq(34. | 
| 105 | 
            +
                    expect(address.latitude).to eq(34.145375)
         | 
| 106 | 
            +
                    expect(address.lat).to      eq(34.145375)
         | 
| 107 107 | 
             
                  end
         | 
| 108 108 |  | 
| 109 109 | 
             
                  it 'has a longitude' do
         | 
| 110 | 
            -
                    expect(address.longitude).to eq(-118. | 
| 111 | 
            -
                    expect(address.lng).to       eq(-118. | 
| 110 | 
            +
                    expect(address.longitude).to eq(-118.151622)
         | 
| 111 | 
            +
                    expect(address.lng).to       eq(-118.151622)
         | 
| 112 112 | 
             
                  end
         | 
| 113 113 |  | 
| 114 114 | 
             
                  it 'has an accuracy' do
         | 
| 115 115 | 
             
                    expect(address.accuracy).to eq(1)
         | 
| 116 116 | 
             
                  end
         | 
| 117 117 | 
             
                end
         | 
| 118 | 
            -
             | 
| 118 | 
            +
             | 
| 119 119 | 
             
                context 'has postdirectional' do
         | 
| 120 120 | 
             
                  subject(:address) do
         | 
| 121 121 | 
             
                    VCR.use_cassette('geocode_with_postdirectional') do
         | 
| @@ -130,11 +130,11 @@ describe Geocodio::Address do | |
| 130 130 | 
             
                  it 'has a street' do
         | 
| 131 131 | 
             
                    expect(address.street).to eq('Pennsylvania')
         | 
| 132 132 | 
             
                  end
         | 
| 133 | 
            -
             | 
| 133 | 
            +
             | 
| 134 134 | 
             
                  it 'has a formatted_street' do
         | 
| 135 135 | 
             
                    expect(address.formatted_street).to eq('Pennsylvania Ave NW')
         | 
| 136 136 | 
             
                  end
         | 
| 137 | 
            -
             | 
| 137 | 
            +
             | 
| 138 138 | 
             
                  it 'has a postdirectional' do
         | 
| 139 139 | 
             
                    expect(address.postdirectional).to eq('NW')
         | 
| 140 140 | 
             
                  end
         | 
| @@ -160,13 +160,13 @@ describe Geocodio::Address do | |
| 160 160 | 
             
                  end
         | 
| 161 161 |  | 
| 162 162 | 
             
                  it 'has a latitude' do
         | 
| 163 | 
            -
                    expect(address.latitude).to eq(38. | 
| 164 | 
            -
                    expect(address.lat).to      eq(38. | 
| 163 | 
            +
                    expect(address.latitude).to eq(38.897675)
         | 
| 164 | 
            +
                    expect(address.lat).to      eq(38.897675)
         | 
| 165 165 | 
             
                  end
         | 
| 166 166 |  | 
| 167 167 | 
             
                  it 'has a longitude' do
         | 
| 168 | 
            -
                    expect(address.longitude).to eq(-77. | 
| 169 | 
            -
                    expect(address.lng).to       eq(-77. | 
| 168 | 
            +
                    expect(address.longitude).to eq(-77.036547)
         | 
| 169 | 
            +
                    expect(address.lng).to       eq(-77.036547)
         | 
| 170 170 | 
             
                  end
         | 
| 171 171 |  | 
| 172 172 | 
             
                  it 'has an accuracy' do
         | 
| @@ -181,8 +181,10 @@ describe Geocodio::Address do | |
| 181 181 | 
             
                    end
         | 
| 182 182 | 
             
                  end
         | 
| 183 183 |  | 
| 184 | 
            -
                  it 'has  | 
| 185 | 
            -
                     | 
| 184 | 
            +
                  it 'has congressional districts' do
         | 
| 185 | 
            +
                    address.congressional_districts.each do |district|
         | 
| 186 | 
            +
                      expect(district).to be_a(Geocodio::CongressionalDistrict)
         | 
| 187 | 
            +
                    end
         | 
| 186 188 | 
             
                  end
         | 
| 187 189 |  | 
| 188 190 | 
             
                  it 'has a house district' do
         | 
    
        data/spec/client_spec.rb
    CHANGED
    
    | @@ -99,17 +99,23 @@ describe Geocodio::Client do | |
| 99 99 | 
             
                    VCR.use_cassette('reverse') do
         | 
| 100 100 | 
             
                      addresses = geocodio.reverse_geocode([coordinates])
         | 
| 101 101 |  | 
| 102 | 
            -
                      expect(addresses.size).to eq( | 
| 102 | 
            +
                      expect(addresses.size).to eq(5)
         | 
| 103 103 | 
             
                      expect(addresses).to be_a(Geocodio::AddressSet)
         | 
| 104 104 | 
             
                    end
         | 
| 105 105 | 
             
                  end
         | 
| 106 106 |  | 
| 107 | 
            +
                  it 'handles a response without legislator house info' do
         | 
| 108 | 
            +
                    VCR.use_cassette('reverse_with_fields_no_house_info') do
         | 
| 109 | 
            +
                      expect { geocodio.reverse_geocode(["41.25,-96.00"], fields: %w[cd stateleg school timezone]) }.not_to raise_error(NoMethodError)
         | 
| 110 | 
            +
                    end
         | 
| 111 | 
            +
                  end
         | 
| 112 | 
            +
             | 
| 107 113 | 
             
                  it 'uses hashes' do
         | 
| 108 114 | 
             
                    VCR.use_cassette('reverse') do
         | 
| 109 115 | 
             
                      lat, lng = coordinates.split(',')
         | 
| 110 116 | 
             
                      addresses = geocodio.reverse_geocode([{ latitude: lat, longitude: lng }])
         | 
| 111 117 |  | 
| 112 | 
            -
                      expect(addresses.size).to eq( | 
| 118 | 
            +
                      expect(addresses.size).to eq(5)
         | 
| 113 119 | 
             
                      expect(addresses).to be_a(Geocodio::AddressSet)
         | 
| 114 120 | 
             
                    end
         | 
| 115 121 | 
             
                  end
         | 
| @@ -119,7 +125,7 @@ describe Geocodio::Client do | |
| 119 125 | 
             
                      lat, lng = coordinates.split(',')
         | 
| 120 126 | 
             
                      addresses = geocodio.reverse_geocode([{ latitude: lat, longitude: lng} ], fields: %w[cd stateleg school timezone])
         | 
| 121 127 |  | 
| 122 | 
            -
                      expect(addresses.size).to eq( | 
| 128 | 
            +
                      expect(addresses.size).to eq(5)
         | 
| 123 129 | 
             
                      expect(addresses).to be_a(Geocodio::AddressSet)
         | 
| 124 130 | 
             
                    end
         | 
| 125 131 | 
             
                  end
         | 
| @@ -5,7 +5,10 @@ describe Geocodio::CongressionalDistrict do | |
| 5 5 |  | 
| 6 6 | 
             
              subject(:district) do
         | 
| 7 7 | 
             
                VCR.use_cassette('geocode_with_fields') do
         | 
| 8 | 
            -
                  geocodio.geocode(['54 West Colorado Boulevard Pasadena CA 91105'], fields: %w[cd stateleg school timezone]). | 
| 8 | 
            +
                  geocodio.geocode(['54 West Colorado Boulevard Pasadena CA 91105'], fields: %w[cd stateleg school timezone]).
         | 
| 9 | 
            +
                    best.
         | 
| 10 | 
            +
                    congressional_districts.
         | 
| 11 | 
            +
                    first
         | 
| 9 12 | 
             
                end
         | 
| 10 13 | 
             
              end
         | 
| 11 14 |  | 
| @@ -18,11 +21,21 @@ describe Geocodio::CongressionalDistrict do | |
| 18 21 | 
             
              end
         | 
| 19 22 |  | 
| 20 23 | 
             
              it 'has a congress_number' do
         | 
| 21 | 
            -
                expect(district.congress_number).to eq( | 
| 24 | 
            +
                expect(district.congress_number).to eq(115)
         | 
| 22 25 | 
             
              end
         | 
| 23 26 |  | 
| 24 27 | 
             
              it 'has a congress_years' do
         | 
| 25 | 
            -
                expect(district.congress_years).to eq( | 
| 28 | 
            +
                expect(district.congress_years).to eq(2017..2019)
         | 
| 26 29 | 
             
              end
         | 
| 27 30 |  | 
| 31 | 
            +
              it 'has a proportion' do
         | 
| 32 | 
            +
                expect(district.proportion).to eq(1)
         | 
| 33 | 
            +
              end
         | 
| 34 | 
            +
             | 
| 35 | 
            +
             | 
| 36 | 
            +
              it 'has current_legislators' do
         | 
| 37 | 
            +
                district.current_legislators.each do |legislator|
         | 
| 38 | 
            +
                  expect(legislator).to be_a(Geocodio::Legislator)
         | 
| 39 | 
            +
                end
         | 
| 40 | 
            +
              end
         | 
| 28 41 | 
             
            end
         | 
| @@ -0,0 +1,116 @@ | |
| 1 | 
            +
            require 'spec_helper'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            describe Geocodio::Legislator do
         | 
| 4 | 
            +
              let(:geocodio) { Geocodio::Client.new }
         | 
| 5 | 
            +
             | 
| 6 | 
            +
              subject(:legislator) do
         | 
| 7 | 
            +
                VCR.use_cassette('geocode_with_fields') do
         | 
| 8 | 
            +
                  geocodio.geocode(['54 West Colorado Boulevard Pasadena CA 91105'], fields: %w[cd stateleg school timezone]).
         | 
| 9 | 
            +
                    best.
         | 
| 10 | 
            +
                    congressional_districts.
         | 
| 11 | 
            +
                    first.
         | 
| 12 | 
            +
                    current_legislators.
         | 
| 13 | 
            +
                    first
         | 
| 14 | 
            +
                end
         | 
| 15 | 
            +
              end
         | 
| 16 | 
            +
             | 
| 17 | 
            +
              it 'has a type' do
         | 
| 18 | 
            +
                expect(legislator.type).to eq('representative')
         | 
| 19 | 
            +
              end
         | 
| 20 | 
            +
             | 
| 21 | 
            +
              it 'has a name' do
         | 
| 22 | 
            +
                expect(legislator.name).to eq('Judy Chu')
         | 
| 23 | 
            +
              end
         | 
| 24 | 
            +
             | 
| 25 | 
            +
              it 'has a birthday' do
         | 
| 26 | 
            +
                expect(legislator.birthday).to eq(Date.new(1953, 07, 07))
         | 
| 27 | 
            +
              end
         | 
| 28 | 
            +
             | 
| 29 | 
            +
              it 'has a gender' do
         | 
| 30 | 
            +
                expect(legislator.gender).to eq('F')
         | 
| 31 | 
            +
              end
         | 
| 32 | 
            +
             | 
| 33 | 
            +
              it 'has a party' do
         | 
| 34 | 
            +
                expect(legislator.party).to eq('Democrat')
         | 
| 35 | 
            +
              end
         | 
| 36 | 
            +
             | 
| 37 | 
            +
              it 'has a url' do
         | 
| 38 | 
            +
                expect(legislator.url).to eq('https://chu.house.gov')
         | 
| 39 | 
            +
              end
         | 
| 40 | 
            +
             | 
| 41 | 
            +
              it 'has a address' do
         | 
| 42 | 
            +
                expect(legislator.address).to eq('2423 Rayburn HOB; Washington DC 20515-0527')
         | 
| 43 | 
            +
              end
         | 
| 44 | 
            +
             | 
| 45 | 
            +
              it 'has a phone' do
         | 
| 46 | 
            +
                expect(legislator.phone).to eq('202-225-5464')
         | 
| 47 | 
            +
              end
         | 
| 48 | 
            +
             | 
| 49 | 
            +
              it 'has a contact_form' do
         | 
| 50 | 
            +
                expect(legislator.contact_form).to be_nil
         | 
| 51 | 
            +
              end
         | 
| 52 | 
            +
             | 
| 53 | 
            +
              it 'has a rss_url' do
         | 
| 54 | 
            +
                expect(legislator.rss_url).to eq('http://chu.house.gov/rss.xml')
         | 
| 55 | 
            +
              end
         | 
| 56 | 
            +
             | 
| 57 | 
            +
              it 'has a twitter' do
         | 
| 58 | 
            +
                expect(legislator.twitter).to eq('RepJudyChu')
         | 
| 59 | 
            +
              end
         | 
| 60 | 
            +
             | 
| 61 | 
            +
              it 'has a facebook' do
         | 
| 62 | 
            +
                expect(legislator.facebook).to eq('RepJudyChu')
         | 
| 63 | 
            +
              end
         | 
| 64 | 
            +
             | 
| 65 | 
            +
              it 'has a youtube' do
         | 
| 66 | 
            +
                expect(legislator.youtube).to eq('RepJudyChu')
         | 
| 67 | 
            +
              end
         | 
| 68 | 
            +
             | 
| 69 | 
            +
              it 'has a youtube_id' do
         | 
| 70 | 
            +
                expect(legislator.youtube_id).to eq('UCfcbYOvdEXZNelM8T05nK-w')
         | 
| 71 | 
            +
              end
         | 
| 72 | 
            +
             | 
| 73 | 
            +
              it 'has a bioguide_id' do
         | 
| 74 | 
            +
                expect(legislator.bioguide_id).to eq('C001080')
         | 
| 75 | 
            +
              end
         | 
| 76 | 
            +
             | 
| 77 | 
            +
              it 'has a thomas_id' do
         | 
| 78 | 
            +
                expect(legislator.thomas_id).to eq('01970')
         | 
| 79 | 
            +
              end
         | 
| 80 | 
            +
             | 
| 81 | 
            +
              it 'has a opensecrets_id' do
         | 
| 82 | 
            +
                expect(legislator.opensecrets_id).to eq('N00030600')
         | 
| 83 | 
            +
              end
         | 
| 84 | 
            +
             | 
| 85 | 
            +
              it 'has a lis_id' do
         | 
| 86 | 
            +
                expect(legislator.lis_id).to be_nil
         | 
| 87 | 
            +
              end
         | 
| 88 | 
            +
             | 
| 89 | 
            +
              it 'has a cspan_id' do
         | 
| 90 | 
            +
                expect(legislator.cspan_id).to eq('92573')
         | 
| 91 | 
            +
              end
         | 
| 92 | 
            +
             | 
| 93 | 
            +
              it 'has a govtrack_id' do
         | 
| 94 | 
            +
                expect(legislator.govtrack_id).to eq('412379')
         | 
| 95 | 
            +
              end
         | 
| 96 | 
            +
             | 
| 97 | 
            +
              it 'has a votesmart_id' do
         | 
| 98 | 
            +
                expect(legislator.votesmart_id).to eq('16539')
         | 
| 99 | 
            +
              end
         | 
| 100 | 
            +
             | 
| 101 | 
            +
              it 'has a ballotpedia_id' do
         | 
| 102 | 
            +
                expect(legislator.ballotpedia_id).to eq('Judy Chu')
         | 
| 103 | 
            +
              end
         | 
| 104 | 
            +
             | 
| 105 | 
            +
              it 'has a washington_post_id' do
         | 
| 106 | 
            +
                expect(legislator.washington_post_id).to be_nil
         | 
| 107 | 
            +
              end
         | 
| 108 | 
            +
             | 
| 109 | 
            +
              it 'has a icpsr_id' do
         | 
| 110 | 
            +
                expect(legislator.icpsr_id).to eq('20955')
         | 
| 111 | 
            +
              end
         | 
| 112 | 
            +
             | 
| 113 | 
            +
              it 'has a wikipedia_id' do
         | 
| 114 | 
            +
                expect(legislator.wikipedia_id).to eq('Judy Chu')
         | 
| 115 | 
            +
              end
         | 
| 116 | 
            +
            end
         |