FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
passkit-python-quickstart/coupons/createCampaign.py at develop · PassKit/passkit-python-quickstart · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
PassKit
/
passkit-python-quickstart
Public
Notifications
You must be signed in to change notification settings
Fork
6
Star
7
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
passkit-python-quickstart
/
coupons
/
createCampaign.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
37 lines (30 loc) · 1.06 KB
Breadcrumbs
passkit-python-quickstart
/
coupons
/
createCampaign.py
Copy path
File metadata and controls
37 lines (30 loc) · 1.06 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
# coupons/createCampaign.py
import
grpc
from
passkit
.
io
.
single_use_coupons
import
a_rpc_pb2_grpc
as
coupons_grpc
,
campaign_pb2
from
passkit
.
io
.
common
.
project_pb2
import
ProjectStatus
# enum values
def
run
(
channel
:
grpc
.
Channel
,
name
:
str
=
"Quickstart Campaign"
)
->
str
:
"""
Create a coupon campaign and return its id.
"""
stub
=
coupons_grpc
.
SingleUseCouponsStub
(
channel
)
campaign
=
campaign_pb2
.
CouponCampaign
()
campaign
.
name
=
name
# status is a repeated enum field — use extend with enum values
campaign
.
status
.
extend
([
ProjectStatus
.
PROJECT_ACTIVE_FOR_OBJECT_CREATION
,
ProjectStatus
.
PROJECT_DRAFT
,
])
if
hasattr
(
campaign
,
"timezone"
):
campaign
.
timezone
=
"Europe/London"
resp
=
stub
.
createCouponCampaign
(
campaign
)
cid
=
getattr
(
resp
,
"id"
,
""
)
print
(
"Created coupon campaign:"
,
cid
)
return
cid
if
__name__
==
"__main__"
:
from
shared
.
grpcConnectionPooling
import
ChannelPool
pool
=
ChannelPool
(
size
=
1
)
try
:
ch
=
pool
.
get
()
run
(
ch
)
finally
:
pool
.
close
()
Back
|
FazBrowse Home
|
New Git URL