Class: GoogleDocSeed
- Inherits:
-
Object
- Object
- GoogleDocSeed
- Defined in:
- lib/google_doc_seed.rb,
lib/google_doc_seed/version.rb
Constant Summary collapse
- VERSION =
"0.0.4"
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(token) ⇒ GoogleDocSeed
constructor
A new instance of GoogleDocSeed.
- #to_csv_string(doc_key, ws_name = nil) ⇒ Object
Constructor Details
#initialize(token) ⇒ GoogleDocSeed
Returns a new instance of GoogleDocSeed.
23 24 25 |
# File 'lib/google_doc_seed.rb', line 23 def initialize(token) @session = GoogleDrive.login_with_oauth(token) end |
Class Method Details
.get_access_token(client_id, client_secret) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/google_doc_seed.rb', line 6 def self.get_access_token(client_id, client_secret) require 'google/api_client' require 'launchy' client = Google::APIClient.new(application_name: 'RubyGoogleDocSeed', application_version: GoogleDocSeed::VERSION) client..client_id = client_id client..client_secret = client_secret client..redirect_uri = 'urn:ietf:wg:oauth:2.0:oob' client..scope = 'https://spreadsheets.google.com/feeds' Launchy.open(client..) STDERR.puts 'Enter authorization code: ' client..code = STDIN.gets.chomp client..fetch_access_token! end |
Instance Method Details
#to_csv_string(doc_key, ws_name = nil) ⇒ Object
27 28 29 30 31 |
# File 'lib/google_doc_seed.rb', line 27 def to_csv_string(doc_key, ws_name = nil) doc = @session.spreadsheet_by_key(doc_key) ws = ws_name ? doc.worksheet_by_title(ws_name) : doc.worksheets[0] CSV.generate { |csv| ws.rows.each { |row| csv << row } } end |