Subversion Repositories SmartDukaan

Rev

Rev 1976 | Rev 3431 | 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
#
3
# Autogenerated by Thrift
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 closeSession()'
25
  print '  void createPromotion(string name, string ruleExecutionSrc, i64 startOn, i64 endOn)'
26
  print '   getAllPromotions()'
27
  print '  Promotion getPromotionById(i64 promotionId)'
28
  print '  void generateCouponsForPromotion(i64 promotionId, string couponCode)'
29
  print '  Cart applyCoupon(string couponCode, i64 cartId)'
30
  print '  void trackCouponUsage(string couponCode, i64 transactionId, i64 userId)'
31
  print '  i64 getCouponUsageCountByUser(string couponCode, i64 userId)'
3385 varun.gupt 32
  print '   getActiveCoupons()'
33
  print '  i64 getSuccessfulPaymentCountForCoupon(string couponCode)'
34
  print '  string getRuleDocString(string ruleName)'
1976 varun.gupt 35
  print ''
36
  sys.exit(0)
37
 
38
pp = pprint.PrettyPrinter(indent = 2)
39
host = 'localhost'
40
port = 9090
41
uri = ''
42
framed = False
43
http = False
44
argi = 1
45
 
46
if sys.argv[argi] == '-h':
47
  parts = sys.argv[argi+1].split(':') 
48
  host = parts[0]
49
  port = int(parts[1])
50
  argi += 2
51
 
52
if sys.argv[argi] == '-u':
53
  url = urlparse(sys.argv[argi+1])
54
  parts = url[1].split(':') 
55
  host = parts[0]
56
  if len(parts) > 1:
57
    port = int(parts[1])
58
  else:
59
    port = 80
60
  uri = url[2]
61
  http = True
62
  argi += 2
63
 
64
if sys.argv[argi] == '-f' or sys.argv[argi] == '-framed':
65
  framed = True
66
  argi += 1
67
 
68
cmd = sys.argv[argi]
69
args = sys.argv[argi+1:]
70
 
71
if http:
72
  transport = THttpClient.THttpClient(host, port, uri)
73
else:
74
  socket = TSocket.TSocket(host, port)
75
  if framed:
76
    transport = TTransport.TFramedTransport(socket)
77
  else:
78
    transport = TTransport.TBufferedTransport(socket)
79
protocol = TBinaryProtocol.TBinaryProtocol(transport)
80
client = PromotionService.Client(protocol)
81
transport.open()
82
 
83
if cmd == 'closeSession':
84
  if len(args) != 0:
85
    print 'closeSession requires 0 args'
86
    sys.exit(1)
87
  pp.pprint(client.closeSession())
88
 
89
elif cmd == 'createPromotion':
90
  if len(args) != 4:
91
    print 'createPromotion requires 4 args'
92
    sys.exit(1)
93
  pp.pprint(client.createPromotion(args[0],args[1],eval(args[2]),eval(args[3]),))
94
 
95
elif cmd == 'getAllPromotions':
96
  if len(args) != 0:
97
    print 'getAllPromotions requires 0 args'
98
    sys.exit(1)
99
  pp.pprint(client.getAllPromotions())
100
 
101
elif cmd == 'getPromotionById':
102
  if len(args) != 1:
103
    print 'getPromotionById requires 1 args'
104
    sys.exit(1)
105
  pp.pprint(client.getPromotionById(eval(args[0]),))
106
 
107
elif cmd == 'generateCouponsForPromotion':
108
  if len(args) != 2:
109
    print 'generateCouponsForPromotion requires 2 args'
110
    sys.exit(1)
111
  pp.pprint(client.generateCouponsForPromotion(eval(args[0]),args[1],))
112
 
113
elif cmd == 'applyCoupon':
114
  if len(args) != 2:
115
    print 'applyCoupon requires 2 args'
116
    sys.exit(1)
117
  pp.pprint(client.applyCoupon(args[0],eval(args[1]),))
118
 
119
elif cmd == 'trackCouponUsage':
120
  if len(args) != 3:
121
    print 'trackCouponUsage requires 3 args'
122
    sys.exit(1)
123
  pp.pprint(client.trackCouponUsage(args[0],eval(args[1]),eval(args[2]),))
124
 
125
elif cmd == 'getCouponUsageCountByUser':
126
  if len(args) != 2:
127
    print 'getCouponUsageCountByUser requires 2 args'
128
    sys.exit(1)
129
  pp.pprint(client.getCouponUsageCountByUser(args[0],eval(args[1]),))
130
 
3385 varun.gupt 131
elif cmd == 'getActiveCoupons':
132
  if len(args) != 0:
133
    print 'getActiveCoupons requires 0 args'
134
    sys.exit(1)
135
  pp.pprint(client.getActiveCoupons())
136
 
137
elif cmd == 'getSuccessfulPaymentCountForCoupon':
138
  if len(args) != 1:
139
    print 'getSuccessfulPaymentCountForCoupon requires 1 args'
140
    sys.exit(1)
141
  pp.pprint(client.getSuccessfulPaymentCountForCoupon(args[0],))
142
 
143
elif cmd == 'getRuleDocString':
144
  if len(args) != 1:
145
    print 'getRuleDocString requires 1 args'
146
    sys.exit(1)
147
  pp.pprint(client.getRuleDocString(args[0],))
148
 
1976 varun.gupt 149
transport.close()