lib/bitmovin/resource.rb in bitmovin-ruby-0.5.0 vs lib/bitmovin/resource.rb in bitmovin-ruby-0.7.0
- old
+ new
@@ -6,11 +6,10 @@
def init(path)
@resource_path = path
end
attr_reader :resource_path
-
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
@@ -20,10 +19,14 @@
response = Bitmovin.client.get File.join(@resource_path, id)
new(Bitmovin::Helpers.result(response))
end
end
+ def init_instance(path)
+ @instance_resource_path = path
+ end
+
attr_accessor :id, :name, :description, :created_at, :modified_at
def initialize(hash = {})
init_from_hash(hash)
@@ -33,11 +36,11 @@
if @id
raise BitmovinError.new(self), "Cannot save already persisted resource"
end
response = Bitmovin.client.post do |post|
- post.url self.class.resource_path
+ post.url resource_path
post.body = collect_attributes
end
yield(response.body) if block_given?
init_from_hash(result(response))
self
@@ -46,19 +49,23 @@
def persisted?
!@id.nil?
end
def delete!
- Bitmovin.client.delete File.join(self.class.resource_path, @id)
+ Bitmovin.client.delete File.join(resource_path, @id)
end
def inspect
"#{self.class.name}(id: #{@id}, name: #{@name})"
end
private
+ def resource_path
+ @instance_resource_path || self.class.resource_path
+ end
+
def init_from_hash(hash = {})
hash.each do |name, value|
instance_variable_set("@#{ActiveSupport::Inflector.underscore(name)}", value)
end
end
@@ -67,13 +74,16 @@
val = Hash.new
ignored_variables = []
if (self.respond_to?(:ignore_fields))
ignored_variables = self.ignore_fields
end
+ ignored_variables.push(:@instance_resource_path)
+
instance_variables.each do |name|
if ignored_variables.include?(name)
next
end
+
if name == :@max_ctu_size
val['maxCTUSize'] = instance_variable_get(name)
else
json_name = ActiveSupport::Inflector.camelize(name.to_s.gsub(/@/, ''), false)
val[json_name] = instance_variable_get(name)