Class: TecDoc::Client
- Inherits:
-
Object
- Object
- TecDoc::Client
- Defined in:
- lib/tec_doc/client.rb
Instance Attribute Summary collapse
-
#connection ⇒ Object
Returns the value of attribute connection.
-
#country ⇒ Object
Returns the value of attribute country.
-
#logger ⇒ Object
Returns the logger.
-
#mode ⇒ Object
Returns the value of attribute mode.
-
#provider ⇒ Object
Returns the value of attribute provider.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
- #log(operation, options) ⇒ Object
- #request(operation, options = {}) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
5 6 7 8 9 10 11 12 13 |
# File 'lib/tec_doc/client.rb', line 5 def initialize( = {}) self.provider = [:provider] self.country = [:country] self.connection = Savon::Client.new do |wsdl, http| proxy = [:proxy] || ENV['http_proxy'] http.proxy = proxy if proxy end self.mode = [:mode] || :live end |
Instance Attribute Details
#connection ⇒ Object
Returns the value of attribute connection.
3 4 5 |
# File 'lib/tec_doc/client.rb', line 3 def connection @connection end |
#country ⇒ Object
Returns the value of attribute country.
3 4 5 |
# File 'lib/tec_doc/client.rb', line 3 def country @country end |
#logger ⇒ Object
Returns the logger. Defaults to an instance of Logger
writing to STDOUT.
52 53 54 |
# File 'lib/tec_doc/client.rb', line 52 def logger @logger ||= ::Logger.new STDOUT end |
#mode ⇒ Object
Returns the value of attribute mode.
46 47 48 |
# File 'lib/tec_doc/client.rb', line 46 def mode @mode end |
#provider ⇒ Object
Returns the value of attribute provider.
3 4 5 |
# File 'lib/tec_doc/client.rb', line 3 def provider @provider end |
Instance Method Details
#log(operation, options) ⇒ Object
56 57 58 59 60 61 62 |
# File 'lib/tec_doc/client.rb', line 56 def log(operation, ) t = Time.now results = yield duration = 1000.0 * (Time.now - t) logger.info "TecDoc: #{operation.inspect} #{options.inspect} #{'(%.1fms)' % duration}" results end |
#request(operation, options = {}) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/tec_doc/client.rb', line 15 def request(operation, = {}) log operation, do response = connection.request(operation) do soap.body = { :in => { :provider => provider }.merge() } end # Parse errors status_node = response.doc.xpath("//status").first if status_node.text != "200" status_text_node = response.doc.xpath("//statusText").first raise Error.new(status_text_node.text) end # Parse the document response.doc.xpath("//data/array/array").map do |node| node_to_hash(node) end # response end end |