lib/datapimp/clients/google.rb in datapimp-1.0.14 vs lib/datapimp/clients/google.rb in datapimp-1.0.15
- old
+ new
@@ -25,10 +25,21 @@
def refreshable?
has_application_keys? && has_refresh_token?
end
+ def browser_authorization_url
+ auth_client.authorization_uri
+ end
+
+ def consume_auth_client_code code
+ auth_client.code = code
+ auth_client.fetch_access_token!
+ Datapimp.config.set "google_refresh_token", auth_client.refresh_token
+ Datapimp.config.set "google_access_token", auth_client.access_token
+ end
+
# Runs through an interactive session where we get the
# necessary tokens needed to integrate with google drive.
def setup(options={})
get_application_keys unless has_application_keys?
@@ -41,15 +52,12 @@
end
if has_refresh_token?
refresh_access_token!
elsif respond_to?(:ask)
- Launchy.open(auth_client.authorization_uri)
+ Launchy.open(browser_authorization_url)
say("\n1. Open this page:\n%s\n\n" % auth_client.authorization_uri)
- auth_client.code = ask("2. Enter the authorization code shown in the page: ", String)
- auth_client.fetch_access_token!
- Datapimp.config.set "google_refresh_token", auth_client.refresh_token
- Datapimp.config.set "google_access_token", auth_client.access_token
+ consume_auth_client_code ask("2. Enter the authorization code shown in the page: ", String)
end
end
def session
api