Class: UniqueResponse::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/unique_response_ruby/client.rb

Constant Summary collapse

HTTP_HEADERS =
{
    'Content-Type' => 'application/json',
    'Accept' => 'application/json',
    'Accept-Charset' => 'utf-8',
    'User-Agent' => 'unique_response_ruby'
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeClient

Returns a new instance of Client.



16
17
18
19
20
21
22
# File 'lib/unique_response_ruby/client.rb', line 16

def initialize
  @account_id = ENV['UNIQUE_RESPONSE_ACCOUNT_ID']
  @auth_token = ENV['UNIQUE_RESPONSE_AUTH_TOKEN']
  if @account_id.nil? || @auth_token.nil?
    raise ArgumentError, 'Account SID and auth token are required'
  end
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



7
8
9
# File 'lib/unique_response_ruby/client.rb', line 7

def data
  @data
end

#successfulObject (readonly)

Returns the value of attribute successful.



7
8
9
# File 'lib/unique_response_ruby/client.rb', line 7

def successful
  @successful
end

Instance Method Details

#save_response(response) ⇒ Object



24
25
26
27
28
29
# File 'lib/unique_response_ruby/client.rb', line 24

def save_response(response)
  @uri = URI(ENV['UNIQUE_RESPONSE_ENDPOINT'])
  @http_request = Net::HTTP::Post.new @uri.path, HTTP_HEADERS
  @http_request.body = response.to_h.to_json
  perform_request
end