class Helpscout::Mailbox::V2::Client::Http

Constants

VERSION

Attributes

base_url[R]
token[R]

Public Class Methods

new(base_url: nil, client_id:, client_secret:) click to toggle source
# 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

Public Instance Methods

json_request(method, path, body, params = nil) click to toggle source
# 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) click to toggle source
# 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

Private Instance Methods

base_request(method, path, headers, params = nil, body = nil) click to toggle source
# File lib/helpscout/mailbox/v2/client/http.rb, line 36
def base_request(method, path, headers, params = nil, body = nil)
  uri = build_uri(path, params)
  http = Net::HTTP.new(uri.host, uri.port)
  http.use_ssl = true
  http.send_request(method, uri, body, headers)
end
build_uri(path, params) click to toggle source
# File lib/helpscout/mailbox/v2/client/http.rb, line 43
def build_uri(path, params)
  uri = URI("#{@base_url}#{path}")
  uri.query = URI.encode_www_form(params) if params
  uri
end