Module: RHapi::Connection::ClassMethods

Included in:
Lead
Defined in:
lib/r_hapi/connection.rb

Overview

Class methods —————————————————————————–

Instance Method Summary collapse

Instance Method Details

#append_options(options) ⇒ Object



33
34
35
36
37
38
39
# File 'lib/r_hapi/connection.rb', line 33

def append_options(options)
  query_string = ""
  options.each do |key, value|
    query_string << "&#{key.to_s}=#{value}"
  end
  query_string
end

#get(url) ⇒ Object



41
42
43
44
45
46
47
48
49
50
# File 'lib/r_hapi/connection.rb', line 41

def get(url)
  response = Curl::Easy.perform(url) do |curl|
    curl.on_failure do |response, err|
      RHapi::ConnectionError.raise_error("#{response.response_code}\n Error is: #{err.inspect}")
    end
  end
  RHapi::ConnectionError.raise_error( response.header_str) unless response.header_str =~ /2\d\d/
  RHapi::ConnectionError.raise_error(response.body_str) if response.body_str =~ /Error/i
  response
end

#url_for(method, id = nil, options = {}) ⇒ Object

Raises:



23
24
25
26
27
28
29
30
31
# File 'lib/r_hapi/connection.rb', line 23

def url_for(method, id=nil, options={})
  url = "#{RHapi.options[:end_point]}/leads/#{RHapi.options[:version]}/#{method}"
  url << "/#{id}" unless id.nil?
  url << "?hapikey=#{RHapi.options[:api_key]}"
  
  raise(RHapi::UriError, "Options must be a hash in order to build the url.") unless options.is_a?(Hash)
  url << append_options(options) unless options.empty?
  url
end