airrecord 1.0.1 → 1.0.6
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 +27 -0
- data/README.md +16 -0
- data/airrecord.gemspec +3 -3
- data/bin/production-test.rb +9 -0
- data/lib/airrecord/table.rb +34 -13
- data/lib/airrecord/version.rb +1 -1
- metadata +19 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 53739239320854267f0a3fa6a03b81b5ea733bcca061728f0a0b2337d5d32c8d
|
4
|
+
data.tar.gz: 4c7d23923d1fc45ff48c3644f83f42598b77878756ef2f41cabd229fb122e61f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f474a334e15a3feeedaa18dcbb5ddc9cc8a3b6ad2707377de076dc821ff4453e2400a39750e03b7cfb73a69d20aea5627c4e9c9aa1474e325a5e625bf6941d1b
|
7
|
+
data.tar.gz: eb8c7b5d6e66677059ab1fed2d25826280e6f9736d7e775422b8d103ad9dd53982708642782e7cbef3797c58cf95c0cfd712b4f370538b8436e10e1204cc5406
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,4 +1,31 @@
|
|
1
|
+
# 1.0.6
|
2
|
+
|
3
|
+
* Ruby 3 compatibility
|
4
|
+
|
5
|
+
# 1.0.5
|
6
|
+
|
7
|
+
* Allow Faraday 1.0 (#70)
|
8
|
+
|
9
|
+
# 1.0.4
|
10
|
+
|
11
|
+
* Correctly set `created_at` on `#find` (#68)
|
12
|
+
|
13
|
+
# 1.0.3
|
14
|
+
|
15
|
+
* Allow passing optional parameters, e.g. `typecast: true`. (#67)
|
16
|
+
|
17
|
+
# 1.0.2
|
18
|
+
|
19
|
+
* When a `has_one` or `belongs_to` association is empty, return `nil` instead of
|
20
|
+
a blank record (#51)
|
21
|
+
|
22
|
+
* When a `has_many` association is empty, do not make a network call to the
|
23
|
+
associated table
|
24
|
+
|
25
|
+
* Relax dependency on `net-http-persistent` to allow latest (#57)
|
26
|
+
|
1
27
|
# 1.0.1
|
28
|
+
|
2
29
|
* Support JRuby 9.0 and CRuby 2.2 (#47)
|
3
30
|
* Fix $stderr warnings in CRurby > 2.3 (#46)
|
4
31
|
|
data/README.md
CHANGED
@@ -222,6 +222,22 @@ tea.save
|
|
222
222
|
Note that column names need to match the exact column names in Airtable,
|
223
223
|
otherwise Airrecord will throw an error that no column matches it.
|
224
224
|
|
225
|
+
|
226
|
+
If you need to include optional request parameters, such as the `typecast` parameter, these can be passed to either `Table.create` or `#save`.
|
227
|
+
This is also supported when updating existing records with the `#save` method.
|
228
|
+
|
229
|
+
```ruby
|
230
|
+
tea = Tea.create(
|
231
|
+
{"Name" => "Feng Gang", "Type" => "Green", "Country" => "China"},
|
232
|
+
{"typecast" => true},
|
233
|
+
)
|
234
|
+
|
235
|
+
# Or with the #save method:
|
236
|
+
tea = Tea.new({"Name" => "Feng Gang", "Type" => "Green"})
|
237
|
+
tea["Name"] = "Feng Gang"
|
238
|
+
tea.save("typecast" => true)
|
239
|
+
```
|
240
|
+
|
225
241
|
_Earlier versions of airrecord provided methods for snake-cased column names
|
226
242
|
and symbols, however this proved error-prone without a proper schema API from
|
227
243
|
Airtable which has still not been released._
|
data/airrecord.gemspec
CHANGED
@@ -20,10 +20,10 @@ Gem::Specification.new do |spec|
|
|
20
20
|
spec.require_paths = ["lib"]
|
21
21
|
spec.required_ruby_version = '>= 2.2'
|
22
22
|
|
23
|
-
spec.add_dependency 'faraday', '
|
24
|
-
spec.add_dependency "net-http-persistent", '
|
23
|
+
spec.add_dependency 'faraday', ['>= 0.10', '< 2.0']
|
24
|
+
spec.add_dependency "net-http-persistent", '>= 2.9'
|
25
25
|
|
26
|
-
spec.add_development_dependency "bundler", "~>
|
26
|
+
spec.add_development_dependency "bundler", "~> 2"
|
27
27
|
spec.add_development_dependency "rake", "~> 10.0"
|
28
28
|
spec.add_development_dependency "minitest", "~> 5.0"
|
29
29
|
spec.add_development_dependency "byebug"
|
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
|
@@ -19,7 +21,9 @@ module Airrecord
|
|
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))
|
22
|
-
|
24
|
+
return table.find_many(ids) unless options[:single]
|
25
|
+
|
26
|
+
(id = ids.first) ? table.find(id) : nil
|
23
27
|
end
|
24
28
|
|
25
29
|
define_method("#{method_name}=".to_sym) do |value|
|
@@ -38,20 +42,22 @@ module Airrecord
|
|
38
42
|
parsed_response = client.parse(response.body)
|
39
43
|
|
40
44
|
if response.success?
|
41
|
-
self.new(parsed_response["fields"], id: id)
|
45
|
+
self.new(parsed_response["fields"], id: id, created_at: parsed_response["createdTime"])
|
42
46
|
else
|
43
47
|
client.handle_error(response.status, parsed_response)
|
44
48
|
end
|
45
49
|
end
|
46
50
|
|
47
51
|
def find_many(ids)
|
52
|
+
return [] if ids.empty?
|
53
|
+
|
48
54
|
or_args = ids.map { |id| "RECORD_ID() = '#{id}'"}.join(',')
|
49
55
|
formula = "OR(#{or_args})"
|
50
56
|
records(filter: formula).sort_by { |record| or_args.index(record.id) }
|
51
57
|
end
|
52
58
|
|
53
|
-
def create(fields)
|
54
|
-
new(fields).tap { |record| record.save }
|
59
|
+
def create(fields, options={})
|
60
|
+
new(fields).tap { |record| record.save(options) }
|
55
61
|
end
|
56
62
|
|
57
63
|
def records(filter: nil, sort: nil, view: nil, offset: nil, paginate: true, fields: nil, max_records: nil, page_size: nil)
|
@@ -103,10 +109,20 @@ module Airrecord
|
|
103
109
|
|
104
110
|
attr_reader :fields, :id, :created_at, :updated_keys
|
105
111
|
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
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
|
110
126
|
end
|
111
127
|
|
112
128
|
def new_record?
|
@@ -125,10 +141,14 @@ module Airrecord
|
|
125
141
|
fields[key] = value
|
126
142
|
end
|
127
143
|
|
128
|
-
def create
|
144
|
+
def create(options={})
|
129
145
|
raise Error, "Record already exists (record has an id)" unless new_record?
|
130
146
|
|
131
|
-
body = {
|
147
|
+
body = {
|
148
|
+
fields: serializable_fields,
|
149
|
+
**options,
|
150
|
+
}.to_json
|
151
|
+
|
132
152
|
response = client.connection.post("/v0/#{self.class.base_key}/#{client.escape(self.class.table_name)}", body, { 'Content-Type' => 'application/json' })
|
133
153
|
parsed_response = client.parse(response.body)
|
134
154
|
|
@@ -141,8 +161,8 @@ module Airrecord
|
|
141
161
|
end
|
142
162
|
end
|
143
163
|
|
144
|
-
def save
|
145
|
-
return create if new_record?
|
164
|
+
def save(options={})
|
165
|
+
return create(options) if new_record?
|
146
166
|
|
147
167
|
return true if @updated_keys.empty?
|
148
168
|
|
@@ -150,7 +170,8 @@ module Airrecord
|
|
150
170
|
body = {
|
151
171
|
fields: Hash[@updated_keys.map { |key|
|
152
172
|
[key, fields[key]]
|
153
|
-
}]
|
173
|
+
}],
|
174
|
+
**options,
|
154
175
|
}.to_json
|
155
176
|
|
156
177
|
response = client.connection.patch("/v0/#{self.class.base_key}/#{client.escape(self.class.table_name)}/#{self.id}", body, { 'Content-Type' => 'application/json' })
|
data/lib/airrecord/version.rb
CHANGED
metadata
CHANGED
@@ -1,41 +1,47 @@
|
|
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.6
|
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-04-17 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
39
|
version: '2.9'
|
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
46
|
version: '2.9'
|
41
47
|
- !ruby/object:Gem::Dependency
|
@@ -44,14 +50,14 @@ dependencies:
|
|
44
50
|
requirements:
|
45
51
|
- - "~>"
|
46
52
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
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: '
|
60
|
+
version: '2'
|
55
61
|
- !ruby/object:Gem::Dependency
|
56
62
|
name: rake
|
57
63
|
requirement: !ruby/object:Gem::Requirement
|
@@ -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,9 +143,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
136
143
|
- !ruby/object:Gem::Version
|
137
144
|
version: '0'
|
138
145
|
requirements: []
|
139
|
-
|
140
|
-
|
141
|
-
signing_key:
|
146
|
+
rubygems_version: 3.1.4
|
147
|
+
signing_key:
|
142
148
|
specification_version: 4
|
143
149
|
summary: Airtable client
|
144
150
|
test_files: []
|