Class: SoarHttpClient

Inherits:
Object
  • Object
show all
Defined in:
lib/soar_http_client.rb,
lib/soar_http_client/version.rb

Constant Summary collapse

VERSION =
"0.1.4"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url:, retries: 2, auditing: nil, persistent_connection: false, timeout: 5, basic_auth: nil, min_sleep_seconds: 0.5, max_sleep_seconds: 1) ⇒ SoarHttpClient

Returns a new instance of SoarHttpClient.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/soar_http_client.rb', line 7

def initialize(url:, retries: 2, auditing: nil, persistent_connection: false, timeout: 5, basic_auth: nil, min_sleep_seconds: 0.5, max_sleep_seconds: 1)
  @semaphore = Mutex.new
  @semaphore.synchronize {
    @url = url
    @retries = retries
    @auditing = auditing
    @persistent_connection = persistent_connection
    @min_sleep_seconds = min_sleep_seconds
    @max_sleep_seconds = max_sleep_seconds

    @connection = Faraday.new(:url => @url) do |faraday|
      faraday.options[:open_timeout] = timeout
      faraday.options[:timeout] = timeout
      faraday.request :url_encoded
      faraday.adapter Faraday.default_adapter if persistent_connection == false
      faraday.adapter :net_http_persistent if persistent_connection == true
      faraday.basic_auth basic_auth[:user], basic_auth[:password] if basic_auth && (basic_auth[:user] && basic_auth[:password])
    end
  }
end

Instance Attribute Details

#auditingObject (readonly)

Returns the value of attribute auditing.



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

def auditing
  @auditing
end

#connectionObject (readonly)

Returns the value of attribute connection.



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

def connection
  @connection
end

#max_sleep_secondsObject (readonly)

Returns the value of attribute max_sleep_seconds.



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

def max_sleep_seconds
  @max_sleep_seconds
end

#min_sleep_secondsObject (readonly)

Returns the value of attribute min_sleep_seconds.



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

def min_sleep_seconds
  @min_sleep_seconds
end

#persistent_connectionObject (readonly)

Returns the value of attribute persistent_connection.



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

def persistent_connection
  @persistent_connection
end

#retriesObject (readonly)

Returns the value of attribute retries.



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

def retries
  @retries
end

#urlObject (readonly)

Returns the value of attribute url.



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

def url
  @url
end

Instance Method Details

#delete(path:, params: nil, body: nil, token: nil, headers: nil, flow_identifier: nil) ⇒ Object



45
46
47
# File 'lib/soar_http_client.rb', line 45

def delete(path:, params: nil, body: nil, token: nil, headers: nil, flow_identifier: nil)
  do_request(verb: 'delete', path: path, params: params, body: body, token: token, headers: headers, flow_identifier: flow_identifier)
end

#get(path:, params: nil, body: nil, token: nil, headers: nil, flow_identifier: nil) ⇒ Object



29
30
31
# File 'lib/soar_http_client.rb', line 29

def get(path:, params: nil, body: nil, token: nil, headers: nil, flow_identifier: nil)
  do_request(verb: 'get', path: path, params: params, body: body, token: token, headers: headers, flow_identifier: flow_identifier)
end

#patch(path:, params: nil, body: nil, token: nil, headers: nil, flow_identifier: nil) ⇒ Object



41
42
43
# File 'lib/soar_http_client.rb', line 41

def patch(path:, params: nil, body: nil, token: nil, headers: nil, flow_identifier: nil)
  do_request(verb: 'patch', path: path, params: params, body: body, token: token, headers: headers, flow_identifier: flow_identifier)
end

#post(path:, params: nil, body: nil, token: nil, headers: nil, flow_identifier: nil) ⇒ Object



33
34
35
# File 'lib/soar_http_client.rb', line 33

def post(path:, params: nil, body: nil, token: nil, headers: nil, flow_identifier: nil)
  do_request(verb: 'post', path: path, params: params, body: body, token: token, headers: headers, flow_identifier: flow_identifier)
end

#put(path:, params: nil, body: nil, token: nil, headers: nil, flow_identifier: nil) ⇒ Object



37
38
39
# File 'lib/soar_http_client.rb', line 37

def put(path:, params: nil, body: nil, token: nil, headers: nil, flow_identifier: nil)
  do_request(verb: 'put', path: path, params: params, body: body, token: token, headers: headers, flow_identifier: flow_identifier)
end