airtable2 0.2.7 → 0.2.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0cb8122de01b3500ed7e204ada1973d50aef0f4137592a2354205f2365294349
4
- data.tar.gz: cddb9e3845811711a9fb7d7767aae1e14213cd9ba026931295bd1fbc26427c11
3
+ metadata.gz: f1badb986f7b3fabd00b1311e03f91e95b16888ce75ebe31477b125975e5ae4b
4
+ data.tar.gz: d734810a0765508d23831fd5f777afcdf3f30df10fcdb27e240bc00c47c95292
5
5
  SHA512:
6
- metadata.gz: 1623bc5b488e6a99f6e4ec90e57afebf46262d02f80bd375c72b6852762dca527a5af9705707747bdd7f09c455376ed1657fabd6e1dc5f784f1241a511362156
7
- data.tar.gz: 0140bf44f2a129e368c08ddec910267bc80565678055d70e1775fede397facd2360f12e8e9870e1c3f42787b94c28112dd824827527b785146cd8dbfb17bdf40
6
+ metadata.gz: 9b9e84cfbbc55b179fa9747d7ee27716ea517c9d3a7303f1eb2b59fe66817d6072b9cbc4beed3abdbd145f9f47ddf6ce59d53ae130e94c40e234240b451f501a
7
+ data.tar.gz: f966f605482ad29b80c83199dfc7e63085b16a847e5cb0df649de6e381aa983c94949f2d4c7ce1d19d3e7cd1e0b3ece316d7b83ddc95768c6e54bd4c14f543c8
data/README.md CHANGED
@@ -108,6 +108,14 @@ A single record or an array of records can be inserted using the `create_records
108
108
  @table.create_records([{ 'Name': 'name value', 'Age': 35 }, { 'Name': 'another name value', 'Age': 40 }])
109
109
  ```
110
110
 
111
+ You can upsert records by calling `upsert_records` and providing the field names to match to (also max 10 at a time):
112
+
113
+ ```ruby
114
+ # Array
115
+ records_to_upsert = [{ 'Name': 'name value', 'Age': 35 }, { 'Name': 'another name value', 'Age': 40 }]
116
+ @table.upsert_records(records_to_upsert, ['Name'])
117
+ ```
118
+
111
119
  A single record or an array of records can be destroyed by passing their ids to the `delete_records` method on a table (max 10 at a time):
112
120
 
113
121
  ```ruby
@@ -71,6 +71,19 @@ class Airtable::Table < Airtable::Resource
71
71
  response['records'].map { Airtable::Record.new(@token, self, _1['id'], _1) }
72
72
  end
73
73
 
74
+ # @param [Array] Record objects to upsert
75
+ # @return [Array<Airtable::Record>]
76
+ # @see https://airtable.com/developers/web/api/update-multiple-records
77
+ # @note API maximum of 10 records at a time
78
+ def upsert_records(records, fields_to_merge_on)
79
+ response = self.class.patch(table_url,
80
+ body: { performUpsert: { fieldsToMergeOn: fields_to_merge_on }, records: Array(records).map { |fields| { fields: } } }.to_json).parsed_response
81
+
82
+ check_and_raise_error(response)
83
+
84
+ response['records'].map { Airtable::Record.new(@token, self, _1['id'], _1) }
85
+ end
86
+
74
87
  # @param [Array] IDs of records to delete
75
88
  # @return [Array] Deleted record ids
76
89
  # @see https://airtable.com/developers/web/api/delete-multiple-records
@@ -2,5 +2,5 @@
2
2
 
3
3
  # Version
4
4
  module Airtable
5
- VERSION = '0.2.7'
5
+ VERSION = '0.2.8'
6
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: airtable2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.7
4
+ version: 0.2.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Seroff
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2024-10-29 00:00:00.000000000 Z
13
+ date: 2024-11-13 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: httparty