Class: Preposterous::HTTPAuth

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/preposterous/httpauth.rb

Defined Under Namespace

Classes: CredentialsError

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(username, password, options = {}) ⇒ HTTPAuth

Returns a new instance of HTTPAuth.



10
11
12
13
14
15
16
# File 'lib/preposterous/httpauth.rb', line 10

def initialize(username, password, options={})
  @username, @password = username, password
  @options = {:ssl => false}.merge(options)
  # posterous' API URL is http://posterous.com/api
  options[:api_endpoint] ||= "posterous.com"
  self.class.base_uri "http#{'s' if options[:ssl]}://#{options[:api_endpoint]}"
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



6
7
8
# File 'lib/preposterous/httpauth.rb', line 6

def options
  @options
end

#passwordObject (readonly)

Returns the value of attribute password.



6
7
8
# File 'lib/preposterous/httpauth.rb', line 6

def password
  @password
end

#usernameObject (readonly)

Returns the value of attribute username.



6
7
8
# File 'lib/preposterous/httpauth.rb', line 6

def username
  @username
end

Class Method Details

.initialize_from_hash(options = {}) ⇒ Object



18
19
20
21
# File 'lib/preposterous/httpauth.rb', line 18

def self.initialize_from_hash(options={})
  unless options.key?(:username) and options.key?(:password) then raise CredentialsError, "You must specify both username and password" end
  new(options[:username], options[:password], options)
end

Instance Method Details

#get(uri, headers = {}) ⇒ Object



23
24
25
# File 'lib/preposterous/httpauth.rb', line 23

def get(uri, headers={})
  self.class.get(uri, :headers => headers, :basic_auth => basic_auth)
end

#post(uri, body = {}, headers = {}) ⇒ Object



27
28
29
# File 'lib/preposterous/httpauth.rb', line 27

def post(uri, body={}, headers={})
  self.class.post(uri, :body => body, :headers => headers, :basic_auth => basic_auth)
end