airtable2 0.2.6 → 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: 183776a7059c794118524cb86bf5d22bc59b94626cba3181dd6b3169f084b341
4
- data.tar.gz: 983079a2e93fba3fd1b594743c7598ad9f8e62d8d2ee1ea46b15ef3ee9a63e84
3
+ metadata.gz: f1badb986f7b3fabd00b1311e03f91e95b16888ce75ebe31477b125975e5ae4b
4
+ data.tar.gz: d734810a0765508d23831fd5f777afcdf3f30df10fcdb27e240bc00c47c95292
5
5
  SHA512:
6
- metadata.gz: 944fc1084b80554fba6071a29298c13bc888050af4450fccdff76b91ac4144a78e36d53bda708d2e7aa84c1902a90147f25344a1509e672f3468535903c3de24
7
- data.tar.gz: ddc2f9d227aeaca38c8921efb305ace62ae888b125371057c73e8557901d7c517205b36b2a407417d4e4f5888418ca37b6f078e3c29b48f59cc558db0215d46e
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
data/lib/airtable/base.rb CHANGED
@@ -17,7 +17,7 @@ class Airtable::Base < Airtable::Resource
17
17
 
18
18
  check_and_raise_error(response)
19
19
 
20
- Airtable::Table.new @token, @id, response
20
+ Airtable::Table.new @token, self, response['id'], response
21
21
  end
22
22
 
23
23
  # @return [Array<Airtable::Table>]
@@ -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.6'
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.6
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