Class: Shipwire::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/shipwire/request.rb

Constant Summary collapse

API_VERSION =
3

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(method: :get, path: '', params: {}, body: {}) ⇒ Request

Returns a new instance of Request.



11
12
13
14
15
16
17
18
# File 'lib/shipwire/request.rb', line 11

def initialize(method: :get, path: '', params: {}, body: {})
  @method = method
  @path = path
  @params = params
  @body = body

  @connection = build_connection
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



9
10
11
# File 'lib/shipwire/request.rb', line 9

def body
  @body
end

#methodObject (readonly)

Returns the value of attribute method.



9
10
11
# File 'lib/shipwire/request.rb', line 9

def method
  @method
end

#pathObject (readonly)

Returns the value of attribute path.



9
10
11
# File 'lib/shipwire/request.rb', line 9

def path
  @path
end

Class Method Details

.send(**args) ⇒ Object



3
4
5
# File 'lib/shipwire/request.rb', line 3

def self.send(**args)
  new(**args).send
end

Instance Method Details

#sendObject



20
21
22
23
24
25
26
# File 'lib/shipwire/request.rb', line 20

def send
  Response.new(underlying_response: make_request)
rescue Faraday::ConnectionFailed
  Response.new(error_summary: 'Unable to connect to Shipwire')
rescue Faraday::TimeoutError
  Response.new(error_summary: 'Shipwire connection timeout')
end