Class: Hubspot::Connection

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/hubspot/connection.rb

Direct Known Subclasses

FilesConnection, FormsConnection, OAuth

Class Method Summary collapse

Class Method Details

.delete_json(path, opts) ⇒ Object



41
42
43
44
45
46
47
# File 'lib/hubspot/connection.rb', line 41

def delete_json(path, opts)
  url = generate_url(path, opts)
  response = delete(url, format: :json, read_timeout: read_timeout(opts), open_timeout: open_timeout(opts))
  log_request_and_response url, response, opts[:body]
  raise(Hubspot::RequestError.new(response)) unless response.success?
  response
end

.get_json(path, opts) ⇒ Object



6
7
8
9
10
11
12
# File 'lib/hubspot/connection.rb', line 6

def get_json(path, opts)
  url = generate_url(path, opts)
  response = get(url, format: :json, read_timeout: read_timeout(opts), open_timeout: open_timeout(opts))
  log_request_and_response url, response
  raise(Hubspot::RequestError.new(response)) unless response.success?
  response.parsed_response
end

.post_json(path, opts) ⇒ Object



14
15
16
17
18
19
20
21
22
23
# File 'lib/hubspot/connection.rb', line 14

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, read_timeout: read_timeout(opts), open_timeout: open_timeout(opts) })
  log_request_and_response url, response, opts[:body]
  raise(Hubspot::RequestError.new(response)) unless response.success?

  no_parse ? response : response.parsed_response
end

.put_json(path, options) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/hubspot/connection.rb', line 25

def put_json(path, options)
  url = generate_url(path, options[:params])

  response = put(
    url,
    body: options[:body].to_json,
    headers: { "Content-Type" => "application/json" },
    format: :json,
    read_timeout: read_timeout(options),
    open_timeout: open_timeout(options),
  )

  log_request_and_response(url, response, options[:body])
  handle_response(response)
end