Class: Ravelin::ProxyClient

Inherits:
Client
  • Object
show all
Defined in:
lib/ravelin/proxy_client.rb

Constant Summary

Constants inherited from Client

Client::API_BASE

Instance Method Summary collapse

Methods inherited from Client

#delete_tag, #get_tag, #send_backfill_event, #send_event, #send_tag

Constructor Details

#initialize(base_url:, username:, password:, api_version: 2, include_rule_output: false) ⇒ ProxyClient

Returns a new instance of ProxyClient.

Raises:

  • (ArgumentError)


3
4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/ravelin/proxy_client.rb', line 3

def initialize(base_url:, username:, password:, api_version: 2, include_rule_output: false)

  raise ArgumentError, "api_version must be 2 or 3" unless [2,3].include? api_version
  @api_version = api_version
  @url_prefix = '/ravelinproxy'
  @include_rule_output = include_rule_output

  @connection = Faraday.new(base_url, faraday_proxy_options) do |conn|
    conn.response :json, context_type: /\bjson$/
    conn.adapter Ravelin.faraday_adapter
    conn.basic_auth(username, password)
  end
end

Instance Method Details

#faraday_proxy_optionsObject



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/ravelin/proxy_client.rb', line 17

def faraday_proxy_options
  options = {
    request: { timeout: Ravelin.faraday_timeout },
    headers: {
      'Content-Type'  => 'application/json; charset=utf-8'.freeze,
      'User-Agent'    => "Ravelin Proxy RubyGem/#{Ravelin::VERSION}".freeze
    }
  }
  if @include_rule_output
    options[:headers]['Accept'] = 'application/vnd.ravelin.score.v2+json'
  end
  options
end