google-cells 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +26 -0
  3. data/.ruby-gemset +1 -0
  4. data/.ruby-version +2 -0
  5. data/CHANGELOG.md +28 -0
  6. data/Gemfile +4 -0
  7. data/Gemfile.lock +73 -0
  8. data/LICENSE.txt +22 -0
  9. data/README.md +75 -0
  10. data/Rakefile +4 -0
  11. data/examples/oauth2_service_account.rb +17 -0
  12. data/examples/oauth2_web_flow.rb +66 -0
  13. data/examples/sinatra/routes.rb +21 -0
  14. data/google_cells.gemspec +30 -0
  15. data/lib/google_cells.rb +80 -0
  16. data/lib/google_cells/author.rb +7 -0
  17. data/lib/google_cells/cell.rb +32 -0
  18. data/lib/google_cells/cell_selector.rb +18 -0
  19. data/lib/google_cells/cell_selector/row_selector.rb +70 -0
  20. data/lib/google_cells/fetcher.rb +27 -0
  21. data/lib/google_cells/folder.rb +7 -0
  22. data/lib/google_cells/google_object.rb +31 -0
  23. data/lib/google_cells/reader.rb +19 -0
  24. data/lib/google_cells/row.rb +7 -0
  25. data/lib/google_cells/spreadsheet.rb +179 -0
  26. data/lib/google_cells/url_helper.rb +37 -0
  27. data/lib/google_cells/util.rb +17 -0
  28. data/lib/google_cells/version.rb +3 -0
  29. data/lib/google_cells/worksheet.rb +63 -0
  30. data/spec/google_cells/cell_selector/row_selector_spec.rb +104 -0
  31. data/spec/google_cells/cell_selector_spec.rb +26 -0
  32. data/spec/google_cells/fetcher_spec.rb +21 -0
  33. data/spec/google_cells/google_object_spec.rb +18 -0
  34. data/spec/google_cells/reader_spec.rb +24 -0
  35. data/spec/google_cells/spreadsheet_spec.rb +171 -0
  36. data/spec/google_cells/url_helper_spec.rb +15 -0
  37. data/spec/google_cells/worksheet_spec.rb +69 -0
  38. data/spec/google_cells_spec.rb +13 -0
  39. data/spec/spec_helper.rb +30 -0
  40. data/spec/vcr_cassettes/google_cells/cell_selector/each.yml +9147 -0
  41. data/spec/vcr_cassettes/google_cells/cell_selector/find_each.yml +10272 -0
  42. data/spec/vcr_cassettes/google_cells/cell_selector/find_each/selection.yml +947 -0
  43. data/spec/vcr_cassettes/google_cells/fetcher.yml +144 -0
  44. data/spec/vcr_cassettes/google_cells/reader.yml +144 -0
  45. data/spec/vcr_cassettes/google_cells/spreadsheet/cell_selector/worksheet.yml +276 -0
  46. data/spec/vcr_cassettes/google_cells/spreadsheet/copy.yml +447 -0
  47. data/spec/vcr_cassettes/google_cells/spreadsheet/copy/content.yml +18555 -0
  48. data/spec/vcr_cassettes/google_cells/spreadsheet/enfold.yml +259 -0
  49. data/spec/vcr_cassettes/google_cells/spreadsheet/folders.yml +319 -0
  50. data/spec/vcr_cassettes/google_cells/spreadsheet/get.yml +135 -0
  51. data/spec/vcr_cassettes/google_cells/spreadsheet/list.yml +276 -0
  52. data/spec/vcr_cassettes/google_cells/spreadsheet/worksheets.yml +276 -0
  53. data/spec/vcr_cassettes/google_cells/worksheet/save.yml +9555 -0
  54. data/spec/vcr_cassettes/google_cells/worksheets.yml +145 -0
  55. metadata +250 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8e91eb8141cc97ad38d072e1986b3de439b103fd
4
+ data.tar.gz: 1e5513c4d68f3a6f399530e376ad01ef85a5006d
5
+ SHA512:
6
+ metadata.gz: bfbe733459648d1e428206fdd530383a6a24d8ddb91b3de3404f398f108fd7d0ca4230ae74b94a5ee52a4517e7b12c7a4b57b8a607ef34b79522e44c52e41cb0
7
+ data.tar.gz: 967e8491a166307e0ca3a09e4edbee55c0d53f9c9fa16cedad097fad35dbc4ed1f47e479fcb072cd79da23f8f049bec46915dcd935725292bb7bfeb579586292
@@ -0,0 +1,26 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ coverage
6
+ InstalledFiles
7
+ lib/bundler/man
8
+ pkg
9
+ rdoc
10
+ spec/reports
11
+ test/tmp
12
+ test/version_tmp
13
+ tmp
14
+
15
+ # YARD artifacts
16
+ .yardoc
17
+ _yardoc
18
+ doc/
19
+
20
+ # vim temp files
21
+ *~
22
+ *.swp
23
+ *.swo
24
+
25
+ # sensitive data
26
+ spec/private_spec_helper.rb
@@ -0,0 +1 @@
1
+ google_cells
@@ -0,0 +1,2 @@
1
+ ruby-2.1.1
2
+
@@ -0,0 +1,28 @@
1
+ Version 0.3.0
2
+ =========================
3
+
4
+ + Added Spreadsheet.subscribe and Spreadsheet.unsubscribe
5
+
6
+ Version 0.2.1
7
+ =========================
8
+
9
+ + Added if-match header to update for new Google sheets compatibility
10
+ Fixes [GH#2](https://github.com/pikimal/google-cells/issues/2)
11
+
12
+ Version 0.2.0
13
+ =========================
14
+
15
+ + Added Spreadsheet#defold to remove from a folder
16
+ + Added explicit title setting to Spreadsheet.copy
17
+
18
+ Version 0.1.1
19
+ =========================
20
+
21
+ + Fixed bug in Spreadsheet.delete
22
+ + Fixed rake default task to run specs
23
+
24
+ Version 0.1.0
25
+ =========================
26
+
27
+ + Added Spreadsheet#delete and Spreadsheet.delete
28
+ Fixes [GH#1](https://github.com/pikimal/google-cells/issues/1)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in google_cells.gemspec
4
+ gemspec
@@ -0,0 +1,73 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ google-cells (0.2.1)
5
+ google-api-client (~> 0.7, >= 0.7.1)
6
+ nokogiri (~> 1.6, >= 1.6.1)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ addressable (2.3.5)
12
+ autoparse (0.3.3)
13
+ addressable (>= 2.3.1)
14
+ extlib (>= 0.9.15)
15
+ multi_json (>= 1.0.0)
16
+ crack (0.4.2)
17
+ safe_yaml (~> 1.0.0)
18
+ diff-lcs (1.2.5)
19
+ extlib (0.9.16)
20
+ faraday (0.9.0)
21
+ multipart-post (>= 1.2, < 3)
22
+ google-api-client (0.7.1)
23
+ addressable (>= 2.3.2)
24
+ autoparse (>= 0.3.3)
25
+ extlib (>= 0.9.15)
26
+ faraday (>= 0.9.0)
27
+ jwt (>= 0.1.5)
28
+ launchy (>= 2.1.1)
29
+ multi_json (>= 1.0.0)
30
+ retriable (>= 1.4)
31
+ signet (>= 0.5.0)
32
+ uuidtools (>= 2.1.0)
33
+ jwt (0.1.11)
34
+ multi_json (>= 1.5)
35
+ launchy (2.4.2)
36
+ addressable (~> 2.3)
37
+ mini_portile (0.5.2)
38
+ multi_json (1.8.4)
39
+ multipart-post (2.0.0)
40
+ nokogiri (1.6.1)
41
+ mini_portile (~> 0.5.0)
42
+ rake (0.9.6)
43
+ retriable (1.4.1)
44
+ rspec (2.14.1)
45
+ rspec-core (~> 2.14.0)
46
+ rspec-expectations (~> 2.14.0)
47
+ rspec-mocks (~> 2.14.0)
48
+ rspec-core (2.14.7)
49
+ rspec-expectations (2.14.4)
50
+ diff-lcs (>= 1.1.3, < 2.0)
51
+ rspec-mocks (2.14.4)
52
+ safe_yaml (1.0.1)
53
+ signet (0.5.0)
54
+ addressable (>= 2.2.3)
55
+ faraday (>= 0.9.0.rc5)
56
+ jwt (>= 0.1.5)
57
+ multi_json (>= 1.0.0)
58
+ uuidtools (2.1.4)
59
+ vcr (2.8.0)
60
+ webmock (1.16.0)
61
+ addressable (>= 2.2.7)
62
+ crack (>= 0.3.2)
63
+
64
+ PLATFORMS
65
+ ruby
66
+
67
+ DEPENDENCIES
68
+ bundler (~> 1.5)
69
+ google-cells!
70
+ rake (~> 0)
71
+ rspec (~> 2.14, >= 2.14.1)
72
+ vcr (~> 2.8, >= 2.8.0)
73
+ webmock (~> 1.16, >= 1.6.0)
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Jessica Megan Thrower
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,75 @@
1
+ # GoogleCells
2
+
3
+ A wrapper for Google's Spreadsheet and Drive APIs.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'google_cells'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install google_cells
18
+
19
+ ## Usage
20
+
21
+ ```ruby
22
+ # configure with Google Service account keys
23
+ GoogleCells.configure do |config|
24
+ config.service_account_email = 'my_service_account@email.here'
25
+ config.key_file = File.dirname(__FILE__) +
26
+ '/path/to/private-key.file/from/Google'
27
+ config.key_secret = 'notasecret'
28
+ end
29
+
30
+ # list all spreadsheets in account
31
+ files = GoogleCells::Spreadsheet.list
32
+ files.each do |s|
33
+ p s.title
34
+ end
35
+
36
+ # get spreadsheet by google key
37
+ s = GoogleCells::Spreadsheet.get('my-spreadsheet-key-here')
38
+
39
+ # spread the love
40
+ s.share(value:'mybestfriend@email.here', type:'user', role:'writer')
41
+
42
+ # create a copy of file
43
+ c = s.copy
44
+
45
+ # put spreadsheet in a folder
46
+ s.enfold('my-folder-key-here')
47
+
48
+ # read cell content
49
+ w = s.worksheets[0]
50
+ w.rows.each do |row|
51
+ row.cells.each do |c|
52
+ p c.value
53
+ p c.input_value
54
+ p c.numeric_value
55
+ end
56
+ end
57
+
58
+ # and write it!
59
+ w.rows.from(1).to(2).each do |row|
60
+ row.cells.each do |c|
61
+ c.input_value = "#{cell.row + cell.col}"
62
+ end
63
+ end
64
+ w.save!
65
+
66
+ ```
67
+
68
+ ## Contributing
69
+
70
+ 1. Fork it ( http://github.com/<my-github-username>/google_cells/fork )
71
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
72
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
73
+ 4. Push to the branch (`git push origin my-new-feature`)
74
+ 5. Create new Pull Request
75
+
@@ -0,0 +1,4 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+ RSpec::Core::RakeTask.new(:spec)
4
+ task :default => :spec
@@ -0,0 +1,17 @@
1
+ require 'rubygems'
2
+ require 'sinatra'
3
+ require "google_cells"
4
+ require 'yaml'
5
+
6
+ path = File.expand_path(File.dirname(__FILE__) + '/../tmp/service_account.yml')
7
+ file = YAML.load_file(path)
8
+
9
+ GoogleCells.configure do |config|
10
+ config.service_account_email = file['email']
11
+ config.key_file = File.dirname(__FILE__) + file['path']
12
+ config.key_secret = file['key_secret']
13
+ end
14
+
15
+ require File.expand_path(File.dirname(__FILE__) + '/sinatra/routes')
16
+
17
+ App::Routes.run!
@@ -0,0 +1,66 @@
1
+ require 'rubygems'
2
+ require 'sinatra'
3
+ require "google_cells"
4
+ require 'yaml'
5
+
6
+ path = File.expand_path(File.dirname(__FILE__) + '/../tmp/web_flow.yml')
7
+ file = YAML.load_file(path)
8
+
9
+ GoogleCells.configure do |config|
10
+ config.client_id = file['client_id']
11
+ config.client_secret = file['client_secret']
12
+ end
13
+
14
+ module App
15
+ class Routes < ::Sinatra::Base
16
+
17
+ enable :sessions
18
+
19
+ set :client, GoogleCells.client
20
+
21
+ def client
22
+ settings.client
23
+ end
24
+
25
+ def authorization
26
+ @authorization ||= (
27
+ auth = client.authorization.dup
28
+ auth.redirect_uri = to('/oauth2_callback')
29
+ auth.update_token!(session)
30
+ auth
31
+ )
32
+ end
33
+
34
+ before do
35
+ # Ensure user has authorized the app
36
+ unless authorization.access_token || request.path_info =~ /^\/oauth2/
37
+ redirect to('/oauth2_authorize')
38
+ end
39
+ GoogleCells.client.authorization = authorization
40
+ end
41
+
42
+ after do
43
+ # Serialize the access/refresh token to the session
44
+ session[:access_token] = authorization.access_token
45
+ session[:refresh_token] = authorization.refresh_token
46
+ session[:expires_in] = authorization.expires_in
47
+ session[:issued_at] = authorization.issued_at
48
+ end
49
+
50
+ get '/oauth2_authorize' do
51
+ # Request authorization
52
+ redirect authorization.authorization_uri.to_s, 303
53
+ end
54
+
55
+ get '/oauth2_callback' do
56
+ # Exchange token
57
+ authorization.code = params[:code] if params[:code]
58
+ authorization.fetch_access_token!
59
+ redirect to('/')
60
+ end
61
+ end
62
+ end
63
+
64
+ require File.expand_path(File.dirname(__FILE__) + '/sinatra/routes')
65
+
66
+ App::Routes.run!
@@ -0,0 +1,21 @@
1
+ require 'sinatra/base'
2
+
3
+ module App
4
+ class Routes < ::Sinatra::Base
5
+ get '/' do
6
+ @spreadsheets = GoogleCells::Spreadsheet.list
7
+ @spreadsheets.sort_by!{|s| s.updated_at}
8
+ @spreadsheets.reverse!
9
+ text = "<h1>All Spreadsheets</h1>"
10
+ if @spreadsheets.empty?
11
+ text << "Nothing here."
12
+ else
13
+ text << "<% for s in @spreadsheets %>"
14
+ text << "<br/><%= s.updated_at %> -- <a href=\"https://docs.google.com/"
15
+ text << "spreadsheet/ccc?key=<%= s.key %>\"><%= s.title %></a>"
16
+ text << "<% end %>"
17
+ end
18
+ erb text
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'google_cells/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "google-cells"
8
+ spec.version = GoogleCells::VERSION
9
+ spec.authors = ["Jessica Megan Thrower"]
10
+ spec.email = ["jmthrower@gmail.com"]
11
+ spec.summary = %q{Google Spreadsheets API wrapper}
12
+ spec.description = %q{An intuitive Google Spreadsheets API wrapper}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency 'google-api-client', '~> 0.7', '>= 0.7.1'
22
+ spec.add_dependency "nokogiri", "~> 1.6", ">= 1.6.1"
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.5"
25
+ spec.add_development_dependency 'rake', '~> 0'
26
+
27
+ spec.add_development_dependency "rspec", '~> 2.14', ">= 2.14.1"
28
+ spec.add_development_dependency "vcr", "~> 2.8", '>= 2.8.0'
29
+ spec.add_development_dependency "webmock", "~> 1.16", ">= 1.6.0"
30
+ end
@@ -0,0 +1,80 @@
1
+ require 'google/api_client'
2
+ require 'nokogiri'
3
+
4
+ require "google_cells/url_helper"
5
+ require "google_cells/fetcher"
6
+ require "google_cells/reader"
7
+ require "google_cells/util"
8
+ require "google_cells/google_object"
9
+ require "google_cells/author"
10
+ require "google_cells/cell"
11
+ require "google_cells/cell_selector"
12
+ require "google_cells/folder"
13
+ require "google_cells/row"
14
+ require "google_cells/spreadsheet"
15
+ require "google_cells/worksheet"
16
+ require "google_cells/version"
17
+
18
+ module GoogleCells
19
+ class << self
20
+ attr_accessor :config, :client
21
+ end
22
+
23
+ def self.configure
24
+ self.config ||= Configuration.new
25
+ yield(config)
26
+
27
+ self.client = Google::APIClient.new(
28
+ :application_name => 'GoogleCells App',
29
+ :application_version => '0.0.3'
30
+ )
31
+ if config.path_to_credentials_file
32
+ config_from_file
33
+ elsif config.client_id
34
+ config_web_application
35
+ else
36
+ config_service_account
37
+ end
38
+ client.authorization.scope = ['https://www.googleapis.com/auth/drive',
39
+ 'https://spreadsheets.google.com/feeds']
40
+ client.authorization.token_credential_uri = 'https://accounts.google.com/o/oauth2/token'
41
+
42
+ config
43
+ end
44
+
45
+ class Configuration
46
+ attr_accessor :service_account_email, :key_secret, :key_file, :client_id,
47
+ :client_secret, :path_to_credentials_file
48
+
49
+ def initialize
50
+ @key_secret = 'notasecret'
51
+
52
+ @api_version = 'v2'
53
+ @cached_api_file = "drive-#{@api_version}.cache"
54
+ end
55
+ end
56
+
57
+ private
58
+
59
+ def self.config_web_application
60
+ client.authorization.client_id = config.client_id
61
+ client.authorization.client_secret = config.client_secret
62
+ end
63
+
64
+ def self.config_service_account
65
+ key = Google::APIClient::KeyUtils.load_from_pkcs12(config.key_file,
66
+ config.key_secret)
67
+ opts = { issuer: config.service_account_email,
68
+ signing_key: key }
69
+
70
+ client.authorization = Signet::OAuth2::Client.new(opts)
71
+ client.authorization.audience = 'https://accounts.google.com/o/oauth2/token'
72
+ end
73
+
74
+ def self.config_from_file
75
+ flow = Google::APIClient::FileStorage.new(
76
+ :path => config.path_to_credentials_file
77
+ )
78
+ client.authorization = flow.authorize
79
+ end
80
+ end