airrecord 1.0.6 → 1.0.9

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: 53739239320854267f0a3fa6a03b81b5ea733bcca061728f0a0b2337d5d32c8d
4
- data.tar.gz: 4c7d23923d1fc45ff48c3644f83f42598b77878756ef2f41cabd229fb122e61f
3
+ metadata.gz: 7751aefc887a2bdd71a1a9f05465ba5fe4c1bc7df38e239f562b9f83cdc03f93
4
+ data.tar.gz: ad1ce14c2dd0f326608a910776100f22bb01bb8a3d5f13d5188911750edaab35
5
5
  SHA512:
6
- metadata.gz: f474a334e15a3feeedaa18dcbb5ddc9cc8a3b6ad2707377de076dc821ff4453e2400a39750e03b7cfb73a69d20aea5627c4e9c9aa1474e325a5e625bf6941d1b
7
- data.tar.gz: eb8c7b5d6e66677059ab1fed2d25826280e6f9736d7e775422b8d103ad9dd53982708642782e7cbef3797c58cf95c0cfd712b4f370538b8436e10e1204cc5406
6
+ metadata.gz: 3f5fdd59c488f214fd60340a82b0a607673b5054f4c402c310d37d2bd96a11f4a5e57b8a4541ae5aeddb26004330aaa01188c071f91eb505c91e42d6161539f6
7
+ data.tar.gz: a3bcc2698d7bab1219b11f6faec3047f104a2a1f6779cf150e7fce7b79653f17c661b1c7c8f8e24b794d932c9bbc4afc26d8a789dde71b016e2050feb6e54fd1
data/CHANGELOG.md CHANGED
@@ -1,3 +1,15 @@
1
+ # 1.0.9
2
+
3
+ * Faraday 2 compatibility round 2 (#90)
4
+
5
+ # 1.0.8
6
+
7
+ * Faraday 2 compatibility (#88)
8
+
9
+ # 1.0.7
10
+
11
+ * Further Ruby 3 compatibility, in particular with Faraday (#83)
12
+
1
13
  # 1.0.6
2
14
 
3
15
  * Ruby 3 compatibility
data/README.md CHANGED
@@ -255,6 +255,8 @@ tea["Village"] = "Feng Gang"
255
255
  tea.save # persist to Airtable
256
256
  ```
257
257
 
258
+ _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
+
258
260
  ### Deleting
259
261
 
260
262
  An instantiated record can be deleted through `#destroy`:
data/airrecord.gemspec CHANGED
@@ -1,4 +1,5 @@
1
1
  # coding: utf-8
2
+
2
3
  lib = File.expand_path('../lib', __FILE__)
3
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
5
  require 'airrecord/version'
@@ -18,13 +19,14 @@ Gem::Specification.new do |spec|
18
19
  spec.bindir = "exe"
19
20
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
21
  spec.require_paths = ["lib"]
21
- spec.required_ruby_version = '>= 2.2'
22
+ spec.required_ruby_version = ">= 2.2"
22
23
 
23
- spec.add_dependency 'faraday', ['>= 0.10', '< 2.0']
24
- spec.add_dependency "net-http-persistent", '>= 2.9'
24
+ spec.add_dependency "faraday", [">= 0.10", "< 3.0"]
25
+ spec.add_dependency "net-http-persistent"
26
+ spec.add_dependency "faraday-net_http_persistent"
25
27
 
26
28
  spec.add_development_dependency "bundler", "~> 2"
27
- spec.add_development_dependency "rake", "~> 10.0"
28
- spec.add_development_dependency "minitest", "~> 5.0"
29
29
  spec.add_development_dependency "byebug"
30
+ spec.add_development_dependency "minitest", "~> 5.0"
31
+ spec.add_development_dependency "rake", "~> 10.0"
30
32
  end
@@ -23,13 +23,13 @@ module Airrecord
23
23
  "User-Agent" => "Airrecord/#{Airrecord::VERSION}",
24
24
  "X-API-VERSION" => "0.1.0",
25
25
  },
26
- request: { params_encoder: Airrecord::QueryString },
27
- ) { |conn|
26
+ request: { params_encoder: Airrecord::QueryString }
27
+ ) do |conn|
28
28
  if Airrecord.throttle?
29
29
  conn.request :airrecord_rate_limiter, requests_per_second: AIRTABLE_RPS_LIMIT
30
30
  end
31
31
  conn.adapter :net_http_persistent
32
- }
32
+ end
33
33
  end
34
34
 
35
35
  def escape(*args)
@@ -43,8 +43,8 @@ module Airrecord
43
43
  end
44
44
 
45
45
  def handle_error(status, error)
46
- if error.is_a?(Hash)
47
- raise Error, "HTTP #{status}: #{error['error']["type"]}: #{error['error']['message']}"
46
+ if error.is_a?(Hash) && error['error']
47
+ raise Error, "HTTP #{status}: #{error['error']['type']}: #{error['error']['message']}"
48
48
  else
49
49
  raise Error, "HTTP #{status}: Communication error: #{error}"
50
50
  end
@@ -37,6 +37,7 @@ module Airrecord
37
37
  def too_many_requests_in_last_second?
38
38
  return false unless @rps
39
39
  return false unless requests.size >= @rps
40
+
40
41
  window_span < 1.0
41
42
  end
42
43
 
@@ -56,5 +57,5 @@ end
56
57
 
57
58
  Faraday::Request.register_middleware(
58
59
  # Avoid polluting the global middleware namespace with a prefix.
59
- :airrecord_rate_limiter => Airrecord::FaradayRateLimiter
60
+ airrecord_rate_limiter: Airrecord::FaradayRateLimiter
60
61
  )
@@ -25,16 +25,16 @@ module Airrecord
25
25
  end
26
26
 
27
27
  TYPES = {
28
- Array => lambda { |prefix, array|
28
+ Array => lambda do |prefix, array|
29
29
  array.each_with_index.map do |value, index|
30
30
  self[value].call("#{prefix}[#{index}]", value)
31
31
  end
32
- },
33
- Hash => lambda { |prefix, hash|
32
+ end,
33
+ Hash => lambda do |prefix, hash|
34
34
  hash.map do |key, value|
35
35
  self[value].call("#{prefix}[#{key}]", value)
36
36
  end
37
- },
37
+ end
38
38
  }.freeze
39
39
 
40
40
  DEFAULT = lambda do |key, value|
@@ -17,7 +17,7 @@ module Airrecord
17
17
 
18
18
  def has_many(method_name, options)
19
19
  define_method(method_name.to_sym) do
20
- # Get association ids in reverse order, because Airtables UI and API
20
+ # Get association ids in reverse order, because Airtable's UI and API
21
21
  # sort associations in opposite directions. We want to match the UI.
22
22
  ids = (self[options.fetch(:column)] || []).reverse
23
23
  table = Kernel.const_get(options.fetch(:class))
@@ -56,7 +56,7 @@ module Airrecord
56
56
  records(filter: formula).sort_by { |record| or_args.index(record.id) }
57
57
  end
58
58
 
59
- def create(fields, options={})
59
+ def create(fields, options = {})
60
60
  new(fields).tap { |record| record.save(options) }
61
61
  end
62
62
 
@@ -104,7 +104,7 @@ module Airrecord
104
104
  client.handle_error(response.status, parsed_response)
105
105
  end
106
106
  end
107
- alias_method :all, :records
107
+ alias all records
108
108
  end
109
109
 
110
110
  attr_reader :fields, :id, :created_at, :updated_keys
@@ -137,16 +137,17 @@ module Airrecord
137
137
  def []=(key, value)
138
138
  validate_key(key)
139
139
  return if fields[key] == value # no-op
140
+
140
141
  @updated_keys << key
141
142
  fields[key] = value
142
143
  end
143
144
 
144
- def create(options={})
145
+ def create(options = {})
145
146
  raise Error, "Record already exists (record has an id)" unless new_record?
146
147
 
147
148
  body = {
148
149
  fields: serializable_fields,
149
- **options,
150
+ **options
150
151
  }.to_json
151
152
 
152
153
  response = client.connection.post("/v0/#{self.class.base_key}/#{client.escape(self.class.table_name)}", body, { 'Content-Type' => 'application/json' })
@@ -161,9 +162,8 @@ module Airrecord
161
162
  end
162
163
  end
163
164
 
164
- def save(options={})
165
+ def save(options = {})
165
166
  return create(options) if new_record?
166
-
167
167
  return true if @updated_keys.empty?
168
168
 
169
169
  # To avoid trying to update computed fields we *always* use PATCH
@@ -171,7 +171,7 @@ module Airrecord
171
171
  fields: Hash[@updated_keys.map { |key|
172
172
  [key, fields[key]]
173
173
  }],
174
- **options,
174
+ **options
175
175
  }.to_json
176
176
 
177
177
  response = client.connection.patch("/v0/#{self.class.base_key}/#{client.escape(self.class.table_name)}/#{self.id}", body, { 'Content-Type' => 'application/json' })
@@ -205,8 +205,7 @@ module Airrecord
205
205
  self.class == other.class &&
206
206
  serializable_fields == other.serializable_fields
207
207
  end
208
-
209
- alias_method :eql?, :==
208
+ alias eql? ==
210
209
 
211
210
  def hash
212
211
  serializable_fields.hash
@@ -221,6 +220,7 @@ module Airrecord
221
220
 
222
221
  def created_at=(created_at)
223
222
  return unless created_at
223
+
224
224
  @created_at = Time.parse(created_at)
225
225
  end
226
226
 
@@ -230,6 +230,7 @@ module Airrecord
230
230
 
231
231
  def validate_key(key)
232
232
  return true unless key.is_a?(Symbol)
233
+
233
234
  raise(Error, [
234
235
  "Airrecord 1.0 dropped support for Symbols as field names.",
235
236
  "Please use the raw field name, a String, instead.",
@@ -1,3 +1,3 @@
1
1
  module Airrecord
2
- VERSION = "1.0.6"
2
+ VERSION = "1.0.9"
3
3
  end
data/lib/airrecord.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require "json"
2
2
  require "faraday"
3
+ require 'faraday/net_http_persistent'
3
4
  require "time"
4
5
  require "airrecord/version"
5
6
  require "airrecord/client"
@@ -7,12 +8,13 @@ require "airrecord/table"
7
8
 
8
9
  module Airrecord
9
10
  extend self
11
+ attr_accessor :api_key, :throttle
12
+
10
13
  Error = Class.new(StandardError)
11
- attr_accessor :api_key
12
- attr_accessor :throttle
13
14
 
14
15
  def throttle?
15
16
  return true if @throttle.nil?
17
+
16
18
  @throttle
17
19
  end
18
20
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: airrecord
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.6
4
+ version: 1.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Simon Eskildsen
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-04-17 00:00:00.000000000 Z
11
+ date: 2022-02-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -19,7 +19,7 @@ dependencies:
19
19
  version: '0.10'
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
- version: '2.0'
22
+ version: '3.0'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -29,21 +29,35 @@ dependencies:
29
29
  version: '0.10'
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
- version: '2.0'
32
+ version: '3.0'
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: net-http-persistent
35
35
  requirement: !ruby/object:Gem::Requirement
36
36
  requirements:
37
37
  - - ">="
38
38
  - !ruby/object:Gem::Version
39
- version: '2.9'
39
+ version: '0'
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ - !ruby/object:Gem::Dependency
48
+ name: faraday-net_http_persistent
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
40
54
  type: :runtime
41
55
  prerelease: false
42
56
  version_requirements: !ruby/object:Gem::Requirement
43
57
  requirements:
44
58
  - - ">="
45
59
  - !ruby/object:Gem::Version
46
- version: '2.9'
60
+ version: '0'
47
61
  - !ruby/object:Gem::Dependency
48
62
  name: bundler
49
63
  requirement: !ruby/object:Gem::Requirement
@@ -59,19 +73,19 @@ dependencies:
59
73
  - !ruby/object:Gem::Version
60
74
  version: '2'
61
75
  - !ruby/object:Gem::Dependency
62
- name: rake
76
+ name: byebug
63
77
  requirement: !ruby/object:Gem::Requirement
64
78
  requirements:
65
- - - "~>"
79
+ - - ">="
66
80
  - !ruby/object:Gem::Version
67
- version: '10.0'
81
+ version: '0'
68
82
  type: :development
69
83
  prerelease: false
70
84
  version_requirements: !ruby/object:Gem::Requirement
71
85
  requirements:
72
- - - "~>"
86
+ - - ">="
73
87
  - !ruby/object:Gem::Version
74
- version: '10.0'
88
+ version: '0'
75
89
  - !ruby/object:Gem::Dependency
76
90
  name: minitest
77
91
  requirement: !ruby/object:Gem::Requirement
@@ -87,19 +101,19 @@ dependencies:
87
101
  - !ruby/object:Gem::Version
88
102
  version: '5.0'
89
103
  - !ruby/object:Gem::Dependency
90
- name: byebug
104
+ name: rake
91
105
  requirement: !ruby/object:Gem::Requirement
92
106
  requirements:
93
- - - ">="
107
+ - - "~>"
94
108
  - !ruby/object:Gem::Version
95
- version: '0'
109
+ version: '10.0'
96
110
  type: :development
97
111
  prerelease: false
98
112
  version_requirements: !ruby/object:Gem::Requirement
99
113
  requirements:
100
- - - ">="
114
+ - - "~>"
101
115
  - !ruby/object:Gem::Version
102
- version: '0'
116
+ version: '10.0'
103
117
  description: Airtable client to make Airtable interactions a breeze
104
118
  email:
105
119
  - sirup@sirupsen.com
@@ -143,7 +157,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
143
157
  - !ruby/object:Gem::Version
144
158
  version: '0'
145
159
  requirements: []
146
- rubygems_version: 3.1.4
160
+ rubygems_version: 3.3.3
147
161
  signing_key:
148
162
  specification_version: 4
149
163
  summary: Airtable client