Class: Preposterous::HTTPAuth
- Inherits:
-
Object
- Object
- Preposterous::HTTPAuth
- Includes:
- HTTParty
- Defined in:
- lib/preposterous/httpauth.rb
Defined Under Namespace
Classes: CredentialsError
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#password ⇒ Object
readonly
Returns the value of attribute password.
-
#username ⇒ Object
readonly
Returns the value of attribute username.
Class Method Summary collapse
Instance Method Summary collapse
- #get(uri, headers = {}) ⇒ Object
-
#initialize(username, password, options = {}) ⇒ HTTPAuth
constructor
A new instance of HTTPAuth.
- #post(uri, body = {}, headers = {}) ⇒ Object
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, ={}) @username, @password = username, password @options = {:ssl => false}.merge() # posterous' API URL is http://posterous.com/api [:api_endpoint] ||= "posterous.com" self.class.base_uri "http#{'s' if [:ssl]}://#{[:api_endpoint]}" end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
6 7 8 |
# File 'lib/preposterous/httpauth.rb', line 6 def @options end |
#password ⇒ Object (readonly)
Returns the value of attribute password.
6 7 8 |
# File 'lib/preposterous/httpauth.rb', line 6 def password @password end |
#username ⇒ Object (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(={}) unless .key?(:username) and .key?(:password) then raise CredentialsError, "You must specify both username and password" end new([:username], [:password], ) 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 |