Class: FeedBooks::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby-feedbooks.rb

Overview

Connection class used to specify credentials and proxy settings

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user = nil, pass = nil) ⇒ 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

#passwordObject

user password



47
48
49
# File 'lib/ruby-feedbooks.rb', line 47

def password
  @password
end

#proxyObject

proxy getter



59
60
61
62
# File 'lib/ruby-feedbooks.rb', line 59

def proxy
  return @proxy unless @proxy.nil?
  ENV["proxy"]
end

#userObject

username



49
50
51
# File 'lib/ruby-feedbooks.rb', line 49

def user
  @user
end

Instance Method Details

#http_optsObject

: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