Class: Locomotive::Coal::Resources::Base

Inherits:
Object
  • Object
show all
Includes:
Concerns::Request
Defined in:
lib/locomotive/coal/resources/base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Concerns::Request

#delete, #do_request, #get, #post, #put, #without_authentication

Constructor Details

#initialize(uri, credentials) ⇒ Base

Returns a new instance of Base.



12
13
14
# File 'lib/locomotive/coal/resources/base.rb', line 12

def initialize(uri, credentials)
  @uri, @credentials = uri, credentials
end

Instance Attribute Details

#credentialsObject

Returns the value of attribute credentials.



10
11
12
# File 'lib/locomotive/coal/resources/base.rb', line 10

def credentials
  @credentials
end

#uriObject

Returns the value of attribute uri.



10
11
12
# File 'lib/locomotive/coal/resources/base.rb', line 10

def uri
  @uri
end

Instance Method Details

#create(attributes = {}) ⇒ Object



24
25
26
27
# File 'lib/locomotive/coal/resources/base.rb', line 24

def create(attributes = {})
  data = post(resources_name, { resource_name => attributes })
  Resource.new(data)
end

#destroy(id) ⇒ Object



39
40
41
42
# File 'lib/locomotive/coal/resources/base.rb', line 39

def destroy(id)
  data = delete("#{resources_name}/#{id}")
  Resource.new(data)
end

#destroy_allObject



44
45
46
# File 'lib/locomotive/coal/resources/base.rb', line 44

def destroy_all
  delete("#{resources_name}")
end

#indexObject Also known as: all



16
17
18
19
20
# File 'lib/locomotive/coal/resources/base.rb', line 16

def index
  get(resources_name).map do |attributes|
    Resource.new(attributes)
  end
end

#update(id, attributes = {}) ⇒ Object



29
30
31
32
# File 'lib/locomotive/coal/resources/base.rb', line 29

def update(id, attributes = {})
  data = put("#{resources_name}/#{id}", { resource_name => attributes })
  Resource.new(data)
end

#update_with_locale(id, attributes = {}, locale = nil) ⇒ Object



34
35
36
37
# File 'lib/locomotive/coal/resources/base.rb', line 34

def update_with_locale(id, attributes = {}, locale = nil)
  data = put("#{resources_name}/#{id}", { _locale: locale, resource_name => attributes })
  Resource.new(data)
end