api-moip-assinaturas 0.2.22 → 0.2.24

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
- Y2I1YjE3ZWY5NzQwNTViNjhiZDJkMzk0OGJhOWUzNGIyMmEyYTc1Mw==
4
+ MjAzNDhjM2NjZTVlZjg5MzZkMGEzMmQzZDZjYzFlZDQ2Y2Y3MTE0Mw==
5
5
  data.tar.gz: !binary |-
6
- MTIzNTM3YzdlY2I2OTIyYzFlOWZkNWQ2MTIyMjcxZWZkOGIwNzJiMw==
6
+ YzlkZjc3ODY4ZTU1NzkxMTA0ZDZhNzU4ODNhMzI2NTFmZWNlZWY4Nw==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- MzY3MzcyZWE1OWY4ZjYyMTViNTU4YTZmZTQxYTRiMDU1OTMyODJiYzMxNzlk
10
- ODFjYjkzYmMwNDU5MmQ3NTM2YzRjYmZiZjFjMzc0ZjFmODA1ZjdjMzZhNDc1
11
- YjdkNzVmOGIwMzk0OWI4ZDI5ZDkwOGY3YjIzYjY3OTAxYjkwNjQ=
9
+ MDM1OGM3MjVlZjFlZWJhODEzZmFjNDA5OTc5MGRiYzYzOGY0Y2E3ZDBjZmVj
10
+ Mzk2ZGQ4OGZmNWJkMzc4NjZjMjlkYWFjMWVkZWM3MjE5ODNiMjA0NTcyYjk2
11
+ ZGY1ZTVmMjg4NDllY2YyNzI5NjI0MDdhODU4Y2NlYWU1M2ZlODc=
12
12
  data.tar.gz: !binary |-
13
- YjI1YTdjYTNlNzZjMDU0M2NiYTc1ODllNWFjODU2YzU2NjYwNTFkZWE1NTYy
14
- YWM2YTllMjcwOGZiNjdmMDE5Y2NjNWNlMzhkNThjZmViMzM3MGVlYWI3MTAw
15
- ZjZiMzExMGU1NzEyYTE4NWJiNzRkOWYzMDU1YjI4OWUxODA2NjQ=
13
+ Y2RjM2RkN2NmNTVhMmE0NTQxNmFhN2E3MzkzOTJkYTkwMWY4ZGNiNzQ4NjY1
14
+ ZjczNmY0ZDMxNzM4NjViZDI5OGI2OWFiYTM5NjYzMDU2OGMzMTdiNGEyYjg2
15
+ MzFiODJhODljMTA5NDcwZDYzZjJiNGYxZjRiOGQwZWYzM2VhMzQ=
@@ -3,7 +3,7 @@ $:.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.2.22'
6
+ s.version = '0.2.24'
7
7
  s.date = '2013-07-02'
8
8
  s.summary = "Moip Assinaturas by Pixxel"
9
9
  s.description = "Gem desenvolvida para atender aos requisitos do moip api de assinaturas"
data/lib/moip/model.rb CHANGED
@@ -15,6 +15,16 @@ module Moip
15
15
  end
16
16
  end
17
17
 
18
+ def build_error response
19
+ if response.key? "errors"
20
+ error = response["errors"][0]
21
+ self.errors.add :moip_error, "[#{error["code"]}] #{error["description"]}"
22
+ false
23
+ else
24
+ true
25
+ end
26
+ end
27
+
18
28
  class << self
19
29
  # metodo que cria um objeto e seta os seus parametros se responder pela chave
20
30
  # recebe um Hash como parametro
@@ -102,9 +102,10 @@ class Moip::Customer < Moip::Model
102
102
  # see http://moiplabs.github.io/assinaturas-docs/api.html#criar_cliente
103
103
  def create
104
104
  if self.valid?
105
- self.class.post(base_url(:customers, :params => "new_vault=true"), default_header(self.to_json)).parsed_response
105
+ response = self.class.post(base_url(:customers, :params => "new_vault=true"), default_header(self.to_json)).parsed_response
106
+ self.validate_response response
106
107
  else
107
- raise Exception.new "#{self.errors.first[0]} #{self.errors.first[1]}"
108
+ false
108
109
  end
109
110
  end
110
111
 
@@ -62,9 +62,10 @@ class Moip::Plan < Moip::Model
62
62
  # see http://moiplabs.github.io/assinaturas-docs/api.html#criar_plano
63
63
  def create
64
64
  if self.valid?
65
- self.class.post(base_url(:plans), default_header(self.to_json)).parsed_response
65
+ response = self.class.post(base_url(:plans), default_header(self.to_json)).parsed_response
66
+ self.validate_response response
66
67
  else
67
- raise Exception.new "#{self.errors.first[0]} #{self.errors.first[1]}"
68
+ false
68
69
  end
69
70
  end
70
71
 
@@ -80,7 +81,7 @@ class Moip::Plan < Moip::Model
80
81
  self.class.put(base_url(:plans, :code => self.code), default_header(self)).parsed_response
81
82
  true
82
83
  else
83
- raise Exception.new "#{self.errors.first[0]} #{self.errors.first[1]}"
84
+ false
84
85
  end
85
86
  end
86
87
 
@@ -5,7 +5,7 @@ class Moip::Subscription < Moip::Model
5
5
 
6
6
  attr_accessor :code, :amount, :plan, :customer,
7
7
  :next_invoice_date, :status, :message,
8
- :errors, :alerts, :invoice, :creation_date,
8
+ :invoice, :creation_date,
9
9
  :expiration_date, :subscriptions
10
10
 
11
11
  validates :code, :amount, :plan, :customer, :presence => true
@@ -23,7 +23,9 @@ class Moip::Subscription < Moip::Model
23
23
  if @plan.is_a? Hash
24
24
  @plan
25
25
  else
26
- { :code => @plan }
26
+ return nil if @plan.nil?
27
+ @plan = { :code => @plan }
28
+ @plan
27
29
  end
28
30
  end
29
31
 
@@ -31,7 +33,9 @@ class Moip::Subscription < Moip::Model
31
33
  if @customer.is_a? Hash
32
34
  @customer
33
35
  else
34
- { :code => @customer }
36
+ return nil if @customer.nil?
37
+ @customer ={ :code => @customer }
38
+ @customer
35
39
  end
36
40
  end
37
41
 
@@ -61,7 +65,12 @@ class Moip::Subscription < Moip::Model
61
65
 
62
66
  # see http://moiplabs.github.io/assinaturas-docs/api.html#criar_assinatura
63
67
  def create
64
- self.class.post(base_url(:subscriptions), default_header(self.to_json)).parsed_response
68
+ if self.valid?
69
+ response = self.class.post(base_url(:subscriptions), default_header(self.to_json)).parsed_response
70
+ self.validate_response response
71
+ else
72
+ false
73
+ end
65
74
  end
66
75
 
67
76
  # To Do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: api-moip-assinaturas
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.22
4
+ version: 0.2.24
5
5
  platform: ruby
6
6
  authors:
7
7
  - Douglas Rossignolli