norairrecord 0.3.0 → 0.4.1
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 +4 -1
- data/lib/norairrecord/client.rb +1 -1
- data/lib/norairrecord/table.rb +14 -3
- data/lib/norairrecord/util.rb +29 -0
- data/lib/norairrecord/version.rb +1 -1
- data/lib/norairrecord.rb +2 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1b4c50fb537aace7ecdf5be404764e05072c943556715daa724cd17870a914e8
|
4
|
+
data.tar.gz: 410a8da439eceead2fb6ee1488ed89e095c71418ea55afe5c26ed2684fee58f2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7056ecbe66dc5dfbdf46016ca7095ba5429fed6c9ea20c7b79f5e096ceb0b74508bbbf372f6411214ffef8de592bc4e65ad7aeb5b6dfa5babc823772ca09bdc5
|
7
|
+
data.tar.gz: 1c619c848753a5940851d50bf46664716d8ef005a7a1d7efcb5b1fc37ba32fd6a062cb382587d158e6871f70efca38736a8f8bdfaf4c6b4b9705a4275b3695eb
|
data/README.md
CHANGED
@@ -55,4 +55,7 @@ stuff not in the OG:
|
|
55
55
|
* `Table#first`, `Table#first_where`
|
56
56
|
* you're not gonna believe it:
|
57
57
|
* `Table.batch_`{update,upsert,create,save}
|
58
|
-
* makes ratelimits much less painful
|
58
|
+
* makes ratelimits much less painful
|
59
|
+
* `Util` (those little methods we have to keep writing again and again, now in one place)
|
60
|
+
* custom RPS limit
|
61
|
+
* `Norairrecord.rps_limit = 3`
|
data/lib/norairrecord/client.rb
CHANGED
@@ -23,7 +23,7 @@ module Norairrecord
|
|
23
23
|
},
|
24
24
|
) do |conn|
|
25
25
|
if Norairrecord.throttle?
|
26
|
-
conn.request :airrecord_rate_limiter, requests_per_second: AIRTABLE_RPS_LIMIT
|
26
|
+
conn.request :airrecord_rate_limiter, requests_per_second: Norairrecord.rps_limit || AIRTABLE_RPS_LIMIT
|
27
27
|
end
|
28
28
|
conn.adapter :net_http_persistent
|
29
29
|
end
|
data/lib/norairrecord/table.rb
CHANGED
@@ -7,6 +7,8 @@ module Norairrecord
|
|
7
7
|
class << self
|
8
8
|
attr_writer :api_key, :base_key, :table_name
|
9
9
|
|
10
|
+
include Norairrecord::Util
|
11
|
+
|
10
12
|
def base_key
|
11
13
|
@base_key || (superclass < Table ? superclass.base_key : nil)
|
12
14
|
end
|
@@ -15,6 +17,16 @@ module Norairrecord
|
|
15
17
|
@table_name || (superclass < Table ? superclass.table_name : nil)
|
16
18
|
end
|
17
19
|
|
20
|
+
|
21
|
+
# finds the actual parent class of a (possibly) subtype class
|
22
|
+
def responsible_class
|
23
|
+
if @base_key
|
24
|
+
self.class
|
25
|
+
else
|
26
|
+
superclass < Table ? superclass.responsible_class : nil
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
18
30
|
def client
|
19
31
|
@@clients ||= {}
|
20
32
|
@@clients[api_key] ||= Client.new(api_key)
|
@@ -66,9 +78,8 @@ module Norairrecord
|
|
66
78
|
def find_many(ids, where: nil, sort: nil)
|
67
79
|
return [] if ids.empty?
|
68
80
|
|
69
|
-
|
70
|
-
formula =
|
71
|
-
formula = "AND(#{formula},#{where})" if where
|
81
|
+
formula = any_of(ids.map { |id| "RECORD_ID() = '#{id}'" })
|
82
|
+
formula = all_of(formula, where) if where
|
72
83
|
records(filter: formula, sort:).sort_by { |record| or_args.index(record.id) }
|
73
84
|
end
|
74
85
|
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Norairrecord
|
2
|
+
module Util
|
3
|
+
def all_of(*args)
|
4
|
+
"AND(#{args.join(',')})"
|
5
|
+
end
|
6
|
+
|
7
|
+
def any_of(*args)
|
8
|
+
"OR(#{args.join(',')})"
|
9
|
+
end
|
10
|
+
|
11
|
+
def none_of(*args)
|
12
|
+
"NOT(#{all_of(*args)})"
|
13
|
+
end
|
14
|
+
|
15
|
+
def field_is_any(field, *args)
|
16
|
+
any_of(*args.map { |arg| "#{field}='#{sanitize(arg)}'" })
|
17
|
+
end
|
18
|
+
|
19
|
+
def sanitize(arg)
|
20
|
+
arg.gsub(/['"]/, '\\\\\0')
|
21
|
+
end
|
22
|
+
|
23
|
+
def mass_sanitize(*args)
|
24
|
+
args.map { |arg| sanitize(arg) }
|
25
|
+
end
|
26
|
+
|
27
|
+
module_function :all_of, :any_of, :none_of, :field_is_any, :sanitize, :mass_sanitize
|
28
|
+
end
|
29
|
+
end
|
data/lib/norairrecord/version.rb
CHANGED
data/lib/norairrecord.rb
CHANGED
@@ -2,13 +2,14 @@ require "json"
|
|
2
2
|
require "faraday"
|
3
3
|
require 'faraday/net_http_persistent'
|
4
4
|
require "time"
|
5
|
+
require "norairrecord/util"
|
5
6
|
require "norairrecord/version"
|
6
7
|
require "norairrecord/client"
|
7
8
|
require "norairrecord/table"
|
8
9
|
|
9
10
|
module Norairrecord
|
10
11
|
extend self
|
11
|
-
attr_accessor :api_key, :throttle, :base_url, :user_agent
|
12
|
+
attr_accessor :api_key, :throttle, :base_url, :user_agent, :rps_limit
|
12
13
|
|
13
14
|
Error = Class.new(StandardError)
|
14
15
|
UnknownTypeError = Class.new(Error)
|
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.
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- nora
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-
|
11
|
+
date: 2025-08-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -107,6 +107,7 @@ files:
|
|
107
107
|
- lib/norairrecord/client.rb
|
108
108
|
- lib/norairrecord/faraday_rate_limiter.rb
|
109
109
|
- lib/norairrecord/table.rb
|
110
|
+
- lib/norairrecord/util.rb
|
110
111
|
- lib/norairrecord/version.rb
|
111
112
|
- norairrecord.gemspec
|
112
113
|
homepage: https://github.com/24c02/norairrecord
|