Class: Garb::Request::Authentication
- Inherits:
-
Object
- Object
- Garb::Request::Authentication
- Defined in:
- lib/garb/request/authentication.rb
Constant Summary collapse
- URL =
'https://www.google.com/accounts/ClientLogin'
Instance Method Summary collapse
- #auth_token(opts = {}) ⇒ Object
- #build_request ⇒ Object
-
#initialize(email, password, opts = {}) ⇒ Authentication
constructor
A new instance of Authentication.
- #parameters ⇒ Object
- #send_request(ssl_mode) ⇒ Object
- #uri ⇒ Object
Constructor Details
#initialize(email, password, opts = {}) ⇒ Authentication
Returns a new instance of Authentication.
6 7 8 9 10 |
# File 'lib/garb/request/authentication.rb', line 6 def initialize(email, password, opts = {}) @email = email @password = password @account_type = opts[:account_type] || 'HOSTED_OR_GOOGLE' end |
Instance Method Details
#auth_token(opts = {}) ⇒ Object
48 49 50 51 |
# File 'lib/garb/request/authentication.rb', line 48 def auth_token(opts = {}) ssl_mode = opts[:secure] ? OpenSSL::SSL::VERIFY_PEER : OpenSSL::SSL::VERIFY_NONE send_request(ssl_mode).body.match(/^Auth=(.*)$/)[1] end |
#build_request ⇒ Object
42 43 44 45 46 |
# File 'lib/garb/request/authentication.rb', line 42 def build_request post = Net::HTTP::Post.new(uri.path) post.set_form_data(parameters) post end |
#parameters ⇒ Object
12 13 14 15 16 17 18 19 20 |
# File 'lib/garb/request/authentication.rb', line 12 def parameters { 'Email' => @email, 'Passwd' => @password, 'accountType' => @account_type, 'service' => 'analytics', 'source' => "sija-garb-v#{Garb::VERSION}" } end |
#send_request(ssl_mode) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/garb/request/authentication.rb', line 26 def send_request(ssl_mode) http = Net::HTTP.new(uri.host, uri.port, Garb.proxy_address, Garb.proxy_port) http.open_timeout = Garb.open_timeout http.read_timeout = Garb.read_timeout http.use_ssl = true http.verify_mode = ssl_mode if ssl_mode == OpenSSL::SSL::VERIFY_PEER http.ca_file = Garb.ca_cert_file end http.request(build_request) do |response| raise AuthError unless response.is_a?(Net::HTTPOK) end end |
#uri ⇒ Object
22 23 24 |
# File 'lib/garb/request/authentication.rb', line 22 def uri @uri ||= URI.parse(URL) end |