lib/intercom/request.rb in intercom-3.7.3 vs lib/intercom/request.rb in intercom-3.7.4

- old
+ new

@@ -17,10 +17,14 @@ def set_basic_auth(method, username, secret) method.basic_auth(CGI.unescape(username), CGI.unescape(secret)) end + def set_api_version(method, api_version) + method.add_field('Intercom-Version', api_version) + end + def self.get(path, params) new(path, Net::HTTP::Get.new(append_query_string_to_url(path, params), default_headers)) end def self.post(path, form_data) @@ -56,15 +60,16 @@ net.read_timeout = read_timeout net.open_timeout = open_timeout net end - def execute(target_base_url=nil, username:, secret: nil, read_timeout: 90, open_timeout: 30) + def execute(target_base_url=nil, username:, secret: nil, read_timeout: 90, open_timeout: 30, api_version: nil) retries = 3 base_uri = URI.parse(target_base_url) set_common_headers(net_http_method, base_uri) set_basic_auth(net_http_method, username, secret) + set_api_version(net_http_method, api_version) if api_version begin client(base_uri, read_timeout: read_timeout, open_timeout: open_timeout).start do |http| begin response = http.request(net_http_method) set_rate_limit_details(response) @@ -178,9 +183,11 @@ raise Intercom::ServiceUnavailableError.new(error_details['message'], error_context) when 'conflict', 'unique_user_constraint' raise Intercom::MultipleMatchingUsersError.new(error_details['message'], error_context) when 'resource_conflict' raise Intercom::ResourceNotUniqueError.new(error_details['message'], error_context) + when 'intercom_version_invalid' + raise Intercom::ApiVersionInvalid.new(error_details['message'], error_context) when nil, '' raise Intercom::UnexpectedError.new(message_for_unexpected_error_without_type(error_details, parsed_http_code), error_context) else raise Intercom::UnexpectedError.new(message_for_unexpected_error_with_type(error_details, parsed_http_code), error_context) end