Class: HornOfPlenty::Adapters::Github::Client

Inherits:
Object
  • Object
show all
Includes:
Wisper::Publisher
Defined in:
lib/horn_of_plenty/adapters/github/client.rb

Constant Summary collapse

RETRY_BACKOFF_MULTIPLIER =
3.5

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url: configuration.base_url, version: configuration.api_version, token: configuration.token, logger: configuration.logger) ⇒ Client

Returns a new instance of Client.



23
24
25
26
27
28
29
30
31
32
# File 'lib/horn_of_plenty/adapters/github/client.rb', line 23

def initialize(url:     configuration.base_url,
               version: configuration.api_version,
               token:   configuration.token,
               logger:  configuration.logger)

  self.url     = url
  self.version = version
  self.token   = token
  self.logger  = logger
end

Instance Attribute Details

#loggerObject

Returns the value of attribute logger.



18
19
20
# File 'lib/horn_of_plenty/adapters/github/client.rb', line 18

def logger
  @logger
end

#tokenObject

Returns the value of attribute token.



18
19
20
# File 'lib/horn_of_plenty/adapters/github/client.rb', line 18

def token
  @token
end

#urlObject

Returns the value of attribute url.



18
19
20
# File 'lib/horn_of_plenty/adapters/github/client.rb', line 18

def url
  @url
end

#versionObject

Returns the value of attribute version.



18
19
20
# File 'lib/horn_of_plenty/adapters/github/client.rb', line 18

def version
  @version
end

Class Method Details

.configurationObject



58
59
60
# File 'lib/horn_of_plenty/adapters/github/client.rb', line 58

def self.configuration
  Github::Configuration.instance
end

.poolObject

rubocop:enable Metrics/LineLength



54
55
56
# File 'lib/horn_of_plenty/adapters/github/client.rb', line 54

def self.pool
  @pool ||= ConnectionPool::Wrapper.new(size: 7, timeout: 20) { new }
end

Instance Method Details

#request(request, retries = 3, _retry_delay_in_ms = 1000) ⇒ Object

rubocop:disable Metrics/LineLength



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/horn_of_plenty/adapters/github/client.rb', line 35

def request(request, retries = 3, _retry_delay_in_ms = 1000)
  broadcast(:horn_of_plenty_request_sent, request.class.name, request.method, request.path, request.to_h, url, retries)

  response = connection.public_send(request.method, request.path, request.to_h)

  broadcast(:horn_of_plenty_response_received, response.class.name, request.method, request.path, response.body, url)

  request.response_class.parse(response)
rescue Github::Errors => exception
  retries -= 1

  broadcast(:horn_of_plenty_request_retried, exception, retries)

  retry if retries.positive?

  raise exception
end