lib/hubspot/connection.rb in hubspot-ruby-0.1.8 vs lib/hubspot/connection.rb in hubspot-ruby-0.2.0

- old
+ new

@@ -4,40 +4,48 @@ class << self def get_json(path, opts) url = generate_url(path, opts) response = get(url, format: :json) + log_request_and_response url, response raise(Hubspot::RequestError.new(response)) unless response.success? response.parsed_response end def post_json(path, opts) no_parse = opts[:params].delete(:no_parse) { false } url = generate_url(path, opts[:params]) response = post(url, body: opts[:body].to_json, headers: { 'Content-Type' => 'application/json' }, format: :json) + log_request_and_response url, response, opts[:body] raise(Hubspot::RequestError.new(response)) unless response.success? no_parse ? response : response.parsed_response end def put_json(path, opts) url = generate_url(path, opts[:params]) response = put(url, body: opts[:body].to_json, headers: { 'Content-Type' => 'application/json' }, format: :json) + log_request_and_response url, response, opts[:body] raise(Hubspot::RequestError.new(response)) unless response.success? response.parsed_response end def delete_json(path, opts) url = generate_url(path, opts) response = delete(url, format: :json) + log_request_and_response url, response, opts[:body] raise(Hubspot::RequestError.new(response)) unless response.success? response end protected + def log_request_and_response(uri, response, body=nil) + Hubspot::Config.logger.info "Hubspot: #{uri}.\nBody: #{body}.\nResponse: #{response.code} #{response.body}" + end + def generate_url(path, params={}, options={}) Hubspot::Config.ensure! :hapikey path = path.clone params = params.clone base_url = options[:base_url] || Hubspot::Config.base_url @@ -83,13 +91,13 @@ end end end class FormsConnection < Connection - follow_redirects false + follow_redirects true def self.submit(path, opts) - url = generate_url(path, opts[:params], { base_url: 'https://forms.hubspot.com' }) - post(url, body: opts[:body].to_json, headers: { 'Content-Type' => 'application/x-www-form-urlencoded' }) + url = generate_url(path, opts[:params], { base_url: 'https://forms.hubspot.com', hapikey: false }) + post(url, body: opts[:body], headers: { 'Content-Type' => 'application/x-www-form-urlencoded' }) end end -end \ No newline at end of file +end