Sha256: 1571897a42a837d838ddb254ab0f6eb786701ad0fc2ba79c3afbc18002eb756e
Contents?: true
Size: 1.22 KB
Versions: 1
Compression:
Stored size: 1.22 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 "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 "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.6 | lib/roart/connection.rb |