Sha256: 62ef931be732b0bff4ce38cedc71f29fdc7e6675e0ba861c19c27a2f6f2940e8

Contents?: true

Size: 855 Bytes

Versions: 1

Compression:

Stored size: 855 Bytes

Contents

module Moip2
  class AccountsApi
    attr_reader :client

    def initialize(client)
      @client = client
    end

    def base_path
      "/v2/accounts"
    end

    def create(account)
      Resource::Account.new client, client.post(base_path, account)
    end

    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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
moip2-1.3.1 lib/moip2/accounts_api.rb