Subversion Repositories SmartDukaan

Rev

Rev 6433 | Rev 6561 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1976 varun.gupt 1
#!/usr/bin/env python
2
#
3431 rajveer 3
# Autogenerated by Thrift Compiler (0.7.0)
1976 varun.gupt 4
#
5
# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
6
#
7
 
8
import sys
9
import pprint
10
from urlparse import urlparse
11
from thrift.transport import TTransport
12
from thrift.transport import TSocket
13
from thrift.transport import THttpClient
14
from thrift.protocol import TBinaryProtocol
15
 
16
import PromotionService
17
from ttypes import *
18
 
19
if len(sys.argv) <= 1 or sys.argv[1] == '--help':
20
  print ''
21
  print 'Usage: ' + sys.argv[0] + ' [-h host:port] [-u url] [-f[ramed]] function [arg1 [arg2...]]'
22
  print ''
23
  print 'Functions:'
24
  print '  void createPromotion(string name, string ruleExecutionSrc, i64 startOn, i64 endOn)'
6301 amit.gupta 25
  print '  Coupon getCoupon(string couponCode)'
26
  print '  bool isGiftVoucher(string couponCode)'
6356 amit.gupta 27
  print '  bool isCodApplicable(string couponCode)'
1976 varun.gupt 28
  print '   getAllPromotions()'
29
  print '  Promotion getPromotionById(i64 promotionId)'
30
  print '  void generateCouponsForPromotion(i64 promotionId, string couponCode)'
31
  print '  Cart applyCoupon(string couponCode, i64 cartId)'
6433 anupam.sin 32
  print '   applyRechargeCoupon(string couponCode, i64 totalAmount, i64 userId)'
1976 varun.gupt 33
  print '  void trackCouponUsage(string couponCode, i64 transactionId, i64 userId)'
34
  print '  i64 getCouponUsageCountByUser(string couponCode, i64 userId)'
6497 amit.gupta 35
  print '   getActiveCodes(i64 promotionId)'
36
  print '  void deleteCoupon(string couponCode)'
3385 varun.gupt 37
  print '   getActiveCoupons()'
6356 amit.gupta 38
  print '  string createCoupon(i64 promotionId, i64 endOn, string email, i64 amount, bool isCod, i64 usage)'
3385 varun.gupt 39
  print '  i64 getSuccessfulPaymentCountForCoupon(string couponCode)'
40
  print '  string getRuleDocString(string ruleName)'
4189 varun.gupt 41
  print '   getItemDiscountMap( itemIds)'
4494 varun.gupt 42
  print '   getDiscountsForEntity(i64 entityId)'
5469 rajveer 43
  print '  void addVoucher(Voucher voucher)'
44
  print '  Voucher assignVoucher(i64 userId, string userEmail, VoucherType voucherType, i64 amount)'
45
  print '  bool markVoucherAsRedeemed(string voucherCode, i64 redeemedOn)'
1976 varun.gupt 46
  print ''
47
  sys.exit(0)
48
 
49
pp = pprint.PrettyPrinter(indent = 2)
50
host = 'localhost'
51
port = 9090
52
uri = ''
53
framed = False
54
http = False
55
argi = 1
56
 
57
if sys.argv[argi] == '-h':
3431 rajveer 58
  parts = sys.argv[argi+1].split(':')
1976 varun.gupt 59
  host = parts[0]
60
  port = int(parts[1])
61
  argi += 2
62
 
63
if sys.argv[argi] == '-u':
64
  url = urlparse(sys.argv[argi+1])
3431 rajveer 65
  parts = url[1].split(':')
1976 varun.gupt 66
  host = parts[0]
67
  if len(parts) > 1:
68
    port = int(parts[1])
69
  else:
70
    port = 80
71
  uri = url[2]
3431 rajveer 72
  if url[4]:
73
    uri += '?%s' % url[4]
1976 varun.gupt 74
  http = True
75
  argi += 2
76
 
77
if sys.argv[argi] == '-f' or sys.argv[argi] == '-framed':
78
  framed = True
79
  argi += 1
80
 
81
cmd = sys.argv[argi]
82
args = sys.argv[argi+1:]
83
 
84
if http:
85
  transport = THttpClient.THttpClient(host, port, uri)
86
else:
87
  socket = TSocket.TSocket(host, port)
88
  if framed:
89
    transport = TTransport.TFramedTransport(socket)
90
  else:
91
    transport = TTransport.TBufferedTransport(socket)
92
protocol = TBinaryProtocol.TBinaryProtocol(transport)
93
client = PromotionService.Client(protocol)
94
transport.open()
95
 
3431 rajveer 96
if cmd == 'createPromotion':
1976 varun.gupt 97
  if len(args) != 4:
98
    print 'createPromotion requires 4 args'
99
    sys.exit(1)
100
  pp.pprint(client.createPromotion(args[0],args[1],eval(args[2]),eval(args[3]),))
101
 
6301 amit.gupta 102
elif cmd == 'getCoupon':
103
  if len(args) != 1:
104
    print 'getCoupon requires 1 args'
105
    sys.exit(1)
106
  pp.pprint(client.getCoupon(args[0],))
107
 
108
elif cmd == 'isGiftVoucher':
109
  if len(args) != 1:
110
    print 'isGiftVoucher requires 1 args'
111
    sys.exit(1)
112
  pp.pprint(client.isGiftVoucher(args[0],))
113
 
6356 amit.gupta 114
elif cmd == 'isCodApplicable':
115
  if len(args) != 1:
116
    print 'isCodApplicable requires 1 args'
117
    sys.exit(1)
118
  pp.pprint(client.isCodApplicable(args[0],))
119
 
1976 varun.gupt 120
elif cmd == 'getAllPromotions':
121
  if len(args) != 0:
122
    print 'getAllPromotions requires 0 args'
123
    sys.exit(1)
124
  pp.pprint(client.getAllPromotions())
125
 
126
elif cmd == 'getPromotionById':
127
  if len(args) != 1:
128
    print 'getPromotionById requires 1 args'
129
    sys.exit(1)
130
  pp.pprint(client.getPromotionById(eval(args[0]),))
131
 
132
elif cmd == 'generateCouponsForPromotion':
133
  if len(args) != 2:
134
    print 'generateCouponsForPromotion requires 2 args'
135
    sys.exit(1)
136
  pp.pprint(client.generateCouponsForPromotion(eval(args[0]),args[1],))
137
 
138
elif cmd == 'applyCoupon':
139
  if len(args) != 2:
140
    print 'applyCoupon requires 2 args'
141
    sys.exit(1)
142
  pp.pprint(client.applyCoupon(args[0],eval(args[1]),))
143
 
6433 anupam.sin 144
elif cmd == 'applyRechargeCoupon':
145
  if len(args) != 3:
146
    print 'applyRechargeCoupon requires 3 args'
147
    sys.exit(1)
148
  pp.pprint(client.applyRechargeCoupon(args[0],eval(args[1]),eval(args[2]),))
149
 
1976 varun.gupt 150
elif cmd == 'trackCouponUsage':
151
  if len(args) != 3:
152
    print 'trackCouponUsage requires 3 args'
153
    sys.exit(1)
154
  pp.pprint(client.trackCouponUsage(args[0],eval(args[1]),eval(args[2]),))
155
 
156
elif cmd == 'getCouponUsageCountByUser':
157
  if len(args) != 2:
158
    print 'getCouponUsageCountByUser requires 2 args'
159
    sys.exit(1)
160
  pp.pprint(client.getCouponUsageCountByUser(args[0],eval(args[1]),))
161
 
6497 amit.gupta 162
elif cmd == 'getActiveCodes':
163
  if len(args) != 1:
164
    print 'getActiveCodes requires 1 args'
165
    sys.exit(1)
166
  pp.pprint(client.getActiveCodes(eval(args[0]),))
167
 
168
elif cmd == 'deleteCoupon':
169
  if len(args) != 1:
170
    print 'deleteCoupon requires 1 args'
171
    sys.exit(1)
172
  pp.pprint(client.deleteCoupon(args[0],))
173
 
3385 varun.gupt 174
elif cmd == 'getActiveCoupons':
175
  if len(args) != 0:
176
    print 'getActiveCoupons requires 0 args'
177
    sys.exit(1)
178
  pp.pprint(client.getActiveCoupons())
179
 
6250 amit.gupta 180
elif cmd == 'createCoupon':
6356 amit.gupta 181
  if len(args) != 6:
182
    print 'createCoupon requires 6 args'
6250 amit.gupta 183
    sys.exit(1)
6356 amit.gupta 184
  pp.pprint(client.createCoupon(eval(args[0]),eval(args[1]),args[2],eval(args[3]),eval(args[4]),eval(args[5]),))
6250 amit.gupta 185
 
3385 varun.gupt 186
elif cmd == 'getSuccessfulPaymentCountForCoupon':
187
  if len(args) != 1:
188
    print 'getSuccessfulPaymentCountForCoupon requires 1 args'
189
    sys.exit(1)
190
  pp.pprint(client.getSuccessfulPaymentCountForCoupon(args[0],))
191
 
192
elif cmd == 'getRuleDocString':
193
  if len(args) != 1:
194
    print 'getRuleDocString requires 1 args'
195
    sys.exit(1)
196
  pp.pprint(client.getRuleDocString(args[0],))
197
 
4189 varun.gupt 198
elif cmd == 'getItemDiscountMap':
199
  if len(args) != 1:
200
    print 'getItemDiscountMap requires 1 args'
201
    sys.exit(1)
202
  pp.pprint(client.getItemDiscountMap(eval(args[0]),))
203
 
4494 varun.gupt 204
elif cmd == 'getDiscountsForEntity':
205
  if len(args) != 1:
206
    print 'getDiscountsForEntity requires 1 args'
207
    sys.exit(1)
208
  pp.pprint(client.getDiscountsForEntity(eval(args[0]),))
209
 
5469 rajveer 210
elif cmd == 'addVoucher':
211
  if len(args) != 1:
212
    print 'addVoucher requires 1 args'
213
    sys.exit(1)
214
  pp.pprint(client.addVoucher(eval(args[0]),))
215
 
216
elif cmd == 'assignVoucher':
217
  if len(args) != 4:
218
    print 'assignVoucher requires 4 args'
219
    sys.exit(1)
220
  pp.pprint(client.assignVoucher(eval(args[0]),args[1],eval(args[2]),eval(args[3]),))
221
 
222
elif cmd == 'markVoucherAsRedeemed':
223
  if len(args) != 2:
224
    print 'markVoucherAsRedeemed requires 2 args'
225
    sys.exit(1)
226
  pp.pprint(client.markVoucherAsRedeemed(args[0],eval(args[1]),))
227
 
3431 rajveer 228
else:
229
  print 'Unrecognized method %s' % cmd
230
  sys.exit(1)
231
 
1976 varun.gupt 232
transport.close()