Class: Chargify::ProductFamily

Inherits:
Base
  • Object
show all
Defined in:
lib/chargify/product_family.rb

Instance Attribute Summary

Attributes inherited from Base

#errors

Class Method Summary collapse

Methods inherited from Base

api_request, #api_request, #attributes=, #initialize

Constructor Details

This class inherits a constructor from Chargify::Base

Class Method Details

.allObject



5
6
7
8
# File 'lib/chargify/product_family.rb', line 5

def all
  result = api_request(:get, "/product_families.json")
  result.map {|p| Hashie::Mash.new p['product_family']}
end

.components(product_family_id) ⇒ Object



39
40
41
42
43
# File 'lib/chargify/product_family.rb', line 39

def components(product_family_id)
  components!(product_family_id)
rescue Chargify::Error::Base => e
  return nil
end

.components!(product_family_id) ⇒ Object



34
35
36
37
# File 'lib/chargify/product_family.rb', line 34

def components!(product_family_id)
  result = api_request(:get, "/product_families/#{product_family_id}/components.json")
  result.map {|p| Hashie::Mash.new p['component']}
end

.find(id) ⇒ Object



17
18
19
20
21
# File 'lib/chargify/product_family.rb', line 17

def find(id)
  find!(id)
rescue Chargify::Error::Base => e
  return nil
end

.find!(id) ⇒ Object



10
11
12
13
14
15
# File 'lib/chargify/product_family.rb', line 10

def find!(id)
  return all if id == :all

  result = api_request(:get, "/product_families/#{id}.json")
  Hashie::Mash.new(result).product_family
end

.find_by_handle(handle) ⇒ Object



28
29
30
31
32
# File 'lib/chargify/product_family.rb', line 28

def find_by_handle(handle)
  find_by_handle!(handle)
rescue Chargify::Error::Base => e
  return nil
end

.find_by_handle!(handle) ⇒ Object



23
24
25
26
# File 'lib/chargify/product_family.rb', line 23

def find_by_handle!(handle)
  result = api_request(:get, "/product_families/lookup.json?handle=#{handle}")
  Hashie::Mash.new(result).product_family
end