Class: TicketingHub::Resource

Inherits:
Hashie::Mash
  • Object
show all
Defined in:
lib/ticketing_hub/resource.rb

Direct Known Subclasses

Option, Order, Ticket, Venue

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, values, path, id) ⇒ Resource

Returns a new instance of Resource.



7
8
9
10
# File 'lib/ticketing_hub/resource.rb', line 7

def initialize(client, values, path, id)
  self.client = client; self.path = path; self.id = id
  super(values)
end

Instance Attribute Details

#clientObject

Returns the value of attribute client.



5
6
7
# File 'lib/ticketing_hub/resource.rb', line 5

def client
  @client
end

#idObject

Returns the value of attribute id.



5
6
7
# File 'lib/ticketing_hub/resource.rb', line 5

def id
  @id
end

#pathObject

Returns the value of attribute path.



5
6
7
# File 'lib/ticketing_hub/resource.rb', line 5

def path
  @path
end

Instance Method Details

#destroyObject



19
20
21
22
23
24
# File 'lib/ticketing_hub/resource.rb', line 19

def destroy
  destroy! attributes
  return true
rescue TicketingHub::UnprocessableEntity
  return false
end

#destroy!Object



33
34
35
36
37
38
# File 'lib/ticketing_hub/resource.rb', line 33

def destroy!
  merge! client.delete "#{path}/#{id}"
rescue TicketingHub::UnprocessableEntity => e
  merge! e.response_body
  raise e
end

#updateObject



12
13
14
15
16
17
# File 'lib/ticketing_hub/resource.rb', line 12

def update
  update! attributes
  return true
rescue TicketingHub::UnprocessableEntity
  return false
end

#update!(attributes) ⇒ Object



26
27
28
29
30
31
# File 'lib/ticketing_hub/resource.rb', line 26

def update! attributes
  merge! client.patch("#{path}/#{id}", attributes)
rescue TicketingHub::UnprocessableEntity => e
  merge! e.response_body
  raise e
end