airrecord 1.0.12 → 1.0.15

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d8f0c64c9918dc87febb581a9606e7efd7790f36c9f00d378a0e60ec00478929
4
- data.tar.gz: 177f93c0f57ef26ea409f053ff0ead57a31929a2a776fc1cfcfa283bafada909
3
+ metadata.gz: 5f2208a75e682cb75d0b1bc0f1e47b627f4c00303525c3d0d119d6cfa6a0767b
4
+ data.tar.gz: b33321f90b7492de6a30f15b3624e3dde7a0efaefdd0035ee05fbeae8b8fe8be
5
5
  SHA512:
6
- metadata.gz: dd7a540d701aced403ae169892d8c819ebd885e6032bf899d4dba684177d204ca1cd96a0683eab9493c5776a915755ea2ed1855cf9483ced1c6617689f99795e
7
- data.tar.gz: 1f136512474cec58ae55f16cd08fc52c58342ef151e0a9200fca10ae9e9681cbff7fa4f0119a5eae7133b2a30ca775b31e98b737c86fbf9f2a36ad08381d4834
6
+ metadata.gz: 4e8459418a8e0dceb68c377db7260d00737eb7faaf68d51f6dbefe24bddb99e3c0c7c90b07e18dd94371deef32a2ad6da0ee6cd8d32bdc4b7a3d4d575e023359
7
+ data.tar.gz: 5be7eb79d64382c66d01973bbaccfae7a48d7de49fd692720fe7f53eb9f131036db96e9af1095d96f8c8c678fc2da82aefbcfc8675cbc8eec1889a802d591c03
data/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ # 1.0.15
2
+
3
+ Changes since 1.0.12, the previous RubyGems release:
4
+
5
+ * Update a record by ID with `Table.update(id, fields, options)` in a single request (#103).
6
+ * Set `Airrecord::Client.api_uri` to use a custom Airtable API endpoint (#117).
7
+ * `Table.find(nil)` raises `ArgumentError` before making an API request (#119).
8
+ * Document personal access tokens and using a table ID in place of a table name (#101, #116).
9
+
1
10
  # 1.0.11
2
11
 
3
12
  * Switch back to default Faraday encoder and change list-records call to POST
data/README.md CHANGED
@@ -79,6 +79,11 @@ Tea.find("rec3838")
79
79
 
80
80
  ### Authentication
81
81
 
82
+ Based on [Changelog](https://airtable.com/developers/web/api/changelog#anchor-2022-11-15) There are two ways to authenticate with Airtable API:
83
+ 1. API key
84
+ 2. Personal Access Token
85
+
86
+ #### API key
82
87
  To obtain your API client, navigate to the [Airtable's API
83
88
  page](https://airtable.com/api), select your base and obtain your API key and
84
89
  application token.
@@ -94,6 +99,19 @@ Airrecord.api_key = "your api key"
94
99
  The app token has to be set on the definitions of the tables (see API below).
95
100
  You can override the API key per table.
96
101
 
102
+ #### Personal Access Token (PAT)
103
+ - To create a PAT, navigate to the [Airtable's Personal Access Tokens](https://airtable.com/create/tokens) page and create a new token.
104
+ - Give your token a unique name. This name will be visible in record revision history.
105
+ - Choose the scopes to grant to your token. This controls what API endpoints the token will be able to use. For more information, see [API scopes](https://airtable.com/api#authentication).
106
+ - Click ‘add a base’ to grant the token access to a base or workspace.
107
+ - Click ‘create token’ to create the token. You will be shown the token’s value. This is the only time you will be able to see the token’s value, so be sure to copy it to a secure location.
108
+
109
+ You can provide a global PAT with:
110
+
111
+ ```ruby
112
+ Airrecord.api_key = "your PAT"
113
+ ```
114
+
97
115
  ### Table
98
116
 
99
117
  The Airrecord API is centered around definitions of `Airrecord::Table` from
@@ -106,7 +124,7 @@ Airrecord.api_key = "your api key" # see authentication section
106
124
 
107
125
  class Tea < Airrecord::Table
108
126
  self.base_key = "app1"
109
- self.table_name = "Teas"
127
+ self.table_name = "Teas" # or the tblX id
110
128
 
111
129
  def location
112
130
  [self["Village"], self["Country"], self["Region"]].compact.join(", ")
@@ -244,8 +262,9 @@ Airtable which has still not been released._
244
262
 
245
263
  ### Updating
246
264
 
247
- Updating a record is done by changing the attributes and persistent to
248
- Airtable with `#save`.
265
+ Updating can be done in two ways:
266
+
267
+ 1. With a record instance, change the attributes and persist to Airtable with `#save`
249
268
 
250
269
  ```ruby
251
270
  tea = Tea.find("someid")
@@ -255,6 +274,12 @@ tea["Village"] = "Feng Gang"
255
274
  tea.save # persist to Airtable
256
275
  ```
257
276
 
277
+ 2. With the `Table.update` class method (to save an API find call)
278
+
279
+ ```ruby
280
+ Tea.update("someid", { "Name" => "Feng Gang Organic", "Village" => "Feng Gang" })
281
+ ```
282
+
258
283
  _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
284
 
260
285
  ### Deleting
data/airrecord.gemspec CHANGED
@@ -28,5 +28,5 @@ Gem::Specification.new do |spec|
28
28
  spec.add_development_dependency "bundler", "~> 2"
29
29
  spec.add_development_dependency "byebug"
30
30
  spec.add_development_dependency "minitest", "~> 5.0"
31
- spec.add_development_dependency "rake", "~> 10.0"
31
+ spec.add_development_dependency "rake", [">= 10.0", "< 14"]
32
32
  end
@@ -14,9 +14,17 @@ module Airrecord
14
14
  @api_key = api_key
15
15
  end
16
16
 
17
+ def self.api_uri=(uri)
18
+ @api_uri = URI.parse(uri)
19
+ end
20
+
21
+ def self.api_uri
22
+ @api_uri || URI.parse("https://api.airtable.com")
23
+ end
24
+
17
25
  def connection
18
26
  @connection ||= Faraday.new(
19
- url: "https://api.airtable.com",
27
+ url: self.class.api_uri,
20
28
  headers: {
21
29
  "Authorization" => "Bearer #{api_key}",
22
30
  "User-Agent" => "Airrecord/#{Airrecord::VERSION}",
@@ -29,7 +37,7 @@ module Airrecord
29
37
  end
30
38
  end
31
39
 
32
- def escape(*args)
40
+ def escape(*args)
33
41
  ERB::Util.url_encode(*args)
34
42
  end
35
43
 
@@ -38,6 +38,8 @@ module Airrecord
38
38
  alias has_one belongs_to
39
39
 
40
40
  def find(id)
41
+ raise ArgumentError, "nil ID" if id.nil?
42
+
41
43
  response = client.connection.get("/v0/#{base_key}/#{client.escape(table_name)}/#{id}")
42
44
  parsed_response = client.parse(response.body)
43
45
 
@@ -56,6 +58,23 @@ module Airrecord
56
58
  records(filter: formula).sort_by { |record| or_args.index(record.id) }
57
59
  end
58
60
 
61
+ def update(id, update_hash = {}, options = {})
62
+ # To avoid trying to update computed fields we *always* use PATCH
63
+ body = {
64
+ fields: update_hash,
65
+ **options
66
+ }.to_json
67
+
68
+ response = client.connection.patch("/v0/#{base_key}/#{client.escape(table_name)}/#{id}", body, { 'Content-Type' => 'application/json' })
69
+ parsed_response = client.parse(response.body)
70
+
71
+ if response.success?
72
+ parsed_response["fields"]
73
+ else
74
+ client.handle_error(response.status, parsed_response)
75
+ end
76
+ end
77
+
59
78
  def create(fields, options = {})
60
79
  new(fields).tap { |record| record.save(options) }
61
80
  end
@@ -166,22 +185,11 @@ module Airrecord
166
185
  return create(options) if new_record?
167
186
  return true if @updated_keys.empty?
168
187
 
169
- # To avoid trying to update computed fields we *always* use PATCH
170
- body = {
171
- fields: Hash[@updated_keys.map { |key|
172
- [key, fields[key]]
173
- }],
174
- **options
175
- }.to_json
176
-
177
- response = client.connection.patch("/v0/#{self.class.base_key}/#{client.escape(self.class.table_name)}/#{self.id}", body, { 'Content-Type' => 'application/json' })
178
- parsed_response = client.parse(response.body)
188
+ update_hash = Hash[@updated_keys.map { |key|
189
+ [key, fields[key]]
190
+ }]
179
191
 
180
- if response.success?
181
- self.fields = parsed_response["fields"]
182
- else
183
- client.handle_error(response.status, parsed_response)
184
- end
192
+ self.fields = self.class.update(self.id, update_hash, options)
185
193
  end
186
194
 
187
195
  def destroy
@@ -1,3 +1,3 @@
1
1
  module Airrecord
2
- VERSION = "1.0.12"
2
+ VERSION = "1.0.15"
3
3
  end
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: airrecord
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.12
4
+ version: 1.0.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Simon Eskildsen
8
- autorequire:
9
8
  bindir: exe
10
9
  cert_chain: []
11
- date: 2023-03-02 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: faraday
@@ -104,16 +103,22 @@ dependencies:
104
103
  name: rake
105
104
  requirement: !ruby/object:Gem::Requirement
106
105
  requirements:
107
- - - "~>"
106
+ - - ">="
108
107
  - !ruby/object:Gem::Version
109
108
  version: '10.0'
109
+ - - "<"
110
+ - !ruby/object:Gem::Version
111
+ version: '14'
110
112
  type: :development
111
113
  prerelease: false
112
114
  version_requirements: !ruby/object:Gem::Requirement
113
115
  requirements:
114
- - - "~>"
116
+ - - ">="
115
117
  - !ruby/object:Gem::Version
116
118
  version: '10.0'
119
+ - - "<"
120
+ - !ruby/object:Gem::Version
121
+ version: '14'
117
122
  description: Airtable client to make Airtable interactions a breeze
118
123
  email:
119
124
  - sirup@sirupsen.com
@@ -141,7 +146,6 @@ homepage: https://github.com/sirupsen/airrecord
141
146
  licenses:
142
147
  - MIT
143
148
  metadata: {}
144
- post_install_message:
145
149
  rdoc_options: []
146
150
  require_paths:
147
151
  - lib
@@ -156,8 +160,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
156
160
  - !ruby/object:Gem::Version
157
161
  version: '0'
158
162
  requirements: []
159
- rubygems_version: 3.2.3
160
- signing_key:
163
+ rubygems_version: 3.6.9
161
164
  specification_version: 4
162
165
  summary: Airtable client
163
166
  test_files: []