fmrest-spyke 0.13.1 → 0.14.0
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/CHANGELOG.md +7 -0
- data/README.md +84 -67
- data/lib/fmrest/spyke/base.rb +15 -0
- data/lib/fmrest/spyke/model/uri.rb +17 -3
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d7208f6230222ff9227d220c31f445337ad1c09a485b4a6dd752f8fed5f94aef
|
4
|
+
data.tar.gz: 2a7424c4c6bc8f2b6ab218ebaab92efa1da644616eaa650e347d680e6008209e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3551a71b87620e499a666b70f3ca1ae7f39ecd67602c778628254b4155d3c3136650d69063b6d3e3d2d26ada8e16d261a0b16ba4186efc997d045f92a65fd322
|
7
|
+
data.tar.gz: 43cca2d89fb4bd051d8fbe0d75f54f65960e707e93488e3815cb849a3637162e1b8ef570b1d9e501045cd29c8c1546c4dafbde6737a98647f888154fe482b890
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,12 @@
|
|
1
1
|
## Changelog
|
2
2
|
|
3
|
+
### 0.14.0
|
4
|
+
|
5
|
+
* Aliased `FmRest::Spyke::Base` as `FmRest::Layout` (now preferred), and
|
6
|
+
provided a shortcut version for setting the layout name (e.g. `class Foo <
|
7
|
+
FmRest::Layout("LayoutName")`)
|
8
|
+
* Made `layout` class setting subclass-inheritable
|
9
|
+
|
3
10
|
### 0.13.1
|
4
11
|
|
5
12
|
* Fix downloading of container field data from FMS19+
|
data/README.md
CHANGED
@@ -17,10 +17,10 @@ to see if a feature you need is natively supported by the gem.
|
|
17
17
|
|
18
18
|
The `fmrest` gem is a wrapper for two other gems:
|
19
19
|
|
20
|
-
* `fmrest-
|
20
|
+
* `fmrest-spyke`, providing an ActiveRecord-like ORM library built on top
|
21
|
+
of `fmrest-core` and [Spyke](https://github.com/balvig/spyke).
|
22
|
+
* `fmrest-core`, providing the core Faraday connection builder, session
|
21
23
|
management, and other core utilities.
|
22
|
-
* `fmrest-spyke`, which provides an ActiveRecord-like ORM library built on top
|
23
|
-
of `fmrest-core` and Spyke.
|
24
24
|
|
25
25
|
## Installation
|
26
26
|
|
@@ -30,7 +30,7 @@ Add this to your Gemfile:
|
|
30
30
|
gem 'fmrest'
|
31
31
|
```
|
32
32
|
|
33
|
-
Or if you just want to use the Faraday connection without the ORM features
|
33
|
+
Or if you just want to use the Faraday connection without the ORM features:
|
34
34
|
|
35
35
|
```ruby
|
36
36
|
gem 'fmrest-core'
|
@@ -40,10 +40,11 @@ gem 'fmrest-core'
|
|
40
40
|
|
41
41
|
### ORM example
|
42
42
|
|
43
|
-
Most people would want to use the ORM features
|
43
|
+
Most people would want to use the ORM features:
|
44
44
|
|
45
45
|
```ruby
|
46
|
-
|
46
|
+
# A Layout model connecting to the "Honeybees Web" FileMaker layout
|
47
|
+
class Honeybee < FmRest::Layout("Honeybees Web")
|
47
48
|
# Connection settings
|
48
49
|
self.fmrest_config = {
|
49
50
|
host: "…",
|
@@ -88,11 +89,11 @@ connection = FmRest::V1.build_connection(
|
|
88
89
|
)
|
89
90
|
|
90
91
|
# Get all records (as parsed JSON)
|
91
|
-
connection.get("layouts/
|
92
|
+
connection.get("layouts/FancyLayout/records")
|
92
93
|
|
93
94
|
# Create new record
|
94
95
|
connection.post do |req|
|
95
|
-
req.url "layouts/
|
96
|
+
req.url "layouts/FancyLayout/records"
|
96
97
|
|
97
98
|
# You can just pass a hash for the JSON body
|
98
99
|
req.body = { … }
|
@@ -157,8 +158,8 @@ FmRest.default_connection_settings = {
|
|
157
158
|
}
|
158
159
|
```
|
159
160
|
|
160
|
-
These settings will be used by default by `FmRest::
|
161
|
-
|
161
|
+
These settings will be used by default by `FmRest::Layout` models whenever you
|
162
|
+
don't set `fmrest_config=` explicitly, as well as by
|
162
163
|
`FmRest::V1.build_connection` in case you're setting up your Faraday connection
|
163
164
|
manually.
|
164
165
|
|
@@ -188,11 +189,11 @@ building REST ORM models. fmrest-ruby builds its ORM features atop Spyke,
|
|
188
189
|
bundled in the `fmrest-spyke` gem (already included if you're using the
|
189
190
|
`fmrest` gem).
|
190
191
|
|
191
|
-
To create a model you can inherit directly from `FmRest::
|
192
|
-
|
192
|
+
To create a model you can inherit directly from `FmRest::Layout` (itself a
|
193
|
+
subclass of `Spyke::Base`).
|
193
194
|
|
194
195
|
```ruby
|
195
|
-
class Honeybee < FmRest::
|
196
|
+
class Honeybee < FmRest::Layout
|
196
197
|
end
|
197
198
|
```
|
198
199
|
|
@@ -216,17 +217,23 @@ bee = Honeybee.find(9) # GET request
|
|
216
217
|
|
217
218
|
It's recommended that you read Spyke's documentation for more information on
|
218
219
|
these basic features. If you've used ActiveRecord or similar ORM libraries
|
219
|
-
|
220
|
+
you'll find it quite familiar.
|
220
221
|
|
221
|
-
|
222
|
+
Notice that `FmRest::Layout` is aliased as `FmRest::Spyke::Base`. Previous
|
223
|
+
versions of fmrest-ruby only provided the latter version, so if you're already
|
224
|
+
using `FmRest::Spyke::Base` there's no need to rename your classes to
|
225
|
+
`FmRest::Layout`, both will continue to work interchangeably.
|
226
|
+
|
227
|
+
In addition, `FmRest::Layout` extends `Spyke::Base` with the following
|
222
228
|
features:
|
223
229
|
|
224
|
-
###
|
230
|
+
### FmRest::Layout.fmrest_config=
|
225
231
|
|
226
|
-
This allows you to set
|
232
|
+
This allows you to set Data API connection settings specific to your model
|
233
|
+
class:
|
227
234
|
|
228
235
|
```ruby
|
229
|
-
class Honeybee < FmRest::
|
236
|
+
class Honeybee < FmRest::Layout
|
230
237
|
self.fmrest_config = {
|
231
238
|
host: "…",
|
232
239
|
database: "…",
|
@@ -244,9 +251,8 @@ does the initial connection setup and then inherit from it in models using that
|
|
244
251
|
same connection. E.g.:
|
245
252
|
|
246
253
|
```ruby
|
247
|
-
class BeeBase < FmRest::
|
248
|
-
self.fmrest_config = { host: "…", … }
|
249
|
-
}
|
254
|
+
class BeeBase < FmRest::Layout
|
255
|
+
self.fmrest_config = { host: "…", database: "…", … }
|
250
256
|
end
|
251
257
|
|
252
258
|
class Honeybee < BeeBase
|
@@ -254,34 +260,45 @@ class Honeybee < BeeBase
|
|
254
260
|
end
|
255
261
|
```
|
256
262
|
|
263
|
+
Also, if not set, your model will try to use
|
264
|
+
`FmRest.default_connection_settings` instead.
|
265
|
+
|
257
266
|
#### Connection settings overlays
|
258
267
|
|
259
268
|
There may be cases where you want to use a different set of connection settings
|
260
269
|
depending on context. For example, if you want to use username and password
|
261
|
-
provided by the user in a web application. Since
|
262
|
-
at the class level, changing the username/password for the model in one
|
263
|
-
would also change it in all other contexts, leading to security issues.
|
270
|
+
provided by the user in a web application. Since `.fmrest_config`
|
271
|
+
is set at the class level, changing the username/password for the model in one
|
272
|
+
context would also change it in all other contexts, leading to security issues.
|
264
273
|
|
265
274
|
To solve this scenario, fmrest-ruby provides a way of defining thread-local and
|
266
|
-
reversible connection settings overlays through
|
275
|
+
reversible connection settings overlays through
|
276
|
+
`.fmrest_config_overlay=`.
|
267
277
|
|
268
278
|
See the [main document on connection setting overlays](docs/ConfigOverlays.md)
|
269
279
|
for details on how it works.
|
270
280
|
|
271
|
-
###
|
281
|
+
### FmRest::Layout.layout
|
272
282
|
|
273
|
-
Use `
|
283
|
+
Use `layout` to set the layout name for your model.
|
274
284
|
|
275
285
|
```ruby
|
276
|
-
class Honeybee < FmRest::
|
286
|
+
class Honeybee < FmRest::Layout
|
277
287
|
layout "Honeybees Web"
|
278
288
|
end
|
279
289
|
```
|
280
290
|
|
281
|
-
|
282
|
-
|
291
|
+
Alternatively, you can set the layout name in the class definition line:
|
292
|
+
|
293
|
+
```ruby
|
294
|
+
class Honeybee < FmRest::Layout("Honeybees Web")
|
295
|
+
```
|
296
|
+
|
297
|
+
Note that you only need to manually set the layout name if the name of the
|
298
|
+
class and the name of the layout differ, otherwise fmrest-ruby will just use
|
299
|
+
the name of the class.
|
283
300
|
|
284
|
-
###
|
301
|
+
### FmRest::Layout.request_auth_token
|
285
302
|
|
286
303
|
Requests a Data API session token using the connection settings in
|
287
304
|
`fmrest_config` and returns it if successful, otherwise returns `false`.
|
@@ -290,16 +307,16 @@ You normally don't need to use this method as fmrest-ruby will automatically
|
|
290
307
|
request and store session tokens for you (provided that `:autologin` is
|
291
308
|
`true`).
|
292
309
|
|
293
|
-
###
|
310
|
+
### FmRest::Layout.logout
|
294
311
|
|
295
|
-
Use
|
312
|
+
Use `.logout` to log out from the database session (you may call it on any
|
296
313
|
model that uses the database session you want to log out from).
|
297
314
|
|
298
315
|
```ruby
|
299
316
|
Honeybee.logout
|
300
317
|
```
|
301
318
|
|
302
|
-
### Mapped
|
319
|
+
### Mapped FmRest::Layout.attributes
|
303
320
|
|
304
321
|
Spyke allows you to define your model's attributes using `attributes`, however
|
305
322
|
sometimes FileMaker's field names aren't very Ruby-ORM-friendly, especially
|
@@ -308,7 +325,7 @@ fmrest-ruby extends `attributes`' functionality to allow you to map
|
|
308
325
|
Ruby-friendly attribute names to FileMaker field names. E.g.:
|
309
326
|
|
310
327
|
```ruby
|
311
|
-
class Honeybee < FmRest::
|
328
|
+
class Honeybee < FmRest::Layout
|
312
329
|
attributes first_name: "First Name", last_name: "Last Name"
|
313
330
|
end
|
314
331
|
```
|
@@ -327,16 +344,16 @@ bee.first_name = "Queen"
|
|
327
344
|
bee.attributes # => { "First Name": "Queen", "Last Name": "Buzz" }
|
328
345
|
```
|
329
346
|
|
330
|
-
###
|
347
|
+
### FmRest::Layout.has_portal
|
331
348
|
|
332
349
|
You can define portal associations on your model wth `has_portal`, as such:
|
333
350
|
|
334
351
|
```ruby
|
335
|
-
class Honeybee < FmRest::
|
352
|
+
class Honeybee < FmRest::Layout
|
336
353
|
has_portal :flowers
|
337
354
|
end
|
338
355
|
|
339
|
-
class Flower < FmRest::
|
356
|
+
class Flower < FmRest::Layout
|
340
357
|
attributes :color, :species
|
341
358
|
end
|
342
359
|
```
|
@@ -393,7 +410,7 @@ detailed information on how those work.
|
|
393
410
|
You can define container fields on your model class with `container`:
|
394
411
|
|
395
412
|
```ruby
|
396
|
-
class Honeybee < FmRest::
|
413
|
+
class Honeybee < FmRest::Layout
|
397
414
|
container :photo, field_name: "Beehive Photo ID"
|
398
415
|
end
|
399
416
|
```
|
@@ -411,7 +428,7 @@ details.
|
|
411
428
|
|
412
429
|
### Setting global field values
|
413
430
|
|
414
|
-
You can call `.set_globals` on any `FmRest::
|
431
|
+
You can call `.set_globals` on any `FmRest::Layout` model to set global
|
415
432
|
field values on the database that model is configured for.
|
416
433
|
|
417
434
|
See the [main document on setting global field values](docs/GlobalFields.md)
|
@@ -435,7 +452,7 @@ FmRest.default_connection_settings = {
|
|
435
452
|
}
|
436
453
|
|
437
454
|
# Or in your model
|
438
|
-
class LoggyBee < FmRest::
|
455
|
+
class LoggyBee < FmRest::Layout
|
439
456
|
self.fmrest_config = {
|
440
457
|
host: "…",
|
441
458
|
…
|
@@ -449,7 +466,7 @@ If you need to set up more complex logging for your models can use the
|
|
449
466
|
Faraday connection, e.g.:
|
450
467
|
|
451
468
|
```ruby
|
452
|
-
class LoggyBee < FmRest::
|
469
|
+
class LoggyBee < FmRest::Layout
|
453
470
|
faraday do |conn|
|
454
471
|
conn.response :logger, MyApp.logger, bodies: true
|
455
472
|
end
|
@@ -460,31 +477,31 @@ end
|
|
460
477
|
|
461
478
|
FM Data API reference: https://fmhelp.filemaker.com/docs/18/en/dataapi/
|
462
479
|
|
463
|
-
| FM 18 Data API feature | Supported by basic connection | Supported by FmRest::
|
464
|
-
|
465
|
-
| Log in using HTTP Basic Auth | Yes | Yes
|
466
|
-
| Log in using OAuth | No | No
|
467
|
-
| Log in to an external data source | No | No
|
468
|
-
| Log in using a FileMaker ID account | No | No
|
469
|
-
| Log out | Yes | Yes
|
470
|
-
| Get product information | Manual* | No
|
471
|
-
| Get database names | Manual* | No
|
472
|
-
| Get script names | Manual* | No
|
473
|
-
| Get layout names | Manual* | No
|
474
|
-
| Get layout metadata | Manual* | No
|
475
|
-
| Create a record | Manual* | Yes
|
476
|
-
| Edit a record | Manual* | Yes
|
477
|
-
| Duplicate a record | Manual* | No
|
478
|
-
| Delete a record | Manual* | Yes
|
479
|
-
| Edit portal records | Manual* | Yes
|
480
|
-
| Get a single record | Manual* | Yes
|
481
|
-
| Get a range of records | Manual* | Yes
|
482
|
-
| Get container data | Manual* | Yes
|
483
|
-
| Upload container data | Manual* | Yes
|
484
|
-
| Perform a find request | Manual* | Yes
|
485
|
-
| Set global field values | Manual* | Yes
|
486
|
-
| Run a script | Manual* | Yes
|
487
|
-
| Run a script with another request | Manual* | Yes
|
480
|
+
| FM 18 Data API feature | Supported by basic connection | Supported by FmRest::Layout |
|
481
|
+
|-------------------------------------|-------------------------------|-----------------------------|
|
482
|
+
| Log in using HTTP Basic Auth | Yes | Yes |
|
483
|
+
| Log in using OAuth | No | No |
|
484
|
+
| Log in to an external data source | No | No |
|
485
|
+
| Log in using a FileMaker ID account | No | No |
|
486
|
+
| Log out | Yes | Yes |
|
487
|
+
| Get product information | Manual* | No |
|
488
|
+
| Get database names | Manual* | No |
|
489
|
+
| Get script names | Manual* | No |
|
490
|
+
| Get layout names | Manual* | No |
|
491
|
+
| Get layout metadata | Manual* | No |
|
492
|
+
| Create a record | Manual* | Yes |
|
493
|
+
| Edit a record | Manual* | Yes |
|
494
|
+
| Duplicate a record | Manual* | No |
|
495
|
+
| Delete a record | Manual* | Yes |
|
496
|
+
| Edit portal records | Manual* | Yes |
|
497
|
+
| Get a single record | Manual* | Yes |
|
498
|
+
| Get a range of records | Manual* | Yes |
|
499
|
+
| Get container data | Manual* | Yes |
|
500
|
+
| Upload container data | Manual* | Yes |
|
501
|
+
| Perform a find request | Manual* | Yes |
|
502
|
+
| Set global field values | Manual* | Yes |
|
503
|
+
| Run a script | Manual* | Yes |
|
504
|
+
| Run a script with another request | Manual* | Yes |
|
488
505
|
|
489
506
|
\* You can manually supply the URL and JSON to a `FmRest` connection.
|
490
507
|
|
data/lib/fmrest/spyke/base.rb
CHANGED
@@ -6,4 +6,19 @@ module FmRest
|
|
6
6
|
include FmRest::Spyke::Model
|
7
7
|
end
|
8
8
|
end
|
9
|
+
|
10
|
+
Layout = Spyke::Base
|
11
|
+
|
12
|
+
# Shortcut for creating a Layout class and setting its FM layout name.
|
13
|
+
#
|
14
|
+
# @param layout [String] The FM layout to connect this class to
|
15
|
+
#
|
16
|
+
# @return [Class] A new subclass of `FmRest::Layout` with the FM layout
|
17
|
+
# setting already set.
|
18
|
+
#
|
19
|
+
def self.Layout(layout)
|
20
|
+
Class.new(Layout) do
|
21
|
+
self.layout layout
|
22
|
+
end
|
23
|
+
end
|
9
24
|
end
|
@@ -6,12 +6,26 @@ module FmRest
|
|
6
6
|
module URI
|
7
7
|
extend ::ActiveSupport::Concern
|
8
8
|
|
9
|
+
included do
|
10
|
+
# Make the layout setting inheritable
|
11
|
+
class_attribute :_layout, instance_predicate: false
|
12
|
+
|
13
|
+
class << self
|
14
|
+
protected :_layout
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
9
18
|
class_methods do
|
10
|
-
# Accessor for FM layout (
|
19
|
+
# Accessor for FM layout (user for building request URIs).
|
20
|
+
#
|
21
|
+
# @param layout [String] The FM layout to connect this class to
|
22
|
+
#
|
23
|
+
# @return [String] The current layout if manually set, or the name of
|
24
|
+
# the class otherwise
|
11
25
|
#
|
12
26
|
def layout(layout = nil)
|
13
|
-
|
14
|
-
|
27
|
+
self._layout = layout.dup.to_s.freeze if layout
|
28
|
+
self._layout || model_name.name
|
15
29
|
end
|
16
30
|
|
17
31
|
# Spyke override -- Extends `uri` to default to FM Data's URI schema
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fmrest-spyke
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.14.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pedro Carbajal
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-03-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fmrest-core
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - '='
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.
|
19
|
+
version: 0.14.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - '='
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0.
|
26
|
+
version: 0.14.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: spyke
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|