Class: Easy::Resource

Inherits:
ActiveResource::Base
  • Object
show all
Defined in:
lib/easy/resource.rb

Direct Known Subclasses

Easy::Resources::Redmine::RedmineBase

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.configure(conf) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
# File 'lib/easy/resource.rb', line 4

def self.configure(conf)
  if conf.is_a?(::Hash)
    if conf[:url].present? && conf[:token].present?
      configure_bearer(conf[:url], conf[:token])
    elsif conf[:url].present?
      self.site = conf[:url]
    end
  elsif conf.is_a?(::OAuth2::AccessToken)
    configure_bearer(conf.client.site, conf.token)
  end
end

.configure_bearer(url, token) ⇒ Object



16
17
18
19
20
# File 'lib/easy/resource.rb', line 16

def self.configure_bearer(url, token)
  self.site                    = url
  self.connection.auth_type    = :bearer
  self.connection.bearer_token = token
end

Instance Method Details

#becomes(entity_class) ⇒ Object



22
23
24
25
26
# File 'lib/easy/resource.rb', line 22

def becomes(entity_class)
  model            = entity_class.new
  model.attributes = self.attributes
  model
end

#patch(method_name, options = {}, body = "") ⇒ Object



28
29
30
31
32
33
34
# File 'lib/easy/resource.rb', line 28

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) ⇒ Object



36
37
38
# File 'lib/easy/resource.rb', line 36

def update_column(attribute, value)
  update_columns(attribute.to_sym => value)
end

#update_columns(**attributes) ⇒ Object



40
41
42
# File 'lib/easy/resource.rb', line 40

def update_columns(**attributes)
  patch(nil, {}, encode_attributes(attributes))
end