Class: Bitmovin::Resource

Inherits:
Object
  • Object
show all
Includes:
Helpers
Defined in:
lib/bitmovin/resource.rb

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Helpers

#camelize_hash, #hash_to_struct, result, #result, #underscore_hash

Constructor Details

#initialize(hash = {}) ⇒ Resource

Returns a new instance of Resource.



31
32
33
# File 'lib/bitmovin/resource.rb', line 31

def initialize(hash = {})
  init_from_hash(hash)
end

Class Attribute Details

.resource_pathObject (readonly)

Returns the value of attribute resource_path.



9
10
11
# File 'lib/bitmovin/resource.rb', line 9

def resource_path
  @resource_path
end

Instance Attribute Details

#created_atObject

Returns the value of attribute created_at.



28
29
30
# File 'lib/bitmovin/resource.rb', line 28

def created_at
  @created_at
end

#descriptionObject

Returns the value of attribute description.



28
29
30
# File 'lib/bitmovin/resource.rb', line 28

def description
  @description
end

#idObject

Returns the value of attribute id.



28
29
30
# File 'lib/bitmovin/resource.rb', line 28

def id
  @id
end

#modified_atObject

Returns the value of attribute modified_at.



28
29
30
# File 'lib/bitmovin/resource.rb', line 28

def modified_at
  @modified_at
end

#nameObject

Returns the value of attribute name.



28
29
30
# File 'lib/bitmovin/resource.rb', line 28

def name
  @name
end

Class Method Details

.find(id) ⇒ Object



18
19
20
21
# 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) ⇒ Object



6
7
8
# File 'lib/bitmovin/resource.rb', line 6

def init(path)
  @resource_path = path
end

.list(limit = 100, offset = 0) ⇒ Object



11
12
13
14
15
16
# 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

Instance Method Details

#delete!Object



53
54
55
# File 'lib/bitmovin/resource.rb', line 53

def delete!
  Bitmovin.client.delete File.join(resource_path, @id)
end

#init_instance(path) ⇒ Object



24
25
26
# File 'lib/bitmovin/resource.rb', line 24

def init_instance(path)
  @instance_resource_path = path
end

#inspectObject



57
58
59
# File 'lib/bitmovin/resource.rb', line 57

def inspect
  "#{self.class.name}(id: #{@id}, name: #{@name})"
end

#persisted?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/bitmovin/resource.rb', line 49

def persisted?
  !@id.nil?
end

#save! {|response.body| ... } ⇒ Object

Yields:

  • (response.body)


35
36
37
38
39
40
41
42
43
44
45
46
47
# 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