Module: Shippo::API

Defined in:
lib/shippo/api.rb,
lib/shippo/api/request.rb,
lib/shippo/api/version.rb,
lib/shippo/api/api_hash.rb,
lib/shippo/api/category.rb,
lib/shippo/api/resource.rb,
lib/shippo/api/api_object.rb,
lib/shippo/api/extend/url.rb,
lib/shippo/api/operations.rb,
lib/shippo/api/category/base.rb,
lib/shippo/api/category/state.rb,
lib/shippo/api/category/source.rb,
lib/shippo/api/category/status.rb,
lib/shippo/api/operations/list.rb,
lib/shippo/api/category/purpose.rb,
lib/shippo/api/extend/operation.rb,
lib/shippo/api/operations/batch.rb,
lib/shippo/api/operations/rates.rb,
lib/shippo/api/operations/track.rb,
lib/shippo/api/operations/create.rb,
lib/shippo/api/operations/update.rb,
lib/shippo/api/transformers/list.rb,
lib/shippo/api/extend/transformers.rb,
lib/shippo/api/operations/validate.rb

Defined Under Namespace

Modules: Category, Extend, Operations, Transformers Classes: ApiHash, ApiObject, Request, Resource

Constant Summary collapse

VERSION =
'4.0.0'

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.baseObject

Returns the value of attribute base.



24
25
26
# File 'lib/shippo/api.rb', line 24

def base
  @base
end

.debugObject

Returns the value of attribute debug.



24
25
26
# File 'lib/shippo/api.rb', line 24

def debug
  @debug
end

.open_timeoutObject

Returns the value of attribute open_timeout.



24
25
26
# File 'lib/shippo/api.rb', line 24

def open_timeout
  @open_timeout
end

.read_timeoutObject

Returns the value of attribute read_timeout.



24
25
26
# File 'lib/shippo/api.rb', line 24

def read_timeout
  @read_timeout
end

.tokenObject



26
27
28
# File 'lib/shippo/api.rb', line 26

def token
  Thread.current[:shippo_api_token] || @token
end

.versionObject

Returns the value of attribute version.



24
25
26
# File 'lib/shippo/api.rb', line 24

def version
  @version
end

.warningsObject

Returns the value of attribute warnings.



24
25
26
# File 'lib/shippo/api.rb', line 24

def warnings
  @warnings
end

Class Method Details

.debug?Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/shippo/api.rb', line 56

def debug?
  self.debug
end

.request(method, uri, params = {}, headers = {}) ⇒ Object

Parameters:

  • method (Symbol)

    One of :get, :put, :post

  • uri (String)

    the URL component after the first slash but before params

  • params (Hash) (defaults to: {})

    hash of optional parameters to add to the URL

  • headers (Hash) (defaults to: {})

    optionally added headers



42
43
44
45
46
47
# File 'lib/shippo/api.rb', line 42

def request(method, uri, params = {}, headers = {})
  ::Shippo::API::Request.new(method:  method,
                             uri:     uri,
                             params:  params,
                             headers: headers).execute
end

.with_token(token) ⇒ Object



30
31
32
33
34
35
36
# File 'lib/shippo/api.rb', line 30

def with_token(token)
  old_thread_token = Thread.current[:shippo_api_token]
  Thread.current[:shippo_api_token] = token
  yield
ensure
  Thread.current[:shippo_api_token] = old_thread_token
end