Class: LucidIntercom::PostRequest

Inherits:
Object
  • Object
show all
Defined in:
lib/lucid_intercom/post_request.rb

Instance Method Summary collapse

Constructor Details

#initialize(http: Container[:http]) ⇒ PostRequest

Returns a new instance of PostRequest.

Parameters:

  • http (HTTP::Client, #headers#post) (defaults to: Container[:http])


10
11
12
# File 'lib/lucid_intercom/post_request.rb', line 10

def initialize(http: Container[:http])
  @http = http
end

Instance Method Details

#call(path, data) ⇒ Response

Parameters:

  • path (String)

    path relative to the domain

  • data (Hash)

Returns:



20
21
22
23
24
25
26
27
28
# File 'lib/lucid_intercom/post_request.rb', line 20

def call(path, data)
  res = @http.headers(
    'Authorization' => "Bearer #{LucidIntercom.config.access_token}",
    'Accept' => 'application/json',
    'Content-Type' => 'application/json'
  ).post("https://api.intercom.io/#{path}", json: data)

  Response.new(res.code, res.headers.to_h, res.to_s)
end