onlinesim library

Typed client for the OnlineSim API: SMS numbers, rent, account and free numbers, inbound webhooks, and MockOnlineSim, an offline fake of the API for tests.

import 'package:onlinesim/onlinesim.dart';

final client = OnlineSim(apiKey: 'your-api-key');
final order = await client.numbers.getWithNumber('google', country: 44);
final code = await client.numbers.waitCode(order.tzid);

Classes

Balance
Account balance, USD.
CountryStat
Services, prices and stock of one country.
FreeApi
Public free numbers: client.free. No key needed.
FreeCountry
A country with free numbers.
FreeList
Result of free.list.
FreeMessage
An SMS of a free number.
FreeMessages
SMS page of the selected free number.
FreeNumber
A free number.
HttpTransport
OnlineSimTransport over a package:http http.Client.
MockOnlineSim
In-process fake OnlineSim API for tests: no network, no key, no money, no clock.
MockOperation
A number operation as the mock stores it (a snapshot).
MockRent
A rent as the mock stores it (a snapshot). Closed rents are removed.
MockRentTariff
Rent tariff of one country: rent days → USD, and whether rents can be extended (1) or not (0).
MockRequest
One request the mock received.
MockSms
One SMS received by an operation or a rent.
NumberOrder
Result of numbers.getWithNumber.
NumbersApi
Numbers for receiving SMS: client.numbers.
OnlineSim
OnlineSim API client.
OnlineSimTransport
What the client needs from HTTP: send one request, return status and body.
Operation
A number operation (a getState item).
OperationSms
One SMS of an operation, when msgList is set.
OperationStatus
States of a number operation (Operation.response).
Paginator<T>
A Laravel paginator page.
PaymentHistory
Result of user.paymentHistory.
PaymentOrder
A top-up order.
Profile
The account profile.
RentApi
Rented numbers: client.rent.
RentItem
A rent operation.
RentSms
One SMS of a rent.
RentTariff
Rent prices of one country.
ServiceStat
One service of a country in numbers.tariffs.
TransportRequest
One HTTP request the client sends.
TransportResponse
The HTTP answer a transport returns: status and body text.
UserApi
The account: client.user.
WebhookLog
One webhook delivery.
WebhookPayload
An inbound webhook body as normalised by parseWebhook: missing or malformed fields are null.

Enums

SortOrder
Order of numbers.state results (orderby).
WebhookType
Kind of an inbound webhook (webhook_type).

Constants

defaultBaseUrl → const String
Default API base.
defaultMockPrices → const MockPrices
Default number prices of the mock.
defaultMockRentTariffs → const Map<int, MockRentTariff>
Default rent tariffs of the mock.
defaultTimeout → const Duration
Default per-request timeout.
errorMessages → const Map<String, String>
Fallback messages for error codes the server sends without a message.
mockBaseUrl → const String
Base URL of clients made by MockOnlineSim.client. Never contacted: the mock answers in-process.

Functions

parseWebhook(Object payload) → WebhookPayload
Parses an inbound webhook body (receiving_sms or rent_sms) from a JSON string or an already decoded map.

Typedefs

MockPrices = Map<int, Map<String, double>>
Number prices: country code → service slug → USD.

Exceptions / Errors

ApiException
The API answered with an error code in response.
NoNumberException
No number is available right now (NO_NUMBER, NO_NUMBER_FOR_FORWARD). Retry later or pick another country.
OnlineSimException
Base of every exception thrown by the SDK.
TransportException
Network failure, request timeout, or a response that is not JSON.
WaitTimeoutException
waitCode gave up: no code arrived within its timeout.
WebhookFormatException
A webhook body passed to parseWebhook is not a JSON object.