Class: Moip::Customer

Inherits:
Model
  • Object
show all
Includes:
HTTParty, Header
Defined in:
lib/moip/models/customer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Header

#auth, #base_url, #default_header

Methods inherited from Model

build, #set_parameters, #to_json

Instance Attribute Details

#addressObject



7
8
9
# File 'lib/moip/models/customer.rb', line 7

def address
  @address
end

#billing_infoObject



7
8
9
# File 'lib/moip/models/customer.rb', line 7

def billing_info
  @billing_info
end

#birthdate_dayObject



7
8
9
# File 'lib/moip/models/customer.rb', line 7

def birthdate_day
  @birthdate_day
end

#birthdate_monthObject



7
8
9
# File 'lib/moip/models/customer.rb', line 7

def birthdate_month
  @birthdate_month
end

#birthdate_yearObject



7
8
9
# File 'lib/moip/models/customer.rb', line 7

def birthdate_year
  @birthdate_year
end

#codeObject



7
8
9
# File 'lib/moip/models/customer.rb', line 7

def code
  @code
end

#cpfObject



7
8
9
# File 'lib/moip/models/customer.rb', line 7

def cpf
  @cpf
end

#customersObject



7
8
9
# File 'lib/moip/models/customer.rb', line 7

def customers
  @customers
end

#emailObject



7
8
9
# File 'lib/moip/models/customer.rb', line 7

def email
  @email
end

#fullnameObject



7
8
9
# File 'lib/moip/models/customer.rb', line 7

def fullname
  @fullname
end

#phone_area_codeObject



7
8
9
# File 'lib/moip/models/customer.rb', line 7

def phone_area_code
  @phone_area_code
end

#phone_numberObject



7
8
9
# File 'lib/moip/models/customer.rb', line 7

def phone_number
  @phone_number
end

Instance Method Details

#attributesObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/moip/models/customer.rb', line 19

def attributes
	{
    "code" => code,
    "email" => email,
    "fullname" => fullname,
    "cpf" => cpf,
    "phone_area_code" => phone_area_code,
    "phone_number" => phone_number,
    "birthdate_day" => birthdate_day,
    "birthdate_month" => birthdate_month,
    "birthdate_year" => birthdate_year,
    "address" => address,
    "billing_info" => billing_info
	}
end

#createObject

metodo que envia as informações para a API do moip e cria um novo cliente see moiplabs.github.io/assinaturas-docs/api.html#criar_cliente



93
94
95
96
97
98
99
# File 'lib/moip/models/customer.rb', line 93

def create
	if self.valid?
		self.class.post(base_url(:customers, :params => "new_vault=true"), default_header(self.to_json)).parsed_response
	else
		raise Exception.new "#{self.errors.first[0]} #{self.errors.first[1]}"
	end
end

#find(code) ⇒ Object



101
102
103
104
# File 'lib/moip/models/customer.rb', line 101

def find code
	response = self.class.get(base_url(:customers, :code => code), default_header).parsed_response
	self.set_parameters response unless response.nil?
end

#loadObject



86
87
88
89
# File 'lib/moip/models/customer.rb', line 86

def load
	list = self.class.get(base_url(:customers), default_header).parsed_response
	self.costumers = list["costumers"]
end

#validates_presence_of_addressObject



55
56
57
58
59
60
61
62
63
# File 'lib/moip/models/customer.rb', line 55

def validates_presence_of_address
	self.errors.add :address, "can't be blank" and return if @address.nil?

	if @address.valid?
		true
	else
		self.errors.add :adress, @address.errors.full_messages.first
	end
end

#validates_presence_of_billing_infoObject



65
66
67
68
69
70
71
72
73
# File 'lib/moip/models/customer.rb', line 65

def validates_presence_of_billing_info
	self.errors.add :billing_info, "can't be blank" and return if @billing_info.nil?

	if @billing_info.valid?
		true
	else
		self.errors.add :adress, @billing_info.errors.full_messages.first
	end
end