Class: Saorin::Client::Faraday

Inherits:
Object
  • Object
show all
Includes:
Base
Defined in:
lib/saorin/client/faraday.rb

Constant Summary collapse

CONTENT_TYPE =
'application/json'.freeze

Instance Attribute Summary collapse

Attributes included from Base

#options

Instance Method Summary collapse

Methods included from Base

#apply, #batch, #call, #notify

Methods included from Formatter

#default_formatter, #formatter

Methods included from Base::UUID

#uuid

Constructor Details

#initialize(options = {}, &block) ⇒ Faraday

Returns a new instance of Faraday.



12
13
14
15
16
17
18
19
20
# File 'lib/saorin/client/faraday.rb', line 12

def initialize(options = {}, &block)
  super options

  @connection = ::Faraday::Connection.new(options) do |builder|
    builder.adapter ::Faraday.default_adapter
    builder.response :raise_error
    block.call builder if block
  end
end

Instance Attribute Details

#connectionObject (readonly)

Returns the value of attribute connection.



10
11
12
# File 'lib/saorin/client/faraday.rb', line 10

def connection
  @connection
end

Instance Method Details

#send_request(content) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/saorin/client/faraday.rb', line 22

def send_request(content)
  response = @connection.post do |req|
    req.headers[:content_type] = CONTENT_TYPE
    req.body = content
  end
  response.body
end