Class: GustoApi::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/gusto_api/request.rb

Direct Known Subclasses

BearerRequest, OauthRequest, TokenRequest

Instance Method Summary collapse

Constructor Details

#initialize(endpoint:, method:, params: {}, auth_token:, auth_type: 'Token') ⇒ Request

Returns a new instance of Request.

Raises:



5
6
7
8
9
10
11
12
13
# File 'lib/gusto_api/request.rb', line 5

def initialize(endpoint:, method:, params: {}, auth_token:, auth_type: 'Token')
  raise Error.new("Invalid method: #{method}. Must be :get or :post") unless %i[get post].include?(method)

  self.endpoint = endpoint
  self.method = method
  self.params = params
  self.auth_token = auth_token
  self.auth_type = auth_type
end

Instance Method Details

#submitObject



15
16
17
18
19
# File 'lib/gusto_api/request.rb', line 15

def submit
  HTTParty.send(method, url, options).tap do |response|
    raise InvalidAuthError.new("Invalid or expired auth token") if response.code == 401
  end
end