hongbao-service-api 0.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 55cea908c0f1e78a3bfb33b075e0f6f0caae18c0
4
+ data.tar.gz: 74c414d91c01ac06ed1692fd5d12fdff30cc75e2
5
+ SHA512:
6
+ metadata.gz: f93c6b848de2eabb0bcff252069c6a33ef10f74e9ca67029993b9f0d274f00b7368f66c86f163bf778ed9941fd130036f4c82c590e0fd166511bdd65c96aa8d7
7
+ data.tar.gz: 6e598206865eef9f8621ce12bbe4269cd7d0440c27bafbe3faf47c3d504d0be5a96024649e62f5590ba39aa46aade781d19f047ab3891f99132832017a363dee
@@ -0,0 +1,364 @@
1
+ #
2
+ # Autogenerated by Thrift Compiler (0.9.3-airbnb11)
3
+ #
4
+ # DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
5
+ #
6
+ # Generated from service IDL version 'no version'
7
+ #
8
+
9
+ require 'thrift'
10
+ require 'sparsam'
11
+ require 'airbnb/service/hongbao/api/hongbao_data_0_forward_declare_types'
12
+ # Generated from service IDL version 'no version'
13
+
14
+
15
+ require 'airbnb/service/api/client_base'
16
+
17
+ module Airbnb
18
+ module Service
19
+ module Hongbao
20
+ module Api
21
+ class ApiClient < ::Airbnb::Service::Api::ClientBase
22
+
23
+ IDL_VERSION = 'no version'
24
+ HOST_KEY = :host
25
+ PORT_KEY = :port
26
+ THRAWN_KEY = :thrawn
27
+ PAYLOAD_TYPE = :thrift
28
+
29
+ CLIENT_CONFIG = {
30
+ name: 'Hongbao',
31
+ caller: 'rails',
32
+ thrawn: {
33
+ host: 'hongbao.synapse',
34
+ port: 6756,
35
+ request_format: :thrift,
36
+ response_format: :thrift,
37
+ raise_errors: true,
38
+ timeout: 10,
39
+ connect_timeout: 10,
40
+ retries: 1,
41
+ down_failures: 3,
42
+ down_retry_delay: 100,
43
+ max_requests: 500,
44
+ },
45
+ }.freeze
46
+
47
+ private_class_method :new
48
+
49
+ def self.instance(params = {})
50
+ @@instance ||= new(params)
51
+ end
52
+
53
+ def initialize(params = {})
54
+ @client_config = client_config(params)
55
+ cert_configs = {}
56
+ if params[:cert_common_name]
57
+ cert_configs[:cert_common_name] = params[:cert_common_name]
58
+ end
59
+ @thrawn_client = ::Airbnb::Service::Api::ClientBase.setup_thrawn(@client_config.merge(cert_configs))
60
+ @options = (params || {})
61
+ @logger = begin
62
+ if defined?(Rails.logger)
63
+ @logger = Rails.logger
64
+ else
65
+ @logger = Logger.new(STDERR)
66
+ @logger.progname = 'Hongbao::ApiClient'
67
+ end
68
+ @logger
69
+ end
70
+ end
71
+
72
+ def client_config(params = {})
73
+ if params.key?(HOST_KEY) or params.key?(PORT_KEY)
74
+ client_config = Marshal.load(Marshal.dump(CLIENT_CONFIG))
75
+ client_config[THRAWN_KEY][HOST_KEY] = params[HOST_KEY] if params[HOST_KEY]
76
+ client_config[THRAWN_KEY][PORT_KEY] = params[PORT_KEY] if params[PORT_KEY]
77
+ client_config
78
+ else
79
+ CLIENT_CONFIG
80
+ end
81
+ end
82
+
83
+ # hello
84
+ def hello(request)
85
+ serialized_req = request.serialize(Sparsam::CompactProtocol)
86
+ response = send_thrawn_request("/Hongbao/hello", "hello", serialized_req)
87
+ if response
88
+ Sparsam::Deserializer.deserialize(::Airbnb::Service::Hongbao::Api::HelloResponse, response, Sparsam::CompactProtocol)
89
+ else
90
+ nil
91
+ end
92
+ rescue Thrawn::UnsuccessfulResponseError => e
93
+ self.class.check_unsuccessful_response_error(e)
94
+ end
95
+
96
+ # getUser
97
+ def get_user(request)
98
+ serialized_req = request.serialize(Sparsam::CompactProtocol)
99
+ response = send_thrawn_request("/Hongbao/getUser", "getUser", serialized_req)
100
+ if response
101
+ Sparsam::Deserializer.deserialize(::Airbnb::Service::Hongbao::Api::UserResponse, response, Sparsam::CompactProtocol)
102
+ else
103
+ nil
104
+ end
105
+ rescue Thrawn::UnsuccessfulResponseError => e
106
+ self.class.check_unsuccessful_response_error(e)
107
+ end
108
+
109
+ # hasChinaCoupon
110
+ def has_china_coupon(request)
111
+ serialized_req = request.serialize(Sparsam::CompactProtocol)
112
+ response = send_thrawn_request("/Hongbao/hasChinaCoupon", "hasChinaCoupon", serialized_req)
113
+ if response
114
+ Sparsam::Deserializer.deserialize(::Airbnb::Service::Hongbao::Api::HasChinaCouponResponse, response, Sparsam::CompactProtocol)
115
+ else
116
+ nil
117
+ end
118
+ rescue Thrawn::UnsuccessfulResponseError => e
119
+ self.class.check_unsuccessful_response_error(e)
120
+ end
121
+
122
+ # fetchCouponState
123
+ def fetch_coupon_state(request)
124
+ serialized_req = request.serialize(Sparsam::CompactProtocol)
125
+ response = send_thrawn_request("/Hongbao/fetchCouponState", "fetchCouponState", serialized_req)
126
+ if response
127
+ Sparsam::Deserializer.deserialize(::Airbnb::Service::Hongbao::Api::HongbaoCouponStateResponse, response, Sparsam::CompactProtocol)
128
+ else
129
+ nil
130
+ end
131
+ rescue Thrawn::UnsuccessfulResponseError => e
132
+ self.class.check_unsuccessful_response_error(e)
133
+ end
134
+
135
+ # fetchCouponData
136
+ def fetch_coupon_data(request)
137
+ serialized_req = request.serialize(Sparsam::CompactProtocol)
138
+ response = send_thrawn_request("/Hongbao/fetchCouponData", "fetchCouponData", serialized_req)
139
+ if response
140
+ Sparsam::Deserializer.deserialize(::Airbnb::Service::Hongbao::Api::HongbaoCouponDataResponse, response, Sparsam::CompactProtocol)
141
+ else
142
+ nil
143
+ end
144
+ rescue Thrawn::UnsuccessfulResponseError => e
145
+ self.class.check_unsuccessful_response_error(e)
146
+ end
147
+
148
+ # fetchActiveCampaign
149
+ def fetch_active_campaign(request)
150
+ serialized_req = request.serialize(Sparsam::CompactProtocol)
151
+ response = send_thrawn_request("/Hongbao/fetchActiveCampaign", "fetchActiveCampaign", serialized_req)
152
+ if response
153
+ Sparsam::Deserializer.deserialize(::Airbnb::Service::Hongbao::Api::HongbaoActiveCampaignResponse, response, Sparsam::CompactProtocol)
154
+ else
155
+ nil
156
+ end
157
+ rescue Thrawn::UnsuccessfulResponseError => e
158
+ self.class.check_unsuccessful_response_error(e)
159
+ end
160
+
161
+ # fetchCampaignData
162
+ def fetch_campaign_data(request)
163
+ serialized_req = request.serialize(Sparsam::CompactProtocol)
164
+ response = send_thrawn_request("/Hongbao/fetchCampaignData", "fetchCampaignData", serialized_req)
165
+ if response
166
+ Sparsam::Deserializer.deserialize(::Airbnb::Service::Hongbao::Api::HongbaoCampaignDataResponse, response, Sparsam::CompactProtocol)
167
+ else
168
+ nil
169
+ end
170
+ rescue Thrawn::UnsuccessfulResponseError => e
171
+ self.class.check_unsuccessful_response_error(e)
172
+ end
173
+
174
+ # getUserChinaCoupons
175
+ def get_user_china_coupons(request)
176
+ serialized_req = request.serialize(Sparsam::CompactProtocol)
177
+ response = send_thrawn_request("/Hongbao/getUserChinaCoupons", "getUserChinaCoupons", serialized_req)
178
+ if response
179
+ Sparsam::Deserializer.deserialize(::Airbnb::Service::Hongbao::Api::HongbaoGetUserChinaCouponsResponse, response, Sparsam::CompactProtocol)
180
+ else
181
+ nil
182
+ end
183
+ rescue Thrawn::UnsuccessfulResponseError => e
184
+ self.class.check_unsuccessful_response_error(e)
185
+ end
186
+
187
+ # getCtaLink
188
+ def get_cta_link(request)
189
+ serialized_req = request.serialize(Sparsam::CompactProtocol)
190
+ response = send_thrawn_request("/Hongbao/getCtaLink", "getCtaLink", serialized_req)
191
+ if response
192
+ Sparsam::Deserializer.deserialize(::Airbnb::Service::Hongbao::Api::HongbaoGetCtaLinkResponse, response, Sparsam::CompactProtocol)
193
+ else
194
+ nil
195
+ end
196
+ rescue Thrawn::UnsuccessfulResponseError => e
197
+ self.class.check_unsuccessful_response_error(e)
198
+ end
199
+
200
+ # getCouponMessages
201
+ def get_coupon_messages(request)
202
+ serialized_req = request.serialize(Sparsam::CompactProtocol)
203
+ response = send_thrawn_request("/Hongbao/getCouponMessages", "getCouponMessages", serialized_req)
204
+ if response
205
+ Sparsam::Deserializer.deserialize(::Airbnb::Service::Hongbao::Api::HongbaoGetCouponMessagesResponse, response, Sparsam::CompactProtocol)
206
+ else
207
+ nil
208
+ end
209
+ rescue Thrawn::UnsuccessfulResponseError => e
210
+ self.class.check_unsuccessful_response_error(e)
211
+ end
212
+
213
+ # canClaimInApp
214
+ def can_claim_in_app(request)
215
+ serialized_req = request.serialize(Sparsam::CompactProtocol)
216
+ response = send_thrawn_request("/Hongbao/canClaimInApp", "canClaimInApp", serialized_req)
217
+ if response
218
+ Sparsam::Deserializer.deserialize(::Airbnb::Service::Hongbao::Api::HongbaoCanClaimInAppResponse, response, Sparsam::CompactProtocol)
219
+ else
220
+ nil
221
+ end
222
+ rescue Thrawn::UnsuccessfulResponseError => e
223
+ self.class.check_unsuccessful_response_error(e)
224
+ end
225
+
226
+ # fetchReferralStatus
227
+ def fetch_referral_status(request)
228
+ serialized_req = request.serialize(Sparsam::CompactProtocol)
229
+ response = send_thrawn_request("/Hongbao/fetchReferralStatus", "fetchReferralStatus", serialized_req)
230
+ if response
231
+ Sparsam::Deserializer.deserialize(::Airbnb::Service::Hongbao::Api::HongbaoReferralStatusResponse, response, Sparsam::CompactProtocol)
232
+ else
233
+ nil
234
+ end
235
+ rescue Thrawn::UnsuccessfulResponseError => e
236
+ self.class.check_unsuccessful_response_error(e)
237
+ end
238
+
239
+ # getCampaignTextData
240
+ def get_campaign_text_data(request)
241
+ serialized_req = request.serialize(Sparsam::CompactProtocol)
242
+ response = send_thrawn_request("/Hongbao/getCampaignTextData", "getCampaignTextData", serialized_req)
243
+ if response
244
+ Sparsam::Deserializer.deserialize(::Airbnb::Service::Hongbao::Api::HongbaoCampaignTextDataResponse, response, Sparsam::CompactProtocol)
245
+ else
246
+ nil
247
+ end
248
+ rescue Thrawn::UnsuccessfulResponseError => e
249
+ self.class.check_unsuccessful_response_error(e)
250
+ end
251
+
252
+ def send_thrawn_request(resource_url, resource_endpoint, request = nil, options = {})
253
+ if request
254
+ options = options.merge({
255
+ :body => request,
256
+ })
257
+ end
258
+
259
+ DOGSTATSD.count('services_platform.client.request.count',
260
+ 1,
261
+ :tags => [
262
+ "caller:#{@client_config[:caller]}",
263
+ 'service:Hongbao',
264
+ 'client_for:Hongbao',
265
+ "resource_endpoint:#{resource_url}",
266
+ "method:#{resource_endpoint}",
267
+ "content_type:#{PAYLOAD_TYPE}",
268
+ 'language:ruby',
269
+ ],
270
+ )
271
+ start_time = Time.now
272
+ response = ::Airbnb::Service::Api::ClientBase.send_request(@thrawn_client, :post, resource_url, @client_config, options)
273
+ status = 'success'
274
+ response
275
+ rescue Thrawn::UnsuccessfulResponseError => e
276
+ status = 'error'
277
+ parsed_body = e.response.parsed_body
278
+ exception_class = e.response.parsed_body['exception_cls'] if (parsed_body && parsed_body.is_a?(Hash))
279
+ exception_type = 'service'
280
+ @logger.error "hongbao Ruby client Timeout:#{e} Path:#{resource_url}"
281
+ raise e
282
+ rescue Exception => e
283
+ status = 'error'
284
+ exception_class = "#{e.class}"
285
+ exception_type = 'unchecked'
286
+ @logger.error "hongbao Ruby client error:#{e} Path:#{resource_url}"
287
+ raise e
288
+ ensure
289
+ elapsed_time_milliseconds = (Time.now - start_time) * 1000.0
290
+ DOGSTATSD.histogram('services_platform.client.response',
291
+ elapsed_time_milliseconds,
292
+ :tags => [
293
+ "caller:#{@client_config[:caller]}",
294
+ 'service:Hongbao',
295
+ 'client_for:Hongbao',
296
+ "resource_endpoint:#{resource_url}",
297
+ "method:#{resource_endpoint}",
298
+ "content_type:#{PAYLOAD_TYPE}",
299
+ 'language:ruby',
300
+ "status:#{status}",
301
+ ],
302
+ )
303
+ if status == 'error'
304
+ DOGSTATSD.count('services_platform.client.exception.count',
305
+ 1,
306
+ :tags => [
307
+ "caller:#{@client_config[:caller]}",
308
+ 'service:Hongbao',
309
+ 'client_for:Hongbao',
310
+ "resource_endpoint:#{resource_url}",
311
+ "method:#{resource_endpoint}",
312
+ "content_type:#{PAYLOAD_TYPE}",
313
+ 'language:ruby',
314
+ "exception_class:#{exception_class}",
315
+ "exception_type:#{exception_type}",
316
+ ],
317
+ )
318
+ end
319
+ end
320
+
321
+ def self.check_unsuccessful_response_error(error)
322
+ status = error.response.status
323
+ # Thrawn thrift format does not parse body
324
+ body = JSON.parse(error.response.parsed_body)
325
+ if status == 851
326
+ case body["exception_cls"]
327
+ when "HasChinaCouponException"
328
+ raise ::Airbnb::Service::Hongbao::Api::HasChinaCouponException.build(body["exception_msg"])
329
+ when "HelloException"
330
+ raise ::Airbnb::Service::Hongbao::Api::HelloException.build(body["exception_msg"])
331
+ when "HongbaoActiveCampaignException"
332
+ raise ::Airbnb::Service::Hongbao::Api::HongbaoActiveCampaignException.build(body["exception_msg"])
333
+ when "HongbaoCampaignDataException"
334
+ raise ::Airbnb::Service::Hongbao::Api::HongbaoCampaignDataException.build(body["exception_msg"])
335
+ when "HongbaoCampaignTextDataException"
336
+ raise ::Airbnb::Service::Hongbao::Api::HongbaoCampaignTextDataException.build(body["exception_msg"])
337
+ when "HongbaoCanClaimInAppException"
338
+ raise ::Airbnb::Service::Hongbao::Api::HongbaoCanClaimInAppException.build(body["exception_msg"])
339
+ when "HongbaoCouponDataException"
340
+ raise ::Airbnb::Service::Hongbao::Api::HongbaoCouponDataException.build(body["exception_msg"])
341
+ when "HongbaoCouponStateException"
342
+ raise ::Airbnb::Service::Hongbao::Api::HongbaoCouponStateException.build(body["exception_msg"])
343
+ when "HongbaoGetCouponMessagesException"
344
+ raise ::Airbnb::Service::Hongbao::Api::HongbaoGetCouponMessagesException.build(body["exception_msg"])
345
+ when "HongbaoGetCtaLinkException"
346
+ raise ::Airbnb::Service::Hongbao::Api::HongbaoGetCtaLinkException.build(body["exception_msg"])
347
+ when "HongbaoGetUserChinaCouponsException"
348
+ raise ::Airbnb::Service::Hongbao::Api::HongbaoGetUserChinaCouponsException.build(body["exception_msg"])
349
+ when "HongbaoReferralStatusException"
350
+ raise ::Airbnb::Service::Hongbao::Api::HongbaoReferralStatusException.build(body["exception_msg"])
351
+ when "UserException"
352
+ raise ::Airbnb::Service::Hongbao::Api::UserException.build(body["exception_msg"])
353
+ end
354
+ else # Hadling framework standard erros, which is not defined by IDL
355
+ rethrow_standard_error(error, body)
356
+ end
357
+ raise error
358
+ end
359
+
360
+ end
361
+ end
362
+ end
363
+ end
364
+ end
@@ -0,0 +1,101 @@
1
+ #
2
+ # Autogenerated by Thrift Compiler (0.9.3-airbnb11)
3
+ #
4
+ # DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
5
+ #
6
+ # Generated from service IDL version 'no version'
7
+ #
8
+
9
+ require 'thrift'
10
+ require 'sparsam'
11
+
12
+
13
+ module Airbnb
14
+ module Service
15
+ module Hongbao
16
+ module Api
17
+ class HelloRequest < ::Sparsam::Struct
18
+ end
19
+
20
+ class HelloResponse < ::Sparsam::Struct
21
+ end
22
+
23
+ class UserRequest < ::Sparsam::Struct
24
+ end
25
+
26
+ class UserResponse < ::Sparsam::Struct
27
+ end
28
+
29
+ class HasChinaCouponRequest < ::Sparsam::Struct
30
+ end
31
+
32
+ class HasChinaCouponResponse < ::Sparsam::Struct
33
+ end
34
+
35
+ class HongbaoCouponStateRequest < ::Sparsam::Struct
36
+ end
37
+
38
+ class HongbaoCouponStateResponse < ::Sparsam::Struct
39
+ end
40
+
41
+ class HongbaoCouponDataRequest < ::Sparsam::Struct
42
+ end
43
+
44
+ class HongbaoCouponDataResponse < ::Sparsam::Struct
45
+ end
46
+
47
+ class CampaignData < ::Sparsam::Struct
48
+ end
49
+
50
+ class HongbaoActiveCampaignRequest < ::Sparsam::Struct
51
+ end
52
+
53
+ class HongbaoActiveCampaignResponse < ::Sparsam::Struct
54
+ end
55
+
56
+ class HongbaoCampaignDataRequest < ::Sparsam::Struct
57
+ end
58
+
59
+ class HongbaoCampaignDataResponse < ::Sparsam::Struct
60
+ end
61
+
62
+ class HongbaoGetUserChinaCouponsRequest < ::Sparsam::Struct
63
+ end
64
+
65
+ class HongbaoGetUserChinaCouponsResponse < ::Sparsam::Struct
66
+ end
67
+
68
+ class HongbaoGetCtaLinkRequest < ::Sparsam::Struct
69
+ end
70
+
71
+ class HongbaoGetCtaLinkResponse < ::Sparsam::Struct
72
+ end
73
+
74
+ class HongbaoGetCouponMessagesRequest < ::Sparsam::Struct
75
+ end
76
+
77
+ class HongbaoGetCouponMessagesResponse < ::Sparsam::Struct
78
+ end
79
+
80
+ class HongbaoCanClaimInAppRequest < ::Sparsam::Struct
81
+ end
82
+
83
+ class HongbaoCanClaimInAppResponse < ::Sparsam::Struct
84
+ end
85
+
86
+ class HongbaoReferralStatusRequest < ::Sparsam::Struct
87
+ end
88
+
89
+ class HongbaoReferralStatusResponse < ::Sparsam::Struct
90
+ end
91
+
92
+ class HongbaoCampaignTextDataRequest < ::Sparsam::Struct
93
+ end
94
+
95
+ class HongbaoCampaignTextDataResponse < ::Sparsam::Struct
96
+ end
97
+
98
+ end
99
+ end
100
+ end
101
+ end
@@ -0,0 +1,17 @@
1
+ #
2
+ # Autogenerated by Thrift Compiler (0.1.1)
3
+ #
4
+ # DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
5
+ #
6
+
7
+ require 'sparsam'
8
+ require 'airbnb/service/hongbao/api/hongbao_data_types'
9
+
10
+ module Airbnb
11
+ module Service
12
+ module Hongbao
13
+ module Api
14
+ end
15
+ end
16
+ end
17
+ end