module MangoApi::Wallets

Provides API method delegates concerning the Wallet entity.

Public Class Methods

create(wallet, id_key = nil) click to toggle source

Creates a new wallet entity.

Wallet properties:

  • Required

    • owners

    • description

    • currency

  • Optional

    • tag

@param wallet [Wallet] model object of wallet to be created @param id_key [String] idempotency key for future response replication @return [Wallet] the newly-created Wallet entity object

# File lib/mangopay/api/service/wallets.rb, line 24
def create(wallet, id_key = nil)
  uri = provide_uri(:create_wallet)
  response = HttpClient.post(uri, wallet, id_key)
  parse response
end
get(id) click to toggle source

Retrieves a wallet entity.

@param id [String] ID of the wallet to be retrieved @return [Wallet] the requested entity

# File lib/mangopay/api/service/wallets.rb, line 50
def get(id)
  uri = provide_uri(:get_wallet, id)
  response = HttpClient.get(uri)
  parse response
end
of_user(id) { |filter_request = filter_request| ... } click to toggle source

Retrieves pages of wallet entities belonging to a certain user entity. Allows configuration of paging and sorting parameters by yielding a filtering object to a provided block. When no filters are specified, will retrieve the first page of 10 newest results.

Allowed FilterRequest params:

  • page

  • per_page

  • sort_field and sort_direction

@param id [String] ID of the user whose wallets to retrieve @return [Array] the requested entities

# File lib/mangopay/api/service/wallets.rb, line 68
def of_user(id)
  uri = provide_uri(:get_users_wallets, id)
  filter_request = nil
  yield filter_request = FilterRequest.new if block_given?
  results = HttpClient.get(uri, filter_request)
  parse_results results
end
update(wallet) click to toggle source

Updates the wallet entity identifiable by the provided wallet object's ID.

Wallet optional properties:

  • tag

  • description

@param wallet [Wallet] wallet object with corresponding ID and updated data @return [Wallet] updated wallet entity

# File lib/mangopay/api/service/wallets.rb, line 40
def update(wallet)
  uri = provide_uri(:update_wallet, wallet)
  response = HttpClient.put(uri, wallet)
  parse response
end

Private Class Methods

parse(response) click to toggle source

Parses a JSON-originating hash into the corresponding Wallet entity object.

@param response [Hash] JSON-originating data hash @return [Wallet] corresponding Wallet entity object

# File lib/mangopay/api/service/wallets.rb, line 94
def parse(response)
  MangoModel::Wallet.new.dejsonify response
end
parse_results(results) click to toggle source

Parses an array of JSON-originating hashes into the corresponding Wallet entity objects.

@param results [Array] JSON-originating data hashes @return [Array] parsed Wallet entity objects

# File lib/mangopay/api/service/wallets.rb, line 83
def parse_results(results)
  results.collect do |entity|
    parse entity
  end
end