Class: Layer::Resources::RichContent

Inherits:
Layer::Resource show all
Defined in:
lib/layer/resources/rich_content.rb

Instance Attribute Summary

Attributes inherited from Layer::Resource

#attributes, #client

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Layer::Resource

class_name, #destroy, find, #initialize, #inspect, list, #method_missing, pluralized_name, #respond_to_missing?, #update, url, #uuid

Constructor Details

This class inherits a constructor from Layer::Resource

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Layer::Resource

Class Method Details

.create(client, url, params = {}) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/layer/resources/rich_content.rb', line 4

def self.create(client, url, params = {})
  mime_type = params[:mime_type]
  file = params[:file]

  headers = {
    "Upload-Content-Type" => mime_type,
    "Upload-Content-Length" => file.size.to_s
  }

  response = client.post(url, body: params.to_json, headers: headers)
  response.merge!("mime_type" => mime_type)

  new(response, client).upload(file)
end

Instance Method Details

#upload(file) ⇒ Object



19
20
21
22
23
# File 'lib/layer/resources/rich_content.rb', line 19

def upload(file)
  file_header = { "Content-Length" => file.size.to_s }
  client.put(upload_url, body: file, headers: file_header)
  self
end