gerencianet 0.0.1 → 0.0.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.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +8 -0
  3. data/README.md +15 -3
  4. data/docs/all-in-one.md +92 -0
  5. data/docs/carnet-detailing.md +61 -0
  6. data/docs/carnet-update.md +55 -0
  7. data/docs/carnets.md +217 -0
  8. data/docs/charge-detailing.md +42 -0
  9. data/docs/charge-payment.md +145 -0
  10. data/docs/charge-update.md +52 -0
  11. data/docs/charge-with-marketplace.md +54 -0
  12. data/docs/charges.md +94 -0
  13. data/docs/examples/.gitignore +1 -0
  14. data/docs/examples/all_in_one.rb +57 -0
  15. data/docs/examples/cancel_charge.rb +15 -0
  16. data/docs/examples/cancel_subscription.rb +15 -0
  17. data/docs/examples/create_billet_payment.rb +33 -0
  18. data/docs/examples/create_card_payment.rb +39 -0
  19. data/docs/examples/create_carnet.rb +32 -0
  20. data/docs/examples/create_charge.rb +24 -0
  21. data/docs/examples/create_plan.rb +17 -0
  22. data/docs/examples/create_subscription.rb +31 -0
  23. data/docs/examples/create_subscription_payment.rb +38 -0
  24. data/docs/examples/credentials.rb +5 -0
  25. data/docs/examples/delete_plan.rb +15 -0
  26. data/docs/examples/detail_carnet.rb +15 -0
  27. data/docs/examples/detail_charge.rb +15 -0
  28. data/docs/examples/detail_subscription.rb +15 -0
  29. data/docs/examples/get_installments.rb +16 -0
  30. data/docs/examples/get_notification.rb +15 -0
  31. data/docs/examples/get_plans.rb +17 -0
  32. data/docs/examples/update_billet.rb +19 -0
  33. data/docs/examples/update_carnet_metadata.rb +20 -0
  34. data/docs/examples/update_charge_metadata.rb +20 -0
  35. data/docs/examples/update_parcel.rb +20 -0
  36. data/docs/examples/update_subscription_metadata.rb +20 -0
  37. data/docs/installments.md +108 -0
  38. data/docs/notifications.md +105 -0
  39. data/docs/subscription-detailing.md +56 -0
  40. data/docs/subscription-payment.md +100 -0
  41. data/docs/subscription-update.md +29 -0
  42. data/docs/subscriptions.md +69 -0
  43. data/lib/gerencianet/constants.rb +1 -1
  44. data/lib/gerencianet/endpoints.rb +14 -19
  45. data/lib/gerencianet/version.rb +1 -1
  46. metadata +41 -2
@@ -65,7 +65,7 @@ module Gerencianet
65
65
  },
66
66
  delete_plan: {
67
67
  route: "/plan/:id",
68
- method: "del"
68
+ method: "delete"
69
69
  },
70
70
  create_subscription: {
71
71
  route: "/plan/:id/subscription",
@@ -26,8 +26,8 @@ module Gerencianet
26
26
 
27
27
  def create_methods
28
28
  @endpoints.each do |key, settings|
29
- self.class.send(:define_method, key) do |params = nil, body = nil|
30
- create(params, body, settings)
29
+ self.class.send(:define_method, key) do |args = {}|
30
+ create(args[:params], args[:body], settings)
31
31
  end
32
32
  end
33
33
  end
@@ -42,7 +42,7 @@ module Gerencianet
42
42
  response = make_request(params, body, settings)
43
43
  end
44
44
 
45
- response
45
+ respond(response)
46
46
  end
47
47
 
48
48
  def make_request(params, body, settings)
@@ -59,10 +59,15 @@ module Gerencianet
59
59
  url = get_url({}, @endpoints[:authorize][:route])
60
60
 
61
61
  response =
62
- HTTP.basic_auth(auth_headers)
62
+ HTTP
63
+ .basic_auth(auth_headers)
63
64
  .post(url, json: auth_body)
64
65
 
65
- respond(response)
66
+ if response.status.to_s == STATUS::UNAUTHORIZED
67
+ fail "unable to authenticate"
68
+ else
69
+ @token = respond(response)
70
+ end
66
71
  end
67
72
 
68
73
  def auth_headers
@@ -77,15 +82,9 @@ module Gerencianet
77
82
  end
78
83
 
79
84
  def respond(response)
80
- if response.status.to_s == STATUS::OK
81
- begin
82
- @token = JSON.parse(response)
83
- rescue JSON::ParserError
84
- raise "unable to parse server response, not a valid json"
85
- end
86
- else
87
- fail "unable to authenticate"
88
- end
85
+ JSON.parse(response)
86
+ rescue JSON::ParserError
87
+ raise "unable to parse server response, not a valid json"
89
88
  end
90
89
 
91
90
  def get_url(params, route)
@@ -123,11 +122,7 @@ module Gerencianet
123
122
  end
124
123
 
125
124
  def current_base_url
126
- if @options[:sandbox]
127
- @urls[:sandbox]
128
- else
129
- @urls[:production]
130
- end
125
+ @options[:sandbox] ? @urls[:sandbox] : @urls[:production]
131
126
  end
132
127
  end
133
128
  end
@@ -1,4 +1,4 @@
1
1
  # :nodoc:
2
2
  module Gerencianet
3
- VERSION = "0.0.1"
3
+ VERSION = "0.0.2"
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gerencianet
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Francisco Carvalho
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-11-13 00:00:00.000000000 Z
11
+ date: 2015-11-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -170,6 +170,45 @@ files:
170
170
  - Rakefile
171
171
  - bin/console
172
172
  - bin/setup
173
+ - docs/all-in-one.md
174
+ - docs/carnet-detailing.md
175
+ - docs/carnet-update.md
176
+ - docs/carnets.md
177
+ - docs/charge-detailing.md
178
+ - docs/charge-payment.md
179
+ - docs/charge-update.md
180
+ - docs/charge-with-marketplace.md
181
+ - docs/charges.md
182
+ - docs/examples/.gitignore
183
+ - docs/examples/all_in_one.rb
184
+ - docs/examples/cancel_charge.rb
185
+ - docs/examples/cancel_subscription.rb
186
+ - docs/examples/create_billet_payment.rb
187
+ - docs/examples/create_card_payment.rb
188
+ - docs/examples/create_carnet.rb
189
+ - docs/examples/create_charge.rb
190
+ - docs/examples/create_plan.rb
191
+ - docs/examples/create_subscription.rb
192
+ - docs/examples/create_subscription_payment.rb
193
+ - docs/examples/credentials.rb
194
+ - docs/examples/delete_plan.rb
195
+ - docs/examples/detail_carnet.rb
196
+ - docs/examples/detail_charge.rb
197
+ - docs/examples/detail_subscription.rb
198
+ - docs/examples/get_installments.rb
199
+ - docs/examples/get_notification.rb
200
+ - docs/examples/get_plans.rb
201
+ - docs/examples/update_billet.rb
202
+ - docs/examples/update_carnet_metadata.rb
203
+ - docs/examples/update_charge_metadata.rb
204
+ - docs/examples/update_parcel.rb
205
+ - docs/examples/update_subscription_metadata.rb
206
+ - docs/installments.md
207
+ - docs/notifications.md
208
+ - docs/subscription-detailing.md
209
+ - docs/subscription-payment.md
210
+ - docs/subscription-update.md
211
+ - docs/subscriptions.md
173
212
  - gerencianet.gemspec
174
213
  - lib/gerencianet.rb
175
214
  - lib/gerencianet/constants.rb