lib/moip-assinaturas/client.rb in moip-assinaturas-0.1.1 vs lib/moip-assinaturas/client.rb in moip-assinaturas-0.1.2
- old
+ new
@@ -31,10 +31,14 @@
def details_plan(code)
peform_action!(:get, "/plans/#{code}", { headers: { 'Content-Type' => 'application/json' } })
end
+ def update_plan(plan)
+ peform_action!(:put, "/plans/#{plan[:code]}", { body: plan.to_json, headers: { 'Content-Type' => 'application/json' } }, true)
+ end
+
def create_customer(customer, new_vault)
peform_action!(:post, "/customers?new_vault=#{new_vault}", { body: customer.to_json, headers: { 'Content-Type' => 'application/json' } })
end
def list_customers
@@ -85,16 +89,23 @@
peform_action!(:get, "/payments/#{id}", { headers: { 'Content-Type' => 'application/json' } })
end
private
- def peform_action!(action_name, url, options = {})
+ def peform_action!(action_name, url, options = {}, accepts_blank_body = false)
if (Moip::Assinaturas.token.blank? or Moip::Assinaturas.key.blank?)
raise(MissingTokenError, "Informe o token e a key para realizar a autenticaĆ§Ć£o no webservice")
end
response = self.send(action_name, url, options)
- raise(WebServerResponseError, "Ocorreu um erro ao chamar o webservice") if response.nil?
+
+ # when updating a plan the response body is empty and then
+ # the response.nil? returns true despite that the response code was 200 OK
+ # that is why I changed the response.nil? by the current
+ if response.nil? && !accepts_blank_body
+ raise(WebServerResponseError, "Ocorreu um erro ao chamar o webservice")
+ end
+
response
end
end
end
\ No newline at end of file