Class: Transloadit
- Inherits:
-
Object
- Object
- Transloadit
- Defined in:
- lib/transloadit.rb,
lib/transloadit/version.rb
Overview
Implements the Transloadit REST API in Ruby. Check the README for usage instructions.
Defined Under Namespace
Modules: Exception Classes: ApiModel, Assembly, Request, Response, Step, Template
Constant Summary collapse
- VERSION =
'2.0.1'
Instance Attribute Summary collapse
-
#duration ⇒ Integer
The duration in seconds that signed API requests generated from this instance remain valid.
-
#key ⇒ String
Your Transloadit auth key.
-
#max_size ⇒ Object
Returns the value of attribute max_size.
-
#secret ⇒ String
Your Transloadit auth secret, for signing requests.
Instance Method Summary collapse
-
#assembly(options = {}) ⇒ Object
Creates a Transloadit::Assembly ready to be sent to the REST API.
-
#bill(month = Date.today.month, year = Date.today.year) ⇒ Object
Gets user billing reports for specified month and year.
-
#initialize(options = {}) ⇒ Transloadit
constructor
Creates a new instance of the Transloadit API.
-
#inspect ⇒ String
A human-readable version of the Transloadit.
-
#step(name, robot, options = {}) ⇒ Step
Creates a Transloadit::Step describing a step in an upload assembly.
-
#template(options = {}) ⇒ Object
Creates a Transloadit::Template instance ready to interact with its corresponding REST API.
-
#to_hash ⇒ Hash
A Transloadit-compatible Hash of the instance's contents.
-
#to_json ⇒ String
JSON-encoded String containing the object's hash contents.
Constructor Details
#initialize(options = {}) ⇒ Transloadit
Creates a new instance of the Transloadit API.
41 42 43 44 45 46 47 48 |
# File 'lib/transloadit.rb', line 41 def initialize( = {}) self.key = [:key] self.secret = [:secret] self.duration = [:duration] || 5 * 60 self.max_size = [:max_size] _ensure_key_provided end |
Instance Attribute Details
#duration ⇒ Integer
Returns the duration in seconds that signed API requests generated from this instance remain valid.
26 27 28 |
# File 'lib/transloadit.rb', line 26 def duration @duration end |
#key ⇒ String
Returns your Transloadit auth key.
19 20 21 |
# File 'lib/transloadit.rb', line 19 def key @key end |
#max_size ⇒ Object
Returns the value of attribute max_size
28 29 30 |
# File 'lib/transloadit.rb', line 28 def max_size @max_size end |
#secret ⇒ String
Returns your Transloadit auth secret, for signing requests.
22 23 24 |
# File 'lib/transloadit.rb', line 22 def secret @secret end |
Instance Method Details
#assembly(options = {}) ⇒ Object
Creates a Transloadit::Assembly ready to be sent to the REST API.
78 79 80 |
# File 'lib/transloadit.rb', line 78 def assembly( = {}) Transloadit::Assembly.new(self, ) end |
#bill(month = Date.today.month, year = Date.today.year) ⇒ Object
Gets user billing reports for specified month and year. Defaults to current month or year if corresponding param is not specified.
101 102 103 104 105 106 107 |
# File 'lib/transloadit.rb', line 101 def bill(month = Date.today.month, year = Date.today.year) # convert month to 2 digit format month = format '%02d', month path = "bill/#{year}-#{month}" Transloadit::Request.new(path, self.secret).get({ :auth => self.to_hash }) end |
#inspect ⇒ String
Returns a human-readable version of the Transloadit.
112 113 114 |
# File 'lib/transloadit.rb', line 112 def inspect self.to_hash.inspect end |
#step(name, robot, options = {}) ⇒ Step
Creates a Transloadit::Step describing a step in an upload assembly.
60 61 62 |
# File 'lib/transloadit.rb', line 60 def step(name, robot, = {}) Transloadit::Step.new(name, robot, ) end |
#template(options = {}) ⇒ Object
Creates a Transloadit::Template instance ready to interact with its corresponding REST API.
See the Transloadit documentation for futher information on Templates and available endpoints.
88 89 90 |
# File 'lib/transloadit.rb', line 88 def template( = {}) Transloadit::Template.new(self, ) end |
#to_hash ⇒ Hash
Returns a Transloadit-compatible Hash of the instance's contents.
119 120 121 122 123 124 |
# File 'lib/transloadit.rb', line 119 def to_hash result = { :key => self.key } result.update(:max_size => self.max_size) unless self.max_size.nil? result.update(:expires => _generate_expiry) unless self.secret.nil? result end |
#to_json ⇒ String
Returns JSON-encoded String containing the object's hash contents.
129 130 131 |
# File 'lib/transloadit.rb', line 129 def to_json MultiJson.dump(self.to_hash) end |