-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #256 from EasyPost/metadata
feat: add carrier metadata beta endpoint
- Loading branch information
Showing
5 changed files
with
635 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# frozen_string_literal: true | ||
|
||
# A CarrierMetadata object contains all the selected metadata for all selected carriers. | ||
class EasyPost::Beta::CarrierMetadata < EasyPost::Resource | ||
# Retrieve metadata for carrier(s). | ||
def self.retrieve_carrier_metadata(carriers = [], types = [], api_key = nil) | ||
path = '/beta/metadata?' | ||
|
||
params = {} | ||
|
||
if carriers.length.positive? | ||
params[:carriers] = carriers.join(',') | ||
end | ||
|
||
if types.length.positive? | ||
params[:types] = types.join(',') | ||
end | ||
|
||
# urlencoded params | ||
path += URI.encode_www_form(params) | ||
|
||
response = EasyPost.make_request(:get, path, api_key, params) | ||
EasyPost::Util.convert_to_easypost_object(response['carriers'] || [], api_key) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper' | ||
|
||
describe EasyPost::Beta::CarrierMetadata do | ||
describe '.retrieve_carrier_metadata' do | ||
it 'retrieve metadata for all carriers' do | ||
metadata = described_class.retrieve_carrier_metadata | ||
|
||
expect(metadata).to be_an_instance_of(Array) | ||
|
||
expect(metadata.find { |carrier| carrier.name == 'usps' }).not_to be_nil | ||
expect(metadata.find { |carrier| carrier.name == 'fedex' }).not_to be_nil | ||
end | ||
|
||
it 'retrieve metadata for a single carrier' do | ||
carrier = 'usps' | ||
types = %w[service_levels predefined_packages] | ||
|
||
metadata = described_class.retrieve_carrier_metadata(['usps'], types) | ||
|
||
expect(metadata).to be_an_instance_of(Array) | ||
|
||
first_entry = metadata.first | ||
|
||
# Assert we only have one carrier, and it's the one we requested | ||
expect(metadata.length).to eq(1) | ||
expect(first_entry[:name]).to eq(carrier) | ||
|
||
# Assert we have the requested types | ||
expect(first_entry).to have_attributes(service_levels: Array, predefined_packages: Array) | ||
end | ||
end | ||
end |
77 changes: 77 additions & 0 deletions
77
...Beta_CarrierMetadata_retrieve_carrier_metadata_retrieve_metadata_for_a_single_carrier.yml
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.