Giter Club home page Giter Club logo

smartystreets-ruby-sdk's Introduction

SMARTY DISCLAIMER: Subject to the terms of the associated license agreement, this software is freely available for your use. This software is FREE, AS IN PUPPIES, and is a gift. Enjoy your new responsibility. This means that while we may consider enhancement requests, we may or may not choose to entertain requests at our sole and absolute discretion.

SmartyStreets Ruby SDK

The official client libraries for accessing SmartyStreets APIs from Ruby

You may have noticed this page is curiously sparse. Don't panic, there's documentation and examples.

Apache 2.0 License


asciicast


Installation

Add this line to your application's Gemfile:

gem 'smartystreets_ruby_sdk'

And then execute:

$ bundle

Or install it yourself as:

$ gem install smartystreets_ruby_sdk    

smartystreets-ruby-sdk's People

Contributors

abbeynels avatar alexanderdavidpan avatar alrwarner avatar andremleblanc avatar andrewjohnsonsmarty avatar ankane avatar benreyn avatar ckholt83 avatar dreid avatar duncanbeutler avatar dwhatcott avatar landonsmarty avatar marcper avatar mattwalston avatar mdwhatcott avatar mouaying avatar ryanlcox1 avatar sampsoncrowley avatar savannah-ryan avatar smartybryan avatar smartycaroine avatar waleo avatar xansmarty avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

smartystreets-ruby-sdk's Issues

International Autocomplete broken postal_code

International Autocomplete API is returning 3 characters postal_code for Canada. While Canada postal code consist of six characters. It look like its missing last 3 characters. Please find my request and response JSON below

Request


{
  "parameters": {
    "search": "115 Strachan St",
    "country": "CAN",
    "license": "international-autocomplete-cloud",
    "auth-id": "AUTH-ID",
    "auth-token": "AUTH_TOKEN"
  },
  "payload": null,
  "url_prefix": "https://international-autocomplete.api.smartystreets.com/lookup",
  "referer": null,
  "headers": {
  },
  "content_type": "application/json"
}

Response

{
  "candidates": [
    {
      "street": "115 Strachan St",
      "locality": "Stratford",
      "administrative_area": "ON",
      "postal_code": "N5A",
      "country_iso3": "CAN"
    },
    {
      "street": "115 Strachan St",
      "locality": "Richmond",
      "administrative_area": "ON",
      "postal_code": "K0A",
      "country_iso3": "CAN"
    },
    {
      "street": "115 Strachan St",
      "locality": "Port Hope",
      "administrative_area": "ON",
      "postal_code": "L1A",
      "country_iso3": "CAN"
    },
    {
      "street": "115 Strachan St E",
      "locality": "Hamilton",
      "administrative_area": "ON",
      "postal_code": "L8L",
      "country_iso3": "CAN"
    }
  ]
}

Not: This isn't smartystreets-ruby-sdk gem issue rather smarty street API issue.

NoMethodError: undefined method `each' for nil:NilClass

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

International Autocomplete Suggestion Bug

I am trying to fetch suggestion for international address

Lookup = SmartyStreets::InternationalAutocomplete::Lookup


lookup = Lookup.new('Louis')
lookup.country = 'FRA'
lookup.locality = 'Paris'

suggestions = client.send(lookup)

And its breaking at

TypeError: no implicit conversion of String into Integer
from /smartystreets_ruby_sdk-5.14.0/lib/smartystreets_ruby_sdk/international_autocomplete/suggestion.rb:8:in `fetch'

The issue is in SmartyStreets::InternationalAutocomplete::Client when suggestion are built instead of object an Array being sent to InternationalAutocomplete::Suggestion which is wrong. Following update will fix the issue

At line https://github.com/smartystreets/smartystreets-ruby-sdk/blob/master/lib/smartystreets_ruby_sdk/international_autocomplete/client.rb#L27 update it with

suggestions = convert_suggestions(result.fetch('candidates', []))

Excessive logging

Is there a practical reason for custom request headers to be logged to stdout? Looking at this diff it looks like they were added for debugging reasons. This causes a lot of unnecessary logging when Smarty Streets is added to a larger application and stubbed in the test suite.

5.6.0 broke sem-ver

The minor version was updated, but it seems to me that the change on is_ews_match changed the field from a boolean to a string since it now is a deprecation warning.

RetrySender with default SmartyStreets::Logger broken in 5.6.0

Hi SmartyStreets devs,

I'm looking at upgrading from 5.5.4 to the 5.6.0 version of the SmartyStreets ruby SDK. However, this looks like a breaking change:

In SmartyStreets::RetrySender there's the method:

def backoff(attempt)
  backoff_duration = [attempt, MAX_BACKOFF_DURATION].min

  @logger.warn("There was an error processing the request. Retrying in #{backoff_duration} seconds...")
  @sleeper.sleep(backoff_duration)
end

However, the default SmartyStreets::Logger doesn't define a :warn method:

module SmartyStreets
  class Logger
    def log(message)
      puts message
    end
  end
end

During my tests, this gives: #<NoMethodError: private method 'warn' called for #<SmartyStreets::Logger:0x00007fe64d17b6d8>>

When I swap out warn for log, everything works fine.

Thank you for investigating.

undefined method `each' for nil:NilClass

Select **<% @adverts.each do |advert| %>** <%= advert.name %> <% end %>
  • Method error in this particular loop line. I dont know how its happening, please anyone explain me or give an right solution

InternationalStreet::Lookup class is not being included automatically

I'm including the gem in a rails app. I can use all of the classes except SmartyStreets::InternationalStreet::Lookup.

All of this code works perfectly.
credentials = SmartyStreets::StaticCredentials.new(auth_id, auth_token)
client = SmartyStreets::ClientBuilder.new(credentials).build_us_zipcode_api_client
lookup = SmartyStreets::USZipcode::Lookup.new
and also
client = SmartyStreets::ClientBuilder.new(credentials).build_international_street_api_client

But, when I call lookup = SmartyStreets::InternationalStreet::Lookup.new("A0A 0A2", 'Canada')
I get the error message:
NameError: uninitialized constant SmartyStreets::InternationalStreet::Lookup

I found that if I manually require that file first, it will work. But not without requiring it first.
require 'smartystreets_ruby_sdk/international_street/lookup'

Different names for equivalent methods on US Street Client and International Street Client

Both US Street Client and International Street Client are very similar when it comes to usage.
I thought it was a bit confusing that both of them provide a method aimed to send lookup, however the first one defines it as send_lookup(lookup) while the other one defines it as send(lookup).

Specially when it comes to the international street client, it also feels weird to call client.send(lookup). For someone who's not familiar with the gem, by doing it like this, it gives the impression that we're trying to call a private method name lookup (using the native Object#send) and forgot to use the : to specify lookup as symbol

Would it make sense to rename it to send_lookup, to avoid confusion in both scenarios?
If positive, I would be happy to help with this change.

Doesn't Play Well with VCR

Was getting the below error message when running tests.

NoMethodError:
       undefined method `<' for nil:NilClass
     # ~.../smartystreets_ruby_sdk/retry_sender.rb:17:in `block in send'

Line that is breaking:

break if response.status_code < STATUS_INTERNAL_SERVER_ERROR

Looks like response is nil in this case.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.