Sha256: 13381cd20d74ae900c64244f3a322a85f135e3de0119129599bcf9585c49d6d3
Contents?: true
Size: 1.28 KB
Versions: 4
Compression:
Stored size: 1.28 KB
Contents
# frozen_string_literal: true module CustomerioAPI class Resource attr_reader :client def initialize(client) @client = client end def get_request(url, params: {}, headers: {}) handle_response client.connection.get(url, params, headers) end def post_request(url, body:, headers: {}) handle_response client.connection.post(url, body, headers) end def put_request(url, body:, headers: {}) handle_response client.connection.put(url, body, headers) end def handle_response(response) error_message = response.body case response.status when 400 raise Error, "A bad request or a validation exception has occurred. #{error_message}" when 401 raise AuthenticationError, "Invalid authorization credentials. #{error_message}" when 403 raise WhiteListError, "IP address is not white listed. #{error_message}" when 404 raise NotFoundError, "The resource you have specified cannot be found. #{error_message}" when 429 raise RateLimitError, "The API rate limit for your application has been exceeded. #{error_message}" when 500 raise ServerError, "An unhandled error with the Customer.io API. #{error_message}" end response end end end
Version data entries
4 entries across 4 versions & 1 rubygems