Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
kulte opened this issue Oct 11, 2017 · 3 comments
Open

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

kulte opened this issue Oct 11, 2017 · 3 comments

Comments

@kulte
Copy link

kulte commented Oct 11, 2017

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
Copy link
Author

kulte commented Oct 11, 2017

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.

@mootrichard
Copy link
Contributor

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).

@sina-s
Copy link

sina-s commented Dec 20, 2018

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants