class Bitmovin::Resource
Attributes
resource_path[R]
created_at[RW]
description[RW]
id[RW]
modified_at[RW]
name[RW]
Public Class Methods
find(id)
click to toggle source
# File lib/bitmovin/resource.rb, line 18 def find(id) response = Bitmovin.client.get File.join(@resource_path, id) new(Bitmovin::Helpers.result(response)) end
init(path)
click to toggle source
# File lib/bitmovin/resource.rb, line 6 def init(path) @resource_path = path end
list(limit = 100, offset = 0)
click to toggle source
# File lib/bitmovin/resource.rb, line 11 def list(limit = 100, offset = 0) response = Bitmovin.client.get @resource_path, limit: limit, offset: offset Bitmovin::Helpers.result(response)['items'].map do |item| new(item) end end
new(hash = {})
click to toggle source
# File lib/bitmovin/resource.rb, line 31 def initialize(hash = {}) init_from_hash(hash) end
Public Instance Methods
delete!()
click to toggle source
# File lib/bitmovin/resource.rb, line 53 def delete! Bitmovin.client.delete File.join(resource_path, @id) end
init_instance(path)
click to toggle source
# File lib/bitmovin/resource.rb, line 24 def init_instance(path) @instance_resource_path = path end
inspect()
click to toggle source
# File lib/bitmovin/resource.rb, line 57 def inspect "#{self.class.name}(id: #{@id}, name: #{@name})" end
persisted?()
click to toggle source
# File lib/bitmovin/resource.rb, line 49 def persisted? !@id.nil? end
save!() { |body| ... }
click to toggle source
# File lib/bitmovin/resource.rb, line 35 def save! if @id raise BitmovinError.new(self), "Cannot save already persisted resource" end response = Bitmovin.client.post do |post| post.url resource_path post.body = collect_attributes end yield(response.body) if block_given? init_from_hash(result(response)) self end
Private Instance Methods
collect_attributes()
click to toggle source
# File lib/bitmovin/resource.rb, line 73 def collect_attributes ignored_variables = [] if (self.respond_to?(:ignore_fields)) ignored_variables = self.ignore_fields end ignored_variables.push(:@instance_resource_path) attributes_value = instance_variables.inject({}) do |result, item| if ignored_variables.include?(item) result else name = item == :@max_ctu_size ? 'maxCTUSize' : item.to_s.gsub(/@/, '') result.merge( name => instance_variable_get(item) ) end end camelize_hash(attributes_value) end
init_from_hash(hash = {})
click to toggle source
# File lib/bitmovin/resource.rb, line 67 def init_from_hash(hash = {}) hash.each do |name, value| instance_variable_set("@#{ActiveSupport::Inflector.underscore(name)}", value) end end
resource_path()
click to toggle source
# File lib/bitmovin/resource.rb, line 63 def resource_path @instance_resource_path || self.class.resource_path end