Module bluevia :: Class BlueVia
[hide private]
[frames] | no frames]

Class BlueVia

source code

Known Subclasses:

The BlueVia base class. All other BlueVia classes are inherited from this class BlueVia.

Mainly Stores consumer and access_token, provides the generic _signAndSend(...) a debug() method

HOWTO USE

oAuth routines

>>> o = bluevia.BlueViaOauth('<secret>', '<key>')
>>> o.fetch_request_token()

Returns the oAuth URL for user authorization

Successful authorization returns an oAuth verifier

>>> o.fetch_access_token("<verifier>")
>>> o.saveAccessToken("newtok.pkl")

SMS outbound routines

>>> s = bluevia.BlueViaOutboundSms()
>>> s.loadAccessToken("newtok.pkl")
>>> s.sendSMS([myMobileNumber], "Hallo Welt")

Returns the delivery URL

>>> s.deliveryStatus("<deliveryURL>")

SMS receive routines

For Sandbox testing use an app that can both send SMS and receive SMS with keyword "BlueViaRocks"

1) Send a fake SMS

>>> s = bluevia.BlueViaOutboundSms()
>>> s.loadAccessToken("smsmo.pkl")
>>> s.sendSMS(["445480605"], "SANDBlueViaRocks so much!")

2) Receive SMS with App

>>> i = bluevia.BlueViaInboundSMS()
>>> i.loadAccessToken("smsmo.pkl")
>>> i.receiveSMS("445480605") # UK shortcode

For live testing use a mobile from the developer (e.g. the one owning the application)

1) Send "TESTBlueViaRocks so much live!" to 445480605

2) Retrieve from Test System

>>> i = bluevia.BlueViaInboundSMS("") # set sandbox parameter to "" makes test calls
>>> i.loadAccessToken("smsmo.pkl")
>>> i.receiveSMS("445480605")

Location routines

>>> l = bluevia.BlueViaLocation()
>>> l.loadAccessToken("newtok.pkl")
>>> l.locateTerminal():

User context routines

>>> u = bluevia.BlueViaUserContext()
>>> u.loadAccessToken("newtok.pkl")
>>> u.getInfo():

Advertising routines

>>> a = bluevia.BlueViaAds("<adspace Id>")
>>> a.loadAccessToken("newtok.pkl")
>>> a.getAd_3l(keywordList = ["sport"])

Payment routines

>>> p = bluevia.BlueViaPayment('<secret>', '<key>')
>>> p.fetch_request_token(<amount>, <currency>, <serviceId>, <serviceName>)
>>> p.fetch_access_token(<verifier>)
>>> p.savePaymentInfo("payment.pkl") # optional, token valid for 48 h
>>> p.loadPaymentInfo("payment.pkl") # optional
>>> p.issuePayment()
>>> p.checkPayment(<transactionId>)
Instance Methods [hide private]
 
_signAndSend(self, requestUrl, method, token, parameters={}, body='', extraHeaders={}, is_form_encoded=False)
Generic method to call an oAuth authorized API in BlueVia including oAuth signature.
source code
 
loadAccessToken(self, path)
Load Consumer Credentials and Access Token from disk (pickle file).
source code
 
setConsumer(self, consumer)
Set the Consumer credentials.
source code
 
setAccessToken(self, access_token)
Set the Access Token.
source code
 
hasCredentials(self)
Check availability of access token
source code
 
setDebug(self, dbgFlag)
Set or unset the debug flag
source code
 
_debug(self, requestUrl, query, headers, body, token, req)
Prints aut anything relevant for oAuth debugging: URL, method, body, headers, signature base string, ...
source code
Class Variables [hide private]
  access_token = None
  consumer = None
  realm = None
  environment = ''
  version = None
  debugFlag = False
  http = httplib2.Http()
Method Details [hide private]

_signAndSend(self, requestUrl, method, token, parameters={}, body='', extraHeaders={}, is_form_encoded=False)

source code 

Generic method to call an oAuth authorized API in BlueVia including oAuth signature.

Parameters:
  • requestUrl - (string): The BlueVia URL
  • method - (string): HTTP method, "GET" or "POST"
  • token - (oauth.Token): Usually the Access Token. During oAuth Dance None or Request Token
  • parameters - (dict): Necessary call paramters, e.g. version, alt. Default: None
  • body - (string): Body of the HTTP call. Default: ""
  • extraHeaders - (dict): Some calls need extra headers, e.g. {"Content-Type":"application/json"}. Default: None
  • is_form_encoded - (boolean): If True parameters are send as form encoded HTTP body. DEFAULT: False
Returns:
(tuple): (HTTP response, HTTP response data)

loadAccessToken(self, path)

source code 

Load Consumer Credentials and Access Token from disk (pickle file).

Parameters:
  • path - (string): Path to pickle file
Returns:
(boolean): True if successfully loaded

Note: Unencrypted storage. Use only for testing!

setConsumer(self, consumer)

source code 

Set the Consumer credentials.

Parameters:
  • consumer - (oauth.Token): The consumer credentials as provided by getCosumer in class BlueViaOauth

setAccessToken(self, access_token)

source code 

Set the Access Token.

Parameters:
  • access_token - (oauth.Token): The oAuth access token as provided by getAccessToken in class BlueViaOauth

setDebug(self, dbgFlag)

source code 

Set or unset the debug flag

Parameters:
  • dbgFlag - (boolean): If True debug information will be printed to stdout

_debug(self, requestUrl, query, headers, body, token, req)

source code 

Prints aut anything relevant for oAuth debugging: URL, method, body, headers, signature base string, ...

Note: Internal method