class SolidusShipstation::Api::RequestRunner

Constants

API_BASE

Attributes

password[R]
username[R]

Public Class Methods

from_config() click to toggle source
# File lib/solidus_shipstation/api/request_runner.rb, line 11
def from_config
  new(
    username: SolidusShipstation.config.api_key,
    password: SolidusShipstation.config.api_secret,
  )
end
new(username:, password:) click to toggle source
# File lib/solidus_shipstation/api/request_runner.rb, line 19
def initialize(username:, password:)
  @username = username
  @password = password
end

Public Instance Methods

call(method, path, params = {}) click to toggle source
# File lib/solidus_shipstation/api/request_runner.rb, line 24
def call(method, path, params = {})
  response = HTTParty.send(
    method,
    URI.join(API_BASE, path),
    body: params.to_json,
    basic_auth: {
      username: @username,
      password: @password,
    },
    headers: {
      'Content-Type' => 'application/json',
      'Accept' => 'application/json',
    },
  )

  case response.code.to_s
  when /2\d{2}/
    response.parsed_response
  when '429'
    raise RateLimitedError.from_response(response)
  else
    raise RequestError.from_response(response)
  end
end