airtable 0.0.8 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE.txt +1 -0
- data/README.md +10 -2
- data/airtable.gemspec +2 -2
- data/lib/airtable/table.rb +35 -2
- data/lib/airtable/version.rb +1 -1
- data/test/airtable_test.rb +17 -1
- metadata +20 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eb153e06bee46ce7fdf9e4dff38f865c4d0b06f7
|
4
|
+
data.tar.gz: f484c60556d41073e7ef37875d7055ce927bf58d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f015c413e7e65127f41be7512ac6d2eb57d3a8a1f4f0a6e17deea2cf96926534236e14827b03e008f781c1edaedd0c6c9ce93a644bd2dec3a0c3180545c2d7eb
|
7
|
+
data.tar.gz: 471dc50590a47da27667d0beb47b8fc0c58113d33482d74b4621497c5d41106c00c537a3f0e4344373bc01de2661a021ef0d6c74a9ce5b3f30731adc127bd8be
|
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -2,6 +2,14 @@
|
|
2
2
|
|
3
3
|
Easily connect to [airtable](https://airtable.com) data using ruby with access to all of the airtable features.
|
4
4
|
|
5
|
+
# Note on library status
|
6
|
+
|
7
|
+
We are currently transitioning this gem to be supported by
|
8
|
+
Airtable. We will maintain it moving forward, but until we fully
|
9
|
+
support it, it will stay in the status of "community libraries". At
|
10
|
+
that time we will remove this notice and add a "ruby" section to the
|
11
|
+
API docs.
|
12
|
+
|
5
13
|
## Installation
|
6
14
|
|
7
15
|
Add this line to your application's Gemfile:
|
@@ -74,7 +82,7 @@ We can also query all records in the table through a series of batch requests wi
|
|
74
82
|
@records = @table.all(:sort => ["Name", :asc])
|
75
83
|
```
|
76
84
|
|
77
|
-
This executes a variable number of network requests (100 records per batch) to retrieve all records in a sheet.
|
85
|
+
This executes a variable number of network requests (100 records per batch) to retrieve all records in a sheet.
|
78
86
|
|
79
87
|
### Finding a Record
|
80
88
|
|
@@ -107,7 +115,7 @@ Records can be updated using the `update` method on a table:
|
|
107
115
|
|
108
116
|
### Deleting Records
|
109
117
|
|
110
|
-
Records can be
|
118
|
+
Records can be destroyed using the `destroy` method on a table:
|
111
119
|
|
112
120
|
```ruby
|
113
121
|
@table.destroy(record)
|
data/airtable.gemspec
CHANGED
@@ -6,8 +6,8 @@ require 'airtable/version'
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "airtable"
|
8
8
|
spec.version = Airtable::VERSION
|
9
|
-
spec.authors = ["Nathan Esquenazi"]
|
10
|
-
spec.email = ["nesquena@gmail.com"]
|
9
|
+
spec.authors = ["Nathan Esquenazi", "Alexander Sorokin"]
|
10
|
+
spec.email = ["nesquena@gmail.com", "syrnick@gmail.com"]
|
11
11
|
spec.summary = %q{Easily connect to airtable data using ruby}
|
12
12
|
spec.description = %q{Easily connect to airtable data using ruby with access to all of the airtable features.}
|
13
13
|
spec.homepage = "https://github.com/nesquena/airtable-ruby"
|
data/lib/airtable/table.rb
CHANGED
@@ -27,6 +27,28 @@ module Airtable
|
|
27
27
|
RecordSet.new(results)
|
28
28
|
end
|
29
29
|
|
30
|
+
# Query for records using a string formula
|
31
|
+
# Options: limit = 100, offset = "as345g", sort = ["Name", "asc"],
|
32
|
+
# fields = [Name, Email], formula = "Count > 5", view = "Main View"
|
33
|
+
#
|
34
|
+
# select(limit: 10, sort: ["Name", "asc"], formula: "Order < 2")
|
35
|
+
def select(options={})
|
36
|
+
options['sortField'], options['sortDirection'] = options.delete(:sort) if options[:sort]
|
37
|
+
options['maxRecords'] = options.delete(:limit) if options[:limit]
|
38
|
+
|
39
|
+
if options[:formula]
|
40
|
+
raise_bad_formula_error unless options[:formula].is_a? String
|
41
|
+
options['filterByFormula'] = options.delete(:formula)
|
42
|
+
end
|
43
|
+
|
44
|
+
results = self.class.get(worksheet_url, query: options).parsed_response
|
45
|
+
RecordSet.new(results)
|
46
|
+
end
|
47
|
+
|
48
|
+
def raise_bad_formula_error
|
49
|
+
raise ArgumentError.new("The value for filter should be a String.")
|
50
|
+
end
|
51
|
+
|
30
52
|
# Returns record based given row id
|
31
53
|
def find(id)
|
32
54
|
result = self.class.get(worksheet_url + "/" + id).parsed_response
|
@@ -59,6 +81,17 @@ module Airtable
|
|
59
81
|
end
|
60
82
|
end
|
61
83
|
|
84
|
+
def update_record_fields(record_id, fields_for_update)
|
85
|
+
result = self.class.patch(worksheet_url + "/" + record_id,
|
86
|
+
:body => { "fields" => fields_for_update }.to_json,
|
87
|
+
:headers => { "Content-type" => "application/json" }).parsed_response
|
88
|
+
if result.present? && result["id"].present?
|
89
|
+
Record.new(result_attributes(result))
|
90
|
+
else # failed
|
91
|
+
false
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
62
95
|
# Deletes record in table based on id
|
63
96
|
def destroy(id)
|
64
97
|
self.class.delete(worksheet_url + "/" + id).parsed_response
|
@@ -71,8 +104,8 @@ module Airtable
|
|
71
104
|
end
|
72
105
|
|
73
106
|
def worksheet_url
|
74
|
-
"/#{app_token}/#{
|
107
|
+
"/#{app_token}/#{CGI.escape(worksheet_name)}"
|
75
108
|
end
|
76
109
|
end # Table
|
77
110
|
|
78
|
-
end # Airtable
|
111
|
+
end # Airtable
|
data/lib/airtable/version.rb
CHANGED
data/test/airtable_test.rb
CHANGED
@@ -22,6 +22,22 @@ describe Airtable do
|
|
22
22
|
assert_equal "abcde", @records.offset
|
23
23
|
end
|
24
24
|
|
25
|
+
it "should select records based on a formula" do
|
26
|
+
query_str = "OR(RECORD_ID() = 'recXYZ1', RECORD_ID() = 'recXYZ2', RECORD_ID() = 'recXYZ3', RECORD_ID() = 'recXYZ4')"
|
27
|
+
escaped_query = HTTParty::Request::NON_RAILS_QUERY_STRING_NORMALIZER.call(filterByFormula: query_str)
|
28
|
+
request_url = "https://api.airtable.com/v0/#{@app_key}/#{@sheet_name}?#{escaped_query}"
|
29
|
+
stub_airtable_response!(request_url, { "records" => []})
|
30
|
+
@table = Airtable::Client.new(@client_key).table(@app_key, @sheet_name)
|
31
|
+
@select_records = @table.select(formula: query_str)
|
32
|
+
assert_equal @select_records.records, []
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should raise an ArgumentError if a formula is not a string" do
|
36
|
+
stub_airtable_response!("https://api.airtable.com/v0/#{@app_key}/#{@sheet_name}", { "records" => [], "offset" => "abcde" })
|
37
|
+
@table = Airtable::Client.new(@client_key).table(@app_key, @sheet_name)
|
38
|
+
proc { @table.select(formula: {foo: 'bar'}) }.must_raise ArgumentError
|
39
|
+
end
|
40
|
+
|
25
41
|
it "should allow creating records" do
|
26
42
|
stub_airtable_response!("https://api.airtable.com/v0/#{@app_key}/#{@sheet_name}",
|
27
43
|
{ "fields" => { "name" => "Sarah Jaine", "email" => "sarah@jaine.com", "foo" => "bar" }, "id" => "12345" }, :post)
|
@@ -44,4 +60,4 @@ describe Airtable do
|
|
44
60
|
end
|
45
61
|
|
46
62
|
end # describe Airtable
|
47
|
-
end # Airtable
|
63
|
+
end # Airtable
|
metadata
CHANGED
@@ -1,108 +1,110 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: airtable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nathan Esquenazi
|
8
|
+
- Alexander Sorokin
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date: 2016-
|
12
|
+
date: 2016-10-18 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: httparty
|
15
16
|
requirement: !ruby/object:Gem::Requirement
|
16
17
|
requirements:
|
17
|
-
- -
|
18
|
+
- - ">="
|
18
19
|
- !ruby/object:Gem::Version
|
19
20
|
version: '0'
|
20
21
|
type: :runtime
|
21
22
|
prerelease: false
|
22
23
|
version_requirements: !ruby/object:Gem::Requirement
|
23
24
|
requirements:
|
24
|
-
- -
|
25
|
+
- - ">="
|
25
26
|
- !ruby/object:Gem::Version
|
26
27
|
version: '0'
|
27
28
|
- !ruby/object:Gem::Dependency
|
28
29
|
name: bundler
|
29
30
|
requirement: !ruby/object:Gem::Requirement
|
30
31
|
requirements:
|
31
|
-
- - ~>
|
32
|
+
- - "~>"
|
32
33
|
- !ruby/object:Gem::Version
|
33
34
|
version: '1.6'
|
34
35
|
type: :development
|
35
36
|
prerelease: false
|
36
37
|
version_requirements: !ruby/object:Gem::Requirement
|
37
38
|
requirements:
|
38
|
-
- - ~>
|
39
|
+
- - "~>"
|
39
40
|
- !ruby/object:Gem::Version
|
40
41
|
version: '1.6'
|
41
42
|
- !ruby/object:Gem::Dependency
|
42
43
|
name: rake
|
43
44
|
requirement: !ruby/object:Gem::Requirement
|
44
45
|
requirements:
|
45
|
-
- -
|
46
|
+
- - ">="
|
46
47
|
- !ruby/object:Gem::Version
|
47
48
|
version: '0'
|
48
49
|
type: :development
|
49
50
|
prerelease: false
|
50
51
|
version_requirements: !ruby/object:Gem::Requirement
|
51
52
|
requirements:
|
52
|
-
- -
|
53
|
+
- - ">="
|
53
54
|
- !ruby/object:Gem::Version
|
54
55
|
version: '0'
|
55
56
|
- !ruby/object:Gem::Dependency
|
56
57
|
name: minitest
|
57
58
|
requirement: !ruby/object:Gem::Requirement
|
58
59
|
requirements:
|
59
|
-
- - ~>
|
60
|
+
- - "~>"
|
60
61
|
- !ruby/object:Gem::Version
|
61
62
|
version: 5.6.0
|
62
63
|
type: :development
|
63
64
|
prerelease: false
|
64
65
|
version_requirements: !ruby/object:Gem::Requirement
|
65
66
|
requirements:
|
66
|
-
- - ~>
|
67
|
+
- - "~>"
|
67
68
|
- !ruby/object:Gem::Version
|
68
69
|
version: 5.6.0
|
69
70
|
- !ruby/object:Gem::Dependency
|
70
71
|
name: fakeweb
|
71
72
|
requirement: !ruby/object:Gem::Requirement
|
72
73
|
requirements:
|
73
|
-
- - ~>
|
74
|
+
- - "~>"
|
74
75
|
- !ruby/object:Gem::Version
|
75
76
|
version: '1.3'
|
76
77
|
type: :development
|
77
78
|
prerelease: false
|
78
79
|
version_requirements: !ruby/object:Gem::Requirement
|
79
80
|
requirements:
|
80
|
-
- - ~>
|
81
|
+
- - "~>"
|
81
82
|
- !ruby/object:Gem::Version
|
82
83
|
version: '1.3'
|
83
84
|
- !ruby/object:Gem::Dependency
|
84
85
|
name: activesupport
|
85
86
|
requirement: !ruby/object:Gem::Requirement
|
86
87
|
requirements:
|
87
|
-
- -
|
88
|
+
- - ">="
|
88
89
|
- !ruby/object:Gem::Version
|
89
90
|
version: '3.0'
|
90
91
|
type: :development
|
91
92
|
prerelease: false
|
92
93
|
version_requirements: !ruby/object:Gem::Requirement
|
93
94
|
requirements:
|
94
|
-
- -
|
95
|
+
- - ">="
|
95
96
|
- !ruby/object:Gem::Version
|
96
97
|
version: '3.0'
|
97
98
|
description: Easily connect to airtable data using ruby with access to all of the
|
98
99
|
airtable features.
|
99
100
|
email:
|
100
101
|
- nesquena@gmail.com
|
102
|
+
- syrnick@gmail.com
|
101
103
|
executables: []
|
102
104
|
extensions: []
|
103
105
|
extra_rdoc_files: []
|
104
106
|
files:
|
105
|
-
- .gitignore
|
107
|
+
- ".gitignore"
|
106
108
|
- Gemfile
|
107
109
|
- LICENSE.txt
|
108
110
|
- README.md
|
@@ -128,17 +130,17 @@ require_paths:
|
|
128
130
|
- lib
|
129
131
|
required_ruby_version: !ruby/object:Gem::Requirement
|
130
132
|
requirements:
|
131
|
-
- -
|
133
|
+
- - ">="
|
132
134
|
- !ruby/object:Gem::Version
|
133
135
|
version: '0'
|
134
136
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
135
137
|
requirements:
|
136
|
-
- -
|
138
|
+
- - ">="
|
137
139
|
- !ruby/object:Gem::Version
|
138
140
|
version: '0'
|
139
141
|
requirements: []
|
140
142
|
rubyforge_project:
|
141
|
-
rubygems_version: 2.
|
143
|
+
rubygems_version: 2.2.2
|
142
144
|
signing_key:
|
143
145
|
specification_version: 4
|
144
146
|
summary: Easily connect to airtable data using ruby
|