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

V3 updates #50

Merged
merged 23 commits into from
Mar 31, 2017
Merged
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
0866750
v3 changes (all just example changes in the README)
daria-lamberson Mar 24, 2017
a9c38ea
cleaned up styling
daria-lamberson Mar 24, 2017
06eb599
last few changes by searching for changed fields
daria-lamberson Mar 24, 2017
97542aa
removed object purpose from address param examples
daria-lamberson Mar 24, 2017
bbb35cb
removed object_[x] attrs from shipment apiobject example
daria-lamberson Mar 24, 2017
3198a43
removed shipment.state example
daria-lamberson Mar 24, 2017
2c38c58
fixed requirement
daria-lamberson Mar 24, 2017
358bf8e
updated api_object file
daria-lamberson Mar 24, 2017
4380589
removed object_status, since it will just be in the object dict under…
daria-lamberson Mar 24, 2017
b37ff8e
added back status because it's used in a few places still
daria-lamberson Mar 24, 2017
a338e77
chnged is_return example value from nil to false
daria-lamberson Mar 27, 2017
cc5fb6c
Merge branch 'master' into v3-updates
daria-lamberson Mar 30, 2017
110e5dc
Merge branch 'master' of https://github.com/goshippo/shippo-ruby-clie…
Mar 30, 2017
57627d2
removed fields for v3 update in examples
daria-lamberson Mar 30, 2017
b40344e
Merge branch 'v3-updates' of https://github.com/goshippo/shippo-ruby-…
Mar 30, 2017
ddda4ce
Update Shippo version to v3 in tests
Mar 31, 2017
278ad80
Update object_status to status
Mar 31, 2017
d0bcc81
Update fixtures
Mar 31, 2017
fa3764a
updated changelog and readme before updating gem
daria-lamberson Mar 31, 2017
52f754a
updated gem version
daria-lamberson Mar 31, 2017
4e46846
updated changelog header size inconsistency
daria-lamberson Mar 31, 2017
60f9f20
expanded parcel and changed to plural
daria-lamberson Mar 31, 2017
dcea188
changed more 'parcel's to be plural
daria-lamberson Mar 31, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
v3 changes (all just example changes in the README)
  • Loading branch information
daria-lamberson committed Mar 24, 2017
commit 0866750eb6f3582dfc341e0b1d29205480eea618
101 changes: 48 additions & 53 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ Shippo::API.token = 'aff988f77afa0fdfdfadf' # not an actual valid token
params = { object_purpose: 'PURCHASE',
async: false,
address_from: {
object_purpose: 'PURCHASE',
is_complete: true,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to make sure. No more object_purpose in the payload, huh?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right but also refresh to the last commit -- no is_complete, either.

name: 'Mr Hippo',
company: 'Shippo',
street1: '215 Clayton St.',
Expand All @@ -57,10 +57,9 @@ params = { object_purpose: 'PURCHASE',
state: 'CA',
zip: '94117',
country: 'US',
phone: '+1 555 341 9393',
email: 'support@goshippo.com' },
phone: '+1 555 341 9393' },
address_to: {
object_purpose: 'PURCHASE',
is_complete: true,
name: 'Mrs Hippo"',
company: 'San Diego Zoo',
street1: '2920 Zoo Drive',
Expand Down Expand Up @@ -96,64 +95,60 @@ Let's take a quick look at what the `Shipment` object looks like:
```ruby
require 'awesome_print'
ap @shipment
# {
# "carrier_accounts" => [],
# "address_from" => "a704eada7494bb1be6184ef64b1646db",
# "address_to" => "92b43fbfa3641644beb32996042eb57a",
# "address_return" => "a1f64ba14b7e41b86a0446de4ebbd769",
# "parcel" => "92df4baac73ea6131940c0d315d70a7d",
# "submission_date" => "2016-07-06T20:33:02.211Z",
# "return_of" => nil,
# "customs_declaration" => nil,
# "insurance_amount" => "0",
# "insurance_currency" => nil,
# "extra" => {},
# "reference_1" => "",
# "reference_2" => "",
# "rates_url" => "https://api.goshippo.com/v1/shipments/a336daf87a8e442992a68daa6622758f/rates/",
# "messages" => [ ] # ommitted for brevity,
# "rates_list" => [ ] # ommitted for brevity.
# { "carrier_accounts" => [],
# "address_from" => [ ... ] # omitted for brevity,
# "address_to" => [ ... ] # omitted for brevity,
# "address_return" => [ ... ] # omitted for brevity,
# "parcel" => [ ... ] # omitted for brevity,
# "shipment_date" => "2016-07-06T20:33:02.211Z",
# "customs_declaration" => nil,
# "extra" => {
# "insurance" => {
# "amount" => 10,
# "currency" => "USD",
# "content" => "",
# "provider" => "FEDEX"
# },
# "is_return" => nil,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we're looking to have is_return have a default False value (schema migration pending) - so it shouldn't ever end up being null

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

# "reference_1" => "",
# "reference_2" => "",
# },
# "rates_url" => "https://api.goshippo.com/v1/shipments/a336daf87a8e442992a68daa6622758f/rates/",
# "messages" => [ ... ], # omitted for brevity
# "rates" => [ ... ] # omitted for brevity
# }
```

#### List Handling

In the case when the API returns a hash with one of the hash values being an array of entities, and if the corresponding key can be mapped into one of the existing API models, then each of the members of the array is coerced from a hash into an object of the model's type.

In the example below we are showing the result of such transformation where the `rates_list` contains a list of fully constructed objects of type `Shippo::Rate` after being coerced from a hash.
In the example below we are showing the result of such transformation where `rates` contains a list of fully constructed objects of type `Shippo::Rate` after being coerced from a hash.

```ruby
ap @shipment.rates_list.first
ap @shipment.rates.first
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So we change the key from rates_list to rates in the response?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yea

# =>
# {
# "shipment" => "20f25e44b16b4051b6dd910cb66fd27b",
# "available_shippo" => true,
# "attributes" => [],
# "amount" => "8.51",
# "currency" => "USD",
# "amount_local" => "8.51",
# "currency_local" => "USD",
# "provider" => "FedEx",
# "provider_image_75" => "https://shippo-static.s3.amazonaws.com/providers/75/FedEx.png",
# "provider_image_200" => "https://shippo-static.s3.amazonaws.com/providers/200/FedEx.png",
# "servicelevel_name" => "Ground",
# "servicelevel_token" => "fedex_ground",
# "servicelevel_terms" => "",
# "days" => 2,
# "arrives_by" => nil,
# "duration_terms" => "",
# "trackable" => true,
# "insurance" => false,
# "insurance_amount_local" => "0.00",
# "insurance_currency_local" => nil,
# "insurance_amount" => "0.00",
# "insurance_currency" => nil,
# "delivery_attempts" => nil,
# "outbound_endpoint" => "door",
# "inbound_endpoint" => "door",
# "messages" => [],
# "carrier_account" => "4b1940bc69524163b669asd361842db",
# "test" => true
# { "shipment" => "20f25e44b16b4051b6dd910cb66fd27b",
# "attributes" => [],
# "amount" => "8.51",
# "currency" => "USD",
# "amount_local" => "8.51",
# "currency_local" => "USD",
# "provider" => "FedEx",
# "provider_image_75" => "https://shippo-static.s3.amazonaws.com/providers/75/FedEx.png",
# "provider_image_200" => "https://shippo-static.s3.amazonaws.com/providers/200/FedEx.png",
# "servicelevel" => {
# "name" => "Ground",
# "token" => "fedex_ground",
# "terms" => ""
# }
# "days" => 2,
# "arrives_by" => nil,
# "duration_terms" => "",
# "trackable" => true,
# "messages" => [],
# "carrier_account" => "4b1940bc69524163b669asd361842db",
# "test" => true
# }
@shipment.rates.first.owner
# ⤷ unittest@gmail.com
Expand Down Expand Up @@ -213,7 +208,7 @@ Finally, here is how we access the rest of the `object_` fields:
# ⤷ valued_customer@gmail.com
```

Here is the fully construted `ApiObject` instance, attached to our `@shipment`:
Here is the fully constructed `ApiObject` instance, attached to our `@shipment`:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. lolol


```ruby
ap @shipment.object
Expand Down