lib/nylas/http_client.rb in nylas-5.1.0 vs lib/nylas/http_client.rb in nylas-5.2.0
- old
+ new
@@ -3,10 +3,12 @@
module Nylas
require "yajl"
# Plain HTTP client that can be used to interact with the Nylas API sans any type casting.
class HttpClient # rubocop:disable Metrics/ClassLength
+ HTTP_SUCCESS_CODES = [200, 302].freeze
+
HTTP_CODE_TO_EXCEPTIONS = {
400 => InvalidRequest,
401 => UnauthorizedRequest,
402 => MessageRejected,
403 => AccessDenied,
@@ -32,40 +34,37 @@
"/delta/streaming" => 3650
}.freeze
SUPPORTED_API_VERSION = "2.2"
include Logging
- attr_accessor :api_server, :service_domain
+ attr_accessor :api_server
attr_writer :default_headers
attr_reader :access_token
attr_reader :app_id
attr_reader :app_secret
# @param app_id [String] Your application id from the Nylas Dashboard
# @param app_secret [String] Your application secret from the Nylas Dashboard
# @param access_token [String] (Optional) Your users access token.
# @param api_server [String] (Optional) Which Nylas API Server to connect to. Only change this if
# you're using a self-hosted Nylas instance.
- # @param service_domain [String] (Optional) Host you are authenticating OAuth against.
# @return [Nylas::HttpClient]
- def initialize(app_id:, app_secret:, access_token: nil, api_server: "https://api.nylas.com",
- service_domain: "api.nylas.com")
+ def initialize(app_id:, app_secret:, access_token: nil, api_server: "https://api.nylas.com")
unless api_server.include?("://")
raise "When overriding the Nylas API server address, you must include https://"
end
@api_server = api_server
@access_token = access_token
@app_secret = app_secret
@app_id = app_id
- @service_domain = service_domain
end
# @return [Nylas::HttpClient[]
def as(access_token)
HttpClient.new(app_id: app_id, access_token: access_token,
- app_secret: app_secret, api_server: api_server, service_domain: service_domain)
+ app_secret: app_secret, api_server: api_server)
end
# Sends a request to the Nylas API and rai
# @param method [Symbol] HTTP method for the API call. Either :get, :post, :delete, or :patch
# @param path [String] (Optional, defaults to nil) - Relative path from the API Base. Preferred way to
@@ -175,10 +174,10 @@
handle_anticipated_failure_mode(http_code: http_code, response: response)
raise UnexpectedResponse, result.msg if result.is_a?(Net::HTTPClientError)
end
def handle_anticipated_failure_mode(http_code:, response:)
- return if http_code == 200
+ return if HTTP_SUCCESS_CODES.include?(http_code)
exception = HTTP_CODE_TO_EXCEPTIONS.fetch(http_code, APIError)
parsed_response = parse_response(response)
raise exception.new(