Class: Hubspot::Connection

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

Class Method Summary collapse

Class Method Details

.delete_json(path, opts) ⇒ Object



51
52
53
54
55
56
# File 'lib/hubspot/connection.rb', line 51

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]
  handle_response(response)
end

.get_json(path, opts) ⇒ Object



6
7
8
9
10
11
# 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
  handle_response(response).parsed_response
end

.post_json(path, opts) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/hubspot/connection.rb', line 13

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]
  handle_response(response).yield_self do |r|
    no_parse ? r : r.parsed_response
  end
end

.put_json(path, options) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/hubspot/connection.rb', line 32

def put_json(path, options)
  no_parse = options[:params].delete(:no_parse) { false }
  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).yield_self do |r|
    no_parse ? r : r.parsed_response
  end
end