Module: HelloBlock::Connection

Included in:
HelloBlock
Defined in:
lib/helloblock/http/connection.rb

Instance Method Summary collapse

Instance Method Details

#connectionObject



5
6
7
8
9
10
11
12
13
# File 'lib/helloblock/http/connection.rb', line 5

def connection
  @connection ||= Faraday.new(base_url, connection_options) do |connection|
    connection.request :json
    connection.response :json
    connection.use FaradayMiddleware::Rashify

    connection.adapter :net_http
  end
end

#connection_optionsObject



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/helloblock/http/connection.rb', line 15

def connection_options
  @connection_options ||= {
    headers: {
      accept: 'application/json',
      user_agent: "HelloBlock Gem #{HelloBlock::VERSION}"
    },
    request: {
      open_timeout: 10,
      timeout: 30
    }
  }
end