class Googleurlshortener::Authenticated

Public Class Methods

new(email, password) click to toggle source
# File lib/googleurlshortener.rb, line 48
def initialize(email, password)
  @auth_token = get_authentication_token(email, password)
end

Public Instance Methods

analytics(short_url) click to toggle source
# File lib/googleurlshortener.rb, line 52
def analytics(short_url)
  return get_json_response("https://www.googleapis.com/urlshortener/v1/url?shortUrl=#{short_url}&projection=FULL")
end

Private Instance Methods

get_authentication_token(email, password) click to toggle source
# File lib/googleurlshortener.rb, line 58
def get_authentication_token(email, password)
  uri = URI("https://www.google.com/accounts/ClientLogin")
  body = ""
  Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https') do |http|
    request = Net::HTTP::Post.new uri.request_uri
    data = "accountType=HOSTED_OR_GOOGLE&Email=#{email}&Passwd=#{password}&service=lh2&source=someapp1"
    response = http.request(request, data)
    body = response.body
  end
  start_index = body.index('Auth=')
  slice_of_auth_to_end = body[start_index..-1]
  end_index = slice_of_auth_to_end.index("\n")
  auth_string = slice_of_auth_to_end[0...end_index]
  auth_token = "GoogleLogin #{auth_string}"
  return auth_token
end