Class: Helpscout::Mailbox::V2::Client::Http

Inherits:
Object
  • Object
show all
Includes:
Paths
Defined in:
lib/helpscout/mailbox/v2/client/http.rb

Constant Summary collapse

VERSION =
'0.1.0'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base_url: nil, client_id:, client_secret:) ⇒ Http

Returns a new instance of Http.



17
18
19
20
# File 'lib/helpscout/mailbox/v2/client/http.rb', line 17

def initialize(base_url: nil, client_id:, client_secret:)
  @base_url = base_url || 'https://api.helpscout.net'
  @token = Helpscout::Api::Auth::Token.new(client_id: client_id, client_secret: client_secret)
end

Instance Attribute Details

#base_urlObject (readonly)

Returns the value of attribute base_url.



13
14
15
# File 'lib/helpscout/mailbox/v2/client/http.rb', line 13

def base_url
  @base_url
end

#tokenObject (readonly)

Returns the value of attribute token.



13
14
15
# File 'lib/helpscout/mailbox/v2/client/http.rb', line 13

def token
  @token
end

Instance Method Details

#json_request(method, path, body, params = nil) ⇒ Object



28
29
30
31
32
# File 'lib/helpscout/mailbox/v2/client/http.rb', line 28

def json_request(method, path, body, params = nil)
  @token.refresh
  headers = { 'Authorization': @token.to_s, 'Content-Type': 'application/json; charset=UTF-8' }
  base_request(method, path, headers, params, body.to_json)
end

#request(method, path, params = nil) ⇒ Object



22
23
24
25
26
# File 'lib/helpscout/mailbox/v2/client/http.rb', line 22

def request(method, path, params = nil)
  @token.refresh
  headers = { 'Authorization': @token.to_s }
  base_request(method, path, headers, params)
end