smartystreets / smartystreets-ruby-sdk

The official client libraries for accessing SmartyStreets APIs from Ruby
https://smartystreets.com/docs/sdk/ruby
Apache License 2.0
23 stars 25 forks source link

NoMethodError: undefined method `each' for nil:NilClass #16

Closed lluchez closed 6 years ago

lluchez commented 6 years ago

Stack trace:

File "/app/vendor/bundle/ruby/2.2.0/gems/smartystreets_ruby_sdk-5.0.0/lib/smartystreets_ruby_sdk/international_street/client.rb" line 50 in convert_candidates
File "/app/vendor/bundle/ruby/2.2.0/gems/smartystreets_ruby_sdk-5.0.0/lib/smartystreets_ruby_sdk/international_street/client.rb" line 20 in send

The issue is probably in all clients, in convert_candidates: https://github.com/smartystreets/smartystreets-ruby-sdk/blob/master/lib/smartystreets_ruby_sdk/international_street/client.rb#L50

And will happen for any failure because as the payload is set to nil here as deserializing nil will result in the value of nil here as:

> JSON.load(nil)
=> nil
MouaYing commented 6 years ago

@lluchez - Thank you for bringing this to our attention. We will look into this.

MouaYing commented 6 years ago

@lluchez - This has now been fixed. Version 5.5.3 contains the changes.

lluchez commented 6 years ago

@MouaYing are you guys keeping a changelog file. We are currently using version 5.0 and we don't really know if there is any breaking change in between.

MouaYing commented 6 years ago

@lluchez - There is currently no changelog file, but you can look at the commits here on GIthub. We try to increment the major version number when there are breaking changes, so you'll probably be fine.

lluchez commented 6 years ago

Sounds good. We will give it a try.

lluchez commented 6 years ago

Hey @MouaYing, we recently updated our SmartyStreet Gem from 5.0.0 to 5.5.4 and we are now having issue using Canadian addresses.

We the previous gem, we are getting the right answer:

[#<SmartyStreets::InternationalStreet::Candidate:0x0000000e5e09a8 @organization=nil, @address1="174 Howey St", @address2="Red Lake ON P0V 2M0", @address3=nil, @address4=nil, @address5=nil, @address6=nil, @address7=nil, @address8=nil, @address9=nil, @address10=nil, @address11=nil, @address12=nil, @components=#<SmartyStreets::InternationalStreet::Components:0x0000000e5e05e8 @country_iso_3="CAN", @super_administrative_area=nil, @administrative_area="ON", @sub_administrative_area=nil, @dependent_locality=nil, @dependent_locality_name=nil, @double_dependent_locality=nil, @locality="Red Lake", @postal_code="P0V 2M0", @postal_code_short="P0V 2M0", @postal_code_extra=nil, @premise="174", @premise_extra=nil, @premise_number="174", @premise_type=nil, @thoroughfare="Howey St", @thoroughfare_predirection=nil, @thoroughfare_postdirection=nil, @thoroughfare_name="Howey", @thoroughfare_trailing_type="St", @thoroughfare_type=nil, @dependent_thoroughfare=nil, @dependent_thoroughfare_predirection=nil, @dependent_thoroughfare_postdirection=nil, @dependent_thoroughfare_name=nil, @dependent_thoroughfare_trailing_type=nil, @dependent_thoroughfare_type=nil, @building=nil, @building_leading_type=nil, @building_name=nil, @building_trailing_type=nil, @sub_building_type=nil, @sub_building_number=nil, @sub_building_name=nil, @sub_building=nil, @post_box=nil, @post_box_type=nil, @post_box_number=nil>, @metadata=#<SmartyStreets::InternationalStreet::Metadata:0x0000000e5dbf48 @latitude=nil, @longitude=nil, @geocode_precision=nil, @max_geocode_precision=nil>, @analysis=#<SmartyStreets::InternationalStreet::Analysis:0x0000000e5dbe30 @verification_status="Verified", @address_precision="Locality", @max_address_precision="DeliveryPoint">>]

But with the new Gem, we are getting the following response:

[#<SmartyStreets::InternationalStreet::Candidate:0x00000006cd2d90 @organization=nil, @address1="174%20howey%20street,%20red%20lake,%20on,%20p0v%202m0", @address2=nil, @address3=nil, @address4=nil, @address5=nil, @address6=nil, @address7=nil, @address8=nil, @address9=nil, @address10=nil, @address11=nil, @address12=nil, @components=#<SmartyStreets::InternationalStreet::Components:0x00000006cd2750 @country_iso_3="CAN", @super_administrative_area=nil, @administrative_area=nil, @sub_administrative_area=nil, @dependent_locality=nil, @dependent_locality_name=nil, @double_dependent_locality=nil, @locality=nil, @postal_code=nil, @postal_code_short=nil, @postal_code_extra=nil, @premise=nil, @premise_extra=nil, @premise_number=nil, @premise_prefix_number=nil, @premise_type=nil, @thoroughfare=nil, @thoroughfare_predirection=nil, @thoroughfare_postdirection=nil, @thoroughfare_name=nil, @thoroughfare_trailing_type=nil, @thoroughfare_type=nil, @dependent_thoroughfare=nil, @dependent_thoroughfare_predirection=nil, @dependent_thoroughfare_postdirection=nil, @dependent_thoroughfare_name=nil, @dependent_thoroughfare_trailing_type=nil, @dependent_thoroughfare_type=nil, @building=nil, @building_leading_type=nil, @building_name=nil, @building_trailing_type=nil, @sub_building_type=nil, @sub_building_number=nil, @sub_building_name=nil, @sub_building=nil, @post_box=nil, @post_box_type=nil, @post_box_number=nil>, @metadata=#<SmartyStreets::InternationalStreet::Metadata:0x00000006cd0bf8 @latitude=nil, @longitude=nil, @geocode_precision=nil, @max_geocode_precision=nil, @address_format=nil>, @analysis=#<SmartyStreets::InternationalStreet::Analysis:0x00000006cd03d8 @verification_status="None", @address_precision="None", @max_address_precision="DeliveryPoint">>]

Could you please assist us? You can email me at lionel.luchez[at]snapsheet.me if you want to take this offline. Thank you

MouaYing commented 6 years ago

@lluchez - It looks like the second time you put the whole address into address1, but the first time you split it into address1 and address2. It's possible that has something to do with it.

lluchez commented 6 years ago

Correct, we are creating the lookup with:

SmartyStreets::InternationalStreet::Lookup.new(URI::encode("174 Howey Street, RED LAKE, ON, P0V 2M0"), 'ca')

This used to work fine with version 5.0.0. Please let us know if this is not supported anymore. Thank you.

MouaYing commented 6 years ago

The new SDK version URI-encodes the address for you. You no longer need to do it yourself.

lluchez commented 6 years ago

Awesome, it works now. Thank you @MouaYing

MouaYing commented 6 years ago

No problem. Glad I could help!