-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReadme.html
More file actions
155 lines (114 loc) · 5.5 KB
/
Readme.html
File metadata and controls
155 lines (114 loc) · 5.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="keywords" content="MultiMarkdown, Markdown, XML, XHTML, XSLT, PDF"/>
<link type="text/css" rel="stylesheet" href="css/print.css"/>
<link type="text/css" rel="stylesheet" href="css/doc-less.css"/>
</head>
<body>
<p>Feel free to download and mess around with this app, it may or may not be updated regularly, when it is we will publicise on our twitter feed (@BlueVia)</p>
<h2 id="getyourpythonenvironmentprepared">Get your Python environment prepared</h2>
<p>There is little to do with python. The tutorial has been prepared with Python 2.6. Further on we need three additional python modules:</p>
<ul>
<li><a href="http://code.google.com/p/httplib2/">httplib2</a>: Makes life with http calls easier</li>
<li><a href="https://github.com/simplegeo/python-oauth2">oauth2</a>: The actual oauth library</li>
<li><a href="http://code.google.com/p/simplejson">simplejson</a>: Makes life with JSON easier</li>
</ul>
<p>The easiest way to get these is <em>easy_install</em> from python setup tools:</p>
<pre><code> easy_install httplib2
easy_install oauth2
easy_install simplejson
</code></pre>
<h2 id="sampleusageofallblueviapythonroutines">Sample usage of all BlueVia python routines</h2>
<h3 id="somepersonalsettings">Some personal settings</h3>
<pre><code> myMobileNumber = "44xxxxxxxxxx"
myShortcode = "445480605" # UK
myAdSpaceId = "xxxxx"
# App with all API's ticked
my3leggedConsumer = 'xxxxxxxxxxxxxxxx'
my3leggedSecret = 'xxxxxxxxxxxx'
# App with advertising only
my2leggedConsumer = 'xxxxxxxxxxxxxxxx'
my2leggedSecret = 'xxxxxxxxxxxx'
</code></pre>
<h3 id="oauthdance">oAuth Dance</h3>
<pre><code> import bluevia
o3 = bluevia.BlueViaOauth(my3leggedConsumer, my3leggedSecret)
o3.fetch_request_token()
# returns the authorization URL. Paste into browser.
# When finished copy verifier, e.g 135791
o3.fetch_access_token("135791")
</code></pre>
<h3 id="sendsmsandtrackdelivery">Send SMS and track delivery</h3>
<pre><code> s = bluevia.BlueViaOutboundSms()
s.loadAccessToken("token.pkl")
r = s.sendSMS([myMobileNumber], "Hello BlueVia")
s.deliveryStatus(r[1])
</code></pre>
<p>Note: to use the real radio network call (this holds for all BlueVia calless below):</p>
<pre><code> s = bluevia.BlueViaOutboundSms(sandbox="")
</code></pre>
<h3 id="receivesmsfirstsendoneormoresmstothesandboxshortcode">Receive SMS (first send one or more SMS to the sandbox shortcode)</h3>
<pre><code> s.sendSMS([shortcode], "SANDBWTUT01 BlueVia")
si = bluevia.BlueViaInboundSMS()
si.loadAccessToken("token.pkl")
si.receiveSMS(shortcode)
</code></pre>
<h3 id="sendmms">Send MMS</h3>
<pre><code> m = bluevia.BlueViaOutboundMms()
m.loadAccessToken("token.pkl")
m.sendMMS(myMobileNumber, "Hello Multimedia BlueVia", \
["Message\n Number 1", "Yet another\n Message"], \
["samples/atextfile.txt", "samples/image.jpg"])
</code></pre>
<p>Receive MMS and retrieve the attachemnts (first send one or more MMS to the sandbox shortcode)</p>
<pre><code> m.sendMMS(myShortcode, "SANDBWTUT01 BlueVia Multimedia", \
["Message\n Number 1", "Yet another\n Message"], \
["samples/atextfile.txt", "samples/image.jpg"])
mi = bluevia.BlueViaInboundMMS()
mi.loadAccessToken("token.pkl")
r = mi.receiveMMS(myShortcode)
mid = r[1]['receivedMessages']['messageIdentifier']
mi.retrieveAttachments(myShortCode, mid)
</code></pre>
<h3 id="usercontextapi">User Context API</h3>
<pre><code> u = bluevia.BlueViaUserContext()
u.loadAccessToken("token.pkl")
u.getUserInfo()
</code></pre>
<h3 id="locationapi">Location API</h3>
<pre><code> l = bluevia.BlueViaLocation()
l.loadAccessToken("token.pkl")
l.locateTerminal()
</code></pre>
<h3 id="advertisingapi3leggedoauth">Advertising API (3 legged oAuth)</h3>
<pre><code> a3 = bluevia.BlueViaAds(myAdSpaceId)
a3.loadAccessToken("token.pkl")
a3.getAd_3l()
</code></pre>
<h3 id="advertisingapi2leggedoauth">Advertising API (2 legged oAuth)</h3>
<pre><code> import oauth2 as oauth
a2 = bluevia.BlueViaAds(myAdSpaceId)
a2.setConsumer(oauth.Token( my2leggedConsumer, my2leggedSecret))
a2.setDebug(debugFlag)
a2.getAd_2l("GB")
</code></pre>
<h3 id="paymentapi">Payment API</h3>
<pre><code> p = bluevia.BlueViaPayment(my3leggedConsumer, my3leggedSecret)
amount = 199 # no float, 199 means 1.99 EUR
currency = "EUR" # EUR, GBP, ...
# In sandbox any strings, commercially the service Id / Name given by the Mobile Payment Partner
serviceId = "123456"
serviceName = "My Digital Good"
p.fetch_request_token(amount, currency, serviceId, serviceName)
# When finished copy verifier, e.g 176539
p.fetch_access_token("176539")
p.savePaymentInfo("payment.pkl") # optional, token valid for 48 h
p.loadPaymentInfo("payment.pkl") # optional
result = p.issuePayment()
txid = result[1]["methodResponse"]["result"]["paymentResult"]["transactionId"]
p.checkPayment(txid)
</code></pre>
</body>
</html>