norairrecord 0.1.2 → 0.1.4
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 +4 -4
- data/README.md +19 -1
- data/lib/norairrecord/table.rb +22 -5
- data/lib/norairrecord/version.rb +1 -1
- data/lib/norairrecord.rb +1 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 910e4c4f488a1f1fb996144d7bc2bd023eca3d386681937af92c337d8f8e2b26
|
4
|
+
data.tar.gz: 55979229a04ec5ad233f49d2858b1179af6c47dc0eaf3c7f260cc808f55083d9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 80beee3c36c56253974af2053e669df452f0d4af0ff5ad88b05eabf2afc7673706848563d57b298a7565a88fa831700d77325b46300e48351a0607e7753d87a0
|
7
|
+
data.tar.gz: 66f75e0a29877db15f9463ae95f65a3b2521f623c0ffa45bf3ddbfb261ff5f67b049d5df68d1f58fcaa21e14988918ecefe4d53d9fab0fcae4c3371a556ab690
|
data/README.md
CHANGED
@@ -29,4 +29,22 @@ stuff not in the OG:
|
|
29
29
|
* custom UA
|
30
30
|
* `Norairrecord.user_agent = "i'm the reason why you're getting 429s!"`
|
31
31
|
* `Table#airtable_url`
|
32
|
-
* what it says on the tin!
|
32
|
+
* what it says on the tin!
|
33
|
+
* `Table.has_subtypes`
|
34
|
+
* hokay so:
|
35
|
+
* ```ruby
|
36
|
+
class Friend < Norairrecord::Table
|
37
|
+
# base_key/table_name, etc...
|
38
|
+
has_subtypes "type", { # based on 'type' column...
|
39
|
+
"person" => "Person", # when 'person' instantiate record as Person
|
40
|
+
"shark" => "Shark"
|
41
|
+
}, strict: true # if strict, unmapped types will raise UnknownTypeError
|
42
|
+
# otherwise they will be instantiated as the base class
|
43
|
+
end
|
44
|
+
|
45
|
+
class Person < Friend; end
|
46
|
+
class Shark < Friend; end
|
47
|
+
|
48
|
+
Friend.all
|
49
|
+
=> [<Person>, <Person>, <Shark>]
|
50
|
+
```
|
data/lib/norairrecord/table.rb
CHANGED
@@ -37,12 +37,18 @@ module Norairrecord
|
|
37
37
|
|
38
38
|
alias has_one belongs_to
|
39
39
|
|
40
|
+
def has_subtypes(column, mapping, strict: false)
|
41
|
+
@subtype_column = column
|
42
|
+
@subtype_mapping = mapping
|
43
|
+
@subtype_strict = strict
|
44
|
+
end
|
45
|
+
|
40
46
|
def find(id)
|
41
47
|
response = client.connection.get("v0/#{base_key}/#{client.escape(table_name)}/#{id}")
|
42
48
|
parsed_response = client.parse(response.body)
|
43
49
|
|
44
50
|
if response.success?
|
45
|
-
self.
|
51
|
+
self.new_with_subtype(parsed_response["fields"], id: id, created_at: parsed_response["createdTime"])
|
46
52
|
else
|
47
53
|
client.handle_error(response.status, parsed_response)
|
48
54
|
end
|
@@ -78,6 +84,18 @@ module Norairrecord
|
|
78
84
|
new(fields).tap { |record| record.save(options) }
|
79
85
|
end
|
80
86
|
|
87
|
+
def new_with_subtype(fields, id:, created_at:)
|
88
|
+
if @subtype_column
|
89
|
+
clazz = self
|
90
|
+
st = @subtype_mapping[fields[@subtype_column]]
|
91
|
+
raise Norairrecord::UnknownTypeError, "#{fields[@subtype_column]}?????" if @subtype_strict && st.nil?
|
92
|
+
clazz = Kernel.const_get(st) if st
|
93
|
+
clazz.new(fields, id:, created_at:)
|
94
|
+
else
|
95
|
+
self.new(fields, id: id, created_at: created_at)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
81
99
|
def records(filter: nil, sort: nil, view: nil, offset: nil, paginate: true, fields: nil, max_records: nil, page_size: nil)
|
82
100
|
options = {}
|
83
101
|
options[:filterByFormula] = filter if filter
|
@@ -100,8 +118,8 @@ module Norairrecord
|
|
100
118
|
|
101
119
|
if response.success?
|
102
120
|
records = parsed_response["records"]
|
103
|
-
records
|
104
|
-
self.
|
121
|
+
records.map! { |record|
|
122
|
+
self.new_with_subtype(record["fields"], id: record["id"], created_at: record["createdTime"])
|
105
123
|
}
|
106
124
|
|
107
125
|
if paginate && parsed_response["offset"]
|
@@ -193,8 +211,7 @@ module Norairrecord
|
|
193
211
|
update_hash = Hash[@updated_keys.map { |key|
|
194
212
|
[key, fields[key]]
|
195
213
|
}]
|
196
|
-
|
197
|
-
self.patch(update_hash, options)
|
214
|
+
self.fields = self.class.update(self.id, update_hash, options)
|
198
215
|
end
|
199
216
|
|
200
217
|
def destroy
|
data/lib/norairrecord/version.rb
CHANGED
data/lib/norairrecord.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: norairrecord
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- nora
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-12-
|
11
|
+
date: 2024-12-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|