Detailled Documentation

register

class ncellapp.register.register(msisdn)

Bases: ncellapp.NcellApp.NcellApp

This class contains the methods for registering an account.

Parameters

msisdn (string) – MSISDN of the user

baseUrl

The base URL of the Ncell API

Type

string

headers

The headers of the Ncell API

Type

string

connectionType

Type of the connection. Defaults to ‘WIFI’

Type

string

languageCode

Language code of the API. Defaults to ‘en’

Type

string

deviceType

Type of the device. Defaults to ‘ANDROID’

Type

string

deviceModel

Device model of the device. Defaults to ‘Samsung Galaxy S7’

Type

string

token

Token of the account

Type

string

Example

>>> from ncellapp import register
>>> reg = register(msisdn='PHONE NUMBER TO REGISTER')
generateOtp()

Request Ncell to send OTP to the given number for registration

Returns

Response from the Ncell server

Return type

ncellapp.models.NcellResponse

Example

>>> reg.generateOtp()
<Response [OTP1000]>
validateOtp(otp)

Send the OTP to the Ncell server for validation and get the token if correct

Parameters

otp (string) – OTP code

Returns

Response from the Ncell server

Return type

ncellapp.models.NcellResponse

Example

>>> reg.validateOtp('123456')
<Response [OTP1000]>
>>> reg.token
'eyJt...'

ncell

class ncellapp.ncell.ncell(token, autoRefresh=False, afterRefresh=[], args=[])

Bases: ncellapp.NcellApp.NcellApp

This class contains the methods for using the features of ncell app.

Parameters
  • token (string) – Token of the account.

  • autoRefresh (bool, optional) – True to automatically refresh the token after it expires, default is False.

  • afterRefresh (list, optional) – List with two elements, first element is the module name and second element is the function name.

  • args (list, optional) – List of the arguments to the afterRefresh function. __token__ is a special parameter which contains the refreshed token.

baseUrl

The base URL of the Ncell API

Type

string

headers

The headers of the Ncell API

Type

string

connectionType

Type of the connection. Defaults to ‘WIFI’

Type

string

languageCode

Language code of the API. Defaults to ‘en’

Type

string

deviceType

Type of the device. Defaults to ‘ANDROID’

Type

string

deviceModel

Device model of the device. Defaults to ‘Samsung Galaxy S7’

Type

string

token

Token of the account

Type

string

Example

>>> from ncellapp import ncell
>>> # Normal object of ncell class where the token expires after certain time.
>>> # You should refresh the token manually after it expires and save the new token for later use.
>>> account = ncell(token='TOKEN')
>>> # In this type of object, the token is refreshed automatically after it expires.
>>> account = ncell(token='TOKEN', autoRefresh=True)
>>> # In this type of object, the token is refreshed automatically after it expires and the afterRefresh function is called.
>>> def showNewToken(token, name):
>>> ...    print(f'Hello {name}, the previous token is expired and the current token is {token}.')
>>> # __name__ can be passed if the afterRefresh function is on the current module.
>>> # __token__ is a special parameter which contains the refreshed token.
>>> account = ncell(token='TOKEN', autoRefresh=True, afterRefresh=[__name__, 'showNewToken'], args=['__token__', 'sir'])
balance()

Get the user’s balance

Returns

Response from the Ncell server

Return type

ncellapp.models.NcellResponse

Example

>>> balance = account.balance()
>>> print(balance.content)
balanceTransfer(destination, amount)

Transfer balance

Parameters
  • destination (string) – MSISDN to transfer the balance

  • amount (string) – Amount to transfer

Returns

Response from the Ncell server

Return type

ncellapp.models.NcellResponse

Example

>>> transfer = account.balanceTransfer('980*******', '100')
>>> print(transfer.content)
balanceTransferHistory()

Get the balance transfer history

Returns

Response from the Ncell server

Return type

ncellapp.models.NcellResponse

Example

>>> history = account.balanceTransferHistory()
>>> print(history.content)
config()

Get the basic app configuration

Returns

Response from the Ncell server

Return type

ncellapp.models.NcellResponse

Example

>>> config = account.config()
>>> print(config.content)
confirmBalanceTransfer(destination, amount, otp)

Confirm the balance transfer

Parameters
  • destination (string) – MSISDN to transfer the balance

  • amount (string) – Amount to transfer

  • otp (string) – OTP code

Returns

Response from the Ncell server

Return type

ncellapp.models.NcellResponse

Example

>>> confirmation = account.confirmBalanceTransfer('980*******', '100', '123456')
>>> print(confirmation.content)
dataPlans(categoryId=None, keyword='')

Get data plans

Parameters
  • categoryId (string, optional) – Category ID to get the plans of certain category. Defaults to None.

  • keyword (string, optional) – Keywords to search the plans.

Returns

Response from the Ncell server

Return type

ncellapp.models.NcellResponse

Example

>>> plans = account.dataPlans()
>>> print(plans.content)
generateTransactionOtp()

Generate a transaction OTP

Returns

Response from the Ncell server

Return type

ncellapp.models.NcellResponse

Example

>>> response = account.generateTransactionOtp()
>>> print(response.content)
onlineRecharge(destination, amount)

Online recharge

Parameters
  • destination (string) – Destination MSISDN to recharge balance

  • amount (string) – Amount to recharge

Returns

Response from the Ncell server

Return type

ncellapp.models.NcellResponse

Example

>>> recharge = account.onlineRecharge('980*******', '100')
>>> print(recharge.content)
profile()

Get the user’s profile

Returns

Response from the Ncell server

Return type

ncellapp.models.NcellResponse

Example

>>> profile = account.profile()
>>> print(profile.content)
recharge(destination, rPin)

Recharge balance with recharge pin

Parameters
  • destination (string) – Destination MSISDN to recharge balance

  • rPin (string) – 16 digit recharge pin

Returns

Response from the Ncell server

Return type

ncellapp.models.NcellResponse

Example

>>> recharge = account.recharge('980*******', '1548754256987456')
>>> print(recharge.content)
rechargeHistory()

Get the recharge history

Returns

Response from the Ncell server

Return type

ncellapp.models.NcellResponse

Example

>>> history = account.rechargeHistory()
>>> print(history.content)
recommendation()

Get recommendations

Returns

Response from the Ncell server

Return type

ncellapp.models.NcellResponse

Example

>>> recommendations = account.recommendation()
>>> print(recommendations.content)
refreshToken()

Refresh the token

Returns

Response from the Ncell server

Return type

ncellapp.models.NcellResponse

Example

>>> account.refreshToken()
>>> print(f'The new token is {account.token}.')
selfOnlineRecharge(amount)

Self online recharge

Parameters

amount (string) – Amount to recharge

Returns

Response from the Ncell server

Return type

ncellapp.models.NcellResponse

Example

>>> onlineRecharge = account.selfOnlineRecharge('1548754256987456', '100')
>>> print(onlineRecharge.content)
selfRecharge(rPin)

Self recharge with recharge pin

Parameters

rPin (string) – 16 digit recharge pin

Returns

Response from the Ncell server

Return type

ncellapp.models.NcellResponse

Example

>>> recharge = account.selfRecharge('1548754256987456')
>>> print(recharge.content)
sendFreeSms(destination, text, schedule='null')

Send free SMS

Parameters
  • destination (string) – MSISDN to send free SMS

  • text (string) – Text to send

  • schedule (str, optional) – Schedule the SMS. Defaults to ‘null’. (Currently Ncell don’t support scheduling)

Returns

Response from the Ncell server

Return type

ncellapp.models.NcellResponse

Example

>>> sms = account.sendFreeSms('980*******', 'Hello World')
>>> print(sms.content)
sendSms(destination, text, schedule='null')

Send SMS using current data plan

Parameters
  • destination (string) – MSISDN to send SMS

  • text (string) – Text to send

  • schedule (str, optional) – Schedule the SMS. Defaults to ‘null’. (Currently Ncell don’t support scheduling)

Returns

Response from the Ncell server

Return type

ncellapp.models.NcellResponse

Example

>>> sms = account.sendSms('980*******', 'Hello World')
>>> print(sms.content)
subscribeProduct(subscriptionCode)

Subscribe a product

Parameters

subscriptionCode (string) – Subscription code of a product

Returns

Response from the Ncell server

Return type

ncellapp.models.NcellResponse

Example

>>> response = account.subscribeProduct('125425')
>>> print(response.content)
subscribedProducts()

Get the subscribed products

Returns

Response from the Ncell server

Return type

ncellapp.models.NcellResponse

Example

>>> subscribed = account.subscribedProducts()
>>> print(subscribed.content)
takeLoan()

Apply for loan

Returns

Response from the Ncell server

Return type

ncellapp.models.NcellResponse

Example

>>> loan = account.takeLoan()
>>> print(loan.content)
transactionHistory(fromDate, toDate)

Get the transaction history

Parameters
  • from (string) – Date from when history is to be returned in the format YY-MM-DDTHH:MM:SS

  • to (string) – Date upto which history is to be returned in the format YY-MM-DDTHH:MM:SS

Returns

Response from the Ncell server

Return type

ncellapp.models.NcellResponse

Example

>>> history = account.transactionHistory('2021-02-06T00:00:00', '2021-02-12T00:00:00')
>>> print(history.content)
transactionSummary(fromDate, toDate)

Get the transaction summary

Parameters
  • from (string) – Date from when summary is to be returned in the format YY-MM-DDTHH:MM:SS

  • to (string) – Date upto which summary is to be returned in the format YY-MM-DDTHH:MM:SS

Returns

Response from the Ncell server

Return type

ncellapp.models.NcellResponse

Example

>>> history = account.transactionSummary('2021-02-06T00:00:00', '2021-02-12T00:00:00')
>>> print(history.content)
unsubscribeProduct(subscriptionCode)

Unsubscribe a product

Parameters

subscriptionCode (string) – Subscription code of a product

Returns

Response from the Ncell server

Return type

ncellapp.models.NcellResponse

Example

>>> response = account.unsubscribeProduct('125425')
>>> print(response.content)
validateTransactionOtp(otp)

Validate the transaction OTP

Parameters

otp (string) – OTP code

Returns

Response from the Ncell server

Return type

ncellapp.models.NcellResponse

Example

>>> response = account.validateTransactionOtp('123456')
>>> print(response.content)
vasPlans(categoryId=None, keyword='')

Get VAS plans and products

Parameters
  • categoryId (string, optional) – Category ID to get the plans of certain category. Defaults to None.

  • keyword (string, optional) – Keywords to search the plans.

Returns

Response from the Ncell server

Return type

ncellapp.models.NcellResponse

Example

>>> plans = account.vasPlans()
>>> print(plans.content)
voiceAndSmsPlans(categoryId=None, keyword='')

Get voice and SMS plans

Parameters
  • categoryId (string, optional) – Category ID to get the plans of certain category. Defaults to None.

  • keyword (string, optional) – Keywords to search the plans.

Returns

Response from the Ncell server

Return type

ncellapp.models.NcellResponse

Example

>>> plans = account.voiceAndSmsPlans()
>>> print(plans.content)

NcellResponse

class ncellapp.models.NcellResponse(response)

Bases: object

property content

Returns the content of the response

property cookies

Returns a CookieJar object with the cookies sent back from the server

property elapsed

Returns a timedelta object with the time elapsed from sending the request to the arrival of the response

property headers

Returns a dictionary of response headers

property ok

Returns True if status_code is less than 400, otherwise False

property reason

Returns a text corresponding to the status code of the response

property request

Returns the request object that requested this response

property responseHeader

Returns a dictionary of response header from ncell

property statusCode

Returns a number that indicates the status (200 is OK, 404 is Not Found)

property url

Returns the URL of the response