Class: GMoney::AuthenticationRequest
- Inherits:
-
Object
- Object
- GMoney::AuthenticationRequest
- Defined in:
- lib/gmoney/authentication_request.rb
Defined Under Namespace
Classes: AuthError
Constant Summary collapse
- AUTH_URL =
'https://www.google.com/accounts/ClientLogin'
Instance Method Summary collapse
- #auth_token(opts = {}) ⇒ Object
- #build_request ⇒ Object
-
#initialize(email, password) ⇒ AuthenticationRequest
constructor
A new instance of AuthenticationRequest.
- #parameters ⇒ Object
- #send_request(ssl_mode) ⇒ Object
- #uri ⇒ Object
Constructor Details
#initialize(email, password) ⇒ AuthenticationRequest
Returns a new instance of AuthenticationRequest.
7 8 9 10 |
# File 'lib/gmoney/authentication_request.rb', line 7 def initialize(email, password) @email = email @password = password end |
Instance Method Details
#auth_token(opts = {}) ⇒ Object
46 47 48 49 |
# File 'lib/gmoney/authentication_request.rb', line 46 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
40 41 42 43 44 |
# File 'lib/gmoney/authentication_request.rb', line 40 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/gmoney/authentication_request.rb', line 12 def parameters { 'Email' => @email, 'Passwd' => @password, 'accountType' => 'HOSTED_OR_GOOGLE', 'service' => 'finance', 'source' => 'gmoney-001' } end |
#send_request(ssl_mode) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/gmoney/authentication_request.rb', line 26 def send_request(ssl_mode) http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = true http.verify_mode = ssl_mode if ssl_mode == OpenSSL::SSL::VERIFY_PEER http.ca_file = 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/gmoney/authentication_request.rb', line 22 def uri URI.parse(AUTH_URL) end |