airrecord 1.0.3 → 1.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +2 -1
- data/CHANGELOG.md +16 -0
- data/README.md +2 -0
- data/airrecord.gemspec +7 -6
- data/bin/production-test.rb +9 -0
- data/lib/airrecord.rb +3 -2
- data/lib/airrecord/client.rb +3 -3
- data/lib/airrecord/faraday_rate_limiter.rb +2 -1
- data/lib/airrecord/query_string.rb +4 -4
- data/lib/airrecord/table.rb +28 -15
- data/lib/airrecord/version.rb +1 -1
- metadata +29 -22
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: deb117e05bbf701e4e1e60cf3cccc659a173c7d4f1fc5cb6f80ee72af5603b0e
|
4
|
+
data.tar.gz: a4e928fbd33774f2d41508136da24e56eb2687775c2b962912df86e99eb34bdf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 890dbffd8a3489d505db3da5149cefeb85acbee754d0cc39a9ecf15e5d38b145735df895de9a16a747e20a0b92ae533e01a954e21220d0e044beb7e73ddc3c3e
|
7
|
+
data.tar.gz: 518f7f4cbc0559bb20931ba39a7c000a5ed632075ebd6ce41ff4555334c5c31251256b1f92105d8cd44b21b93b79e52e6b820ab2f5875bbd26a219dd3334967b
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,19 @@
|
|
1
|
+
# 1.0.7
|
2
|
+
|
3
|
+
* Further Ruby 3 compatibility, in particular with Faraday (#83)
|
4
|
+
|
5
|
+
# 1.0.6
|
6
|
+
|
7
|
+
* Ruby 3 compatibility
|
8
|
+
|
9
|
+
# 1.0.5
|
10
|
+
|
11
|
+
* Allow Faraday 1.0 (#70)
|
12
|
+
|
13
|
+
# 1.0.4
|
14
|
+
|
15
|
+
* Correctly set `created_at` on `#find` (#68)
|
16
|
+
|
1
17
|
# 1.0.3
|
2
18
|
|
3
19
|
* Allow passing optional parameters, e.g. `typecast: true`. (#67)
|
data/README.md
CHANGED
@@ -255,6 +255,8 @@ tea["Village"] = "Feng Gang"
|
|
255
255
|
tea.save # persist to Airtable
|
256
256
|
```
|
257
257
|
|
258
|
+
_Airtable's API doesn't allow you to change attachment's filename. As a workaround you can delete the original attachment and [upload a new one](https://github.com/sirupsen/airrecord#file-uploads) with the original URL and a new filename._
|
259
|
+
|
258
260
|
### Deleting
|
259
261
|
|
260
262
|
An instantiated record can be deleted through `#destroy`:
|
data/airrecord.gemspec
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# coding: utf-8
|
2
|
+
|
2
3
|
lib = File.expand_path('../lib', __FILE__)
|
3
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
5
|
require 'airrecord/version'
|
@@ -18,13 +19,13 @@ Gem::Specification.new do |spec|
|
|
18
19
|
spec.bindir = "exe"
|
19
20
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
21
|
spec.require_paths = ["lib"]
|
21
|
-
spec.required_ruby_version =
|
22
|
+
spec.required_ruby_version = ">= 2.2"
|
22
23
|
|
23
|
-
spec.add_dependency
|
24
|
-
spec.add_dependency "net-http-persistent"
|
24
|
+
spec.add_dependency "faraday", [">= 0.10", "< 2.0"]
|
25
|
+
spec.add_dependency "net-http-persistent"
|
25
26
|
|
26
|
-
spec.add_development_dependency "bundler", "~> 2
|
27
|
-
spec.add_development_dependency "rake", "~> 10.0"
|
28
|
-
spec.add_development_dependency "minitest", "~> 5.0"
|
27
|
+
spec.add_development_dependency "bundler", "~> 2"
|
29
28
|
spec.add_development_dependency "byebug"
|
29
|
+
spec.add_development_dependency "minitest", "~> 5.0"
|
30
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
30
31
|
end
|
data/lib/airrecord.rb
CHANGED
@@ -7,12 +7,13 @@ require "airrecord/table"
|
|
7
7
|
|
8
8
|
module Airrecord
|
9
9
|
extend self
|
10
|
+
attr_accessor :api_key, :throttle
|
11
|
+
|
10
12
|
Error = Class.new(StandardError)
|
11
|
-
attr_accessor :api_key
|
12
|
-
attr_accessor :throttle
|
13
13
|
|
14
14
|
def throttle?
|
15
15
|
return true if @throttle.nil?
|
16
|
+
|
16
17
|
@throttle
|
17
18
|
end
|
18
19
|
end
|
data/lib/airrecord/client.rb
CHANGED
@@ -23,13 +23,13 @@ module Airrecord
|
|
23
23
|
"User-Agent" => "Airrecord/#{Airrecord::VERSION}",
|
24
24
|
"X-API-VERSION" => "0.1.0",
|
25
25
|
},
|
26
|
-
request: { params_encoder: Airrecord::QueryString }
|
27
|
-
)
|
26
|
+
request: { params_encoder: Airrecord::QueryString }
|
27
|
+
) do |conn|
|
28
28
|
if Airrecord.throttle?
|
29
29
|
conn.request :airrecord_rate_limiter, requests_per_second: AIRTABLE_RPS_LIMIT
|
30
30
|
end
|
31
31
|
conn.adapter :net_http_persistent
|
32
|
-
|
32
|
+
end
|
33
33
|
end
|
34
34
|
|
35
35
|
def escape(*args)
|
@@ -37,6 +37,7 @@ module Airrecord
|
|
37
37
|
def too_many_requests_in_last_second?
|
38
38
|
return false unless @rps
|
39
39
|
return false unless requests.size >= @rps
|
40
|
+
|
40
41
|
window_span < 1.0
|
41
42
|
end
|
42
43
|
|
@@ -56,5 +57,5 @@ end
|
|
56
57
|
|
57
58
|
Faraday::Request.register_middleware(
|
58
59
|
# Avoid polluting the global middleware namespace with a prefix.
|
59
|
-
:
|
60
|
+
airrecord_rate_limiter: Airrecord::FaradayRateLimiter
|
60
61
|
)
|
@@ -25,16 +25,16 @@ module Airrecord
|
|
25
25
|
end
|
26
26
|
|
27
27
|
TYPES = {
|
28
|
-
Array => lambda
|
28
|
+
Array => lambda do |prefix, array|
|
29
29
|
array.each_with_index.map do |value, index|
|
30
30
|
self[value].call("#{prefix}[#{index}]", value)
|
31
31
|
end
|
32
|
-
|
33
|
-
Hash => lambda
|
32
|
+
end,
|
33
|
+
Hash => lambda do |prefix, hash|
|
34
34
|
hash.map do |key, value|
|
35
35
|
self[value].call("#{prefix}[#{key}]", value)
|
36
36
|
end
|
37
|
-
|
37
|
+
end
|
38
38
|
}.freeze
|
39
39
|
|
40
40
|
DEFAULT = lambda do |key, value|
|
data/lib/airrecord/table.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'rubygems' # For Gem::Version
|
2
|
+
|
1
3
|
module Airrecord
|
2
4
|
class Table
|
3
5
|
class << self
|
@@ -15,7 +17,7 @@ module Airrecord
|
|
15
17
|
|
16
18
|
def has_many(method_name, options)
|
17
19
|
define_method(method_name.to_sym) do
|
18
|
-
# Get association ids in reverse order, because Airtable
|
20
|
+
# Get association ids in reverse order, because Airtable's UI and API
|
19
21
|
# sort associations in opposite directions. We want to match the UI.
|
20
22
|
ids = (self[options.fetch(:column)] || []).reverse
|
21
23
|
table = Kernel.const_get(options.fetch(:class))
|
@@ -40,7 +42,7 @@ module Airrecord
|
|
40
42
|
parsed_response = client.parse(response.body)
|
41
43
|
|
42
44
|
if response.success?
|
43
|
-
self.new(parsed_response["fields"], id: id)
|
45
|
+
self.new(parsed_response["fields"], id: id, created_at: parsed_response["createdTime"])
|
44
46
|
else
|
45
47
|
client.handle_error(response.status, parsed_response)
|
46
48
|
end
|
@@ -54,7 +56,7 @@ module Airrecord
|
|
54
56
|
records(filter: formula).sort_by { |record| or_args.index(record.id) }
|
55
57
|
end
|
56
58
|
|
57
|
-
def create(fields, options={})
|
59
|
+
def create(fields, options = {})
|
58
60
|
new(fields).tap { |record| record.save(options) }
|
59
61
|
end
|
60
62
|
|
@@ -102,15 +104,25 @@ module Airrecord
|
|
102
104
|
client.handle_error(response.status, parsed_response)
|
103
105
|
end
|
104
106
|
end
|
105
|
-
|
107
|
+
alias all records
|
106
108
|
end
|
107
109
|
|
108
110
|
attr_reader :fields, :id, :created_at, :updated_keys
|
109
111
|
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
112
|
+
# This is an awkward definition for Ruby 3 to remain backwards compatible.
|
113
|
+
# It's easier to read by reading the 2.x definition below.
|
114
|
+
if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.0.0")
|
115
|
+
def initialize(*one, **two)
|
116
|
+
@id = one.first && two.delete(:id)
|
117
|
+
self.created_at = one.first && two.delete(:created_at)
|
118
|
+
self.fields = one.first || two
|
119
|
+
end
|
120
|
+
else
|
121
|
+
def initialize(fields, id: nil, created_at: nil)
|
122
|
+
@id = id
|
123
|
+
self.created_at = created_at
|
124
|
+
self.fields = fields
|
125
|
+
end
|
114
126
|
end
|
115
127
|
|
116
128
|
def new_record?
|
@@ -125,16 +137,17 @@ module Airrecord
|
|
125
137
|
def []=(key, value)
|
126
138
|
validate_key(key)
|
127
139
|
return if fields[key] == value # no-op
|
140
|
+
|
128
141
|
@updated_keys << key
|
129
142
|
fields[key] = value
|
130
143
|
end
|
131
144
|
|
132
|
-
def create(options={})
|
145
|
+
def create(options = {})
|
133
146
|
raise Error, "Record already exists (record has an id)" unless new_record?
|
134
147
|
|
135
148
|
body = {
|
136
149
|
fields: serializable_fields,
|
137
|
-
**options
|
150
|
+
**options
|
138
151
|
}.to_json
|
139
152
|
|
140
153
|
response = client.connection.post("/v0/#{self.class.base_key}/#{client.escape(self.class.table_name)}", body, { 'Content-Type' => 'application/json' })
|
@@ -149,9 +162,8 @@ module Airrecord
|
|
149
162
|
end
|
150
163
|
end
|
151
164
|
|
152
|
-
def save(options={})
|
165
|
+
def save(options = {})
|
153
166
|
return create(options) if new_record?
|
154
|
-
|
155
167
|
return true if @updated_keys.empty?
|
156
168
|
|
157
169
|
# To avoid trying to update computed fields we *always* use PATCH
|
@@ -159,7 +171,7 @@ module Airrecord
|
|
159
171
|
fields: Hash[@updated_keys.map { |key|
|
160
172
|
[key, fields[key]]
|
161
173
|
}],
|
162
|
-
**options
|
174
|
+
**options
|
163
175
|
}.to_json
|
164
176
|
|
165
177
|
response = client.connection.patch("/v0/#{self.class.base_key}/#{client.escape(self.class.table_name)}/#{self.id}", body, { 'Content-Type' => 'application/json' })
|
@@ -193,8 +205,7 @@ module Airrecord
|
|
193
205
|
self.class == other.class &&
|
194
206
|
serializable_fields == other.serializable_fields
|
195
207
|
end
|
196
|
-
|
197
|
-
alias_method :eql?, :==
|
208
|
+
alias eql? ==
|
198
209
|
|
199
210
|
def hash
|
200
211
|
serializable_fields.hash
|
@@ -209,6 +220,7 @@ module Airrecord
|
|
209
220
|
|
210
221
|
def created_at=(created_at)
|
211
222
|
return unless created_at
|
223
|
+
|
212
224
|
@created_at = Time.parse(created_at)
|
213
225
|
end
|
214
226
|
|
@@ -218,6 +230,7 @@ module Airrecord
|
|
218
230
|
|
219
231
|
def validate_key(key)
|
220
232
|
return true unless key.is_a?(Symbol)
|
233
|
+
|
221
234
|
raise(Error, [
|
222
235
|
"Airrecord 1.0 dropped support for Symbols as field names.",
|
223
236
|
"Please use the raw field name, a String, instead.",
|
data/lib/airrecord/version.rb
CHANGED
metadata
CHANGED
@@ -1,71 +1,77 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: airrecord
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Simon Eskildsen
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-08-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '0.10'
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '2.0'
|
20
23
|
type: :runtime
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
23
26
|
requirements:
|
24
|
-
- - "
|
27
|
+
- - ">="
|
25
28
|
- !ruby/object:Gem::Version
|
26
29
|
version: '0.10'
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '2.0'
|
27
33
|
- !ruby/object:Gem::Dependency
|
28
34
|
name: net-http-persistent
|
29
35
|
requirement: !ruby/object:Gem::Requirement
|
30
36
|
requirements:
|
31
37
|
- - ">="
|
32
38
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
39
|
+
version: '0'
|
34
40
|
type: :runtime
|
35
41
|
prerelease: false
|
36
42
|
version_requirements: !ruby/object:Gem::Requirement
|
37
43
|
requirements:
|
38
44
|
- - ">="
|
39
45
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
46
|
+
version: '0'
|
41
47
|
- !ruby/object:Gem::Dependency
|
42
48
|
name: bundler
|
43
49
|
requirement: !ruby/object:Gem::Requirement
|
44
50
|
requirements:
|
45
51
|
- - "~>"
|
46
52
|
- !ruby/object:Gem::Version
|
47
|
-
version: 2
|
53
|
+
version: '2'
|
48
54
|
type: :development
|
49
55
|
prerelease: false
|
50
56
|
version_requirements: !ruby/object:Gem::Requirement
|
51
57
|
requirements:
|
52
58
|
- - "~>"
|
53
59
|
- !ruby/object:Gem::Version
|
54
|
-
version: 2
|
60
|
+
version: '2'
|
55
61
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
62
|
+
name: byebug
|
57
63
|
requirement: !ruby/object:Gem::Requirement
|
58
64
|
requirements:
|
59
|
-
- - "
|
65
|
+
- - ">="
|
60
66
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
67
|
+
version: '0'
|
62
68
|
type: :development
|
63
69
|
prerelease: false
|
64
70
|
version_requirements: !ruby/object:Gem::Requirement
|
65
71
|
requirements:
|
66
|
-
- - "
|
72
|
+
- - ">="
|
67
73
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
74
|
+
version: '0'
|
69
75
|
- !ruby/object:Gem::Dependency
|
70
76
|
name: minitest
|
71
77
|
requirement: !ruby/object:Gem::Requirement
|
@@ -81,19 +87,19 @@ dependencies:
|
|
81
87
|
- !ruby/object:Gem::Version
|
82
88
|
version: '5.0'
|
83
89
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
90
|
+
name: rake
|
85
91
|
requirement: !ruby/object:Gem::Requirement
|
86
92
|
requirements:
|
87
|
-
- - "
|
93
|
+
- - "~>"
|
88
94
|
- !ruby/object:Gem::Version
|
89
|
-
version: '0'
|
95
|
+
version: '10.0'
|
90
96
|
type: :development
|
91
97
|
prerelease: false
|
92
98
|
version_requirements: !ruby/object:Gem::Requirement
|
93
99
|
requirements:
|
94
|
-
- - "
|
100
|
+
- - "~>"
|
95
101
|
- !ruby/object:Gem::Version
|
96
|
-
version: '0'
|
102
|
+
version: '10.0'
|
97
103
|
description: Airtable client to make Airtable interactions a breeze
|
98
104
|
email:
|
99
105
|
- sirup@sirupsen.com
|
@@ -110,6 +116,7 @@ files:
|
|
110
116
|
- Rakefile
|
111
117
|
- airrecord.gemspec
|
112
118
|
- bin/console
|
119
|
+
- bin/production-test.rb
|
113
120
|
- bin/setup
|
114
121
|
- lib/airrecord.rb
|
115
122
|
- lib/airrecord/client.rb
|
@@ -121,7 +128,7 @@ homepage: https://github.com/sirupsen/airrecord
|
|
121
128
|
licenses:
|
122
129
|
- MIT
|
123
130
|
metadata: {}
|
124
|
-
post_install_message:
|
131
|
+
post_install_message:
|
125
132
|
rdoc_options: []
|
126
133
|
require_paths:
|
127
134
|
- lib
|
@@ -136,8 +143,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
136
143
|
- !ruby/object:Gem::Version
|
137
144
|
version: '0'
|
138
145
|
requirements: []
|
139
|
-
rubygems_version: 3.
|
140
|
-
signing_key:
|
146
|
+
rubygems_version: 3.2.15
|
147
|
+
signing_key:
|
141
148
|
specification_version: 4
|
142
149
|
summary: Airtable client
|
143
150
|
test_files: []
|