Class: CPS::Client
Constant Summary collapse
- DEFAULT_TIMEOUT =
The Integer maximum time to run a cps query, expressed in seconds.
10
- CA_FILE =
crt file - deployed by puppet!
'/etc/ssl/certs/bundle.crt'
Instance Method Summary collapse
- #data ⇒ Object
- #entity(path) ⇒ Object
- #get_binding ⇒ Object
-
#initialize(options = {}) ⇒ Client
constructor
Initializes a new
Cps::Client
withoptions
. -
#query(object) ⇒ Object
Returns.
- #request ⇒ Object
- #result_code ⇒ Object
- #result_message ⇒ Object
- #template(xml) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Client
Initializes a new Cps::Client
with options
.
new( = {})
Parameters
- options
-
Hash of options: :timeout - The Integer script timeout, expressed in seconds (default: DEFAULT_TIMEOUT). :cid - Customer number :uid - User :pwd - Password
If block
is given, yields self
.
Returns
- Cps::Client
-
The client instance.
Examples
client = Cps::Client.new do |c|
c.timeout = nil
end
client.query("google.com")
42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/cps-client/client.rb', line 42 def initialize( = {}) @cid = [:cid] @uid = [:uid] @pwd = [:pwd] @production = [:production] == false ? false : true @timeout = [:timeout] || DEFAULT_TIMEOUT @request = "" @response = "" @data = "" end |
Instance Method Details
#data ⇒ Object
81 82 83 |
# File 'lib/cps-client/client.rb', line 81 def data @data.to_s end |
#entity(path) ⇒ Object
89 90 91 92 |
# File 'lib/cps-client/client.rb', line 89 def entity(path) d = Document.new(@data) d.root.elements[path].text rescue "" end |
#get_binding ⇒ Object
107 108 109 |
# File 'lib/cps-client/client.rb', line 107 def get_binding binding end |
#query(object) ⇒ Object
Returns
true: if the call was successful false: if the call failed
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/cps-client/client.rb', line 63 def query( object ) # AlwaysVerifySSLCertificates.ca_file = CA_FILE url = @production == true ? URL_PRD : URL_DEV uri = URI.parse("#{PROTO}://#{url}:#{PORT}") @request = self.template(object) begin http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = true if PROTO == 'https' req = Net::HTTP::Post.new( PATH ) @response, @data = http.request(req, @request) self.result_code >= '1000' && self.result_code <= '1003' ? true : false rescue # OpenSSL::SSL::SSLError false end end |
#request ⇒ Object
85 86 87 |
# File 'lib/cps-client/client.rb', line 85 def request @request.to_s end |
#result_code ⇒ Object
94 95 96 |
# File 'lib/cps-client/client.rb', line 94 def result_code self.entity('/response/result/code') end |
#result_message ⇒ Object
98 99 100 |
# File 'lib/cps-client/client.rb', line 98 def self.entity('/response/result/message') end |