lib/vncpost_api/resources/base.rb in vncpost_api-0.1.0 vs lib/vncpost_api/resources/base.rb in vncpost_api-0.2.0

- old
+ new

@@ -1,11 +1,10 @@ module VNCPostAPI class Base < ::ActiveResource::Base self.include_root_in_json = false self.include_format_in_path = false self.connection_class = VNCPostAPI::Connection - self.site = VNCPostAPI.config&.api_host def create self.class.retrieve_token format_before_send_request super @@ -24,12 +23,13 @@ private def self.retrieve_token clear_auth_token + if VNCPostAPI.config&.username && VNCPostAPI.config&.password - response = connection.post("/User/Login", { + response = connection.post("#{Base.site}/User/Login", { Username: VNCPostAPI.config.username, Password: VNCPostAPI.config.password }.to_json) connection.auth_type = :bearer connection.bearer_token = JSON.parse(response.body)["token"] @@ -42,18 +42,19 @@ connection.auth_type = nil connection.bearer_token = nil end def format_before_send_request - @attributes.transform_keys!(&:camelcase) + @attributes.deep_transform_keys!(&:camelcase) end def reset_attributes_format - @attributes.transform_keys!(&:underscore) + @attributes.deep_transform_keys!(&:underscore) end def load_attributes_from_response(response) super reset_attributes_format end + end end