Class: FeedBooks::Connection
- Inherits:
-
Object
- Object
- FeedBooks::Connection
- Defined in:
- lib/ruby-feedbooks.rb
Overview
Connection class used to specify credentials and proxy settings
Instance Attribute Summary collapse
-
#password ⇒ Object
user password.
-
#proxy ⇒ Object
proxy getter.
-
#user ⇒ Object
username.
Instance Method Summary collapse
-
#http_opts ⇒ Object
:nodoc:.
-
#initialize(user = nil, pass = nil) ⇒ Connection
constructor
A new instance of Connection.
-
#openfb(url) ⇒ Object
:nodoc:.
Constructor Details
#initialize(user = nil, pass = nil) ⇒ Connection
Returns a new instance of Connection.
53 54 55 56 |
# File 'lib/ruby-feedbooks.rb', line 53 def initialize(user=nil,pass=nil) @user=user @password=pass end |
Instance Attribute Details
#password ⇒ Object
user password
47 48 49 |
# File 'lib/ruby-feedbooks.rb', line 47 def password @password end |
#proxy ⇒ Object
proxy getter
59 60 61 62 |
# File 'lib/ruby-feedbooks.rb', line 59 def proxy return @proxy unless @proxy.nil? ENV["proxy"] end |
#user ⇒ Object
username
49 50 51 |
# File 'lib/ruby-feedbooks.rb', line 49 def user @user end |
Instance Method Details
#http_opts ⇒ Object
:nodoc:
75 76 77 78 79 80 81 |
# File 'lib/ruby-feedbooks.rb', line 75 def http_opts #:nodoc: ret={} ret[:http_basic_authentication]=[user,Digest::MD5.hexdigest(password)] unless user.nil? ret[:proxy]=proxy ret["User-Agent"]=USER_AGENT return ret end |
#openfb(url) ⇒ Object
:nodoc:
64 65 66 67 68 69 70 71 72 73 |
# File 'lib/ruby-feedbooks.rb', line 64 def openfb(url) #:nodoc: begin return open(url,"r",http_opts) rescue OpenURI::HTTPError => e if e.io.status.first.to_i == 401 raise (user.nil? ? FeedBooks::UnauthenticatedError.new : FeedBooks::WrongCredentialsError.new ) end raise e end end |