Sha256: 175859ee8bc7e7d7a3220b9bd74a4e29d86d5b618e5831eeea4f50a1f99fcb9b
Contents?: true
Size: 1.57 KB
Versions: 1
Compression:
Stored size: 1.57 KB
Contents
require 'httparty' require 'logger' module ShadowfaxApi class << self def logger @logger ||= begin logger= Logger.new(STDOUT) logger.level = Logger::WARN logger end end def logger=(logger) @logger=logger end def get_servicable_pincodes response = send_request(url('serviceable_pincodes'),respond: 'requests') end def check_serviceable_pincode(pincode) response = send_request(url('check_serviceable_pincodes',pincode.to_s)) end def get_delivery_details(awb_number) response = send_request(url(awb_number)) end def cancel_delivery_request(data) send_request(url('cancel_order'),method: :put,data: data) end def create_package(data) send_request(url,method: :post,data: data) end def get_bulk_query(data) send_request(url('bulk_query'),method: :post,data: data) end private def url(*args) args.size == 0 ? Configuration.config[:url] : "#{Configuration.config[:url]}/" + args.join("/") end def send_request(url,method: :get,data: nil,respond: nil) options = {headers: headers} options[:body] = data.to_json if data response = HTTParty.send(method,url,options) logger.debug(response.to_s) if respond.present? response[respond] || Exception.raise_exception(response) else JSON.parse(response.body) end end def headers @headers ||= {'Authorization' => "Token #{Configuration.config[:key]}", 'Content-Type' => 'application/json'}.freeze end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
shadowfax_api-0.1.0 | lib/shadowfax_api/shadowfax_api.rb |