Module: RHapi::Connection::ClassMethods
- Included in:
- Lead
- Defined in:
- lib/r_hapi/connection.rb
Overview
Class methods —————————————————————————–
Instance Method Summary collapse
- #append_options(options) ⇒ Object
- #get(url) ⇒ Object
- #url_for(method, id = nil, options = {}) ⇒ Object
Instance Method Details
#append_options(options) ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/r_hapi/connection.rb', line 33 def () query_string = "" .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
23 24 25 26 27 28 29 30 31 |
# File 'lib/r_hapi/connection.rb', line 23 def url_for(method, id=nil, ={}) url = "#{RHapi.[:end_point]}/leads/#{RHapi.[:version]}/#{method}" url << "/#{id}" unless id.nil? url << "?hapikey=#{RHapi.[:api_key]}" raise(RHapi::UriError, "Options must be a hash in order to build the url.") unless .is_a?(Hash) url << () unless .empty? url end |