Class: Moip::Assinaturas::Plan
- Inherits:
-
Object
- Object
- Moip::Assinaturas::Plan
- Defined in:
- lib/moip-assinaturas/plan.rb
Class Method Summary collapse
- .create(plan, opts = {}) ⇒ Object
- .details(code, opts = {}) ⇒ Object
- .list(opts = {}) ⇒ Object
- .update(plan, opts = {}) ⇒ Object
Class Method Details
.create(plan, opts = {}) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/moip-assinaturas/plan.rb', line 6 def create(plan, opts={}) response = Moip::Assinaturas::Client.create_plan(plan, opts) hash = JSON.load(response.body).with_indifferent_access case response.code when 201 return { success: true, plan: hash } when 400 return { success: false, message: hash['message'], errors: hash['errors'] } else raise(WebServerResponseError, "Ocorreu um erro no retorno do webservice") end end |
.details(code, opts = {}) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/moip-assinaturas/plan.rb', line 42 def details(code, opts={}) response = Moip::Assinaturas::Client.details_plan(code, opts) hash = JSON.load(response.body) hash = hash.with_indifferent_access if hash case response.code when 200 return { success: true, plan: hash } when 404 return { success: false, message: 'not found' } else raise(WebServerResponseError, "Ocorreu um erro no retorno do webservice") end end |
.list(opts = {}) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/moip-assinaturas/plan.rb', line 27 def list(opts={}) response = Moip::Assinaturas::Client.list_plans(opts) hash = JSON.load(response.body).with_indifferent_access case response.code when 200 return { success: true, plans: hash[:plans] } else raise(WebServerResponseError, "Ocorreu um erro no retorno do webservice") end end |
.update(plan, opts = {}) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/moip-assinaturas/plan.rb', line 63 def update(plan, opts={}) response = Moip::Assinaturas::Client.update_plan(plan, opts) # in the current implementation the Moip signatures API only # returns response code 200 with an empty body even if the update fails case response.code when 200 return { success: true } else raise(WebServerResponseError, "Ocorreu um erro no retorno do webservice") end end |