google_sheets_appendroid 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +74 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/google_sheets_appendroid.gemspec +34 -0
- data/lib/google_sheets_appendroid.rb +20 -0
- data/lib/google_sheets_appendroid/append_rows.rb +47 -0
- data/lib/google_sheets_appendroid/authorize.rb +11 -0
- data/lib/google_sheets_appendroid/configuration.rb +10 -0
- data/lib/google_sheets_appendroid/version.rb +3 -0
- metadata +133 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5d4f601bf9572a2ad73017bd70650e98e493c4ee
|
4
|
+
data.tar.gz: 851875fe583934f9d28db59b575aa29fc942b5e3
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: efc7a680a4e234491cac87af1fbf48c233af0c40d7a4d13d0ee9a4074d32c9798f1e8b5a4221e5ea604f90109b49a95c2ee47b466cbe205d5a9def0ec72c929f
|
7
|
+
data.tar.gz: 28343562406a5d7d7b0ba00111ee35fcc7e20dbedd0ce572c71107c84f61bcd2459c0ffb0bf80a7c95bf51617bc63b596601e7f7b812a1c250f491341dcc91ec
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Alex Miller
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
[![Build
|
2
|
+
Status](https://travis-ci.org/apmiller108/google_sheets_appendroid.svg?branch=master)](https://travis-ci.org/apmiller108/google_sheets_appendroid)
|
3
|
+
# Google Sheets Appendroid
|
4
|
+
|
5
|
+
Append rows to a Google Sheet spreadsheet.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'google_sheets_appendroid'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install google_sheets_appendroid
|
22
|
+
|
23
|
+
## Overview
|
24
|
+
|
25
|
+
This library uses the
|
26
|
+
[google-auth-library-ruby](https://github.com/google/google-auth-library-ruby)
|
27
|
+
in order to take advantage of [Application Default Credentials](https://developers.google.com/identity/protocols/application-default-credentials). This makes
|
28
|
+
getting credentials for calling Google APIs quite simple.
|
29
|
+
|
30
|
+
Also, this library is designed for use in server-to-server interactions and
|
31
|
+
therefore requires a [Google Service
|
32
|
+
Account](https://developers.google.com/identity/protocols/OAuth2ServiceAccount).
|
33
|
+
Follow the instructions
|
34
|
+
[here](https://developers.google.com/identity/protocols/OAuth2ServiceAccount)
|
35
|
+
for setting one up. It's easy.
|
36
|
+
|
37
|
+
Lastly, using Application Defualt Credentials via [google-auth-library-ruby](https://github.com/google/google-auth-library-ruby) requires that you set an environment variable `GOOGLE_APPLICATION_CREDENTIALS` that points to the location of your credentials file exported from your Google Service Account. You can read more about this [here](https://developers.google.com/identity/protocols/application-default-credentials).
|
38
|
+
|
39
|
+
Note: this uses Google Sheets API v4.
|
40
|
+
## Usage
|
41
|
+
|
42
|
+
Configure with a `sheet_id`. In Rails, this can go in an initializer.
|
43
|
+
|
44
|
+
```ruby
|
45
|
+
GoogleSheetsAppendroid.configure do |config|
|
46
|
+
config.sheet_id = '12345'
|
47
|
+
end
|
48
|
+
```
|
49
|
+
|
50
|
+
Append some rows to your sheet by passing in rows in the form of a two
|
51
|
+
dimensional array and a range in [A1 notation](https://developers.google.com/sheets/guides/concepts#a1_notation). In this example, two rows will be appended after the last rows on the sheet.
|
52
|
+
|
53
|
+
```ruby
|
54
|
+
rows = [['one', 'two'], ['three', 'four']]
|
55
|
+
range = 'My Sheet!A1'
|
56
|
+
|
57
|
+
GoogleSheetsAppendroid.append(rows, range)
|
58
|
+
```
|
59
|
+
|
60
|
+
## Development
|
61
|
+
|
62
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
63
|
+
|
64
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
65
|
+
|
66
|
+
## Contributing
|
67
|
+
|
68
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/google_sheets_appendroid.
|
69
|
+
|
70
|
+
|
71
|
+
## License
|
72
|
+
|
73
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
74
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "google_sheets_appendroid"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'google_sheets_appendroid/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "google_sheets_appendroid"
|
8
|
+
spec.version = GoogleSheetsAppendroid::VERSION
|
9
|
+
spec.authors = ["Alex Miller"]
|
10
|
+
spec.email = ["apmiller108@yahoo.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Apppend rows to a Google Sheets spreadsheet}
|
13
|
+
spec.description = %q{Apppend rows to a Google Sheets spreadsheet. Uses Google Sheets API v4 with server-to-server authentication}
|
14
|
+
spec.homepage = "https://github.com/apmiller108/google_sheets_appendroid"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
if spec.respond_to?(:metadata)
|
18
|
+
spec.metadata['allowed_push_host'] = "https://rubygems.org"
|
19
|
+
else
|
20
|
+
raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
21
|
+
end
|
22
|
+
|
23
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
24
|
+
spec.bindir = "bin"
|
25
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
26
|
+
spec.require_paths = ["lib"]
|
27
|
+
|
28
|
+
spec.add_dependency 'googleauth', '~> 0.5.1'
|
29
|
+
|
30
|
+
spec.add_development_dependency "bundler", "~> 1.11"
|
31
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
32
|
+
spec.add_development_dependency 'rspec', '~> 3.5'
|
33
|
+
spec.add_development_dependency 'pry', '~> 0.10.4'
|
34
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'google_sheets_appendroid/version'
|
2
|
+
require 'google_sheets_appendroid/configuration'
|
3
|
+
require 'google_sheets_appendroid/append_rows'
|
4
|
+
require 'google_sheets_appendroid/authorize'
|
5
|
+
|
6
|
+
module GoogleSheetsAppendroid
|
7
|
+
|
8
|
+
class << self
|
9
|
+
attr_accessor :configuration
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.configure
|
13
|
+
self.configuration ||= Configuration.new
|
14
|
+
yield configuration if block_given?
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.append(rows, range)
|
18
|
+
AppendRows.new(rows, range).punch_it
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
|
3
|
+
module GoogleSheetsAppendroid
|
4
|
+
class AppendRows
|
5
|
+
|
6
|
+
attr_reader :rows, :access_token, :range
|
7
|
+
|
8
|
+
def initialize(rows, range)
|
9
|
+
@access_token = Authorize.get_access_token
|
10
|
+
@rows = rows
|
11
|
+
@range = range
|
12
|
+
end
|
13
|
+
|
14
|
+
def punch_it
|
15
|
+
req = create_request
|
16
|
+
Net::HTTP.start(
|
17
|
+
uri.hostname,
|
18
|
+
uri.port,
|
19
|
+
use_ssl: uri.scheme == 'https'
|
20
|
+
) { |http| http.request(req) }
|
21
|
+
end
|
22
|
+
|
23
|
+
protected
|
24
|
+
|
25
|
+
def create_request
|
26
|
+
req = Net::HTTP::Post.new(uri)
|
27
|
+
req['Content-Type'] = 'application/json'
|
28
|
+
req['Authorization'] = "Bearer #{access_token}"
|
29
|
+
req.body = value_range_object
|
30
|
+
req
|
31
|
+
end
|
32
|
+
|
33
|
+
def uri
|
34
|
+
sheet_id = GoogleSheetsAppendroid.configuration.sheet_id
|
35
|
+
uri = "https://sheets.googleapis.com/v4/spreadsheets/#{sheet_id}/"\
|
36
|
+
"values/#{range}:append?valueInputOption=USER_ENTERED"
|
37
|
+
encoded_uri = URI.encode(uri)
|
38
|
+
URI encoded_uri
|
39
|
+
end
|
40
|
+
|
41
|
+
def value_range_object
|
42
|
+
JSON.generate({ range: range,
|
43
|
+
majorDimension: "ROWS",
|
44
|
+
values: rows })
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'googleauth'
|
2
|
+
module GoogleSheetsAppendroid
|
3
|
+
class Authorize
|
4
|
+
|
5
|
+
def self.get_access_token
|
6
|
+
scopes = GoogleSheetsAppendroid.configuration.scopes
|
7
|
+
authorization = Google::Auth.get_application_default(scopes)
|
8
|
+
authorization.fetch_access_token!['access_token']
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
metadata
ADDED
@@ -0,0 +1,133 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: google_sheets_appendroid
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Alex Miller
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-08-21 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: googleauth
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.5.1
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.5.1
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.11'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.11'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.5'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.5'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: pry
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 0.10.4
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 0.10.4
|
83
|
+
description: Apppend rows to a Google Sheets spreadsheet. Uses Google Sheets API v4
|
84
|
+
with server-to-server authentication
|
85
|
+
email:
|
86
|
+
- apmiller108@yahoo.com
|
87
|
+
executables:
|
88
|
+
- console
|
89
|
+
- setup
|
90
|
+
extensions: []
|
91
|
+
extra_rdoc_files: []
|
92
|
+
files:
|
93
|
+
- ".gitignore"
|
94
|
+
- ".rspec"
|
95
|
+
- ".travis.yml"
|
96
|
+
- Gemfile
|
97
|
+
- LICENSE.txt
|
98
|
+
- README.md
|
99
|
+
- Rakefile
|
100
|
+
- bin/console
|
101
|
+
- bin/setup
|
102
|
+
- google_sheets_appendroid.gemspec
|
103
|
+
- lib/google_sheets_appendroid.rb
|
104
|
+
- lib/google_sheets_appendroid/append_rows.rb
|
105
|
+
- lib/google_sheets_appendroid/authorize.rb
|
106
|
+
- lib/google_sheets_appendroid/configuration.rb
|
107
|
+
- lib/google_sheets_appendroid/version.rb
|
108
|
+
homepage: https://github.com/apmiller108/google_sheets_appendroid
|
109
|
+
licenses:
|
110
|
+
- MIT
|
111
|
+
metadata:
|
112
|
+
allowed_push_host: https://rubygems.org
|
113
|
+
post_install_message:
|
114
|
+
rdoc_options: []
|
115
|
+
require_paths:
|
116
|
+
- lib
|
117
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
118
|
+
requirements:
|
119
|
+
- - ">="
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: '0'
|
122
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
123
|
+
requirements:
|
124
|
+
- - ">="
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
version: '0'
|
127
|
+
requirements: []
|
128
|
+
rubyforge_project:
|
129
|
+
rubygems_version: 2.5.1
|
130
|
+
signing_key:
|
131
|
+
specification_version: 4
|
132
|
+
summary: Apppend rows to a Google Sheets spreadsheet
|
133
|
+
test_files: []
|