Class: Podio::Voucher

Inherits:
ActivePodio::Base show all
Includes:
ActivePodio::Updatable
Defined in:
lib/podio/models/voucher.rb

Instance Attribute Summary

Attributes inherited from ActivePodio::Base

#attributes

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ActivePodio::Updatable

#remove_nil_values, #update_attributes

Methods inherited from ActivePodio::Base

#==, #[], #[]=, #api_friendly_ref_type, #as_json, collection, delegate_to_hash, has_many, has_one, #hash, #initialize, #initialize_attributes, klass_from_string, list, member, #new_record?, output_attribute_as_json, #parent_model, #persisted?, property, #to_param

Constructor Details

This class inherits a constructor from ActivePodio::Base

Class Method Details

.create(attributes) ⇒ Object



27
28
29
30
31
32
# File 'lib/podio/models/voucher.rb', line 27

def create(attributes)
  member Podio.connection.post { |req|
    req.url "/campaign/#{attributes[:campaign_id]}/voucher"
    req.body = attributes
  }.body
end

.delete(id) ⇒ Object



48
49
50
# File 'lib/podio/models/voucher.rb', line 48

def delete(id)
  Podio.connection.delete("/campaign/voucher/#{id}").status
end

.export(campaign_id, options = {}) ⇒ Object



62
63
64
65
66
# File 'lib/podio/models/voucher.rb', line 62

def export(campaign_id, options = {})
  Podio.connection.get { |req|
    req.url("/campaign/#{campaign_id}/voucher/export", options)
  }.body
end

.find(id) ⇒ Object



52
53
54
# File 'lib/podio/models/voucher.rb', line 52

def find(id)
  member Podio.connection.get("/campaign/voucher/#{id}").body
end

.find_all(campaign_id, options = {}) ⇒ Object



56
57
58
59
60
# File 'lib/podio/models/voucher.rb', line 56

def find_all(campaign_id, options = {})
  list Podio.connection.get { |req|
    req.url("/campaign/#{campaign_id}/voucher", options)
  }.body
end

.generate(attributes) ⇒ Object



34
35
36
37
38
39
# File 'lib/podio/models/voucher.rb', line 34

def generate(attributes)
  Podio.connection.post { |req|
    req.url "/campaign/#{attributes[:campaign_id]}/voucher/generate"
    req.body = attributes
  }.status
end

.update(id, attributes) ⇒ Object



41
42
43
44
45
46
# File 'lib/podio/models/voucher.rb', line 41

def update(id, attributes)
  member Podio.connection.put { |req|
    req.url "/campaign/voucher/#{id}"
    req.body = attributes
  }.body
end

Instance Method Details

#createObject



12
13
14
15
# File 'lib/podio/models/voucher.rb', line 12

def create
  result = self.class.create(self.attributes)
  self.update_attributes(result.attributes)
end

#deleteObject



22
23
24
# File 'lib/podio/models/voucher.rb', line 22

def delete
  self.class.delete(self.voucher_id)
end

#updateObject



17
18
19
20
# File 'lib/podio/models/voucher.rb', line 17

def update
  result = self.class.update(self.voucher_id, self.attributes)
  self.update_attributes(result.attributes)
end