Class: Vonage::Subaccounts

Inherits:
Namespace
  • Object
show all
Defined in:
lib/vonage/subaccounts.rb

Defined Under Namespace

Classes: ListResponse

Instance Method Summary collapse

Instance Method Details

#create(name:, **params) ⇒ Object

Create a subaccount.

Examples:

response = client.subaccounts.create(name: 'Foo')

Parameters:

  • params (Hash)

    a customizable set of options

Options Hash (**params):

  • :name (required, String)

    The name of the subaccount

  • :secret (optional, String)

    An account secret for use by the subaccount. Can be used in combination with your API key to authenticate your API requests. Requirements:

    • 8 characters and no more than 25
    • 1 lower-case letter
    • 1 capital letter
    • 1 digit
    • must be unique
  • :use_primary_account_balance (optional, Boolean)

    Whether the subaccount uses the primary account balance (true, the default) or has its own balance (false). Once set to false cannot be changed back to true

See Also:



58
59
60
# File 'lib/vonage/subaccounts.rb', line 58

def create(name:, **params)
  request("/accounts/#{@config.api_key}/subaccounts", params: params.merge(name: name), type: Post)
end

#find(subaccount_key:) ⇒ Object

Retrieve a subaccount.

Examples:

response = client.subaccounts.find(subaccount_key: 'abc123')

Parameters:

  • params (Hash)

    a customizable set of options

See Also:



31
32
33
# File 'lib/vonage/subaccounts.rb', line 31

def find(subaccount_key:)
  request("/accounts/#{@config.api_key}/subaccounts/#{subaccount_key}")
end

#listObject

Retrieve list of subaccounts.

Examples:

response = client.subaccounts.list

See Also:



17
18
19
# File 'lib/vonage/subaccounts.rb', line 17

def list
  request("/accounts/#{@config.api_key}/subaccounts", response_class: ListResponse)
end

#list_balance_transfers(start_date: "1970-01-01T00:00:00Z", **params) ⇒ Object

Retrieve list of balance transfers.

Examples:

response = client.subaccounts.list_balance_transfers(start_date: "2023-06-15T15:53:50Z")

Parameters:

  • params (Hash)

    a customizable set of options

Options Hash (**params):

  • :start_date (optional, String)

    The ISO format datetime from which to list transfers. Example: 2019-03-02T16:34:49Z. Defaults to "1970-01-01T00:00:00Z" if omitted

  • :end_date (optional, String)

    The ISO format datetime to which to list transfers. Example: 2019-03-02T16:34:49Z. If absent then all transfers until now is returned.

  • :subaccount (optional, String)

    Subaccount to filter by.

See Also:



151
152
153
154
155
# File 'lib/vonage/subaccounts.rb', line 151

def list_balance_transfers(start_date: "1970-01-01T00:00:00Z", **params)
  path = "/accounts/#{@config.api_key}/balance-transfers?#{Params.encode(params.merge(start_date: start_date))}"

  request(path, response_class: BalanceTransfers::ListResponse)
end

#list_credit_transfers(start_date: "1970-01-01T00:00:00Z", **params) ⇒ Object

Retrieve list of credit transfers.

Examples:

response = client.subaccounts.list_credit_transfers(start_date: "2023-06-15T15:53:50Z")

Parameters:

  • params (Hash)

    a customizable set of options

Options Hash (**params):

  • :start_date (optional, String)

    The ISO format datetime from which to list transfers. Example: 2019-03-02T16:34:49Z. Defaults to "1970-01-01T00:00:00Z" if omitted

  • :end_date (optional, String)

    The ISO format datetime to which to list transfers. Example: 2019-03-02T16:34:49Z. If absent then all transfers until now is returned.

  • :subaccount (optional, String)

    Subaccount to filter by.

See Also:



104
105
106
107
108
# File 'lib/vonage/subaccounts.rb', line 104

def list_credit_transfers(start_date: "1970-01-01T00:00:00Z", **params)
  path = "/accounts/#{@config.api_key}/credit-transfers?#{Params.encode(params.merge(start_date: start_date))}"

  request(path, response_class: CreditTransfers::ListResponse)
end

#transfer_balance(from:, to:, amount:, **params) ⇒ Object

Transfer balance.

Examples:

response = client.subaccounts.transfer_balance(from: 'abc123', to: 'def456', amount: 10.00)

Parameters:

  • params (Hash)

    a customizable set of options

Options Hash (**params):

  • :from (required, String)

    The API key of the account or subaccount to transfer balance from.

  • :to (required, String)

    The API key of the account or subaccount to transfer balance to.

  • :amount (required, Number)

    The amount to transfer

  • :reference (optional, String)

    A reference for the transfer.

See Also:



176
177
178
# File 'lib/vonage/subaccounts.rb', line 176

def transfer_balance(from:, to:, amount:, **params)
  request("/accounts/#{@config.api_key}/balance-transfers", params: params.merge(from: from, to: to, amount: amount), type: Post)
end

#transfer_credit(from:, to:, amount:, **params) ⇒ Object

Transfer credit.

Examples:

response = client.subaccounts.transfer_credit(from: 'abc123', to: 'def456', amount: 10.00)

Parameters:

  • params (Hash)

    a customizable set of options

Options Hash (**params):

  • :from (required, String)

    The API key of the account or subaccount to transfer credit from.

  • :to (required, String)

    The API key of the account or subaccount to transfer credit to.

  • :amount (required, Number)

    The amount to transfer

  • :reference (optional, String)

    A reference for the transfer.

See Also:



129
130
131
# File 'lib/vonage/subaccounts.rb', line 129

def transfer_credit(from:, to:, amount:, **params)
  request("/accounts/#{@config.api_key}/credit-transfers", params: params.merge(from: from, to: to, amount: amount), type: Post)
end

#transfer_number(from:, to:, number:, country:) ⇒ Object

Transfer number.

Examples:

response = client.subaccounts.transfer_number(from: 'abc123', to: 'def456', number: 447900000000, country: 'GB')

Parameters:

  • params (Hash)

    a customizable set of options

See Also:



199
200
201
# File 'lib/vonage/subaccounts.rb', line 199

def transfer_number(from:, to:, number:, country:)
  request("/accounts/#{@config.api_key}/transfer-number", params: {from: from, to: to, number: number, country: country}, type: Post)
end

#update(subaccount_key:, **params) ⇒ Object

Modify a subaccount.

Examples:

response = client.subaccounts.update(name: 'Bar')

Parameters:

  • params (Hash)

    a customizable set of options

Options Hash (**params):

  • :subaccount_key (required, String)

    The API key for the subaccount you want to modify

  • :name (optional, String)

    The name of the subaccount

  • :use_primary_account_balance (optional, Boolean)

    Whether the subaccount uses the primary account balance (true, the default) or has its own balance (false). Once set to false cannot be changed back to true

  • :suspended (optional, String)

    Whether the subaccount is suspended (true) or not (false, the default)

See Also:



82
83
84
# File 'lib/vonage/subaccounts.rb', line 82

def update(subaccount_key:, **params)
  request("/accounts/#{@config.api_key}/subaccounts/#{subaccount_key}", params: params, type: Patch)
end