Class: Puree::Server
- Inherits:
-
Object
- Object
- Puree::Server
- Defined in:
- lib/puree/server.rb
Overview
Server
Instance Attribute Summary collapse
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Instance Method Summary collapse
-
#get ⇒ Hash
(also: #find)
Get.
-
#initialize(endpoint: nil, username: nil, password: nil, basic_auth: nil) ⇒ Server
constructor
A new instance of Server.
-
#metadata ⇒ Hash
All metadata.
-
#version ⇒ String
Version.
Constructor Details
#initialize(endpoint: nil, username: nil, password: nil, basic_auth: nil) ⇒ Server
Returns a new instance of Server.
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/puree/server.rb', line 13 def initialize(endpoint: nil, username: nil, password: nil, basic_auth: nil) @resource_type = :server @api_map = Puree::Map.new.get @endpoint = endpoint.nil? ? Puree.endpoint : endpoint @basic_auth = basic_auth.nil? ? Puree.basic_auth : basic_auth if @basic_auth === true @username = username.nil? ? Puree.username : username @password = password.nil? ? Puree.password : password end end |
Instance Attribute Details
#response ⇒ Object (readonly)
Returns the value of attribute response.
7 8 9 |
# File 'lib/puree/server.rb', line 7 def response @response end |
Instance Method Details
#get ⇒ Hash Also known as: find
Get
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/puree/server.rb', line 30 def get missing = missing_credentials if !missing.empty? missing.each do |m| puts "#{self.class.name}" + '#' + "#{__method__} missing #{m}" end exit end # strip any trailing slash @endpoint = @endpoint.sub(/(\/)+$/, '') @auth = Base64::strict_encode64(@username + ':' + @password) @options = { basic_auth: @basic_auth, latest_api: true, resource_type: @resource_type.to_sym, rendering: :system, } headers = { 'Accept' => 'application/xml', 'Authorization' => 'Basic ' + @auth } query = {} query['rendering'] = @options[:rendering] begin url = build_url req = HTTP.headers accept: headers['Accept'] if @options[:basic_auth] req = req.auth headers['Authorization'] end @response = req.get(url, params: query) @doc = Nokogiri::XML @response.body @doc.remove_namespaces! rescue HTTP::Error => e puts 'HTTP::Error '+ e. end get_data? ? : {} end |
#metadata ⇒ Hash
All metadata
75 76 77 78 79 |
# File 'lib/puree/server.rb', line 75 def o = {} o['version'] = version o end |
#version ⇒ String
Version
84 85 86 87 |
# File 'lib/puree/server.rb', line 84 def version path = service_response_name + '/baseVersion' xpath_query(path).text.strip end |