Class: Chargify::Product

Inherits:
Base
  • Object
show all
Defined in:
lib/chargify/product.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



6
7
8
9
# File 'lib/chargify/product.rb', line 6

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

.find(id) ⇒ Object



18
19
20
21
22
# File 'lib/chargify/product.rb', line 18

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

.find!(id) ⇒ Object



11
12
13
14
15
16
# File 'lib/chargify/product.rb', line 11

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

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

.find_by_handle(handle) ⇒ Object



24
25
26
27
28
# File 'lib/chargify/product.rb', line 24

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

.find_by_handle!(handle) ⇒ Object



30
31
32
33
# File 'lib/chargify/product.rb', line 30

def find_by_handle!(handle)
  result = api_request(:get, "/products/handle/#{handle}.json")
  Hashie::Mash.new(result).product
end