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(base_url: 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(base_url: 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 26 |
# File 'lib/puree/server.rb', line 13 def initialize(base_url: nil, username: nil, password: nil, basic_auth: nil) @resource_type = :server @api_map = Puree::Map.new.get @base_url = base_url.nil? ? Puree.base_url : base_url @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 @metadata = {} 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
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 71 |
# File 'lib/puree/server.rb', line 31 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 @base_url = @base_url.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
76 77 78 |
# File 'lib/puree/server.rb', line 76 def @metadata end |
#version ⇒ String
Version
83 84 85 |
# File 'lib/puree/server.rb', line 83 def version @metadata['version'] end |