lib/monday/client.rb in monday_ruby-0.6.2 vs lib/monday/client.rb in monday_ruby-1.0.0
- old
+ new
@@ -13,24 +13,29 @@
module Monday
# Client executes requests against the monday.com's API and
# allows a user to mutate and retrieve resources.
class Client
- include Resources
-
JSON_CONTENT_TYPE = "application/json"
private_constant :JSON_CONTENT_TYPE
attr_reader :config
def initialize(config_args = {})
- @config = config_options(config_args)
+ @config = configure(config_args)
+ Resources.initialize(self)
end
+ def make_request(body)
+ response = Request.post(uri, body, request_headers)
+
+ handle_response(Response.new(response))
+ end
+
private
- def config_options(config_args)
+ def configure(config_args)
return Monday.config if config_args.empty?
Configuration.new(**config_args)
end
@@ -43,24 +48,18 @@
"Content-Type": "application/json",
Authorization: @config.token
}
end
- def make_request(body)
- response = Request.post(uri, body, request_headers)
-
- handle_response(Response.new(response))
- end
-
def handle_response(response)
return response if response.success?
raise_errors(response)
end
def raise_errors(response)
- raise default_exception(response) unless (200..299).cover?(response.status)
+ raise default_exception(response) unless successful_response?(response.status)
raise response_exception(response)
end
def response_exception(response)
@@ -72,8 +71,12 @@
exception_klass.new(message: error_code, response: response, code: code)
end
def default_exception(response)
Util.status_code_exceptions_mapping(response.status).new(response: response)
+ end
+
+ def successful_response?(status)
+ (200..299).cover?(status)
end
end
end