airtable2 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,270 @@
1
+ <!DOCTYPE html>
2
+ <html >
3
+ <head>
4
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
5
+ <meta charset="utf-8" />
6
+
7
+ <link rel="stylesheet" href="css/full_list.css" type="text/css" media="screen" />
8
+
9
+ <link rel="stylesheet" href="css/common.css" type="text/css" media="screen" />
10
+
11
+
12
+
13
+ <script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
14
+
15
+ <script type="text/javascript" charset="utf-8" src="js/full_list.js"></script>
16
+
17
+
18
+ <title>Method List</title>
19
+ <base id="base_target" target="_parent" />
20
+ </head>
21
+ <body>
22
+ <div id="content">
23
+ <div class="fixed_header">
24
+ <h1 id="full_list_header">Method List</h1>
25
+ <div id="full_list_nav">
26
+
27
+ <span><a target="_self" href="class_list.html">
28
+ Classes
29
+ </a></span>
30
+
31
+ <span><a target="_self" href="method_list.html">
32
+ Methods
33
+ </a></span>
34
+
35
+ <span><a target="_self" href="file_list.html">
36
+ Files
37
+ </a></span>
38
+
39
+ </div>
40
+
41
+ <div id="search">
42
+ <label for="search-class">Search:</label>
43
+ <input id="search-class" type="text" />
44
+ </div>
45
+ </div>
46
+
47
+ <ul id="full_list" class="method">
48
+
49
+
50
+ <li class="odd ">
51
+ <div class="item">
52
+ <span class='object_link'><a href="Airtable/Table.html#add_records-instance_method" title="Airtable::Table#add_records (method)">#add_records</a></span>
53
+ <small>Airtable::Table</small>
54
+ </div>
55
+ </li>
56
+
57
+
58
+ <li class="even ">
59
+ <div class="item">
60
+ <span class='object_link'><a href="Airtable/Client.html#base-instance_method" title="Airtable::Client#base (method)">#base</a></span>
61
+ <small>Airtable::Client</small>
62
+ </div>
63
+ </li>
64
+
65
+
66
+ <li class="odd ">
67
+ <div class="item">
68
+ <span class='object_link'><a href="Airtable/Base.html#base_url-instance_method" title="Airtable::Base#base_url (method)">#base_url</a></span>
69
+ <small>Airtable::Base</small>
70
+ </div>
71
+ </li>
72
+
73
+
74
+ <li class="even ">
75
+ <div class="item">
76
+ <span class='object_link'><a href="Airtable/Client.html#bases-instance_method" title="Airtable::Client#bases (method)">#bases</a></span>
77
+ <small>Airtable::Client</small>
78
+ </div>
79
+ </li>
80
+
81
+
82
+ <li class="odd ">
83
+ <div class="item">
84
+ <span class='object_link'><a href="Airtable/Resource.html#check_and_raise_error-instance_method" title="Airtable::Resource#check_and_raise_error (method)">#check_and_raise_error</a></span>
85
+ <small>Airtable::Resource</small>
86
+ </div>
87
+ </li>
88
+
89
+
90
+ <li class="even ">
91
+ <div class="item">
92
+ <span class='object_link'><a href="Airtable/Base.html#create_table-instance_method" title="Airtable::Base#create_table (method)">#create_table</a></span>
93
+ <small>Airtable::Base</small>
94
+ </div>
95
+ </li>
96
+
97
+
98
+ <li class="odd ">
99
+ <div class="item">
100
+ <span class='object_link'><a href="Airtable/Table.html#delete_records-instance_method" title="Airtable::Table#delete_records (method)">#delete_records</a></span>
101
+ <small>Airtable::Table</small>
102
+ </div>
103
+ </li>
104
+
105
+
106
+ <li class="even ">
107
+ <div class="item">
108
+ <span class='object_link'><a href="Airtable/Table.html#dump-instance_method" title="Airtable::Table#dump (method)">#dump</a></span>
109
+ <small>Airtable::Table</small>
110
+ </div>
111
+ </li>
112
+
113
+
114
+ <li class="odd ">
115
+ <div class="item">
116
+ <span class='object_link'><a href="Airtable/Record.html#fields-instance_method" title="Airtable::Record#fields (method)">#fields</a></span>
117
+ <small>Airtable::Record</small>
118
+ </div>
119
+ </li>
120
+
121
+
122
+ <li class="even ">
123
+ <div class="item">
124
+ <span class='object_link'><a href="Airtable/Resource.html#id-instance_method" title="Airtable::Resource#id (method)">#id</a></span>
125
+ <small>Airtable::Resource</small>
126
+ </div>
127
+ </li>
128
+
129
+
130
+ <li class="odd ">
131
+ <div class="item">
132
+ <span class='object_link'><a href="Airtable/Base.html#initialize-instance_method" title="Airtable::Base#initialize (method)">#initialize</a></span>
133
+ <small>Airtable::Base</small>
134
+ </div>
135
+ </li>
136
+
137
+
138
+ <li class="even ">
139
+ <div class="item">
140
+ <span class='object_link'><a href="Airtable/Table.html#initialize-instance_method" title="Airtable::Table#initialize (method)">#initialize</a></span>
141
+ <small>Airtable::Table</small>
142
+ </div>
143
+ </li>
144
+
145
+
146
+ <li class="odd ">
147
+ <div class="item">
148
+ <span class='object_link'><a href="Airtable/Resource.html#initialize-instance_method" title="Airtable::Resource#initialize (method)">#initialize</a></span>
149
+ <small>Airtable::Resource</small>
150
+ </div>
151
+ </li>
152
+
153
+
154
+ <li class="even ">
155
+ <div class="item">
156
+ <span class='object_link'><a href="Airtable/Client.html#initialize-instance_method" title="Airtable::Client#initialize (method)">#initialize</a></span>
157
+ <small>Airtable::Client</small>
158
+ </div>
159
+ </li>
160
+
161
+
162
+ <li class="odd ">
163
+ <div class="item">
164
+ <span class='object_link'><a href="Airtable/Record.html#initialize-instance_method" title="Airtable::Record#initialize (method)">#initialize</a></span>
165
+ <small>Airtable::Record</small>
166
+ </div>
167
+ </li>
168
+
169
+
170
+ <li class="even ">
171
+ <div class="item">
172
+ <span class='object_link'><a href="Airtable/Error.html#initialize-instance_method" title="Airtable::Error#initialize (method)">#initialize</a></span>
173
+ <small>Airtable::Error</small>
174
+ </div>
175
+ </li>
176
+
177
+
178
+ <li class="odd ">
179
+ <div class="item">
180
+ <span class='object_link'><a href="Airtable/Error.html#message-instance_method" title="Airtable::Error#message (method)">#message</a></span>
181
+ <small>Airtable::Error</small>
182
+ </div>
183
+ </li>
184
+
185
+
186
+ <li class="even ">
187
+ <div class="item">
188
+ <span class='object_link'><a href="Airtable/Table.html#name-instance_method" title="Airtable::Table#name (method)">#name</a></span>
189
+ <small>Airtable::Table</small>
190
+ </div>
191
+ </li>
192
+
193
+
194
+ <li class="odd ">
195
+ <div class="item">
196
+ <span class='object_link'><a href="Airtable/Table.html#record-instance_method" title="Airtable::Table#record (method)">#record</a></span>
197
+ <small>Airtable::Table</small>
198
+ </div>
199
+ </li>
200
+
201
+
202
+ <li class="even ">
203
+ <div class="item">
204
+ <span class='object_link'><a href="Airtable/Table.html#records-instance_method" title="Airtable::Table#records (method)">#records</a></span>
205
+ <small>Airtable::Table</small>
206
+ </div>
207
+ </li>
208
+
209
+
210
+ <li class="odd ">
211
+ <div class="item">
212
+ <span class='object_link'><a href="Airtable/Base.html#table-instance_method" title="Airtable::Base#table (method)">#table</a></span>
213
+ <small>Airtable::Base</small>
214
+ </div>
215
+ </li>
216
+
217
+
218
+ <li class="even ">
219
+ <div class="item">
220
+ <span class='object_link'><a href="Airtable/Table.html#table_url-instance_method" title="Airtable::Table#table_url (method)">#table_url</a></span>
221
+ <small>Airtable::Table</small>
222
+ </div>
223
+ </li>
224
+
225
+
226
+ <li class="odd ">
227
+ <div class="item">
228
+ <span class='object_link'><a href="Airtable/Base.html#tables-instance_method" title="Airtable::Base#tables (method)">#tables</a></span>
229
+ <small>Airtable::Base</small>
230
+ </div>
231
+ </li>
232
+
233
+
234
+ <li class="even ">
235
+ <div class="item">
236
+ <span class='object_link'><a href="Airtable/Resource.html#token-instance_method" title="Airtable::Resource#token (method)">#token</a></span>
237
+ <small>Airtable::Resource</small>
238
+ </div>
239
+ </li>
240
+
241
+
242
+ <li class="odd ">
243
+ <div class="item">
244
+ <span class='object_link'><a href="Airtable/Error.html#type-instance_method" title="Airtable::Error#type (method)">#type</a></span>
245
+ <small>Airtable::Error</small>
246
+ </div>
247
+ </li>
248
+
249
+
250
+ <li class="even ">
251
+ <div class="item">
252
+ <span class='object_link'><a href="Airtable/Table.html#update-instance_method" title="Airtable::Table#update (method)">#update</a></span>
253
+ <small>Airtable::Table</small>
254
+ </div>
255
+ </li>
256
+
257
+
258
+ <li class="odd ">
259
+ <div class="item">
260
+ <span class='object_link'><a href="Airtable/Client.html#whoami-instance_method" title="Airtable::Client#whoami (method)">#whoami</a></span>
261
+ <small>Airtable::Client</small>
262
+ </div>
263
+ </li>
264
+
265
+
266
+
267
+ </ul>
268
+ </div>
269
+ </body>
270
+ </html>
@@ -0,0 +1,110 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>
7
+ Top Level Namespace
8
+
9
+ &mdash; Documentation by YARD 0.9.37
10
+
11
+ </title>
12
+
13
+ <link rel="stylesheet" href="css/style.css" type="text/css" />
14
+
15
+ <link rel="stylesheet" href="css/common.css" type="text/css" />
16
+
17
+ <script type="text/javascript">
18
+ pathId = "";
19
+ relpath = '';
20
+ </script>
21
+
22
+
23
+ <script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
24
+
25
+ <script type="text/javascript" charset="utf-8" src="js/app.js"></script>
26
+
27
+
28
+ </head>
29
+ <body>
30
+ <div class="nav_wrap">
31
+ <iframe id="nav" src="class_list.html?1"></iframe>
32
+ <div id="resizer"></div>
33
+ </div>
34
+
35
+ <div id="main" tabindex="-1">
36
+ <div id="header">
37
+ <div id="menu">
38
+
39
+ <a href="_index.html">Index</a> &raquo;
40
+
41
+
42
+ <span class="title">Top Level Namespace</span>
43
+
44
+ </div>
45
+
46
+ <div id="search">
47
+
48
+ <a class="full_list_link" id="class_list_link"
49
+ href="class_list.html">
50
+
51
+ <svg width="24" height="24">
52
+ <rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect>
53
+ <rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect>
54
+ <rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect>
55
+ </svg>
56
+ </a>
57
+
58
+ </div>
59
+ <div class="clear"></div>
60
+ </div>
61
+
62
+ <div id="content"><h1>Top Level Namespace
63
+
64
+
65
+
66
+ </h1>
67
+ <div class="box_info">
68
+
69
+
70
+
71
+
72
+
73
+
74
+
75
+
76
+
77
+
78
+
79
+ </div>
80
+
81
+ <h2>Defined Under Namespace</h2>
82
+ <p class="children">
83
+
84
+
85
+ <strong class="modules">Modules:</strong> <span class='object_link'><a href="Airtable.html" title="Airtable (module)">Airtable</a></span>
86
+
87
+
88
+
89
+
90
+ </p>
91
+
92
+
93
+
94
+
95
+
96
+
97
+
98
+
99
+
100
+ </div>
101
+
102
+ <div id="footer">
103
+ Generated on Fri Oct 25 21:49:51 2024 by
104
+ <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
105
+ 0.9.37 (ruby-3.3.5).
106
+ </div>
107
+
108
+ </div>
109
+ </body>
110
+ </html>
data/lib/airtable/base.rb CHANGED
@@ -9,6 +9,8 @@ class Airtable::Base < Airtable::Resource
9
9
  end
10
10
 
11
11
  # Expects {name:,description:,fields:[]}
12
+ # @see https://airtable.com/developers/web/api/create-table
13
+ # @return [Airtable::Table]
12
14
  def create_table(table_data)
13
15
  response = self.class.post("#{base_url}/tables",
14
16
  body: table_data.to_json).parsed_response
@@ -18,6 +20,8 @@ class Airtable::Base < Airtable::Resource
18
20
  Airtable::Table.new @token, @id, response
19
21
  end
20
22
 
23
+ # @see https://airtable.com/developers/web/api/get-base-schema
24
+ # @return [Array]<Airtable::Table>
21
25
  def tables
22
26
  response = self.class.get("#{base_url}/tables")
23
27
 
@@ -26,7 +30,14 @@ class Airtable::Base < Airtable::Resource
26
30
  response['tables'].map { Airtable::Table.new(@token, @id, _1) }
27
31
  end
28
32
 
33
+ # Instantiate table in base
34
+ # @return [Airtable::Table]
35
+ def table(table_id)
36
+ Airtable::Table.new(@token, @id, table_id)
37
+ end
38
+
29
39
  protected
30
40
 
41
+ # Instantiate table in base
31
42
  def base_url = "/v0/meta/bases/#{@id}"
32
43
  end
@@ -1,12 +1,43 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # Client carrying authorization token
4
- class Airtable::Client
4
+ class Airtable::Client < Airtable::Resource
5
5
  def initialize(token)
6
6
  @token = token
7
+ self.class.headers({ 'Authorization': "Bearer #{@token}", 'Content-Type': 'application/json' })
7
8
  end
8
9
 
10
+ # @see https://airtable.com/developers/web/api/list-bases
11
+ # @return [Array]<Airtable::Base>
12
+ def bases
13
+ response = self.class.get('/v0/meta/bases').parsed_response
14
+
15
+ check_and_raise_error(response)
16
+
17
+ response['bases'].map { Airtable::Base.new(@token, _1['id']) }
18
+ end
19
+
20
+ # @see https://airtable.com/developers/web/api/create-base
21
+ # def create_base(base_data)
22
+ # response = self.class.post('/v0/meta/bases'
23
+ # body: base_data.to_json).parsed_response
24
+ # check_and_raise_error(response)
25
+ # Airtable::Base.new @token, response
26
+ # end
27
+
28
+ # Instantiate base
29
+ # @return [Airtable::Base]
9
30
  def base(base_id)
10
31
  Airtable::Base.new(@token, base_id)
11
32
  end
33
+
34
+ # @see https://airtable.com/developers/web/api/get-user-id-scopes
35
+ # @return [Hash]
36
+ def whoami
37
+ response = self.class.get('/v0/meta/whoami').parsed_response
38
+
39
+ check_and_raise_error(response)
40
+
41
+ response
42
+ end
12
43
  end
@@ -13,6 +13,7 @@ class Airtable::Resource
13
13
  self.class.headers({ 'Authorization': "Bearer #{@token}", 'Content-Type': 'application/json' })
14
14
  end
15
15
 
16
+ # If API response is an error, raises an Airtable::Error with the error message
16
17
  def check_and_raise_error(response)
17
18
  response['error'] ? raise(Error, response['error']) : false
18
19
  end
@@ -13,6 +13,8 @@ class Airtable::Table < Airtable::Resource
13
13
  self.class.headers({ 'Authorization': "Bearer #{@token}", 'Content-Type': 'application/json' })
14
14
  end
15
15
 
16
+ # @see https://airtable.com/developers/web/api/list-records
17
+ # @return [Array<Airtable::Record>]
16
18
  def records
17
19
  response = self.class.get(table_url)
18
20
 
@@ -21,6 +23,14 @@ class Airtable::Table < Airtable::Resource
21
23
  response['records'].map { Airtable::Record.new(@token, @base_id, @table_id, _1) }
22
24
  end
23
25
 
26
+ # Instantiate record in table
27
+ # @return [Airtable::Table]
28
+ def record(record_id)
29
+ Airtable::Table.new(@token, @base_id, @id, record_id)
30
+ end
31
+
32
+ # @see https://airtable.com/developers/web/api/update-table
33
+ # @return [Airtable::Table]
24
34
  def update(table_data)
25
35
  response = self.class.patch("/v0/meta/bases/#{@base_id}/tables/#{@id}",
26
36
  body: table_data.to_json).parsed_response
@@ -30,7 +40,9 @@ class Airtable::Table < Airtable::Resource
30
40
  Airtable::Table.new @token, @base_id, response
31
41
  end
32
42
 
33
- # limit 10 records
43
+ # @note API maximum of 10 records at a time
44
+ # @see https://airtable.com/developers/web/api/create-records
45
+ # @return [Array<Airtable::Record>]
34
46
  def add_records(records)
35
47
  response = self.class.post(table_url,
36
48
  body: { records: Array(records).map { |fields| { fields: } } }.to_json).parsed_response
@@ -40,6 +52,8 @@ class Airtable::Table < Airtable::Resource
40
52
  response['records'].map { Airtable::Record.new(@token, @base_id, @id, _1) }
41
53
  end
42
54
 
55
+ # @see https://airtable.com/developers/web/api/delete-multiple-records
56
+ # @return [Array] Deleted record ids
43
57
  def delete_records(record_ids)
44
58
  params = Array(record_ids).compact.map { "records[]=#{_1}" }.join('&')
45
59
  response = self.class.delete("#{table_url}?#{params}").parsed_response
@@ -49,6 +63,7 @@ class Airtable::Table < Airtable::Resource
49
63
  record_ids
50
64
  end
51
65
 
66
+ # Deletes all table's records
52
67
  def dump
53
68
  records.map(&:id).each_slice(10) do |record_id_set|
54
69
  delete_records(record_id_set)
@@ -2,5 +2,5 @@
2
2
 
3
3
  # Version
4
4
  module Airtable
5
- VERSION = '0.2.0'
5
+ VERSION = '0.2.1'
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.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Seroff
@@ -166,6 +166,20 @@ dependencies:
166
166
  - - ">="
167
167
  - !ruby/object:Gem::Version
168
168
  version: '0'
169
+ - !ruby/object:Gem::Dependency
170
+ name: yard
171
+ requirement: !ruby/object:Gem::Requirement
172
+ requirements:
173
+ - - ">="
174
+ - !ruby/object:Gem::Version
175
+ version: '0'
176
+ type: :development
177
+ prerelease: false
178
+ version_requirements: !ruby/object:Gem::Requirement
179
+ requirements:
180
+ - - ">="
181
+ - !ruby/object:Gem::Version
182
+ version: '0'
169
183
  description: Easily connect to airtable data using ruby with access to all of the
170
184
  airtable features.
171
185
  email:
@@ -175,11 +189,33 @@ extensions: []
175
189
  extra_rdoc_files: []
176
190
  files:
177
191
  - ".gitignore"
192
+ - ".yardopts"
178
193
  - Gemfile
179
194
  - LICENSE.txt
180
195
  - README.md
181
196
  - Rakefile
182
197
  - airtable.gemspec
198
+ - docs/Airtable.html
199
+ - docs/Airtable/Base.html
200
+ - docs/Airtable/Client.html
201
+ - docs/Airtable/Error.html
202
+ - docs/Airtable/Record.html
203
+ - docs/Airtable/Resource.html
204
+ - docs/Airtable/Table.html
205
+ - docs/_index.html
206
+ - docs/class_list.html
207
+ - docs/css/common.css
208
+ - docs/css/full_list.css
209
+ - docs/css/style.css
210
+ - docs/file.README.html
211
+ - docs/file_list.html
212
+ - docs/frames.html
213
+ - docs/index.html
214
+ - docs/js/app.js
215
+ - docs/js/full_list.js
216
+ - docs/js/jquery.js
217
+ - docs/method_list.html
218
+ - docs/top-level-namespace.html
183
219
  - lib/airtable.rb
184
220
  - lib/airtable/base.rb
185
221
  - lib/airtable/client.rb