Class: ShippingEasy::Http::FaradayAdapter

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/shipping_easy/http/faraday_adapter.rb

Defined Under Namespace

Classes: CustomUserAgent

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request) ⇒ FaradayAdapter

Returns a new instance of FaradayAdapter.



10
11
12
# File 'lib/shipping_easy/http/faraday_adapter.rb', line 10

def initialize(request)
  @request = request
end

Instance Attribute Details

#requestObject (readonly)

Returns the value of attribute request.



8
9
10
# File 'lib/shipping_easy/http/faraday_adapter.rb', line 8

def request
  @request
end

Instance Method Details

#connect!Object



14
15
16
# File 'lib/shipping_easy/http/faraday_adapter.rb', line 14

def connect!
  send(http_method)
end

#connectionObject



32
33
34
35
36
37
38
# File 'lib/shipping_easy/http/faraday_adapter.rb', line 32

def connection
  @connection ||= Faraday.new(url: base_url) do |faraday|
    faraday.use FaradayMiddleware::FollowRedirects, limit: 3, standards_compliant: true
    faraday.use CustomUserAgent, "shipping_easy-ruby/#{ShippingEasy::VERSION}"
    faraday.adapter Faraday.default_adapter
  end
end

#getObject



25
26
27
28
29
30
# File 'lib/shipping_easy/http/faraday_adapter.rb', line 25

def get
  connection.get do |req|
    req.url uri, params
    req.body = request.body
  end
end

#postObject



18
19
20
21
22
23
# File 'lib/shipping_easy/http/faraday_adapter.rb', line 18

def post
  connection.post do |req|
    req.url uri, params
    req.body = request.body
  end
end