### Install Dependencies for Contributing Source: https://github.com/shipengine/shipengine-ruby/blob/main/README.md Install project dependencies using Bundler. This command should be run after installing the gem. ```bash ./bin/setup ``` -------------------------------- ### Install ShipEngine Ruby SDK Source: https://github.com/shipengine/shipengine-ruby/blob/main/README.md Install the ShipEngine SDK Gem using RubyGems. Ensure you have an API Key for configuration. ```bash gem install shipengine_sdk ``` -------------------------------- ### Start Pry REPL with ShipEngine Source: https://github.com/shipengine/shipengine-ruby/blob/main/README.md Launch a Pry REPL session with the ShipEngine SDK pre-required. This is useful for interactive development and exploration. ```bash ./bin/console ``` -------------------------------- ### Example Tracking Result Output Source: https://github.com/shipengine/shipengine-ruby/blob/main/docs/track-by-label-id.md This is an example of the tracking information returned by the `track_using_label_id` method, showing shipment status and details. ```ruby # ``` -------------------------------- ### Example Tracking Result Object Source: https://github.com/shipengine/shipengine-ruby/blob/main/docs/track-using-carrier-code-and-tracking-number.md This is an example of the response object returned when tracking a package. It contains details such as carrier status, estimated delivery, and events. ```ruby # ``` -------------------------------- ### Successful Void Label Result Example Source: https://github.com/shipengine/shipengine-ruby/blob/main/docs/void-label-by-id.md An example of the output structure when a void label request is successfully processed. Note that 'approved' may be false even if the void is successful, as indicated by the message. ```ruby # ``` -------------------------------- ### Successful Create Label Result Output Source: https://github.com/shipengine/shipengine-ruby/blob/main/docs/create-label-from-shipment-details.md This is an example of the successful response object returned after creating a label. It contains details such as tracking number, costs, and download links for the label in various formats. ```ruby # @is_international=false, @is_return_label=false, @label_download= # @label_format="pdf", @label_id="se-75290114", @label_image_id=nil, @label_layout="4x6", @package_code="package", @packages= [#, @external_package_id=nil, @insured_value= # @label_messages= #, @package_code="package", @tracking_number="1Z63R0960331651653", @weight= #>], @rma_number=nil, @service_code="ups_ground", @ship_date="2021-08-03T00:00:00Z", @shipment_cost= # @shipment_id="se-144018968", @status="completed", @trackable=true, @tracking_number="1Z63R0960331651653", @tracking_status="in_transit", @voided=false, @voided_at=nil> ``` -------------------------------- ### Example Output of Validated Addresses Source: https://github.com/shipengine/shipengine-ruby/blob/main/docs/validate-addresses.md This shows the expected output structure when validating an array of addresses, including verified addresses and addresses with errors or warnings. ```ruby [# @messages=[], @original_address= #, @status="verified">, # #], @original_address= # @status="error"> ] ``` -------------------------------- ### Successful Create Label From Rate Result in Ruby Source: https://github.com/shipengine/shipengine-ruby/blob/main/docs/create-label-from-rate.md This is an example of the successful response object returned by the `create_label_from_rate` method, detailing the created label's properties. ```ruby # @is_international=false, @is_return_label=false, @label_download= # @label_format="pdf", @label_id="se-75301494", @label_image_id=nil, @label_layout="4x6", @package_code="package", @packages= [#, @external_package_id=nil, @insured_value= #, @label_messages= #, @package_code="package", @tracking_number="9400111899560334170636", @weight= #>], @rma_number=nil, @service_code="usps_first_class_mail", @ship_date="2021-08-03T00:00:00Z", @shipment_cost= # @shipment_id="se-144039990", @status="completed", @trackable=true, @tracking_number="9400111899560334170636", @tracking_status="in_transit", @voided=false, @voided_at=nil> ``` -------------------------------- ### Get Rates With Shipment Details in Ruby Source: https://github.com/shipengine/shipengine-ruby/blob/main/docs/get-rates-with-shipment-details.md Use this snippet to retrieve rate quotes by providing shipment details and rate options. Ensure you have initialized the ShipEngine client with your API key. Handles potential ShipEngine errors. ```ruby def get_rates_with_shipment_details_demo_function() client = ShipEngine::Client.new("API-Key") rate_shipment_details = { rate_options: { carrier_ids: [ "se-423887" ] }, shipment: { validate_address: "no_validation", ship_to: { name: "Amanda Miller", phone: "555-555-5555", address_line1: "525 S Winchester Blvd", city_locality: "San Jose", state_province: "CA", postal_code: "95128", country_code: "US", address_residential_indicator: "yes" }, ship_from: { company_name: "Example Corp.", name: "John Doe", phone: "111-111-1111", address_line1: "4009 Marathon Blvd", address_line2: "Suite 300", city_locality: "Austin", state_province: "TX", postal_code: "78756", country_code: "US", address_residential_indicator: "no" }, packages: [ { weight: { value: 1.0, unit: "ounce" } } ] } } begin result = client.get_rates_with_shipment_details(rate_shipment_details) puts result rescue ShipEngine::Exceptions::ShipEngineError => err puts err end end get_rates_with_shipment_details_demo_function ``` -------------------------------- ### List Connected Carrier Accounts Source: https://github.com/shipengine/shipengine-ruby/blob/main/docs/list-carriers.md Use this method to retrieve all carrier accounts connected to your ShipEngine account. Ensure you have initialized the ShipEngine client with your API key. This example demonstrates basic usage and error handling. ```ruby def list_carriers_demo_function() client = ShipEngine::Client.new("API-Key") begin result = client.list_carriers puts result rescue ShipEngine::Exceptions::ShipEngineError => err puts err end end list_carriers_demo_function ``` -------------------------------- ### Successful Get Rates Result Object Source: https://github.com/shipengine/shipengine-ruby/blob/main/docs/get-rates-with-shipment-details.md This snippet displays the structure of a successful response object when retrieving shipping rates with shipment details. It includes details about the shipment, return-to and ship-from addresses, ship-to address, and a list of available rates. ```ruby @service_type="USPS Priority Mail Express", @ship_date="2021-08-03T00:00:00Z", @shipping_amount= # @tax_amount=nil, @trackable=true, @validation_status="valid", @warning_messages=[], @zone=7>, # @delivery_days=6, @error_messages=[], @estimated_delivery_date="2021-08-10T00:00:00Z", @guaranteed_service=false, @insurance_amount= # @negotiated_rate=false, @other_amount= # @package_type="package", @rate_id="se-795654967", @rate_type="shipment", @service_code="usps_media_mail", @service_type="USPS Media Mail", @ship_date="2021-08-03T00:00:00Z", @shipping_amount= # @tax_amount=nil, @trackable=true, @validation_status="valid", @warning_messages=[], @zone=7>, # @delivery_days=6, @error_messages=[], @estimated_delivery_date="2021-08-10T00:00:00Z", @guaranteed_service=false, @insurance_amount= # @negotiated_rate=false, @other_amount= # @package_type="package", @rate_id="se-795654968", @rate_type="shipment", @service_code="usps_parcel_select", @service_type="USPS Parcel Select Ground", @ship_date="2021-08-03T00:00:00Z", @shipping_amount= # @tax_amount=nil, @trackable=true, @validation_status="valid", @warning_messages=[], @zone=7>], @shipment_id="se-144033517", @status="completed"> @return_to= # @service_code=nil, @ship_date="2021-08-03T00:00:00Z", @ship_from= # @ship_to= # @shipment_id="se-144033517", @shipment_status="pending", @tags=[], @tax_identifiers=nil, @total_weight= #, @warehouse_id=nil ``` -------------------------------- ### Successful Get Rates Result in Ruby Source: https://github.com/shipengine/shipengine-ruby/blob/main/docs/get-rates-with-shipment-details.md This snippet shows a successful response object when retrieving shipping rates with shipment details using the ShipEngine Ruby SDK. It outlines the structure of the response, including advanced options, customs information, package details, and the specific rates returned by carriers. ```ruby #, @carrier_id="se-423887", @confirmation="none", @created_at="2021-08-03T19:39:09.587Z", @customs= # @external_order_id=nil, @external_shipment_id=nil, @insurance_provider="none", @items=[], @modified_at="2021-08-03T19:39:09.587Z", @order_source_code=nil, @origin_type=nil, @packages= [#, @external_package_id=nil, @insured_value= # @label_messages= #, @package_code="package", @tracking_number=nil, @weight= #>], @rate_response= # @delivery_days=3, @error_messages=[], @estimated_delivery_date="2021-08-06T00:00:00Z", @guaranteed_service=false, @insurance_amount= # @negotiated_rate=false, @other_amount= # @package_type="letter", @rate_id="se-795654951", @rate_type="shipment", @service_code="usps_first_class_mail", @service_type="USPS First Class Mail", @ship_date="2021-08-03T00:00:00Z", @shipping_amount= # @tax_amount=nil, @trackable=false, @validation_status="valid", @warning_messages=[], @zone=7>, # @delivery_days=3, @error_messages=[], @estimated_delivery_date="2021-08-06T00:00:00Z", @guaranteed_service=false, @insurance_amount= # @negotiated_rate=false, @other_amount= # @package_type="large_envelope_or_flat", @rate_id="se-795654952", @rate_type="shipment", @service_code="usps_first_class_mail", @service_type="USPS First Class Mail", @ship_date="2021-08-03T00:00:00Z", @shipping_amount= # @tax_amount=nil, @trackable=false, @validation_status="valid" ``` -------------------------------- ### Instantiate ShipEngine Client Source: https://github.com/shipengine/shipengine-ruby/blob/main/README.md Initialize the ShipEngine client with your API key. The API key can be set as an environment variable. ```ruby require "shipengine" api_key = ENV["SHIPENGINE_API_KEY"] shipengine = ShipEngine::Client.new(api_key) ``` -------------------------------- ### Validate Addresses with ShipEngine Ruby Source: https://github.com/shipengine/shipengine-ruby/blob/main/docs/validate-addresses.md This snippet demonstrates how to initialize the ShipEngine client and validate an array of addresses. It includes error handling for ShipEngine-specific exceptions. ```ruby def validate_addresses_demo_function() client = ShipEngine::Client.new("API-Key") addresses_to_be_validated = [ { name: "John Smith", company_name: "ShipStation", address_line1: "3800 N Lamar Blvd", address_line2: "#220", postal_code: '78756', country_code: "US", address_residential_indicator: 'no', }, { name: "John Smith", company: "ShipMate", city_locality: "Toronto", state_province: "On", postal_code: "M6K 3C3", country_code: "CA", address_line1: "123 Foo", } ] begin result = client.validate_addresses(addresses_to_be_validated) puts Pry::ColorPrinter.pp(result) rescue ShipEngine::Exceptions::ShipEngineError => err puts err end end validate_addresses_demo_function ``` -------------------------------- ### Run Tests Continuously with Guard Source: https://github.com/shipengine/shipengine-ruby/blob/main/README.md Use Guard to automatically re-run tests when file changes are detected. This facilitates a rapid development cycle. ```bash guard ``` -------------------------------- ### Create Label From Rate in Ruby Source: https://github.com/shipengine/shipengine-ruby/blob/main/docs/create-label-from-rate.md Use this snippet to create a shipping label from a rate ID. Ensure you have the ShipEngine client initialized with your API key and provide the rate ID along with label customization parameters. ```ruby def create_label_from_rate_demo_function() client = ShipEngine::Client.new("API-Key") params = { validate_address: "no_validation", label_layout: "4x6", label_format: "pdf", label_download_type: "url", display_scheme: "label" } begin result = client.create_label_from_rate('se-795684260', params) puts result rescue ShipEngine::Exceptions::ShipEngineError => err puts err end end create_label_from_rate_demo_function ``` -------------------------------- ### Create Label from Shipment Details in Ruby Source: https://github.com/shipengine/shipengine-ruby/blob/main/docs/create-label-from-shipment-details.md Use the `create_label_from_shipment_details` method to generate a shipping label. Ensure you have initialized the ShipEngine client with your API key. This method handles the creation and returns a response object containing label details. ```ruby def create_label_from_shipment_details_demo_function() client = ShipEngine::Client.new("API-Key") shipment_details = { shipment: { service_code: "ups_ground", ship_to: { name: "Jane Doe", address_line1: "525 S Winchester Blvd", city_locality: "San Jose", state_province: "CA", postal_code: "95128", country_code: "US", address_residential_indicator: "yes" }, ship_from: { name: "John Doe", company_name: "Example Corp", phone: "555-555-5555", address_line1: "4009 Marathon Blvd", city_locality: "Austin", state_province: "TX", postal_code: "78756", country_code: "US", address_residential_indicator: "no" }, packages: [ { weight: { value: 20, unit: "ounce" }, dimensions: { height: 6, width: 12, length: 24, unit: "inch" } } ] } } begin result = client.create_label_from_shipment_details(shipment_details) puts result rescue ShipEngine::Exceptions::ShipEngineError => err puts err end end create_label_from_shipment_details_demo_function ``` -------------------------------- ### Track Package using Carrier Code and Tracking Number Source: https://github.com/shipengine/shipengine-ruby/blob/main/docs/track-using-carrier-code-and-tracking-number.md Use this method to retrieve tracking information for a specific shipment by providing its carrier code and tracking number. Ensure you have your ShipEngine API key initialized. ```ruby def track_using_carrier_code_and_tracking_number_demo_function() client = ShipEngine::Client.new("API-Key") begin result = client.track_using_carrier_code_and_tracking_number("stamps_com", "9461211899560335605036") puts result rescue ShipEngine::Exceptions::ShipEngineError => err puts err end end track_using_carrier_code_and_tracking_number_demo_function ``` -------------------------------- ### Void Label by ID Source: https://github.com/shipengine/shipengine-ruby/blob/main/docs/void-label-by-id.md Demonstrates how to void a label using its ID. This method requires the label ID as a string argument. It handles potential ShipEngine errors during the voiding process. ```ruby def void_label_with_label_id_demo_function() client = ShipEngine::Client.new("API-Key") begin result = client.void_label_with_label_id('se-451990109') puts result rescue ShipEngine::Exceptions::ShipEngineError => err puts err end end void_label_with_label_id_demo_function ``` -------------------------------- ### List of Carrier Packages Source: https://github.com/shipengine/shipengine-ruby/blob/main/docs/list-carriers.md This snippet shows an array of package types available for a carrier, such as FedEx. It includes details like package code, name, and description. ```ruby #, #, #, #, #, #, #, #, #, #, #, #, #, # ``` -------------------------------- ### create_label_from_shipment_details Source: https://github.com/shipengine/shipengine-ruby/blob/main/docs/create-label-from-shipment-details.md The `create_label_from_shipment_details` method allows you to generate a shipping label by passing shipment details. It returns a response object containing the created label information. ```APIDOC ## create_label_from_shipment_details ### Description Creates a shipping label using the provided shipment details. ### Method `client.create_label_from_shipment_details(shipment_details)` ### Parameters #### Request Body - **shipment_details** (object) - Required - An object containing shipment details. - **shipment** (object) - Required - Details of the shipment. - **service_code** (string) - Required - The code for the shipping service (e.g., "ups_ground"). - **ship_to** (object) - Required - Information about the recipient. - **name** (string) - Required - Recipient's name. - **address_line1** (string) - Required - First line of the recipient's address. - **city_locality** (string) - Required - Recipient's city. - **state_province** (string) - Required - Recipient's state or province. - **postal_code** (string) - Required - Recipient's postal code. - **country_code** (string) - Required - Recipient's country code (e.g., "US"). - **address_residential_indicator** (string) - Required - Indicates if the address is residential ('yes' or 'no'). - **ship_from** (object) - Required - Information about the sender. - **name** (string) - Required - Sender's name. - **company_name** (string) - Optional - Sender's company name. - **phone** (string) - Optional - Sender's phone number. - **address_line1** (string) - Required - First line of the sender's address. - **city_locality** (string) - Required - Sender's city. - **state_province** (string) - Required - Sender's state or province. - **postal_code** (string) - Required - Sender's postal code. - **country_code** (string) - Required - Sender's country code (e.g., "US"). - **address_residential_indicator** (string) - Required - Indicates if the address is residential ('yes' or 'no'). - **packages** (array) - Required - An array of package details. - **weight** (object) - Required - Package weight. - **value** (number) - Required - The weight value. - **unit** (string) - Required - The weight unit (e.g., "ounce"). - **dimensions** (object) - Required - Package dimensions. - **height** (number) - Required - Package height. - **width** (number) - Required - Package width. - **length** (number) - Required - Package length. - **unit** (string) - Required - The dimension unit (e.g., "inch"). ### Response #### Success Response Returns a `ShipEngine::Domain::Labels::CreateFromShipmentDetails::Response` object containing the created label details. #### Response Example ```ruby # @is_international=false, @is_return_label=false, @label_download= # @label_format="pdf", @label_id="se-75290114", @label_image_id=nil, @label_layout="4x6", @package_code="package", @packages= [#, @external_package_id=nil, @insured_value= # @label_messages= #, @package_code="package", @tracking_number="1Z63R0960331651653", @weight= #>], @rma_number=nil, @service_code="ups_ground", @ship_date="2021-08-03T00:00:00Z", @shipment_cost= # @shipment_id="se-144018968", @status="completed", @trackable=true, @tracking_number="1Z63R0960331651653", @tracking_status="in_transit", @voided=false, @voided_at=nil> ``` ### Error Handling - **ShipEngine::Exceptions::ShipEngineError**: Catches errors specific to the ShipEngine API. ```