Class: Scim::Kit::Http

Inherits:
Object
  • Object
show all
Defined in:
lib/scim/kit/http.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(driver: Http.default_driver, retries: 3) ⇒ Http

Returns a new instance of Http.



8
9
10
11
# File 'lib/scim/kit/http.rb', line 8

def initialize(driver: Http.default_driver, retries: 3)
  @driver = driver
  @retries = retries
end

Instance Attribute Details

#driverObject (readonly)



6
7
8
# File 'lib/scim/kit/http.rb', line 6

def driver
  @driver
end

#retriesObject (readonly)



6
7
8
# File 'lib/scim/kit/http.rb', line 6

def retries
  @retries
end

Class Method Details

.default_driverObject



23
24
25
26
27
28
29
30
31
# File 'lib/scim/kit/http.rb', line 23

def self.default_driver
  @default_driver ||= Net::Hippie::Client.new(
    follow_redirects: 3,
    headers: headers,
    logger: Scim::Kit.logger,
    open_timeout: 1,
    read_timeout: 5
  )
end

.headersObject



33
34
35
36
37
38
39
# File 'lib/scim/kit/http.rb', line 33

def self.headers
  {
    'Accept' => 'application/scim+json',
    'Content-Type' => 'application/scim+json',
    'User-Agent' => "scim/kit #{Scim::Kit::VERSION}"
  }
end

Instance Method Details

#get(uri) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/scim/kit/http.rb', line 13

def get(uri)
  driver.with_retry(retries: retries) do |client|
    response = client.get(uri)
    ok?(response) ? JSON.parse(response.body, symbolize_names: true) : {}
  end
rescue *Net::Hippie::CONNECTION_ERRORS => error
  Scim::Kit.logger.error(error)
  {}
end