Class: Jeckle::API

Inherits:
Object
  • Object
show all
Defined in:
lib/jeckle/api.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#base_uriObject



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

def base_uri
  [@base_uri, *namespaces.values].join '/'
end

#basic_authObject

Returns the value of attribute basic_auth.



5
6
7
# File 'lib/jeckle/api.rb', line 5

def basic_auth
  @basic_auth
end

#headersObject



34
35
36
# File 'lib/jeckle/api.rb', line 34

def headers
  @headers || {}
end

#loggerObject

Returns the value of attribute logger.



3
4
5
# File 'lib/jeckle/api.rb', line 3

def logger
  @logger
end

#namespacesObject



38
39
40
# File 'lib/jeckle/api.rb', line 38

def namespaces
  @namespaces || {}
end

#open_timeout=(value) ⇒ Object (writeonly)

Sets the attribute open_timeout

Parameters:

  • value

    the value to set the attribute open_timeout to.



4
5
6
# File 'lib/jeckle/api.rb', line 4

def open_timeout=(value)
  @open_timeout = value
end

#paramsObject



30
31
32
# File 'lib/jeckle/api.rb', line 30

def params
  @params || {}
end

#read_timeout=(value) ⇒ Object (writeonly)

Sets the attribute read_timeout

Parameters:

  • value

    the value to set the attribute read_timeout to.



4
5
6
# File 'lib/jeckle/api.rb', line 4

def read_timeout=(value)
  @read_timeout = value
end

#request_timeoutObject (readonly)

Returns the value of attribute request_timeout.



5
6
7
# File 'lib/jeckle/api.rb', line 5

def request_timeout
  @request_timeout
end

Instance Method Details

#connectionObject



7
8
9
10
11
12
13
14
15
16
# File 'lib/jeckle/api.rb', line 7

def connection
  @connection ||= Faraday.new(url: base_uri, request: timeout).tap do |conn|
    conn.headers = headers
    conn.params = params
    conn.response :logger, logger

    conn.basic_auth basic_auth[:username], basic_auth[:password] if basic_auth
    conn.instance_exec &@middlewares_block if @middlewares_block
  end
end

#middlewares(&block) ⇒ Object



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

def middlewares(&block)
  raise Jeckle::ArgumentError, 'A block is required when configuring API middlewares' unless block_given?

  @middlewares_block = block
end

#timeoutObject



48
49
50
51
52
53
# File 'lib/jeckle/api.rb', line 48

def timeout
  {}.tap do |t|
    t[:open_timeout] = @open_timeout if @open_timeout
    t[:timeout] = @read_timeout if @read_timeout
  end
end