Class: Gitloggl::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/gitloggl/connection.rb

Constant Summary collapse

USER_AGENT =
'Gitloggl bot'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url, headers: {}, verbose: false) {|_self| ... } ⇒ Connection

Returns a new instance of Connection.

Yields:

  • (_self)

Yield Parameters:



9
10
11
12
13
14
15
# File 'lib/gitloggl/connection.rb', line 9

def initialize(url, headers: {}, verbose: false)
  @url = url
  @headers = headers
  @verbose = verbose

  yield(self) if block_given?
end

Instance Attribute Details

#headersObject (readonly)

Returns the value of attribute headers.



5
6
7
# File 'lib/gitloggl/connection.rb', line 5

def headers
  @headers
end

#urlObject (readonly)

Returns the value of attribute url.



5
6
7
# File 'lib/gitloggl/connection.rb', line 5

def url
  @url
end

#verboseObject (readonly)

Returns the value of attribute verbose.



5
6
7
# File 'lib/gitloggl/connection.rb', line 5

def verbose
  @verbose
end

Instance Method Details

#default_headersObject



27
28
29
30
31
# File 'lib/gitloggl/connection.rb', line 27

def default_headers
  @default_headers ||= {
    'User-Agent' => USER_AGENT
  }
end

#transportObject



17
18
19
20
21
22
23
24
25
# File 'lib/gitloggl/connection.rb', line 17

def transport
  @transport ||= Faraday.new(url: url, headers: default_headers.merge(headers)) do |conn|
    conn.use Faraday::Request::UrlEncoded
    conn.use Faraday::Response::RaiseError
    conn.response :json
    conn.use Faraday::Response::Logger, self, bodies: true if verbose
    conn.adapter :typhoeus
  end
end