Class: SpreeBoxnow::ApiClient
- Inherits:
-
Object
- Object
- SpreeBoxnow::ApiClient
- Includes:
- Spree::IntegrationsConcern
- Defined in:
- app/lib/spree_boxnow/api_client.rb
Defined Under Namespace
Classes: ApiError
Constant Summary collapse
- TOKEN_MARGIN =
seconds before expiry to refresh
60
Instance Method Summary collapse
- #cancel_parcel(parcel_id) ⇒ Object
- #create_delivery_request(params) ⇒ Object
- #destinations(params = {}) ⇒ Object
- #fetch_label(parcel_id, format: 'pdf') ⇒ Object
-
#initialize ⇒ ApiClient
constructor
A new instance of ApiClient.
Constructor Details
#initialize ⇒ ApiClient
Returns a new instance of ApiClient.
10 11 12 13 14 15 16 17 |
# File 'app/lib/spree_boxnow/api_client.rb', line 10 def initialize integration = store_integration('boxnow') raise 'BoxNow integration not configured' unless integration @client_id = integration.preferred_client_id @client_secret = integration.preferred_client_secret @api_url = integration.preferred_api_url.to_s.chomp('/') end |
Instance Method Details
#cancel_parcel(parcel_id) ⇒ Object
27 28 29 |
# File 'app/lib/spree_boxnow/api_client.rb', line 27 def cancel_parcel(parcel_id) post("/api/v1/parcels/#{parcel_id}:cancel", {}) end |
#create_delivery_request(params) ⇒ Object
19 20 21 |
# File 'app/lib/spree_boxnow/api_client.rb', line 19 def create_delivery_request(params) post('/api/v1/delivery-requests', params) end |
#destinations(params = {}) ⇒ Object
31 32 33 |
# File 'app/lib/spree_boxnow/api_client.rb', line 31 def destinations(params = {}) get('/api/v1/destinations', params: params) end |
#fetch_label(parcel_id, format: 'pdf') ⇒ Object
23 24 25 |
# File 'app/lib/spree_boxnow/api_client.rb', line 23 def fetch_label(parcel_id, format: 'pdf') get("/api/v1/parcels/#{parcel_id}/label.#{format}", raw: true) end |