lib/lightspeed_restaurant/request.rb in lightspeed_restaurant-0.1.3 vs lib/lightspeed_restaurant/request.rb in lightspeed_restaurant-0.1.4

- old
+ new

@@ -5,17 +5,17 @@ require 'lightspeed_restaurant/errors/not_found_error' require 'uri' module LightspeedRestaurant class Request - def initialize(base_url, path, token, body = {}, query = {}) - @base_url = base_url || 'http://staging-exact-integration.posios.com' + def initialize(base_uri, path, token, body = {}, query = {}) + @base_uri = base_uri || 'http://staging-exact-integration.posios.com' @headers = { 'Content-Type' => 'application/json', 'X-Auth-Token' => token } @body = body.to_json @query = query @path = '/PosServer' + path - @connection = Excon.new(@base_url) + @connection = Excon.new(@base_uri) end def perform(**args) response = @connection.request(args.merge(path: @path, headers: @headers, body: @body, query: @query)) if [200, 201].include?(response.status) @@ -28,18 +28,18 @@ private def handle_error(response) case response.status when 400 - fail invalid_request_error(response) + raise invalid_request_error(response) when 401 - fail authentication_error(response) + raise authentication_error(response) when 403 - fail unauthorized_error(response) + raise unauthorized_error(response) when 404 - fail not_found_error(response) + raise not_found_error(response) else - fail response_object_error(response) + raise response_object_error(response) end end def unauthorized_error(response) UnauthorizedError.new('Unauthorized resource', response.status, response.body, response.headers)