Class: FriendlyShipping::Services::ShipEngine
- Inherits:
-
Object
- Object
- FriendlyShipping::Services::ShipEngine
- Defined in:
- lib/friendly_shipping/services/ship_engine.rb,
lib/friendly_shipping/services/ship_engine/bad_request.rb,
lib/friendly_shipping/services/ship_engine/label_options.rb,
lib/friendly_shipping/services/ship_engine/label_item_options.rb,
lib/friendly_shipping/services/ship_engine/bad_request_handler.rb,
lib/friendly_shipping/services/ship_engine/parse_void_response.rb,
lib/friendly_shipping/services/ship_engine/parse_label_response.rb,
lib/friendly_shipping/services/ship_engine/label_customs_options.rb,
lib/friendly_shipping/services/ship_engine/label_package_options.rb,
lib/friendly_shipping/services/ship_engine/parse_carrier_response.rb,
lib/friendly_shipping/services/ship_engine/rate_estimates_options.rb,
lib/friendly_shipping/services/ship_engine/serialize_label_shipment.rb,
lib/friendly_shipping/services/ship_engine/parse_rate_estimate_response.rb,
lib/friendly_shipping/services/ship_engine/serialize_rate_estimate_request.rb
Defined Under Namespace
Classes: BadRequest, BadRequestHandler, LabelCustomsOptions, LabelItemOptions, LabelOptions, LabelPackageOptions, ParseCarrierResponse, ParseLabelResponse, ParseRateEstimateResponse, ParseVoidResponse, RateEstimatesOptions, SerializeLabelShipment, SerializeRateEstimateRequest
Constant Summary collapse
- API_BASE =
"https://api.shipengine.com/v1/"
- API_PATHS =
{ carriers: "carriers", labels: "labels" }.freeze
Instance Method Summary collapse
-
#carriers(debug: false) ⇒ Result<ApiResult<Array<Carrier>>>
Get configured carriers from ShipEngine.
-
#initialize(token:, test: true, client: FriendlyShipping::HttpClient.new(error_handler: BadRequestHandler)) ⇒ ShipEngine
constructor
A new instance of ShipEngine.
-
#labels(shipment, options:) ⇒ Result<ApiResult<Array<FriendlyShipping::Label>>>
Get label(s) from ShipEngine.
-
#rate_estimates(shipment, options: FriendlyShipping::Services::ShipEngine::RateEstimatesOptions.new, debug: false) ⇒ Result<ApiResult<Array<FriendlyShipping::Rate>>>
Get rate estimates from ShipEngine.
- #void(label, debug: false) ⇒ Object
Constructor Details
#initialize(token:, test: true, client: FriendlyShipping::HttpClient.new(error_handler: BadRequestHandler)) ⇒ ShipEngine
Returns a new instance of ShipEngine.
25 26 27 28 29 |
# File 'lib/friendly_shipping/services/ship_engine.rb', line 25 def initialize(token:, test: true, client: FriendlyShipping::HttpClient.new(error_handler: BadRequestHandler)) @token = token @test = test @client = client end |
Instance Method Details
#carriers(debug: false) ⇒ Result<ApiResult<Array<Carrier>>>
Get configured carriers from ShipEngine
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/friendly_shipping/services/ship_engine.rb', line 34 def carriers(debug: false) request = FriendlyShipping::Request.new( url: API_BASE + API_PATHS[:carriers], http_method: "GET", headers: request_headers, debug: debug ) client.get(request).fmap do |response| ParseCarrierResponse.call(request: request, response: response) end end |
#labels(shipment, options:) ⇒ Result<ApiResult<Array<FriendlyShipping::Label>>>
Get label(s) from ShipEngine
77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/friendly_shipping/services/ship_engine.rb', line 77 def labels(shipment, options:) request = FriendlyShipping::Request.new( url: API_BASE + API_PATHS[:labels], http_method: "POST", body: SerializeLabelShipment.call(shipment: shipment, options: , test: test).to_json, headers: request_headers ) client.post(request).fmap do |response| ParseLabelResponse.call(request: request, response: response) end end |
#rate_estimates(shipment, options: FriendlyShipping::Services::ShipEngine::RateEstimatesOptions.new, debug: false) ⇒ Result<ApiResult<Array<FriendlyShipping::Rate>>>
Get rate estimates from ShipEngine
55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/friendly_shipping/services/ship_engine.rb', line 55 def rate_estimates(shipment, options: FriendlyShipping::Services::ShipEngine::RateEstimatesOptions.new, debug: false) request = FriendlyShipping::Request.new( url: "#{API_BASE}rates/estimate", http_method: "POST", body: SerializeRateEstimateRequest.call(shipment: shipment, options: ).to_json, headers: request_headers, debug: debug ) client.post(request).bind do |response| ParseRateEstimateResponse.call(response: response, request: request, options: ) end end |
#void(label, debug: false) ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/friendly_shipping/services/ship_engine.rb', line 89 def void(label, debug: false) request = FriendlyShipping::Request.new( url: "#{API_BASE}labels/#{label.id}/void", http_method: "PUT", body: '', headers: request_headers, debug: debug ) client.put(request).bind do |response| ParseVoidResponse.call(request: request, response: response) end end |