Sha256: 59d314376b4146b0358d6ef21b5650b6efa22d5d92064e0db005ddda2c3a133b

Contents?: true

Size: 1 KB

Versions: 24

Compression:

Stored size: 1 KB

Contents

require_relative 'city'
require_relative 'zip_code'

module SmartyStreets
  module USZipcode
    # See "https://smartystreets.com/docs/cloud/us-zipcode-api#root"
    class Result
      attr_reader :reason, :input_index, :cities, :zipcodes, :status

      def initialize(obj)
        @status = obj['status']
        @reason = obj['reason']
        @input_index = obj['input_index']
        @cities = obj.fetch('city_states', [])
        @zipcodes = obj.fetch('zipcodes', [])

        @cities = convert_cities
        @zipcodes = convert_zipcodes
      end

      def valid?
        @status.nil? and @reason.nil?
      end

      def convert_cities
        converted_cities = []

        @cities.each do |city|
          converted_cities.push(City.new(city))
        end

        converted_cities
      end

      def convert_zipcodes
        converted_zipcodes = []

        @zipcodes.each do |zipcode|
          converted_zipcodes.push(ZipCode.new(zipcode))
        end

        converted_zipcodes
      end
    end
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
smartystreets_ruby_sdk-5.7.0 lib/smartystreets_ruby_sdk/us_zipcode/result.rb
smartystreets_ruby_sdk-5.6.2 lib/smartystreets_ruby_sdk/us_zipcode/result.rb
smartystreets_ruby_sdk-5.6.1 lib/smartystreets_ruby_sdk/us_zipcode/result.rb
smartystreets_ruby_sdk-5.6.0 lib/smartystreets_ruby_sdk/us_zipcode/result.rb
smartystreets_ruby_sdk-5.5.4 lib/smartystreets_ruby_sdk/us_zipcode/result.rb
smartystreets_ruby_sdk-5.5.3 lib/smartystreets_ruby_sdk/us_zipcode/result.rb
smartystreets_ruby_sdk-5.5.2 lib/smartystreets_ruby_sdk/us_zipcode/result.rb
smartystreets_ruby_sdk-5.5.1 lib/smartystreets_ruby_sdk/us_zipcode/result.rb
smartystreets_ruby_sdk-5.5.0 lib/smartystreets_ruby_sdk/us_zipcode/result.rb
smartystreets_ruby_sdk-5.4.0 lib/smartystreets_ruby_sdk/us_zipcode/result.rb
smartystreets_ruby_sdk-5.3.3 lib/smartystreets_ruby_sdk/us_zipcode/result.rb
smartystreets_ruby_sdk-5.3.2 lib/smartystreets_ruby_sdk/us_zipcode/result.rb
smartystreets_ruby_sdk-5.3.1 lib/smartystreets_ruby_sdk/us_zipcode/result.rb
smartystreets_ruby_sdk-5.3.0 lib/smartystreets_ruby_sdk/us_zipcode/result.rb
smartystreets_ruby_sdk-5.2.2 lib/smartystreets_ruby_sdk/us_zipcode/result.rb
smartystreets_ruby_sdk-5.2.1 lib/smartystreets_ruby_sdk/us_zipcode/result.rb
smartystreets_ruby_sdk-5.2.0 lib/smartystreets_ruby_sdk/us_zipcode/result.rb
smartystreets_ruby_sdk-5.1.1 lib/smartystreets_ruby_sdk/us_zipcode/result.rb
smartystreets_ruby_sdk-5.1.0 lib/smartystreets_ruby_sdk/us_zipcode/result.rb
smartystreets_ruby_sdk-5.0.0 lib/smartystreets_ruby_sdk/us_zipcode/result.rb