Class: ActsAsAtdw::Client
- Inherits:
-
Object
- Object
- ActsAsAtdw::Client
- Defined in:
- lib/client.rb
Instance Method Summary collapse
- #get_specific_product_record(options = {}) ⇒ Object
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
- #query_product_records(options = {}) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
7 8 9 10 11 12 13 14 15 |
# File 'lib/client.rb', line 7 def initialize( = {}) @api_key = [:api_key] Savon.configure do |config| config.log = false end @client = Savon::Client.new do wsdl.document = "http://national.atdw.com.au/soap/AustralianTourismWebService.asmx?WSDL" end end |
Instance Method Details
#get_specific_product_record(options = {}) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/client.rb', line 50 def get_specific_product_record( = {}) api_key = @api_key response = @client.request "get_specific_product_record" do soap.namespaces["xmlns:xsi"] = "http://www.w3.org/2001/XMLSchema-instance" soap.namespaces["xmlns:xsd"] = "http://www.w3.org/2001/XMLSchema" soap.namespaces["xmlns:soap"] = "http://schemas.xmlsoap.org/soap/envelope/" soap.body = {"DistributorKey" => "#{api_key}"} .each do |key, value| soap.body[key] = value end end result = XmlSimple.xml_in(response.body[:get_specific_product_record_response][:get_specific_product_record_result].gsub("<?xml version=\"1.0\" encoding=\"utf-16\" ?>", "")) if result["error"] && result["error"] == ["No rows returned"] return nil elsif result["product_distribution"] return result["product_distribution"].first else return nil end end |
#query_product_records(options = {}) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/client.rb', line 17 def query_product_records( = {}) api_key = @api_key response = @client.request "query_product_records" do soap.namespaces["xmlns:xsi"] = "http://www.w3.org/2001/XMLSchema-instance" soap.namespaces["xmlns:xsd"] = "http://www.w3.org/2001/XMLSchema" soap.namespaces["xmlns:soap"] = "http://schemas.xmlsoap.org/soap/envelope/" soap.body = {"DistributorKey" => "#{api_key}"} .each do |key, value| soap.body[key] = value end end result = XmlSimple.xml_in(response.body[:query_product_records_response][:query_product_records_result].gsub("<?xml version=\"1.0\" encoding=\"utf-16\" ?>", "")) if result["error"] && result["error"] == ["No rows returned"] return [] elsif result["product_distribution"] results = [] result["product_distribution"].each do |result| results << Hashit.new(result["product_record"].first) #results << result end return results else return [] end end |