fmrest-core 0.13.1 → 0.14.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +7 -0
  3. data/README.md +84 -67
  4. data/lib/fmrest/version.rb +1 -1
  5. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 53d29a0e4e2956b66ae0054f5f4fd355115a9889fab57dae36506b37f5d68cf2
4
- data.tar.gz: b4228ee457a91c8e1b1f217678c66d7d86a23e5b8dd6420120904e801b61224d
3
+ metadata.gz: cba0e445e2ed4490aff12280984c77731b69c293df1a9d2e4e5f67c87b256a6c
4
+ data.tar.gz: c1ab4d1a181fe2a0430f77e70094a5b56690401cae73610ddd16c269fc28bb19
5
5
  SHA512:
6
- metadata.gz: 3b0909eaef29e7ba596aa469ef62eccf60f7e73ab33fb3e2ab5d88b4fce1d96d15fd3ebcb3404eb767d15ccfd262713c0b190af0cff51bbd5a72f7c9bf31f134
7
- data.tar.gz: 56ab9b3d5a8ebc11ca44c04c1200b6bfdff8c49da0aa767be74965d1df11b0fcb836d88dcff7d4a954585cb54ac316c15d6a7b71a5306e6b62cab1d2562d04e9
6
+ metadata.gz: c25310aa7a1ff1dfc74519551eb91f78fdead52c90e35841f8c356e0f9fc10599aade957b99ee87c86730a12b7a58027f26e7781acfe7258be32840c49155f99
7
+ data.tar.gz: a5553c69a3e238c49d548f7e749d86fc226525ef626d8b00f6f0f529efdb19fc3d7b117e80098193dc2a56169dec804207d466630ab36ef4bd48cd6f69115782
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-core`, which provides the core Faraday connection builder, session
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, do:
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 provided by `fmrest-spyke`:
43
+ Most people would want to use the ORM features:
44
44
 
45
45
  ```ruby
46
- class Honeybee < FmRest::Spyke::Base
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/MyFancyLayout/records")
92
+ connection.get("layouts/FancyLayout/records")
92
93
 
93
94
  # Create new record
94
95
  connection.post do |req|
95
- req.url "layouts/MyFancyLayout/records"
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::Spyke::Base` models whenever
161
- you don't set `fmrest_config=` explicitly, as well as by
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::Spyke::Base`, which is
192
- itself a subclass of `Spyke::Base`.
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::Spyke::Base
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
- however you'll find it quite familiar.
220
+ you'll find it quite familiar.
220
221
 
221
- In addition, `FmRest::Spyke::Base` extends `Spyke::Base` with the following
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
- ### Model.fmrest_config=
230
+ ### FmRest::Layout.fmrest_config=
225
231
 
226
- This allows you to set your Data API connection settings on your model:
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::Spyke::Base
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::Spyke::Base
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 `Model.fmrest_config` is set
262
- at the class level, changing the username/password for the model in one context
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 `Model.fmrest_config_overlay=`.
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
- ### Model.layout
281
+ ### FmRest::Layout.layout
272
282
 
273
- Use `Model.layout` to define the layout for your model.
283
+ Use `layout` to set the layout name for your model.
274
284
 
275
285
  ```ruby
276
- class Honeybee < FmRest::Spyke::Base
286
+ class Honeybee < FmRest::Layout
277
287
  layout "Honeybees Web"
278
288
  end
279
289
  ```
280
290
 
281
- Note that you only need to set this if the name of the model and the name of
282
- the layout differ, otherwise the default will just work.
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
- ### Model.request_auth_token
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
- ### Model.logout
310
+ ### FmRest::Layout.logout
294
311
 
295
- Use `Model.logout` to log out from the database session (you may call it on any
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 Model.attributes
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::Spyke::Base
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
- ### Model.has_portal
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::Spyke::Base
352
+ class Honeybee < FmRest::Layout
336
353
  has_portal :flowers
337
354
  end
338
355
 
339
- class Flower < FmRest::Spyke::Base
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::Spyke::Base
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::Spyke::Base` model to set global
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::Spyke::Base
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::Spyke::Base
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::Spyke::Base |
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
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module FmRest
4
- VERSION = "0.13.1"
4
+ VERSION = "0.14.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fmrest-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.13.1
4
+ version: 0.14.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pedro Carbajal
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-02-16 00:00:00.000000000 Z
11
+ date: 2021-03-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday