Class: Keeper::Containers
- Inherits:
-
Object
- Object
- Keeper::Containers
- Defined in:
- lib/keeper/valuelist.rb
Instance Method Summary collapse
- #categories ⇒ Object
- #get(path) ⇒ Object
-
#initialize(name, options) ⇒ Containers
constructor
A new instance of Containers.
- #partners ⇒ Object
- #roles ⇒ Object
- #viewparts ⇒ Object
- #xmlfields ⇒ Object
Constructor Details
#initialize(name, options) ⇒ Containers
Returns a new instance of Containers.
4 5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/keeper/valuelist.rb', line 4 def initialize(name, ) super require 'net/https' require 'uri' @uri = URI.parse([:url]) @username = [:username] @password = [:password] @connection = Net::HTTP.new( @uri.host, @uri.port ) # from http://www.rubyinside.com/nethttp-cheat-sheet-2940.html @connection.use_ssl = true if @uri.scheme == "https" @connection.verify_mode = OpenSSL::SSL::VERIFY_NONE end |
Instance Method Details
#categories ⇒ Object
18 19 20 |
# File 'lib/keeper/valuelist.rb', line 18 def categories @categories ||= values_of "list_categories", "/value" end |
#get(path) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/keeper/valuelist.rb', line 34 def get(path) # $stderr.puts "Get #{@uri.path} + #{path}" request = Net::HTTP::Get.new @uri.path + path request.basic_auth @username, @password response = @connection.request request raise ArgumentError unless response raise( RuntimeError, "Server returned #{response.code}" ) unless response.code.to_i == 200 # $stderr.puts "#{response.inspect}" # response.each { |k,v| $stderr.puts "#{k}: #{v}" } # $stderr.puts "Encoding >#{response['content-encoding']}<" # check # content-type: text/xml;charset=UTF-8 # content-encoding: gzip raise TypeError unless response['content-type'] =~ /xml/ body = response.body if response['content-encoding'] == "gzip" require 'zlib' require 'stringio' # http://stackoverflow.com/questions/1361892/how-to-decompress-gzip-string-in-ruby body = Zlib::GzipReader.new(StringIO.new(body)).read end Nokogiri::XML body end |
#partners ⇒ Object
21 22 23 |
# File 'lib/keeper/valuelist.rb', line 21 def partners @partners ||= values_of "list_partner", "/value" end |
#roles ⇒ Object
24 25 26 |
# File 'lib/keeper/valuelist.rb', line 24 def roles @roles ||= values_of "list_roles" end |
#viewparts ⇒ Object
27 28 29 |
# File 'lib/keeper/valuelist.rb', line 27 def viewparts @viewparts ||= values_of("list_view_parts") end |
#xmlfields ⇒ Object
30 31 32 |
# File 'lib/keeper/valuelist.rb', line 30 def xmlfields @xmlfields ||= values_of("list_xmlfields") end |