sheetsu 0.1.1 → 1.0.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.
- checksums.yaml +4 -4
- data/.gitignore +3 -0
- data/.rspec +0 -1
- data/.simplecov +2 -1
- data/.travis.yml +4 -2
- data/CODE_OF_CONDUCT.md +1 -1
- data/README.md +212 -23
- data/Rakefile +2 -6
- data/bin/console +3 -3
- data/lib/sheetsu.rb +12 -3
- data/lib/sheetsu/client.rb +23 -16
- data/lib/sheetsu/create.rb +18 -0
- data/lib/sheetsu/delete.rb +12 -0
- data/lib/sheetsu/errors.rb +21 -10
- data/lib/sheetsu/read.rb +12 -0
- data/lib/sheetsu/request.rb +107 -0
- data/lib/sheetsu/update.rb +19 -0
- data/lib/sheetsu/util.rb +53 -0
- data/lib/sheetsu/version.rb +1 -1
- data/sheetsu.gemspec +24 -19
- metadata +35 -42
- data/.codeclimate.yml +0 -19
- data/.ruby-version +0 -1
- data/LICENSE +0 -22
- data/LICENSE.txt +0 -21
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: db726ef445452fbdbe85cebc1ee15a5be88bdb9f
|
4
|
+
data.tar.gz: 6086857bd23fd0dca6675593323cf979d6ebbff9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aa671f1d8c3434f1702712cacda63f475b82ebcc5d8702287d52dd7ddbc7cb7471c4bcd4cfe67ad5e50192f21db81b306f6b9b7e5d9ea42383981f1e8a91a5be
|
7
|
+
data.tar.gz: 6281fe94c204e9c08cf0a3337d6b084f705c5ca2c817a54b32e1642b77cc0e08b272141470011640a489adca2eab73d6187a8308c3ebd9583c481eba413a9500
|
data/.gitignore
CHANGED
data/.rspec
CHANGED
data/.simplecov
CHANGED
data/.travis.yml
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
language: ruby
|
2
2
|
rvm:
|
3
|
-
- 2.
|
3
|
+
- 2.1.0
|
4
|
+
- 2.2.0
|
5
|
+
- 2.3.3
|
4
6
|
before_install: gem install bundler -v 1.11.0
|
5
7
|
addons:
|
6
8
|
code_climate:
|
7
|
-
repo_token:
|
9
|
+
repo_token: b99895016b0aab6980784d071a2f50a3273bf1bbbf03c976a5c98280c326ae1b
|
data/CODE_OF_CONDUCT.md
CHANGED
@@ -35,7 +35,7 @@ This code of conduct applies both within project spaces and in public spaces
|
|
35
35
|
when an individual is representing the project or its community.
|
36
36
|
|
37
37
|
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
38
|
-
reported by contacting a project maintainer at
|
38
|
+
reported by contacting a project maintainer at jb41.mail@gmail.com. All
|
39
39
|
complaints will be reviewed and investigated and will result in a response that
|
40
40
|
is deemed necessary and appropriate to the circumstances. Maintainers are
|
41
41
|
obligated to maintain confidentiality with regard to the reporter of an
|
data/README.md
CHANGED
@@ -1,17 +1,13 @@
|
|
1
|
-
[](https://travis-ci.org/sheetsu/sheetsu-ruby) [](https://codeclimate.com/github/sheetsu/sheetsu-ruby) [](https://codeclimate.com/github/sheetsu/sheetsu-ruby/coverage)
|
2
|
+
# sheetsu-ruby
|
3
|
+
Ruby bindings for the Sheetsu API (https://sheetsu.com/docs).
|
8
4
|
|
9
5
|
## Installation
|
10
6
|
|
11
7
|
Add this line to your application's Gemfile:
|
12
8
|
|
13
9
|
```ruby
|
14
|
-
gem 'sheetsu'
|
10
|
+
gem 'sheetsu-ruby'
|
15
11
|
```
|
16
12
|
|
17
13
|
And then execute:
|
@@ -20,36 +16,229 @@ And then execute:
|
|
20
16
|
|
21
17
|
Or install it yourself as:
|
22
18
|
|
23
|
-
$ gem install sheetsu
|
19
|
+
$ gem install sheetsu-ruby
|
24
20
|
|
25
21
|
## Usage
|
26
22
|
|
27
|
-
|
28
|
-
|
23
|
+
### Generating a Client
|
24
|
+
|
25
|
+
You need to create a new Sheetsu::Client object, and populate it with your Sheetsu API URL. You can find this URL on [Sheetsu Dashboard](https://sheetsu.com/your-apis).
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
require 'sheetsu'
|
29
|
+
|
30
|
+
# Create new client object
|
31
|
+
client = Sheetsu::Client.new("https://sheetsu.com/apis/v1.0/020b2c0f")
|
32
|
+
```
|
33
|
+
or
|
34
|
+
```ruby
|
35
|
+
# Create new client object
|
36
|
+
client = Sheetsu::Client.new("020b2c0f")
|
37
|
+
```
|
38
|
+
|
39
|
+
If you have HTTP Basic Authentication turned on for your API, you should pass `api_key` and `api_secret` here, like:
|
40
|
+
```ruby
|
41
|
+
# Create new client object with HTTP Basic Auth keys
|
42
|
+
client = Sheetsu::Client.new("020b2c0f", api_key: "YOUR_API_KEY", api_secret: "YOUR_API_SECRET")
|
43
|
+
```
|
44
|
+
|
45
|
+
### CRUD
|
46
|
+
|
47
|
+
Sheetsu gives you the ability to use full CRUD on your Google Spreadsheet. Remember to populate the first row of every sheet with column names. You can look at [example spreadsheet](https://docs.google.com/spreadsheets/d/1WTwXrh2ZDXmXATZlQIuapdv4ldyhJGZg7LX8GlzPdZw/edit?usp=sharing).
|
48
|
+
|
49
|
+
### Create
|
50
|
+
[Link to docs](https://sheetsu.com/docs#post)
|
51
|
+
|
52
|
+
To add data to Google Spreadsheets, send a hash or an array of hashes.
|
53
|
+
```ruby
|
54
|
+
# Adds single row
|
55
|
+
client.create({ id: 7, name: "Glenn", score: "69" })
|
56
|
+
|
57
|
+
# Adds bunch of rows
|
58
|
+
rows = [
|
59
|
+
{ id: 7, name: "Glenn", score: "69" },
|
60
|
+
{ id: 8, name: "Brian", score: "77" },
|
61
|
+
{ id: 9, name: "Joe", score: "45" }
|
62
|
+
]
|
63
|
+
client.create(rows)
|
64
|
+
```
|
65
|
+
|
66
|
+
By default, all writes are performed on the first sheet (worksheet). Pass name of a sheet as a 2nd param to add data to other worksheet.
|
67
|
+
```ruby
|
68
|
+
# Adds single row to worksheet named "Sheet3"
|
69
|
+
client.create({ "foo" => "bar", "baz" => "quux" }, "Sheet3")
|
70
|
+
```
|
71
|
+
|
72
|
+
On success returns a hash or an array of hashes with created values. On error check [errors](#errors).
|
73
|
+
|
74
|
+
### Read
|
75
|
+
[Link to docs](https://sheetsu.com/docs#get)
|
76
|
+
|
77
|
+
Read the whole sheet
|
78
|
+
```ruby
|
79
|
+
client.read
|
80
|
+
```
|
81
|
+
|
82
|
+
You can pass hash with options
|
83
|
+
- `sheet` - get data from named worksheet
|
84
|
+
- `limit` - limit number of results
|
85
|
+
- `offset` - start from N first record
|
86
|
+
- `search` - hash with search params [(more below)](#search)
|
87
|
+
|
88
|
+
```ruby
|
89
|
+
# Get first two rows from worksheet named "Sheet2"
|
90
|
+
client.read(sheet: "Sheet2", limit: 2)
|
91
|
+
|
92
|
+
# Get 5th record from worksheet named "Sheet3"
|
93
|
+
client.read(
|
94
|
+
offset: 4, # because rows are numbered from 0
|
95
|
+
limit: 1, # because only one row
|
96
|
+
sheet: "Sheet3"
|
97
|
+
)
|
98
|
+
```
|
99
|
+
|
100
|
+
#### search
|
101
|
+
[Link to docs](https://sheetsu.com/docs#get_search)
|
102
|
+
|
103
|
+
To get rows that match search criteria, pass a hash with search params
|
104
|
+
|
105
|
+
```ruby
|
106
|
+
# Get all rows where column 'id' is 'foo' and column 'value' is 'bar'
|
107
|
+
client.read(search: { id: "foo", value: "bar" })
|
108
|
+
|
109
|
+
# Get all rows where column 'First name' is 'Peter' and column 'Score' is '42'
|
110
|
+
client.read(search: { "First name" => "Peter", "Score" => 42 })
|
111
|
+
|
112
|
+
# Get first two row where column 'First name' is 'Peter',
|
113
|
+
# column 'Score' is '42' from sheet named "Sheet3"
|
114
|
+
client.read(
|
115
|
+
search: { "First name" => "Peter", "Score" => 42 } # search criteria
|
116
|
+
limit: 2 # first two rows
|
117
|
+
sheet: "Sheet3" # Sheet name
|
118
|
+
)
|
119
|
+
```
|
120
|
+
|
121
|
+
On success returns an array of hashes. On error check [errors](#errors).
|
29
122
|
|
30
|
-
|
123
|
+
### Update
|
124
|
+
[Link to docs](https://sheetsu.com/docs#patch)
|
31
125
|
|
32
|
-
|
33
|
-
# {"status"=>200, "success"=>true, "result"=>[]}
|
126
|
+
To update row(s), pass column name and its value which is used to find row(s).
|
34
127
|
|
35
|
-
|
36
|
-
|
37
|
-
|
128
|
+
```ruby
|
129
|
+
# Update all columns where 'name' is 'Peter' to have 'score' = 99 and 'last name' = 'Griffin'
|
130
|
+
client.update(
|
131
|
+
"name", # column name
|
132
|
+
"Peter", # value to search for
|
133
|
+
{ "score": 99, "last name" => "Griffin" }, # hash with updates
|
134
|
+
)
|
135
|
+
```
|
136
|
+
|
137
|
+
By default, [PATCH request](https://sheetsu.com/docs#patch) is sent, which is updating only values which are in the hash passed to the method. To send [PUT request](https://sheetsu.com/docs#put), pass 4th argument being `true`. [Read more about the difference between PUT and PATCH in our docs](https://sheetsu.com/docs#patch).
|
138
|
+
|
139
|
+
|
140
|
+
```ruby
|
141
|
+
# Update all columns where 'name' is 'Peter' to have 'score' = 99 and 'last name' = 'Griffin'
|
142
|
+
# Empty all cells which matching, which are not 'score' or 'last name'
|
143
|
+
client.update(
|
144
|
+
"name", # column name
|
145
|
+
"Peter", # value to search for
|
146
|
+
{ "score": 99, "last name" => "Griffin" }, # hash with updates
|
147
|
+
true # nullify all fields not passed in the hash above
|
148
|
+
)
|
149
|
+
```
|
150
|
+
|
151
|
+
To perform `#update` on different than the first sheet, pass sheet name as a 5th argument.
|
152
|
+
```ruby
|
153
|
+
# Update all columns where 'name' is 'Peter' to have 'score' = 99 and 'last name' = 'Griffin'
|
154
|
+
# In sheet named 'Sheet3'
|
155
|
+
# Empty all cells which matching, which are not 'score' or 'last name'
|
156
|
+
client.update(
|
157
|
+
"name", # column name
|
158
|
+
"Peter", # value to search for
|
159
|
+
{ "score": 99, "last name" => "Griffin" }, # hash with updates
|
160
|
+
true, # nullify all fields not passed in the hash above
|
161
|
+
"Sheet3"
|
162
|
+
)
|
163
|
+
```
|
164
|
+
|
165
|
+
On success returns an array of hashes with updated values. On error check [errors](#errors).
|
166
|
+
|
167
|
+
### Delete
|
168
|
+
[Link to docs](https://sheetsu.com/docs#delete)
|
169
|
+
|
170
|
+
To delete row(s), pass column name and its value which is used to find row(s).
|
171
|
+
|
172
|
+
```ruby
|
173
|
+
# Delete all rows where 'name' equals 'Peter'
|
174
|
+
client.delete(
|
175
|
+
"name", # column name
|
176
|
+
"Peter" # value to search for
|
177
|
+
)
|
178
|
+
```
|
179
|
+
|
180
|
+
You can pass sheet name as a 3rd argument. All operations are performed on the first sheet, by default.
|
181
|
+
```ruby
|
182
|
+
# Delete all rows where 'foo' equals 'bar' in sheet 'Sheet3'
|
183
|
+
client.delete(
|
184
|
+
"foo", # column name
|
185
|
+
"bar", # value to search for
|
186
|
+
"Sheet3" # sheet name
|
187
|
+
)
|
188
|
+
```
|
189
|
+
|
190
|
+
If success returns `:ok` symbol. If error check [errors](#errors).
|
191
|
+
|
192
|
+
### Errors
|
193
|
+
There are different styles of error handling. We choose to throw exceptions and signal failure loudly. You do not need to deal with any HTTP responses from the API calls directly. All exceptions are matching particular response code from Sheetsu API. You can [read more about it here](https://sheetsu.com/docs#statuses).
|
38
194
|
|
39
|
-
|
40
|
-
|
195
|
+
All exceptions are a subclass of `Sheetsu::SheetsuError`. The list of different error subclasses is listed below. You can choose to rescue each of them or rescue just the parent class (`Sheetsu::SheetsuError`).
|
196
|
+
|
197
|
+
|
198
|
+
```ruby
|
199
|
+
Sheetsu::NotFoundError
|
200
|
+
Sheetsu::ForbiddenError
|
201
|
+
Sheetsu::LimitExceedError
|
202
|
+
Sheetsu::UnauthorizedError
|
203
|
+
```
|
41
204
|
|
42
205
|
## Development
|
43
206
|
|
44
|
-
After checking out the repo, run `bin/setup` to install dependencies.
|
207
|
+
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
45
208
|
|
46
209
|
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).
|
47
210
|
|
211
|
+
Run all tests:
|
212
|
+
```
|
213
|
+
rspec
|
214
|
+
```
|
215
|
+
|
216
|
+
Run a single test:
|
217
|
+
```
|
218
|
+
rspec spec/read_spec.rb
|
219
|
+
```
|
220
|
+
|
48
221
|
## Contributing
|
49
222
|
|
50
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
223
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/sheetsu/sheetsu-ruby. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
224
|
+
|
225
|
+
### Pull Requests
|
226
|
+
|
227
|
+
- **Add tests!** Your patch won't be accepted if it doesn't have tests.
|
228
|
+
|
229
|
+
- **Create topic branches**. Please, always create a branch with meaningful name. Don't ask us to pull from your master branch.
|
230
|
+
|
231
|
+
- **One pull request per feature**. If you want to do more than one thing, please send
|
232
|
+
multiple pull requests.
|
233
|
+
|
234
|
+
- **Send coherent history**. Make sure each individual commit in your pull
|
235
|
+
request is meaningful. If you had to make multiple intermediate commits while
|
236
|
+
developing, please squash them before sending them to us.
|
51
237
|
|
238
|
+
### Docs
|
52
239
|
|
53
|
-
|
240
|
+
[Sheetsu documentation sits on GitHub](https://github.com/sheetsu/docs). We would love your contributions! We want to make these docs accessible and easy to understand for everyone. Please send us Pull Requests or open issues on GitHub.
|
54
241
|
|
55
|
-
|
242
|
+
# To do
|
243
|
+
- CodeClimate
|
244
|
+
- RuboCop
|
data/Rakefile
CHANGED
data/bin/console
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require "bundler/setup"
|
4
|
+
require "sheetsu"
|
5
5
|
|
6
6
|
# You can add fixtures and/or initialization code here to make experimenting
|
7
7
|
# with your gem easier. You can also use a different console, if you like.
|
@@ -10,5 +10,5 @@ require 'sheetsu'
|
|
10
10
|
# require "pry"
|
11
11
|
# Pry.start
|
12
12
|
|
13
|
-
require
|
13
|
+
require "irb"
|
14
14
|
IRB.start
|
data/lib/sheetsu.rb
CHANGED
@@ -1,7 +1,16 @@
|
|
1
|
-
require '
|
1
|
+
require 'sheetsu/client'
|
2
|
+
require 'sheetsu/request'
|
3
|
+
require 'sheetsu/errors'
|
4
|
+
require 'sheetsu/create'
|
5
|
+
require 'sheetsu/read'
|
6
|
+
require 'sheetsu/update'
|
7
|
+
require 'sheetsu/delete'
|
8
|
+
require 'sheetsu/util'
|
2
9
|
require 'sheetsu/version'
|
3
10
|
|
11
|
+
require 'cgi'
|
12
|
+
require 'net/http'
|
13
|
+
require 'json'
|
14
|
+
|
4
15
|
module Sheetsu
|
5
|
-
require 'sheetsu/errors'
|
6
|
-
require 'sheetsu/client'
|
7
16
|
end
|
data/lib/sheetsu/client.rb
CHANGED
@@ -1,31 +1,38 @@
|
|
1
1
|
module Sheetsu
|
2
2
|
class Client
|
3
|
-
include HTTParty
|
4
3
|
|
5
|
-
def initialize(
|
6
|
-
@
|
7
|
-
|
4
|
+
def initialize(api_url, auth_credentials={})
|
5
|
+
@api_url = Sheetsu::Util.parse_api_url(api_url)
|
6
|
+
@http_basic_auth = auth_credentials
|
8
7
|
end
|
9
8
|
|
10
|
-
def
|
11
|
-
|
9
|
+
def create(data, sheet=nil)
|
10
|
+
if data.is_a?(Hash)
|
11
|
+
Sheetsu::Create.new(@api_url, @http_basic_auth).row(data, { sheet: sheet })
|
12
|
+
elsif data.is_a?(Array)
|
13
|
+
Sheetsu::Create.new(@api_url, @http_basic_auth).rows(data, { sheet: sheet })
|
14
|
+
end
|
15
|
+
end
|
12
16
|
|
13
|
-
|
14
|
-
|
17
|
+
def read(options={})
|
18
|
+
Sheetsu::Read.new(@api_url, @http_basic_auth).rows(options)
|
15
19
|
end
|
16
20
|
|
17
|
-
def
|
18
|
-
|
21
|
+
def update(column, value, data, update_whole=false, sheet=nil)
|
22
|
+
options = { column: column, value: value, data: data, update_whole: update_whole, sheet: sheet }
|
19
23
|
|
20
|
-
|
21
|
-
|
24
|
+
if update_whole
|
25
|
+
Sheetsu::Update.new(@api_url, @http_basic_auth).put(options)
|
26
|
+
else
|
27
|
+
Sheetsu::Update.new(@api_url, @http_basic_auth).patch(options)
|
28
|
+
end
|
22
29
|
end
|
23
30
|
|
24
|
-
def
|
25
|
-
|
31
|
+
def delete(column, value, sheet=nil)
|
32
|
+
options = { column: column, value: value, sheet: sheet }
|
26
33
|
|
27
|
-
|
28
|
-
response
|
34
|
+
Sheetsu::Delete.new(@api_url, @http_basic_auth).rows(options)
|
29
35
|
end
|
36
|
+
|
30
37
|
end
|
31
38
|
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Sheetsu
|
2
|
+
class Create < Sheetsu::Request
|
3
|
+
|
4
|
+
def row(row, options={})
|
5
|
+
add_options_to_url(options)
|
6
|
+
|
7
|
+
response = call(:post, row)
|
8
|
+
parse_response(response)
|
9
|
+
end
|
10
|
+
|
11
|
+
def rows(rows, options={})
|
12
|
+
add_options_to_url(options)
|
13
|
+
|
14
|
+
response = call(:post, { rows: rows })
|
15
|
+
parse_response(response)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/lib/sheetsu/errors.rb
CHANGED
@@ -1,14 +1,25 @@
|
|
1
1
|
module Sheetsu
|
2
|
-
class
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
end
|
2
|
+
class SheetsuError < StandardError
|
3
|
+
attr_reader :message
|
4
|
+
attr_reader :http_status
|
5
|
+
attr_reader :http_body
|
6
|
+
|
7
|
+
def initialize(message = nil, http_status = nil, http_body = nil)
|
8
|
+
@message = message
|
9
|
+
@http_status = http_status
|
10
|
+
@http_body = http_body
|
12
11
|
end
|
13
12
|
end
|
13
|
+
|
14
|
+
class NotFoundError < SheetsuError
|
15
|
+
end
|
16
|
+
|
17
|
+
class ForbiddenError < SheetsuError
|
18
|
+
end
|
19
|
+
|
20
|
+
class LimitExceedError < SheetsuError
|
21
|
+
end
|
22
|
+
|
23
|
+
class UnauthorizedError < SheetsuError
|
24
|
+
end
|
14
25
|
end
|
data/lib/sheetsu/read.rb
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
module Sheetsu
|
2
|
+
class Request
|
3
|
+
|
4
|
+
def initialize(url, basic_auth)
|
5
|
+
@url = url
|
6
|
+
@basic_auth = basic_auth
|
7
|
+
end
|
8
|
+
|
9
|
+
def call(method, body=nil)
|
10
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
11
|
+
http.use_ssl = true
|
12
|
+
|
13
|
+
request = request(method)
|
14
|
+
request = add_headers(request)
|
15
|
+
request = add_basic_auth(request)
|
16
|
+
request = add_body(request, body)
|
17
|
+
|
18
|
+
http.request(request)
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def uri
|
24
|
+
@uri ||= URI.parse(@url)
|
25
|
+
end
|
26
|
+
|
27
|
+
def request(method)
|
28
|
+
request = http_klass(method).new(uri.request_uri)
|
29
|
+
add_headers(request)
|
30
|
+
|
31
|
+
request
|
32
|
+
end
|
33
|
+
|
34
|
+
def add_headers(request)
|
35
|
+
Sheetsu::Util.default_headers.each_pair { |k,v| request[k] = v }
|
36
|
+
request
|
37
|
+
end
|
38
|
+
|
39
|
+
def add_basic_auth(request)
|
40
|
+
if @basic_auth.keys.any?
|
41
|
+
request.basic_auth(CGI.unescape(@basic_auth[:api_key]), CGI.unescape(@basic_auth[:api_secret]))
|
42
|
+
end
|
43
|
+
request
|
44
|
+
end
|
45
|
+
|
46
|
+
def add_body(request, body)
|
47
|
+
if body
|
48
|
+
request.body = body.to_json
|
49
|
+
end
|
50
|
+
request
|
51
|
+
end
|
52
|
+
|
53
|
+
def http_klass(method)
|
54
|
+
case method
|
55
|
+
when :get then Net::HTTP::Get
|
56
|
+
when :post then Net::HTTP::Post
|
57
|
+
when :put then Net::HTTP::Put
|
58
|
+
when :patch then Net::HTTP::Patch
|
59
|
+
when :delete then Net::HTTP::Delete
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def parse_response(response)
|
64
|
+
Sheetsu::Util.parse_response(response)
|
65
|
+
end
|
66
|
+
|
67
|
+
def add_options_to_url(options)
|
68
|
+
add_sheet_to_url(options)
|
69
|
+
add_column_value_to_url(options)
|
70
|
+
add_query_params_to_url(options)
|
71
|
+
end
|
72
|
+
|
73
|
+
def add_column_value_to_url(options)
|
74
|
+
if options[:column] && options[:value]
|
75
|
+
@url += Sheetsu::Util.encoded_column(options)
|
76
|
+
|
77
|
+
options.delete(:column)
|
78
|
+
options.delete(:value)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
def add_sheet_to_url(options)
|
83
|
+
if options[:sheet]
|
84
|
+
@url += ['/sheets/', CGI::escape(options[:sheet]).to_s].join('')
|
85
|
+
|
86
|
+
options.delete(:sheet)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
def add_query_params_to_url(options)
|
91
|
+
h = Hash.new.tap do |hash|
|
92
|
+
hash[:limit] = options[:limit] if options[:limit]
|
93
|
+
hash[:offset] = options[:offset] if options[:offset]
|
94
|
+
|
95
|
+
if options[:search]
|
96
|
+
hash.merge!(options[:search])
|
97
|
+
@url += '/search'
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
if h.keys.any?
|
102
|
+
@url = Sheetsu::Util.append_query_string_to_url(@url, h)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
end
|
107
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Sheetsu
|
2
|
+
class Update < Sheetsu::Request
|
3
|
+
|
4
|
+
def put(options)
|
5
|
+
add_options_to_url(options)
|
6
|
+
|
7
|
+
response = call(:put, options[:data])
|
8
|
+
parse_response(response)
|
9
|
+
end
|
10
|
+
|
11
|
+
def patch(options)
|
12
|
+
add_options_to_url(options)
|
13
|
+
|
14
|
+
response = call(:patch, options[:data])
|
15
|
+
parse_response(response)
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
data/lib/sheetsu/util.rb
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
module Sheetsu
|
2
|
+
module Util
|
3
|
+
|
4
|
+
SHEETSU_API_URL_BEGINNING = "https://sheetsu.com/apis/v1.0/"
|
5
|
+
|
6
|
+
def self.default_headers
|
7
|
+
{
|
8
|
+
'Accept-Encoding' => 'gzip, deflate',
|
9
|
+
'Accept' => 'application/vnd.sheetsu.3+json',
|
10
|
+
'Content-Type' => 'application/json',
|
11
|
+
'User-Agent' => "Sheetsu-Ruby/#{Sheetsu::VERSION}"
|
12
|
+
}
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.parse_api_url(url)
|
16
|
+
if url.start_with?(SHEETSU_API_URL_BEGINNING)
|
17
|
+
url
|
18
|
+
else
|
19
|
+
[SHEETSU_API_URL_BEGINNING, url].join('')
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.append_query_string_to_url(url, options)
|
24
|
+
url + "?#{query_string(options)}"
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.encoded_column(options)
|
28
|
+
['/', CGI::escape(options[:column].to_s), '/', CGI::escape(options[:value].to_s)].join('')
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.parse_response(response)
|
32
|
+
case response.code.to_i
|
33
|
+
when 200 then JSON.parse(response.body)
|
34
|
+
when 201 then JSON.parse(response.body)
|
35
|
+
when 204 then :ok
|
36
|
+
when 401 then raise Sheetsu::UnauthorizedError
|
37
|
+
when 403 then raise Sheetsu::ForbiddenError
|
38
|
+
when 404 then raise Sheetsu::NotFoundError
|
39
|
+
when 429 then raise Sheetsu::LimitExceedError
|
40
|
+
else
|
41
|
+
raise Sheetsu::SheetsuError.new(nil, response.code, response.body)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
def self.query_string(options)
|
47
|
+
options.map do |k,v|
|
48
|
+
"#{k}=#{CGI::escape(v.to_s)}"
|
49
|
+
end.join('&')
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
end
|
data/lib/sheetsu/version.rb
CHANGED
data/sheetsu.gemspec
CHANGED
@@ -1,31 +1,36 @@
|
|
1
|
-
# coding: utf-8
|
1
|
+
# coding: utf-8
|
2
2
|
lib = File.expand_path('../lib', __FILE__)
|
3
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
4
|
require 'sheetsu/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name =
|
7
|
+
spec.name = "sheetsu"
|
8
8
|
spec.version = Sheetsu::VERSION
|
9
|
-
spec.authors = [
|
10
|
-
spec.email = [
|
9
|
+
spec.authors = ["Michael Oblak"]
|
10
|
+
spec.email = ["m@sheetsu.com"]
|
11
11
|
|
12
|
-
spec.summary =
|
13
|
-
spec.
|
14
|
-
spec.
|
12
|
+
spec.summary = %q{Turn Google Spreadsheets into REST APIs}
|
13
|
+
spec.description = %q{Official Sheetsu API wrapper (https://sheetsu.com/docs). Sheetsu allows you to automate Google Spreadsheets and use them as a resource in a REST API. It is easier than using standard Google Spreadsheets API because Sheetsu handles all the 'dirty' work for you.}
|
14
|
+
spec.homepage = "https://sheetsu.com"
|
15
|
+
|
16
|
+
spec.post_install_message = %q{
|
17
|
+
There are major changes in the v. 1.0 of this gem. Check docs (https://github.com/sheetsu/sheetsu-ruby) to be sure we don't break your app.
|
18
|
+
|
19
|
+
Happy hacking!
|
20
|
+
}
|
21
|
+
|
22
|
+
spec.license = "MIT"
|
15
23
|
|
16
24
|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
-
spec.bindir =
|
25
|
+
spec.bindir = "exe"
|
18
26
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
|
-
spec.require_paths = [
|
20
|
-
|
21
|
-
spec.required_ruby_version = '>= 2.2.3'
|
27
|
+
spec.require_paths = ["lib"]
|
22
28
|
|
23
|
-
spec.
|
24
|
-
spec.add_development_dependency
|
25
|
-
spec.add_development_dependency
|
26
|
-
spec.add_development_dependency
|
27
|
-
spec.add_development_dependency
|
28
|
-
spec.add_development_dependency
|
29
|
-
spec.add_development_dependency
|
30
|
-
spec.add_development_dependency 'codeclimate-test-reporter', '~> 0.4.8'
|
29
|
+
spec.add_development_dependency "bundler", "~> 1.11"
|
30
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
31
|
+
spec.add_development_dependency "rspec", "~> 3.5"
|
32
|
+
spec.add_development_dependency "webmock", "~> 2.3"
|
33
|
+
spec.add_development_dependency "pry", "~> 0"
|
34
|
+
spec.add_development_dependency "simplecov", "~> 0.11.1"
|
35
|
+
spec.add_development_dependency "codeclimate-test-reporter", "~> 1.0"
|
31
36
|
end
|
metadata
CHANGED
@@ -1,29 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sheetsu
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
7
|
+
- Michael Oblak
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-02-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: httparty
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - "~>"
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: 0.13.7
|
20
|
-
type: :runtime
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - "~>"
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: 0.13.7
|
27
13
|
- !ruby/object:Gem::Dependency
|
28
14
|
name: bundler
|
29
15
|
requirement: !ruby/object:Gem::Requirement
|
@@ -58,102 +44,108 @@ dependencies:
|
|
58
44
|
requirements:
|
59
45
|
- - "~>"
|
60
46
|
- !ruby/object:Gem::Version
|
61
|
-
version: '3.
|
47
|
+
version: '3.5'
|
62
48
|
type: :development
|
63
49
|
prerelease: false
|
64
50
|
version_requirements: !ruby/object:Gem::Requirement
|
65
51
|
requirements:
|
66
52
|
- - "~>"
|
67
53
|
- !ruby/object:Gem::Version
|
68
|
-
version: '3.
|
54
|
+
version: '3.5'
|
69
55
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
56
|
+
name: webmock
|
71
57
|
requirement: !ruby/object:Gem::Requirement
|
72
58
|
requirements:
|
73
59
|
- - "~>"
|
74
60
|
- !ruby/object:Gem::Version
|
75
|
-
version:
|
61
|
+
version: '2.3'
|
76
62
|
type: :development
|
77
63
|
prerelease: false
|
78
64
|
version_requirements: !ruby/object:Gem::Requirement
|
79
65
|
requirements:
|
80
66
|
- - "~>"
|
81
67
|
- !ruby/object:Gem::Version
|
82
|
-
version:
|
68
|
+
version: '2.3'
|
83
69
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
70
|
+
name: pry
|
85
71
|
requirement: !ruby/object:Gem::Requirement
|
86
72
|
requirements:
|
87
73
|
- - "~>"
|
88
74
|
- !ruby/object:Gem::Version
|
89
|
-
version: '
|
75
|
+
version: '0'
|
90
76
|
type: :development
|
91
77
|
prerelease: false
|
92
78
|
version_requirements: !ruby/object:Gem::Requirement
|
93
79
|
requirements:
|
94
80
|
- - "~>"
|
95
81
|
- !ruby/object:Gem::Version
|
96
|
-
version: '
|
82
|
+
version: '0'
|
97
83
|
- !ruby/object:Gem::Dependency
|
98
|
-
name:
|
84
|
+
name: simplecov
|
99
85
|
requirement: !ruby/object:Gem::Requirement
|
100
86
|
requirements:
|
101
87
|
- - "~>"
|
102
88
|
- !ruby/object:Gem::Version
|
103
|
-
version: 0.
|
89
|
+
version: 0.11.1
|
104
90
|
type: :development
|
105
91
|
prerelease: false
|
106
92
|
version_requirements: !ruby/object:Gem::Requirement
|
107
93
|
requirements:
|
108
94
|
- - "~>"
|
109
95
|
- !ruby/object:Gem::Version
|
110
|
-
version: 0.
|
96
|
+
version: 0.11.1
|
111
97
|
- !ruby/object:Gem::Dependency
|
112
98
|
name: codeclimate-test-reporter
|
113
99
|
requirement: !ruby/object:Gem::Requirement
|
114
100
|
requirements:
|
115
101
|
- - "~>"
|
116
102
|
- !ruby/object:Gem::Version
|
117
|
-
version: 0
|
103
|
+
version: '1.0'
|
118
104
|
type: :development
|
119
105
|
prerelease: false
|
120
106
|
version_requirements: !ruby/object:Gem::Requirement
|
121
107
|
requirements:
|
122
108
|
- - "~>"
|
123
109
|
- !ruby/object:Gem::Version
|
124
|
-
version: 0
|
125
|
-
description:
|
110
|
+
version: '1.0'
|
111
|
+
description: Official Sheetsu API wrapper (https://sheetsu.com/docs). Sheetsu allows
|
112
|
+
you to automate Google Spreadsheets and use them as a resource in a REST API. It
|
113
|
+
is easier than using standard Google Spreadsheets API because Sheetsu handles all
|
114
|
+
the 'dirty' work for you.
|
126
115
|
email:
|
127
|
-
-
|
116
|
+
- m@sheetsu.com
|
128
117
|
executables: []
|
129
118
|
extensions: []
|
130
119
|
extra_rdoc_files: []
|
131
120
|
files:
|
132
|
-
- ".codeclimate.yml"
|
133
121
|
- ".gitignore"
|
134
122
|
- ".rspec"
|
135
|
-
- ".ruby-version"
|
136
123
|
- ".simplecov"
|
137
124
|
- ".travis.yml"
|
138
125
|
- CODE_OF_CONDUCT.md
|
139
126
|
- Gemfile
|
140
|
-
- Gemfile.lock
|
141
|
-
- LICENSE
|
142
|
-
- LICENSE.txt
|
143
127
|
- README.md
|
144
128
|
- Rakefile
|
145
129
|
- bin/console
|
146
130
|
- bin/setup
|
147
131
|
- lib/sheetsu.rb
|
148
132
|
- lib/sheetsu/client.rb
|
133
|
+
- lib/sheetsu/create.rb
|
134
|
+
- lib/sheetsu/delete.rb
|
149
135
|
- lib/sheetsu/errors.rb
|
136
|
+
- lib/sheetsu/read.rb
|
137
|
+
- lib/sheetsu/request.rb
|
138
|
+
- lib/sheetsu/update.rb
|
139
|
+
- lib/sheetsu/util.rb
|
150
140
|
- lib/sheetsu/version.rb
|
151
141
|
- sheetsu.gemspec
|
152
|
-
homepage: https://
|
142
|
+
homepage: https://sheetsu.com
|
153
143
|
licenses:
|
154
144
|
- MIT
|
155
145
|
metadata: {}
|
156
|
-
post_install_message:
|
146
|
+
post_install_message: "\n There are major changes in the v. 1.0 of this gem. Check
|
147
|
+
docs (https://github.com/sheetsu/sheetsu-ruby) to be sure we don't break your app.\n\n
|
148
|
+
\ Happy hacking!\n "
|
157
149
|
rdoc_options: []
|
158
150
|
require_paths:
|
159
151
|
- lib
|
@@ -161,7 +153,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
161
153
|
requirements:
|
162
154
|
- - ">="
|
163
155
|
- !ruby/object:Gem::Version
|
164
|
-
version:
|
156
|
+
version: '0'
|
165
157
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
166
158
|
requirements:
|
167
159
|
- - ">="
|
@@ -169,8 +161,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
169
161
|
version: '0'
|
170
162
|
requirements: []
|
171
163
|
rubyforge_project:
|
172
|
-
rubygems_version: 2.
|
164
|
+
rubygems_version: 2.4.8
|
173
165
|
signing_key:
|
174
166
|
specification_version: 4
|
175
|
-
summary:
|
167
|
+
summary: Turn Google Spreadsheets into REST APIs
|
176
168
|
test_files: []
|
169
|
+
has_rdoc:
|
data/.codeclimate.yml
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
---
|
2
|
-
engines:
|
3
|
-
bundler-audit:
|
4
|
-
enabled: true
|
5
|
-
duplication:
|
6
|
-
enabled: true
|
7
|
-
config:
|
8
|
-
languages:
|
9
|
-
- ruby
|
10
|
-
fixme:
|
11
|
-
enabled: true
|
12
|
-
rubocop:
|
13
|
-
enabled: true
|
14
|
-
ratings:
|
15
|
-
paths:
|
16
|
-
- Gemfile.lock
|
17
|
-
- "**.rb"
|
18
|
-
exclude_paths:
|
19
|
-
- spec/**/*
|
data/.ruby-version
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
2.2.3
|
data/LICENSE
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
The MIT License (MIT)
|
2
|
-
|
3
|
-
Copyright (c) 2015 William Notowidagdo
|
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 all
|
13
|
-
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 THE
|
21
|
-
SOFTWARE.
|
22
|
-
|
data/LICENSE.txt
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
The MIT License (MIT)
|
2
|
-
|
3
|
-
Copyright (c) 2015 William Notowidagdo
|
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.
|