Module: TinyBuilder::ApigatewayHelper
- Included in:
- ZaloraQuantity
- Defined in:
- lib/tiny_builder/apigateway_helper.rb
Instance Method Summary collapse
- #headers ⇒ Object
- #rest_client(params, rescued_codes = 200) ⇒ Object
- #zalora_stock_payload(listing) ⇒ Object
- #zalora_stock_url ⇒ Object
Instance Method Details
#headers ⇒ Object
22 23 24 |
# File 'lib/tiny_builder/apigateway_helper.rb', line 22 def headers { content_type: :json, accept: :json } end |
#rest_client(params, rescued_codes = 200) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/tiny_builder/apigateway_helper.rb', line 5 def rest_client(params, rescued_codes = 200) RestClient::Request.execute(params.merge(timeout: 3)) do |response| code = response.code resp = response.body.to_str unless Array.wrap(rescued_codes).include?(code) raise "Response Code is #{code}" unless resp.include?('Response code = 404') end response end end |
#zalora_stock_payload(listing) ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/tiny_builder/apigateway_helper.rb', line 26 def zalora_stock_payload(listing) { "credential": credential, "data": { "productId": listing[:local_id] } }.to_json end |
#zalora_stock_url ⇒ Object
17 18 19 20 |
# File 'lib/tiny_builder/apigateway_helper.rb', line 17 def zalora_stock_url url = ENV['API_GATEWAY_URL'] || raise('api gateway is not set') url + "/zalora/listing_stock" end |