moip-assinaturas 0.1.1 → 0.1.2

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.
data/.gitignore CHANGED
@@ -15,3 +15,5 @@ spec/reports
15
15
  test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
+ .ruby-gemset
19
+ .ruby-version
data/README.md CHANGED
@@ -91,6 +91,12 @@ Obter detalhes do plano:
91
91
  Moip::Assinaturas::Plan.details(plan_code)
92
92
  ```
93
93
 
94
+ Atualizar informações do plano:
95
+
96
+ ```ruby
97
+ Moip::Assinaturas::Plan.update(plan_attributes)
98
+ ```
99
+
94
100
  ## Clientes
95
101
 
96
102
  Criar um novo cliente:
@@ -33,6 +33,10 @@ module Moip::Assinaturas
33
33
  peform_action!(:get, "/plans/#{code}", { headers: { 'Content-Type' => 'application/json' } })
34
34
  end
35
35
 
36
+ def update_plan(plan)
37
+ peform_action!(:put, "/plans/#{plan[:code]}", { body: plan.to_json, headers: { 'Content-Type' => 'application/json' } }, true)
38
+ end
39
+
36
40
  def create_customer(customer, new_vault)
37
41
  peform_action!(:post, "/customers?new_vault=#{new_vault}", { body: customer.to_json, headers: { 'Content-Type' => 'application/json' } })
38
42
  end
@@ -87,13 +91,20 @@ module Moip::Assinaturas
87
91
 
88
92
  private
89
93
 
90
- def peform_action!(action_name, url, options = {})
94
+ def peform_action!(action_name, url, options = {}, accepts_blank_body = false)
91
95
  if (Moip::Assinaturas.token.blank? or Moip::Assinaturas.key.blank?)
92
96
  raise(MissingTokenError, "Informe o token e a key para realizar a autenticação no webservice")
93
97
  end
94
98
 
95
99
  response = self.send(action_name, url, options)
96
- raise(WebServerResponseError, "Ocorreu um erro ao chamar o webservice") if response.nil?
100
+
101
+ # when updating a plan the response body is empty and then
102
+ # the response.nil? returns true despite that the response code was 200 OK
103
+ # that is why I changed the response.nil? by the current
104
+ if response.nil? && !accepts_blank_body
105
+ raise(WebServerResponseError, "Ocorreu um erro ao chamar o webservice")
106
+ end
107
+
97
108
  response
98
109
  end
99
110
 
@@ -54,6 +54,21 @@ module Moip::Assinaturas
54
54
  end
55
55
  end
56
56
 
57
+ def update(plan)
58
+ response = Moip::Assinaturas::Client.update_plan(plan)
59
+
60
+ # in the current implementation the Moip signatures API only
61
+ # returns response code 200 with an empty body even if the update fails
62
+ case response.code
63
+ when 200
64
+ return {
65
+ success: true
66
+ }
67
+ else
68
+ raise(WebServerResponseError, "Ocorreu um erro no retorno do webservice")
69
+ end
70
+ end
71
+
57
72
  end
58
73
  end
59
74
  end
@@ -1,5 +1,5 @@
1
1
  module Moip
2
2
  module Assinaturas
3
- VERSION = "0.1.1"
3
+ VERSION = "0.1.2"
4
4
  end
5
5
  end
@@ -22,6 +22,9 @@ describe Moip::Assinaturas::Plan do
22
22
  }
23
23
  }
24
24
 
25
+ @plan_update = @plan.clone
26
+ @plan_update[:name] = 'Plano Especial 2'
27
+
25
28
  FakeWeb.register_uri(
26
29
  :post,
27
30
  "https://TOKEN:KEY@api.moip.com.br/assinaturas/v1/plans",
@@ -42,6 +45,13 @@ describe Moip::Assinaturas::Plan do
42
45
  body: File.join(File.dirname(__FILE__), '..', 'fixtures', 'details_plan.json'),
43
46
  status: [200, 'OK']
44
47
  )
48
+
49
+ FakeWeb.register_uri(
50
+ :put,
51
+ "https://TOKEN:KEY@api.moip.com.br/assinaturas/v1/plans/plano01",
52
+ body: "",
53
+ status: [200, 'OK']
54
+ )
45
55
  end
46
56
 
47
57
  it "should can create a new plan" do
@@ -62,6 +72,11 @@ describe Moip::Assinaturas::Plan do
62
72
  request[:plan][:code].should == 'plano01'
63
73
  end
64
74
 
75
+ it "should update an existing plan" do
76
+ request = Moip::Assinaturas::Plan.update(@plan_update)
77
+ request[:success].should be_true
78
+ end
79
+
65
80
  context "Trial" do
66
81
  it "should get details from a plan with trial" do
67
82
  request = Moip::Assinaturas::Plan.details('plano01')
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: moip-assinaturas
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-12-23 00:00:00.000000000 Z
12
+ date: 2014-01-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec