api-moip-assinaturas 0.1.6 → 0.1.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YTI1NDFjNjhjODY2YjFiN2Y1ODllMjQyZTYzYTFkMTc3ODU2NGIxMQ==
4
+ ZWU4NGFkYTNhZTU5NjFmMzAxNzc5YTlkMjgyN2U1YmQ5ZGM5OGEyNw==
5
5
  data.tar.gz: !binary |-
6
- YjIzMzBjZDRiYWJkNTIxMDM3MzQ5YTEwODYzN2JjYzljZDBhODc0Yg==
6
+ N2U4YjFkMWQ0ZjM3YWVlNWUxZGE4ZDVhOWRjYjkwNTQ5ZjJhNThkOA==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- NTk4OWIyNzk2MTg1OGM1NTIxYjNlMTcwZmY0MWQzNjRmNmE4OTU4NjZmZmFk
10
- YWExYTUwZjA3MzAyOTcyZmVmMjhmNzAwYzllYjU3OTMzODY2MDIxZTc3NmFj
11
- YjI1YmFmZmM3NTFmNWRkYWM4ODEzYzUyZTQzMTUwNmE5NDhlMGM=
9
+ ZGNiNjgxMGVjNGEzMmViMTJkMTI1NWM0OGQ2ZDM4ZWIyZjA0OTViNjIzNGZj
10
+ NjNjOGFiOWE2ZjEzYmIzZjQ1NDQ4ODM3ZTI2Yzg3OGRlZDU5NzdkMDhlYjQ3
11
+ NmM0YjNiZTI2ZGQyNGIzZjNmNzlmMjVmZWI4OGVhZTJlZDhjNmY=
12
12
  data.tar.gz: !binary |-
13
- MWIyNmM5YWMyMDMwMjNiN2E0ZjM5ZDYxNGY2MTgwNmFiZTQ1ZmU1ZGRiMjE5
14
- ZDYzOWI3NmYzNDc3MjFhOGRhZDFmODZiYjQyZmIxZjUxODRkN2VhZmFhZDg5
15
- NTY4NWFjZjdkNTY5Y2I4NjUzMGFmOTBkN2RiNjYxZmQ2OTNiYjI=
13
+ NWIwN2M2N2Q1Nzc4NWY2OGM3YjRkY2M5NDM2NDQ2MWM0ZTM2NzY4YjMwMWYz
14
+ NGFjNzVkZGZjM2FkZTYwYzM1ZTFkMGVhYzk4ZWZiMDFlMTUzNTFmOWJiYTNk
15
+ YjhjYWE0ZjBhNmYxMDVlZGVlOGJhNzI1MTg4ZTUxYTVhMzhiNTg=
@@ -3,8 +3,8 @@ $:.push File.expand_path("../lib", __FILE__)
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = 'api-moip-assinaturas'
6
- s.version = '0.1.6'
7
- s.date = '2013-06-10'
6
+ s.version = '0.1.8'
7
+ s.date = '2013-06-12'
8
8
  s.summary = "Moip Assinaturas by Pixxel"
9
9
  s.description = "Gem desenvolvida para atender aos requisitos do moip api de assinaturas"
10
10
  s.authors = ["Douglas Rossignolli"]
@@ -10,7 +10,7 @@ require 'moip/model'
10
10
  require 'moip/webhooks'
11
11
  require 'moip/models/address'
12
12
  require 'moip/models/billing_info'
13
- require 'moip/models/custumer'
13
+ require 'moip/models/customer'
14
14
  require 'moip/models/invoice'
15
15
  require 'moip/models/payment'
16
16
  require 'moip/models/plan'
@@ -1,12 +1,12 @@
1
1
  # encoding: utf-8
2
- class Moip::Custumer < Moip::Model
2
+ class Moip::Customer < Moip::Model
3
3
  include HTTParty
4
4
  include Moip::Header
5
5
 
6
6
  # see http://moiplabs.github.io/assinaturas-docs/api.html#criar_cliente
7
7
  attr_accessor :code, :email, :fullname, :cpf, :phone_area_code,
8
8
  :phone_number, :birthdate_day, :birthdate_month,
9
- :birthdate_year, :address, :billing_info, :costumers
9
+ :birthdate_year, :address, :billing_info, :customers
10
10
 
11
11
  validates :code, :email, :fullname, :cpf, :phone_area_code,
12
12
  :phone_number, :birthdate_day, :birthdate_month,
@@ -72,14 +72,14 @@ class Moip::Custumer < Moip::Model
72
72
  end
73
73
  end
74
74
 
75
- def custumers= hash
76
- @custumers = []
75
+ def customers= hash
76
+ @customers = []
77
77
  hash.each do |e|
78
- costumer = self.class.new
79
- costumer.set_parameters e
80
- @custumers << costumer
78
+ customer = self.class.new
79
+ customer.set_parameters e
80
+ @customers << customer
81
81
  end
82
- @custumers
82
+ @customers
83
83
  end
84
84
 
85
85
 
@@ -4,7 +4,7 @@ class Moip::Invoice < Moip::Model
4
4
  include Moip::Header
5
5
 
6
6
  attr_accessor :id, :amount, :subscription_code, :occurrence,
7
- :status, :items, :plan, :customer, :creation_date, :invoices
7
+ :status, :items, :plan, :customer, :creation_date, :invoices
8
8
 
9
9
  def attributes
10
10
  {
@@ -32,11 +32,11 @@ class Moip::Invoice < Moip::Model
32
32
 
33
33
  def full_status
34
34
  status = case self.status
35
- when 1 then "Em aberto" # A fatura foi gerada mas ainda não foi paga pelo assinante.
36
- when 2 then "Aguardando Confirmação" # A fatura foi paga pelo assinante, mas o pagamento está em processo de análise de risco.
37
- when 3 then "Pago" # A fatura foi paga pelo assinante e confirmada.
38
- when 4 then "Não Pago" # O assinante tentou pagar a fatura, mas o pagamento foi negado pelo banco emissor do cartão de crédito ou a análise de risco detectou algum problema. Veja os motivos possíveis.
39
- when 5 then "Atrasada" # O pagamento da fatura foi cancelado e serão feitas novas tentativas de cobrança de acordo com a configuração de retentativa automática.
35
+ when 1 then "Em aberto" # A fatura foi gerada mas ainda não foi paga pelo assinante.
36
+ when 2 then "Aguardando Confirmação" # A fatura foi paga pelo assinante, mas o pagamento está em processo de análise de risco.
37
+ when 3 then "Pago" # A fatura foi paga pelo assinante e confirmada.
38
+ when 4 then "Não Pago" # O assinante tentou pagar a fatura, mas o pagamento foi negado pelo banco emissor do cartão de crédito ou a análise de risco detectou algum problema. Veja os motivos possíveis.
39
+ when 5 then "Atrasada" # O pagamento da fatura foi cancelado e serão feitas novas tentativas de cobrança de acordo com a configuração de retentativa automática.
40
40
  end
41
41
  status
42
42
  end
@@ -56,7 +56,7 @@ class Moip::Invoice < Moip::Model
56
56
  end
57
57
 
58
58
  def payments
59
-
59
+ @payments ||= Moip::Payment.build(:subscription_code => self.code).payments
60
60
  end
61
61
 
62
62
  end
@@ -1,4 +1,52 @@
1
1
  module Moip
2
- module Webhooks
2
+ # see http://moiplabs.github.io/assinaturas-docs/webhooks.html
3
+ class Webhooks
4
+ attr_accessor :event, :date, :env, :resource
5
+
6
+ def events
7
+ @events ||= {}
8
+ end
9
+
10
+ def on event, kind, &block
11
+ self.events[event] = { :kind => kind, :runnable => block }
12
+ end
13
+
14
+ def run
15
+ event = self.event.split(".")[0]
16
+ kind = self.event.split(".")[1]
17
+ action = nil
18
+
19
+ self.events.each do |key, hash|
20
+ if event == key.to_s and hash[:kind].to_s == kind
21
+ action = hash[:runnable]
22
+ end
23
+ end
24
+ action.call if action.is_a? Proc
25
+ end
26
+
27
+ def resource= params
28
+ klass = "Moip::#{self.event.split(".")[0].capitalize}" # E.g Moip::Plan when event plan.created
29
+ klass = eval klass
30
+ @resource = klass.build params
31
+ end
32
+
33
+ class << self
34
+ def build params
35
+ object = new
36
+
37
+ params.each do |key, value|
38
+ object.send("#{key}=".to_sym, value) if object.respond_to? key.to_sym
39
+ end
40
+
41
+ object
42
+ end
43
+
44
+ def listen(json, &block)
45
+ hook = build json
46
+ yield hook
47
+ hook.run
48
+ end
49
+ end
50
+
3
51
  end
4
52
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: api-moip-assinaturas
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Douglas Rossignolli
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-06-10 00:00:00.000000000 Z
11
+ date: 2013-06-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -123,7 +123,7 @@ files:
123
123
  - lib/moip/model.rb
124
124
  - lib/moip/models/address.rb
125
125
  - lib/moip/models/billing_info.rb
126
- - lib/moip/models/custumer.rb
126
+ - lib/moip/models/customer.rb
127
127
  - lib/moip/models/invoice.rb
128
128
  - lib/moip/models/payment.rb
129
129
  - lib/moip/models/plan.rb