Sha256: 87c9df718b1099bd26ac52cc5bad3984fffa20b9c62cc3e1cd5cb4e0eeaf1e76
Contents?: true
Size: 1.24 KB
Versions: 1
Compression:
Stored size: 1.24 KB
Contents
require 'yaml' require 'mechanize' module Roart module Connections RequiredConfig = %w(server adapter) RequiredToLogin = %w( user pass ) end class Connection attr_reader :agent attr_reader :conf def initialize(conf) if conf.is_a?(String) raise RoartError, "Loading Config File not yet implemented" elsif conf.class.name == Hash.name #TODO: Figure out why conf.is_a?(Hash) doesn't work @conf = conf end if Roart::check_keys(conf, Roart::Connections::RequiredConfig) @agent = @conf[:login] add_methods! @connection = ConnectionAdapter.new(@conf) else raise RoartError, "Configuration Error" end end def authenticate(conf) if Roart::check_keys(conf, Roart::Connections::RequiredToLogin) @connection.authenticate(conf) self end end def rest_path self.server + '/REST/1.0/' end def get(uri) @connection.get(uri) end def post(uri, payload) @connection.post(uri, payload) end protected def add_methods! @conf.each do |key, value| (class << self; self; end).send :define_method, key do return value end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
roart-0.1.7 | lib/roart/connection.rb |