mirror of
https://github.com/andwati/telecom-platform.git
synced 2026-10-18 19:12:54 +00:00
- Add README.md with installation instructions, architecture overview, and API examples for all SDK modules - Refactor TelecomSDK main module to use modular API clients (SubscribersAPI, UsageAPI, PaymentAPI, RatingPlanAPI, SystemAPI, GraphQLAPI) - Add AuthProvider class with API key and JWT token support (generate_jwt_token, validate_jwt_token methods) - Add HTTPClient base
38 lines
1.3 KiB
Elixir
38 lines
1.3 KiB
Elixir
defmodule TelecomSDK.UsageAPI do
|
|
@moduledoc """
|
|
API for usage management
|
|
"""
|
|
|
|
defstruct [:client]
|
|
|
|
def new(client) do
|
|
%__MODULE__{client: client}
|
|
end
|
|
|
|
def get_stats(api, subscriber_id, start_date, end_date) do
|
|
params = %{
|
|
start_date: DateTime.to_iso8601(start_date),
|
|
end_date: DateTime.to_iso8601(end_date)
|
|
}
|
|
TelecomSDK.HTTPClient.get(api.client, "/v1/subscribers/#{subscriber_id}/usage", params)
|
|
end
|
|
|
|
def list_events(api, opts \\ []) do
|
|
params = %{
|
|
page: Keyword.get(opts, :page, 1),
|
|
page_size: Keyword.get(opts, :page_size, 50)
|
|
}
|
|
|
|
params = if Keyword.get(opts, :subscriber_id), do: Map.put(params, :subscriber_id, Keyword.get(opts, :subscriber_id)), else: params
|
|
params = if Keyword.get(opts, :usage_type), do: Map.put(params, :usage_type, Keyword.get(opts, :usage_type)), else: params
|
|
params = if Keyword.get(opts, :start_date), do: Map.put(params, :start_date, DateTime.to_iso8601(Keyword.get(opts, :start_date))), else: params
|
|
params = if Keyword.get(opts, :end_date), do: Map.put(params, :end_date, DateTime.to_iso8601(Keyword.get(opts, :end_date))), else: params
|
|
|
|
TelecomSDK.HTTPClient.get(api.client, "/v1/usage/events", params)
|
|
end
|
|
|
|
def get_realtime(api, subscriber_id) do
|
|
TelecomSDK.HTTPClient.get(api.client, "/v1/subscribers/#{subscriber_id}/realtime")
|
|
end
|
|
end
|