Class: Layer::Content
Overview
Note:
This is available in both the REST and the Platform API. Please refer to the respective documentation to see which methods are available.
Instance Attribute Summary
Attributes inherited from Resource
#attributes, #client
Class Method Summary
collapse
Instance Method Summary
collapse
create
find
#reload
Methods inherited from Resource
class_name, from_response, #id, #initialize, #respond_to_missing?
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
in the class Layer::Resource
Class Method Details
.create(mime_type, file, client = self.client) ⇒ Object
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/layer/content.rb', line 27
def self.create(mime_type, file, client = self.client)
response = client.post(url, {}, {
'Upload-Content-Type' => mime_type,
'Upload-Content-Length' => file.size
})
attributes = response.merge('size' => file.size, 'mime_type' => mime_type)
from_response(attributes, client).tap do |content|
content.upload(file)
end
end
|
.url ⇒ Object
40
41
42
|
# File 'lib/layer/content.rb', line 40
def self.url
'/content'
end
|
Instance Method Details
#as_json(*args) ⇒ Object
52
53
54
|
# File 'lib/layer/content.rb', line 52
def as_json(*args)
{ id: id, size: size }
end
|
#to_json(*args) ⇒ Object
56
57
58
|
# File 'lib/layer/content.rb', line 56
def to_json(*args)
as_json.to_json(*args)
end
|
#upload(file) ⇒ Object
44
45
46
|
# File 'lib/layer/content.rb', line 44
def upload(file)
RestClient.put(upload_url, file)
end
|
#url ⇒ Object
48
49
50
|
# File 'lib/layer/content.rb', line 48
def url
attributes['refresh_url'] || "#{self.class.url}/#{Layer::Client.normalize_id(id)}"
end
|