goshippo/shippo-ruby-client

Shippo::Address.get("object_id").validate returns nil

kulte opened this issue · 3 comments

kulte commented

I'm about to look into this more to see if I can possibly make a pull request for you guys, but 100% of the time that I issue this command in the console, I get nil returned.

kulte commented

Okay, I still cannot tell what is going on here, however you appear to have at least 2 things that are suspect, and at least 1 of those things looks like a confirmed bug per your API docs on your website.

The first thing that, and I'm not sure if this is a bug or you know about this, but you cannot possibly call a missing method on an instance of Shippo::Address. I couldn't possibly see the value in this, which makes me think it might be a bug, and I grepped the entrie codebase for a declaration of method_missing and couldn't find one. But essentially the reason Shippo::Address.get("object_id").validate returns nil is because Shippo::Address.get("object_id").ksjfgjsgd also returns nil! This is nuts to me and I'm not sure if you meant to do this or not... 😄

The second thing, and this again is a confirmed bug because of https://goshippo.com/docs/reference/bash?version=2017-08-01#addresses-validate, is that a) I can't call this, as stated in the issue title, and b) there's got to be something going wrong in this area:

module Shippo
  class Address < ::Shippo::API::Resource
    operations :list, :create, :validate
  end
end

There's either a bug in Shippo::API::Resource or in this operations thing you guys do. Happy to help any way I can, hopefully this will give one of you guys a lightbulb moment who is more familiar with your codebase.

Although I am by no means proficient with Ruby, I can say that doing Shippo::Address.get("object_id") will return your desired Address serialized into a Hash-like object. So it would mean that any key not found on that object would return nil.

If you're trying to validate an address, then you'd want to use Shippo::Address.validate("object_id") and you would be returned back your validated address (also serialized into a Hash-like object).

The Shippo client uses Hashie to transform responses into these Hash-like objects, so its better to think of your returned response to behave more like a JavaScript object than a Ruby object, with missing keys returning nil (just like undefined in JavaScript).

As for the way described in the references docs, I will actually update that to better reflect the way to validate an address with Ruby (since the way shown there is no longer correct).

Just to reiterate that the ruby example in the docs is still incorrect: https://goshippo.com/docs/reference/rb#addresses-validate