Class: MDEXClient::Client
- Inherits:
-
Object
- Object
- MDEXClient::Client
- Defined in:
- lib/mdex_client/client.rb
Constant Summary collapse
- NAMESPACES =
{ "env" => "http://schemas.xmlsoap.org/soap/envelope/", "mdata" => "http://www.endeca.com/MDEX/data/IR600" }
Instance Attribute Summary collapse
-
#login ⇒ Object
Returns the value of attribute login.
-
#password ⇒ Object
Returns the value of attribute password.
-
#soap_client ⇒ Object
readonly
Returns the value of attribute soap_client.
Class Method Summary collapse
Instance Method Summary collapse
- #dimension_value_id_from_path(path) ⇒ Object
-
#initialize(&block) ⇒ Client
constructor
A new instance of Client.
- #navigation_query(params = nil) ⇒ Object
- #query_each(params) ⇒ Object
- #xquery(xquery) ⇒ Object
Constructor Details
#initialize(&block) ⇒ Client
Returns a new instance of Client.
21 22 23 24 25 |
# File 'lib/mdex_client/client.rb', line 21 def initialize(&block) @soap_client = Savon::Client.new do process 1, &block if block end end |
Instance Attribute Details
#login ⇒ Object
Returns the value of attribute login.
7 8 9 |
# File 'lib/mdex_client/client.rb', line 7 def login @login end |
#password ⇒ Object
Returns the value of attribute password.
7 8 9 |
# File 'lib/mdex_client/client.rb', line 7 def password @password end |
#soap_client ⇒ Object (readonly)
Returns the value of attribute soap_client.
6 7 8 |
# File 'lib/mdex_client/client.rb', line 6 def soap_client @soap_client end |
Class Method Details
.namespace_declarations ⇒ Object
14 15 16 17 18 19 |
# File 'lib/mdex_client/client.rb', line 14 def self.namespace_declarations NAMESPACES.inject({}) do |memo, (name, uri)| memo["xmlns:#{name}"] = uri memo end end |
Instance Method Details
#dimension_value_id_from_path(path) ⇒ Object
43 44 45 46 47 48 49 50 51 |
# File 'lib/mdex_client/client.rb', line 43 def dimension_value_id_from_path(path) quoted_path = path.collect do |item| "\"#{item}\"" end response = xquery("mdex:dimension-value-id-from-path((#{quoted_path.join(",")}))") result = response.xpath("mdata:UntypedResult/mdata:Result", NAMESPACES) result && result.text.to_i end |
#navigation_query(params = nil) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/mdex_client/client.rb', line 53 def (params=nil) query = case params when MData::NavigationQuery params else MData::NavigationQuery.new(params) end xml = Builder::XmlMarkup.new xml.mdata :Query do query.write_xml!(xml) end response = xquery("mdex:navigation-query(#{xml.target!})") MData::NavigationResult.new(response.xpath("mdata:TypedResult/mdata:NavigationResults", NAMESPACES)) end |
#query_each(params) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/mdex_client/client.rb', line 70 def query_each(params) query = case params when MData::NavigationQuery params.dup else MData::NavigationQuery.new(params) end query.record_offset ||= 0 while true result = (query) result.records.each do |record| yield record end break if result.records_per_page + result.offset > result.total_record_count query.record_offset += result.records_per_page end end |
#xquery(xquery) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/mdex_client/client.rb', line 27 def xquery(xquery) response = @soap_client.request("Request") do soap.xml do |xml| xml.env(:Envelope, MDEXClient::Client.namespace_declarations) do xml.env :Header xml.env(:Body) do xml.mdata :Request, xquery end end end end response_xml = Nokogiri::XML::Document.parse(response.to_xml) response_xml.xpath("/env:Envelope/env:Body/mdata:Response", NAMESPACES) end |