moip-assinaturas 0.2.0 → 0.2.1
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/README.md +6 -0
- data/lib/moip-assinaturas/client.rb +16 -11
- data/lib/moip-assinaturas/subscription.rb +18 -1
- data/lib/moip-assinaturas/version.rb +1 -1
- data/spec/moip-assinaturas/subscription_spec.rb +35 -22
- metadata +2 -2
data/README.md
CHANGED
@@ -125,6 +125,12 @@ Criar uma nova assinatura:
|
|
125
125
|
Moip::Assinaturas::Subscription.create(subscription_attributes, new_customer = false)
|
126
126
|
```
|
127
127
|
|
128
|
+
Atualizar uma assinatura:
|
129
|
+
|
130
|
+
```ruby
|
131
|
+
Moip::Assinaturas::Subscription.update(subscription_code, { plan: { code: 'plan2' } })
|
132
|
+
```
|
133
|
+
|
128
134
|
Listar todas assinaturas:
|
129
135
|
|
130
136
|
```ruby
|
@@ -66,9 +66,14 @@ module Moip::Assinaturas
|
|
66
66
|
peform_action!(:post, "/subscriptions?new_customer=#{new_customer}", opts)
|
67
67
|
end
|
68
68
|
|
69
|
+
def update_subscription(subscription_code, subscription_changes, opts={})
|
70
|
+
prepare_options(opts, { body: subscription_changes.to_json, headers: { 'Content-Type' => 'application/json' } })
|
71
|
+
peform_action!(:put, "/subscriptions/#{subscription_code}", opts, true)
|
72
|
+
end
|
73
|
+
|
69
74
|
def list_subscriptions(opts={})
|
70
75
|
prepare_options(opts, { headers: { 'Content-Type' => 'application/json' } })
|
71
|
-
peform_action!(:get, "/subscriptions", opts)
|
76
|
+
peform_action!(:get, "/subscriptions", opts)
|
72
77
|
end
|
73
78
|
|
74
79
|
def details_subscription(code, opts={})
|
@@ -78,7 +83,7 @@ module Moip::Assinaturas
|
|
78
83
|
|
79
84
|
def suspend_subscription(code, opts={})
|
80
85
|
prepare_options(opts, { headers: { 'Content-Type' => 'application/json' } })
|
81
|
-
peform_action!(:put, "/subscriptions/#{code}/suspend", opts, true)
|
86
|
+
peform_action!(:put, "/subscriptions/#{code}/suspend", opts, true)
|
82
87
|
end
|
83
88
|
|
84
89
|
def activate_subscription(code, opts={})
|
@@ -98,12 +103,12 @@ module Moip::Assinaturas
|
|
98
103
|
|
99
104
|
def list_payments(invoice_id, opts={})
|
100
105
|
prepare_options(opts, { headers: { 'Content-Type' => 'application/json' } })
|
101
|
-
peform_action!(:get, "/invoices/#{invoice_id}/payments", opts)
|
106
|
+
peform_action!(:get, "/invoices/#{invoice_id}/payments", opts)
|
102
107
|
end
|
103
108
|
|
104
109
|
def details_payment(id, opts={})
|
105
|
-
prepare_options(opts, { headers: { 'Content-Type' => 'application/json' } })
|
106
|
-
peform_action!(:get, "/payments/#{id}", opts)
|
110
|
+
prepare_options(opts, { headers: { 'Content-Type' => 'application/json' } })
|
111
|
+
peform_action!(:get, "/payments/#{id}", opts)
|
107
112
|
end
|
108
113
|
|
109
114
|
private
|
@@ -112,8 +117,8 @@ module Moip::Assinaturas
|
|
112
117
|
custom_options.merge!(required_options)
|
113
118
|
|
114
119
|
if custom_options.include?(:moip_auth)
|
115
|
-
custom_options[:basic_auth] = {
|
116
|
-
username: custom_options[:moip_auth][:token],
|
120
|
+
custom_options[:basic_auth] = {
|
121
|
+
username: custom_options[:moip_auth][:token],
|
117
122
|
password: custom_options[:moip_auth][:key]
|
118
123
|
}
|
119
124
|
|
@@ -123,7 +128,7 @@ module Moip::Assinaturas
|
|
123
128
|
else
|
124
129
|
custom_options[:base_uri] = "https://api.moip.com.br/assinaturas/v1"
|
125
130
|
end
|
126
|
-
end
|
131
|
+
end
|
127
132
|
|
128
133
|
custom_options.delete(:moip_auth)
|
129
134
|
end
|
@@ -133,16 +138,16 @@ module Moip::Assinaturas
|
|
133
138
|
|
134
139
|
def peform_action!(action_name, url, options = {}, accepts_blank_body = false)
|
135
140
|
if (Moip::Assinaturas.token.blank? or Moip::Assinaturas.key.blank?)
|
136
|
-
raise(MissingTokenError, "Informe o token e a key para realizar a autenticação no webservice")
|
141
|
+
raise(MissingTokenError, "Informe o token e a key para realizar a autenticação no webservice")
|
137
142
|
end
|
138
143
|
|
139
144
|
response = self.send(action_name, url, options)
|
140
|
-
|
145
|
+
|
141
146
|
# when updating a plan the response body is empty and then
|
142
147
|
# the response.nil? returns true despite that the response code was 200 OK
|
143
148
|
# that is why I changed the response.nil? by the current
|
144
149
|
if response.nil? && !accepts_blank_body
|
145
|
-
raise(WebServerResponseError, "Ocorreu um erro ao chamar o webservice")
|
150
|
+
raise(WebServerResponseError, "Ocorreu um erro ao chamar o webservice")
|
146
151
|
end
|
147
152
|
|
148
153
|
response
|
@@ -22,9 +22,26 @@ module Moip::Assinaturas
|
|
22
22
|
else
|
23
23
|
raise(WebServerResponseError, "Ocorreu um erro no retorno do webservice")
|
24
24
|
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def update(subscription_code, subscription_changes, opts = {})
|
28
|
+
response = Moip::Assinaturas::Client.update_subscription(subscription_code, subscription_changes, opts)
|
25
29
|
|
30
|
+
case response.code
|
31
|
+
when 200
|
32
|
+
return {
|
33
|
+
success: true
|
34
|
+
}
|
35
|
+
when 400
|
36
|
+
return {
|
37
|
+
success: false
|
38
|
+
}
|
39
|
+
else
|
40
|
+
raise(WebServerResponseError, "Ocorreu um erro no retorno do webservice")
|
41
|
+
end
|
26
42
|
end
|
27
43
|
|
44
|
+
|
28
45
|
def list(opts={})
|
29
46
|
response = Moip::Assinaturas::Client.list_subscriptions(opts)
|
30
47
|
hash = JSON.load(response.body).with_indifferent_access
|
@@ -53,7 +70,7 @@ module Moip::Assinaturas
|
|
53
70
|
}
|
54
71
|
else
|
55
72
|
raise(WebServerResponseError, "Ocorreu um erro no retorno do webservice")
|
56
|
-
end
|
73
|
+
end
|
57
74
|
end
|
58
75
|
|
59
76
|
def suspend(code, opts={})
|
@@ -3,13 +3,13 @@ require 'spec_helper'
|
|
3
3
|
|
4
4
|
RSpec::Matchers.define :have_valid_trial_dates do
|
5
5
|
match do |actual|
|
6
|
-
(actual[:start][:day] == 27 && actual[:start][:month] == 9 && actual[:start][:year] == 2013) &&
|
6
|
+
(actual[:start][:day] == 27 && actual[:start][:month] == 9 && actual[:start][:year] == 2013) &&
|
7
7
|
(actual[:end][:day] == 17 && actual[:end][:month] == 10 && actual[:end][:year] == 2013)
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
11
11
|
describe Moip::Assinaturas::Subscription do
|
12
|
-
|
12
|
+
|
13
13
|
before(:all) do
|
14
14
|
@subscription = {
|
15
15
|
code: "assinatura1",
|
@@ -34,71 +34,79 @@ describe Moip::Assinaturas::Subscription do
|
|
34
34
|
}
|
35
35
|
|
36
36
|
FakeWeb.register_uri(
|
37
|
-
:post,
|
38
|
-
"https://TOKEN:KEY@api.moip.com.br/assinaturas/v1/subscriptions?new_customer=false",
|
37
|
+
:post,
|
38
|
+
"https://TOKEN:KEY@api.moip.com.br/assinaturas/v1/subscriptions?new_customer=false",
|
39
39
|
body: File.join(File.dirname(__FILE__), '..', 'fixtures', 'create_subscription.json'),
|
40
40
|
status: [201, 'CREATED']
|
41
41
|
)
|
42
42
|
|
43
43
|
FakeWeb.register_uri(
|
44
|
-
:get,
|
45
|
-
"https://TOKEN:KEY@api.moip.com.br/assinaturas/v1/subscriptions",
|
44
|
+
:get,
|
45
|
+
"https://TOKEN:KEY@api.moip.com.br/assinaturas/v1/subscriptions",
|
46
46
|
body: File.join(File.dirname(__FILE__), '..', 'fixtures', 'list_subscriptions.json'),
|
47
47
|
status: [200, 'OK']
|
48
48
|
)
|
49
49
|
|
50
50
|
FakeWeb.register_uri(
|
51
|
-
:get,
|
52
|
-
"https://TOKEN:KEY@api.moip.com.br/assinaturas/v1/subscriptions/assinatura1",
|
51
|
+
:get,
|
52
|
+
"https://TOKEN:KEY@api.moip.com.br/assinaturas/v1/subscriptions/assinatura1",
|
53
53
|
body: File.join(File.dirname(__FILE__), '..', 'fixtures', 'details_subscription.json'),
|
54
54
|
status: [200, 'OK']
|
55
55
|
)
|
56
56
|
|
57
57
|
FakeWeb.register_uri(
|
58
|
-
:put,
|
58
|
+
:put,
|
59
59
|
"https://TOKEN:KEY@api.moip.com.br/assinaturas/v1/subscriptions/assinatura1/activate",
|
60
|
-
body: '',
|
60
|
+
body: '',
|
61
61
|
status: [200, 'OK']
|
62
62
|
)
|
63
63
|
|
64
64
|
FakeWeb.register_uri(
|
65
|
-
:put,
|
66
|
-
"https://TOKEN:KEY@api.moip.com.br/assinaturas/v1/subscriptions/assinatura1/suspend",
|
65
|
+
:put,
|
66
|
+
"https://TOKEN:KEY@api.moip.com.br/assinaturas/v1/subscriptions/assinatura1/suspend",
|
67
67
|
body: '',
|
68
68
|
status: [200, 'OK']
|
69
69
|
)
|
70
70
|
|
71
71
|
FakeWeb.register_uri(
|
72
|
-
:post,
|
73
|
-
"https://TOKEN2:KEY2@api.moip.com.br/assinaturas/v1/subscriptions?new_customer=false",
|
72
|
+
:post,
|
73
|
+
"https://TOKEN2:KEY2@api.moip.com.br/assinaturas/v1/subscriptions?new_customer=false",
|
74
74
|
body: File.join(File.dirname(__FILE__), '..', 'fixtures', 'custom_authentication', 'create_subscription.json'),
|
75
75
|
status: [201, 'CREATED']
|
76
76
|
)
|
77
77
|
|
78
|
+
# UPDATE SUBSCRIPTION
|
78
79
|
FakeWeb.register_uri(
|
79
|
-
:
|
80
|
-
"https://
|
80
|
+
:put,
|
81
|
+
"https://TOKEN:KEY@api.moip.com.br/assinaturas/v1/subscriptions/assinatura1",
|
82
|
+
body: '',
|
83
|
+
status: [200, 'OK']
|
84
|
+
)
|
85
|
+
|
86
|
+
FakeWeb.register_uri(
|
87
|
+
:get,
|
88
|
+
"https://TOKEN2:KEY2@api.moip.com.br/assinaturas/v1/subscriptions",
|
81
89
|
body: File.join(File.dirname(__FILE__), '..', 'fixtures', 'custom_authentication', 'list_subscriptions.json'),
|
82
90
|
status: [200, 'OK']
|
83
91
|
)
|
84
92
|
|
85
93
|
FakeWeb.register_uri(
|
86
|
-
:get,
|
87
|
-
"https://TOKEN2:KEY2@api.moip.com.br/assinaturas/v1/subscriptions/assinatura2",
|
94
|
+
:get,
|
95
|
+
"https://TOKEN2:KEY2@api.moip.com.br/assinaturas/v1/subscriptions/assinatura2",
|
88
96
|
body: File.join(File.dirname(__FILE__), '..', 'fixtures', 'custom_authentication', 'details_subscription.json'),
|
89
97
|
status: [200, 'OK']
|
90
98
|
)
|
91
99
|
|
92
100
|
FakeWeb.register_uri(
|
93
|
-
:put,
|
101
|
+
:put,
|
94
102
|
"https://TOKEN2:KEY2@api.moip.com.br/assinaturas/v1/subscriptions/assinatura2/activate",
|
95
|
-
body: '',
|
103
|
+
body: '',
|
96
104
|
status: [200, 'OK']
|
97
105
|
)
|
98
106
|
|
99
107
|
FakeWeb.register_uri(
|
100
|
-
:put,
|
101
|
-
"https://TOKEN2:KEY2@api.moip.com.br/assinaturas/v1/subscriptions/assinatura2/suspend",
|
108
|
+
:put,
|
109
|
+
"https://TOKEN2:KEY2@api.moip.com.br/assinaturas/v1/subscriptions/assinatura2/suspend",
|
102
110
|
body: '',
|
103
111
|
status: [200, 'OK']
|
104
112
|
)
|
@@ -110,6 +118,11 @@ describe Moip::Assinaturas::Subscription do
|
|
110
118
|
request[:subscription][:code].should == 'ass_homolog_72'
|
111
119
|
end
|
112
120
|
|
121
|
+
it "should update a subscription" do
|
122
|
+
request = Moip::Assinaturas::Subscription.update(@subscription[:code], { amount: 9990 })
|
123
|
+
request[:success].should be_true
|
124
|
+
end
|
125
|
+
|
113
126
|
it "should list all subscriptions" do
|
114
127
|
request = Moip::Assinaturas::Subscription.list
|
115
128
|
request[:success].should be_true
|
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.2.
|
4
|
+
version: 0.2.1
|
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: 2014-01-
|
12
|
+
date: 2014-01-28 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|