Class: RestClient

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/clearconnect/rest_client.rb

Instance Method Summary collapse

Constructor Details

#initialize(username, password) ⇒ RestClient

Returns a new instance of RestClient.



4
5
6
7
8
9
10
11
12
# File 'lib/clearconnect/rest_client.rb', line 4

def initialize(username, password)
  self.class.base_uri ClearConnect.configuration.endpoints[:clearconnect]
  self.class.default_params :resultType => ClearConnect.configuration.format.to_s
  self.class.format ClearConnect.configuration.format
  @username = username
  @password = password
  @session = false
  @sessionKey = nil
end

Instance Method Details

#get_no_session(query) ⇒ Object



28
29
30
31
32
# File 'lib/clearconnect/rest_client.rb', line 28

def get_no_session(query)
  query = normalize_query(query.merge(:username => @username, :password => @password))
  options = { :query => query }
  self.class.get("", options)
end

#get_request(query) ⇒ Object

Takes a query of the format { key: ‘value’, key2: ‘value’ } where the keys are symbols corresponding to the parameters passed to the ClearConnect REST API



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/clearconnect/rest_client.rb', line 16

def get_request(query)
  if @session and @sessionKey.nil?
    raise "Invalid session key. You must first acquire a session key by calling 'get_session_key' before executing requests."
  elsif not @session
    query = normalize_query(query.merge(:sessionKey => @sessionKey))
    options = { :query => query }
    self.class.get("", options)
  else
    get_no_session(query)
  end
end

#set_session_key(key) ⇒ Object



34
35
36
37
38
# File 'lib/clearconnect/rest_client.rb', line 34

def set_session_key(key)
  puts "Setting session key: #{key}."
  @session = true
  @sessionKey = key
end