Class: Moip::Assinaturas::Customer
- Inherits:
-
Object
- Object
- Moip::Assinaturas::Customer
- Defined in:
- lib/moip-assinaturas/customer.rb
Class Method Summary collapse
- .create(customer, new_valt = true, opts = {}) ⇒ Object
- .details(code, opts = {}) ⇒ Object
- .list(opts = {}) ⇒ Object
- .update(code, changes, opts = {}) ⇒ Object
- .update_credit_card(customer_code, credit_card, opts = {}) ⇒ Object
Class Method Details
.create(customer, new_valt = true, 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/customer.rb', line 6 def create(customer, new_valt = true, opts = {}) response = Moip::Assinaturas::Client.create_customer(customer, new_valt, opts) hash = JSON.load(response.body).with_indifferent_access case response.code when 201 return { success: true, message: hash['message'] } 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
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/moip-assinaturas/customer.rb', line 68 def details(code, opts = {}) response = Moip::Assinaturas::Client.details_customer(code, opts) hash = JSON.load(response.body) hash = hash.with_indifferent_access if hash case response.code when 200 return { success: true, customer: 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/customer.rb', line 27 def list(opts = {}) response = Moip::Assinaturas::Client.list_customers(opts) hash = JSON.load(response.body).with_indifferent_access case response.code when 200 return { success: true, customers: hash['customers'] } else raise(WebServerResponseError, "Ocorreu um erro no retorno do webservice") end end |
.update(code, changes, opts = {}) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/moip-assinaturas/customer.rb', line 42 def update(code, changes, opts = {}) response = Moip::Assinaturas::Client.update_customer(code, changes, opts) hash = JSON.load(response.body) hash = hash ? hash.with_indifferent_access : {} case response.code when 200 return { success: true } when 404 return { success: false, message: 'not found' } when 400 return { success: false, message: hash[:message], errors: hash[:errors] } else raise(WebServerResponseError, "Ocorreu um erro no retorno do webservice") end end |
.update_credit_card(customer_code, credit_card, opts = {}) ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/moip-assinaturas/customer.rb', line 89 def update_credit_card(customer_code, credit_card, opts = {}) response = Moip::Assinaturas::Client.update_credit_card(customer_code, credit_card, opts) hash = JSON.load(response.body).with_indifferent_access case response.code when 200 return { success: true, message: hash[:message] } when 400 return { success: false, message: hash[:message], errors: hash[:errors] } else raise(WebServerResponseError, "Ocorreu um erro no retorno do webservice") end end |