class Easy::Resource
Public Class Methods
configure(conf)
click to toggle source
# File lib/easy/resource.rb, line 4 def self.configure(conf) case conf when ::Hash if conf[:url].present? && conf[:token].present? configure_bearer(conf[:url], conf[:token]) elsif conf[:url].present? self.site = conf[:url] end when ::OAuth2::AccessToken configure_bearer(conf.client.site, conf.token) else # do nothing, unknown configuration end end
configure_bearer(url, token)
click to toggle source
# File lib/easy/resource.rb, line 19 def self.configure_bearer(url, token) self.site = url connection.auth_type = :bearer connection.bearer_token = token end
Public Instance Methods
becomes(entity_class)
click to toggle source
# File lib/easy/resource.rb, line 25 def becomes(entity_class) model = entity_class.new model.attributes = attributes model end
patch(method_name, options = {}, body = "")
click to toggle source
Calls superclass method
# File lib/easy/resource.rb, line 31 def patch(method_name, options = {}, body = "") if method_name.nil? connection.patch(element_path(options), body, self.class.headers) else super end end
update_column(attribute, value)
click to toggle source
# File lib/easy/resource.rb, line 39 def update_column(attribute, value) update_columns(attribute.to_sym => value) end
update_columns(attributes)
click to toggle source
# File lib/easy/resource.rb, line 43 def update_columns(attributes) patch(nil, {}, encode_attributes(attributes)) end
Protected Instance Methods
encode_attributes(attributes)
click to toggle source
# File lib/easy/resource.rb, line 49 def encode_attributes(attributes) case self.class.format.extension when "json" attributes.to_json(include_root_in_json ? { root: self.class.element_name } : {}) when "xml" attributes.to_xml(root: self.class.element_name) end end