class CrateAPI::Base
Base
class which is used to authenticate user and perform calls.
Constants
Attributes
auth[RW]
@attr [Hash] :auth auth hash.
Public Class Methods
call(url, verb, params={})
click to toggle source
Class method that return the response body of the call.
@param [String] url URL endpoint to make the call to. @param [Symbol] verb HTTP verb used for call. @param [Optional] params Hash of params used for call. @return [Object] body object from the response.
# File lib/crate_api/base.rb, line 53 def self.call(url, verb, params={}) params.merge!({:basic_auth => @@auth}) resp = nil case verb when :get resp = self.get(url, params) when :post resp = self.post(url, params) end if resp.code == 200 return resp.body end end
new(username, password)
click to toggle source
Default initializer for the CrateAPI
Client
@param [String] username username for the Crate
user. @param [String] password password for the Crate
user. @return [CrateAPI::Base] this will return the base class instance. @raise [NotValidUserError] this will occur if the username/password pair is not valid.
# File lib/crate_api/base.rb, line 41 def initialize(username, password) raise NotValidUserError unless CrateAPI::Base.authorized?(username, password) @@auth = {:username => username, :password => password} end
Public Instance Methods
crates()
click to toggle source