User

Balance, profile, payments and the webhook URL — client.user.

balance

Balance in USD.

balance # => {"balance" => Float, "zbalance" => Float, "income" => Float (when sent)}

balance includes the sum frozen by numbers and unconfirmed rents in progress (zbalance, which may be negative): available = balance − max(zbalance, 0). income is the partner income. The server caches the answer for 60 s.

b = client.user.balance
available = b["balance"] - [b["zbalance"], 0].max

Errors: ApiError ERROR_WRONG_KEY, ACCOUNT_BLOCKED, API_ACCESS_DISABLED, API_ACCESS_IP.

profile

The account profile.

profile # => Hash

Profile: {"id", "name", "username", "email", "locale", "currency", "number_country", "number_reject", "webhook_url", "api_access", …}.

profile = client.user.profile
puts profile.values_at("email", "webhook_url").join(" ")

payment_history

Top-up orders (paginated, newest first) and the available payment methods.

payment_history(page = 1) # => Hash

{"orders" => paginator, "paylist", "domains"?, "forms"?, "currency"?, "buttons"?}. An order's sum stays a decimal string ("89.00"); currency and form_text may be nil. paylist maps a group id to its payment methods, or is an Array when the ids are 0, 1, 2… (the server sends a JSON array then).

orders = client.user.payment_history["orders"]
puts "#{orders['total']} orders, page #{orders['current_page']}/#{orders['last_page']}"

set_webhook_url

Set the URL that receives SMS webhooks (see Webhooks).

set_webhook_url(url) # => true
client.user.set_webhook_url("https://example.com/onlinesim-hook")

Errors: ApiError VALIDATION_ERROR for an invalid URL; message holds the server's field messages.

clear_webhook_url

Remove the webhook URL, also from operations in progress.

clear_webhook_url # => true
client.user.clear_webhook_url

webhook_logs

Webhook delivery log, newest first, 10 per page.

webhook_logs(page = 1) # => paginator Hash

A log entry: {"id", "user_id", "webhook_url", "type", "params", "status", "error", "created_at", "updated_at"} — type is receiving_sms or rent_sms, status is success, fail or pending, params the payload that was sent.

client.user.webhook_logs["data"].each do |log|
  puts log.values_at("created_at", "status", "error").join(" ")
end