Package: reloadly-giftcard
GiftCards APIThe implementation is based on theGiftCards API Docs.UsageCreate anGiftcardAPIinstance by providing the Application details (client id & secret) from
thedashboard.Some key things to keep in mind regarding the Airtime API :The API has 2 environments, SANDBOX (for development & testing) and LIVE.Environment.GIFTCARDis used for the Live environmnent andEnvironment.GIFTCARD_SANDBOXis for the Sandbox.If neither environment is specified, the SDK defaults to SANDBOXEach environment has a set of credentials (client id & secret) that are different from the other.SANBOX credentials can only be used for SANDBOX environmentLIVE credentials can only be used for LIVE environmentIf not environment is specified the SDK defaults to SANDBOXYou MUST supply either the credentials, or an access token in order to call the APIAs stated above, requests to the Airtime API require authentication/authorization, there are several options :Option 1Set the client id & client secret; this is probably the most straight-forward or simplest way. An access token will be
acquired automatically before the API call is made.fromreloadly_core.core.enums.EnvironmentimportEnvironmentfromreloadly_giftcard.giftcard.sdk.client.giftcardAPIimportGiftCardsgiftcardAPI=GiftCards(clientId="*****",clientSecret="*****",environment=Environment.GIFTCARD_SANDBOX)response=giftcardAPI.products().List_without_filter()print(response)Option 2You may alternatively acquire an access token from theAuthenticationAPIand then set it.fromreloadly_auth.authentication.client.AuthenticationAPIimportAuthenticationAPIfromreloadly_core.core.enums.ServiceimportServicefromreloadly_core.core.enums.EnvironmentimportEnvironmentfromreloadly_giftcard.giftcard.sdk.client.giftcardAPIimportGiftCardssample=AuthenticationAPI()a=sample.clientCredentials(clientId="*****",clientSecret="*****"service=Service.GIFTCARD_SANDBOX).getAccessToken(Service.GIFTCARD_SANDBOX)giftcardAPI=GiftCards(accessToken=a,Environment.GIFTCARD_SANDBOX)response=giftcardAPI.products().List_without_filter()print(response)Note : Access tokens obtain for Reloadly APIs have a finite
lifetime.See the API docsUsing the example above has some benefits and drawbacks:ProAPI requests become efficient & performant.Setting the access token skips the automatic token acquisition API calls that would have otherwise been made before
each Airtime API service calls.ConsHowever, because access tokens have a finite lifetime, you now have to manage or handle the expiration of the access
token in your application code.In the sample above, the AirtimeAPI will continue using the same access token until it expires. Therefore, the
responsibility falls on you to handle token renewal when the token expires.Sample token expiration handlingfromreloadly_core.core.enums.EnvironmentimportEnvironmentfromreloadly_giftcard.giftcard.sdk.client.giftcardAPIimportGiftCards# Refresh token using AuthenticationAPIsample=AuthenticationAPI()a=sample.clientCredentials(clientId="*****",clientSecret="*****"service=Service.GIFTCARD_SANDBOX).getAccessToken(Service.GIFTCARD_SANDBOX)giftcardAPI=GiftCards(accessToken=a,Environment.GIFTCARD_SANDBOX)try:request=giftcardAPI.products().List_without_filter()ifresponse['errorCode']=="TOKEN_EXPIRED":response=giftcardAPI.refreshAccessToken(request)returnresponseelse:# add logicexcept:raiseException("ReloadlyException")Logging request & responseTo enable API request/response logging, setenableloggingto true when intiaiting the AirtimeAPI classgiftcardAPI=GiftCards(clientId="*****",clientSecret="*****",environment=Environment.GIFTCARD_SANDBOX,enablelogging=True)....Customizing The API Client InstanceConfiguring TimeoutsUsed to configure additional options, connect and read timeouts can be configured globally:giftcardAPI=GiftCards(clientId="*****",clientSecret="*****",environment=Environment.GIFTCARD_SANDBOX,options=HttpOptions(readTimeout=60,writeTimeout=60,connectTimeout=60))....Proxy ConfigurationproxyPort=8085;# Your proxy portproxyUsername="your-proxy-authentication-username";# Optional proxy username if your proxy requires authenticationproxyPassword="your-proxy-authentication-password";# Optional proxy password if your proxy requires authenticationproxyHost="you-proxy-host-name.com";Proxyproxy=newProxy(Proxy.Type.HTTP,newInetSocketAddress(proxyHost,proxyPort));giftcardAPI=GiftCards(clientId="*****",clientSecret="*****",environment=Environment.GIFTCARD_SANDBOX,options=HttpOptions())........# If proxy does NOT require authentication....Request latency telemetryBy default, the library sends request latency telemetry to Reloadly. These numbers help Reloadly improve the overall
latency of its API for all users.You can disable this behavior if you prefer:giftcardAPI=GiftCards(clientId="*****",clientSecret="*****",environment=Environment.GIFTCARD_SANDBOX,enableTelemetry=False)....