lib/moip2/accounts_api.rb in moip2-1.2.1 vs lib/moip2/accounts_api.rb in moip2-1.3.1
- old
+ new
@@ -12,16 +12,28 @@
def create(account)
Resource::Account.new client, client.post(base_path, account)
end
- def exists?(tax_document)
- response = client.get("#{base_path}/exists?tax_document=#{tax_document}")
+ def exists?(data)
+ raise "Use: {email: 'dev@moip.com'} or {tax_document: '999.999.999-99'}" unless has_attribute_to_search(data)
+ response = client.get("#{base_path}/exists?#{to_search(data)}")
+
response.success?
end
def show(id)
Resource::Account.new client, client.get("#{base_path}/#{id}")
+ end
+
+ private
+
+ def has_attribute_to_search(data)
+ data.key?(:tax_document) || data.key?(:email)
+ end
+
+ def to_search(data)
+ data.key?(:tax_document) ? "tax_document=#{data[:tax_document]}" : "email=#{data[:email]}"
end
end
end