fmrest 0.2.0 → 0.2.1

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: d9ac0ed8884efb3c03f32de33e934f5ba7298ff17fd6f2531bc31c09fff53654
4
- data.tar.gz: c1b29afaf072953515843db4c95e9e7426662a64bc8df3aa88ec99dc7c3715f6
3
+ metadata.gz: 82a15caf470d1410554f5d83be7424fe52f765c9dd3e767de8f46dd7269155ea
4
+ data.tar.gz: bedcd15af94048c775b67a68532044f88cd7c7787a94b93c2b01d60cb8024177
5
5
  SHA512:
6
- metadata.gz: 685dbf33e5fb4fd929e7fd5dba1a35ba6791f81590dd34e3abef16ea129b1603403e1c5fb09ea82b536e501ff7ab072a62e24b85223a53ab85602f757e825831
7
- data.tar.gz: 25fd66ec79dfb9356c7939641e97ef65e6ba49decfc289fd4cdfc373de9656392b4889d143f91bf5df5a5c9e020913c068e1bfcdfe9573a16063a598cf86b8b9
6
+ metadata.gz: 10df0d8b008c1b0dbf0920fc6dc0f77a04bd638c8269d76f95d3046fdc3c15256ead1a32b4108fcab9bfbfd33afd2e1b80f760a53d7846023d0773d93b415c4d
7
+ data.tar.gz: 9bcf3d0816ec7f00472a9525af97cc7b26fc4b6e71f9b032e4bcb2ae8edb03e59e6413166e9d2c1a47215fd5d07caf0a2435d79e1d58e6c0ae7298190cea1c7a
data/README.md CHANGED
@@ -14,7 +14,8 @@ anyway).
14
14
  If you're looking for a Ruby client for the legacy XML/Custom Web Publishing
15
15
  API try the fabulous [ginjo-rfm gem](https://github.com/ginjo/rfm) instead.
16
16
 
17
- fmrest-ruby does not currently implement the full spec of FileMaker Data API.
17
+ fmrest-ruby does not currently implement the full spec of FileMaker 17's Data
18
+ API.
18
19
 
19
20
  ## Installation
20
21
 
@@ -141,7 +142,7 @@ require "fmrest/spyke"
141
142
  And finally extend your Spyke models with `FmRest::Spyke`:
142
143
 
143
144
  ```ruby
144
- class Kitty < Spyke::Base
145
+ class Honeybee < Spyke::Base
145
146
  include FmRest::Spyke
146
147
  end
147
148
  ```
@@ -155,37 +156,35 @@ Alternatively you can inherit directly from the shorthand
155
156
  `FmRest::Spyke` already included:
156
157
 
157
158
  ```ruby
158
- class Kitty < FmRest::Spyke::Base
159
+ class Honeybee < FmRest::Spyke::Base
159
160
  end
160
161
  ```
161
162
 
162
163
  In this case you can pass the `fmrest_config` hash as an argument to `Base()`:
163
164
 
164
165
  ```ruby
165
- class Kitty < FmRest::Spyke::Base(host: "...", database: "...", username: "...", password: "...")
166
+ class Honeybee < FmRest::Spyke::Base(host: "...", database: "...", username: "...", password: "...")
166
167
  end
167
168
 
168
- Kitty.fmrest_config # => { host: "...", database: "...", username: "...", password: "..." }
169
+ Honeybee.fmrest_config # => { host: "...", database: "...", username: "...", password: "..." }
169
170
  ```
170
171
 
171
172
  All of Spyke's basic ORM operations work:
172
173
 
173
174
  ```ruby
174
- kitty = Kitty.new
175
+ bee = Honeybee.new
175
176
 
176
- kitty.name = "Felix"
177
+ bee.name = "Hutch"
178
+ bee.save # POST request
177
179
 
178
- kitty.save # POST request
180
+ bee.name = "ハッチ"
181
+ bee.save # PATCH request
179
182
 
180
- kitty.name = "Tom"
183
+ bee.reload # GET request
181
184
 
182
- kitty.save # PATCH request
185
+ bee.destroy # DELETE request
183
186
 
184
- kitty.reload # GET request
185
-
186
- kitty.destroy # DELETE request
187
-
188
- kitty = Kitty.find(9) # GET request
187
+ bee = Honeybee.find(9) # GET request
189
188
  ```
190
189
 
191
190
  Read Spyke's documentation for more information on these basic features.
@@ -198,7 +197,7 @@ features:
198
197
  Usually to tell a Spyke object to use a certain Faraday connection you'd use:
199
198
 
200
199
  ```ruby
201
- class Kitty < Spyke::Base
200
+ class Honeybee < Spyke::Base
202
201
  self.connection = Faraday.new(...)
203
202
  end
204
203
  ```
@@ -207,14 +206,14 @@ fmrest-ruby simplfies the process of setting up your Spyke model with a Faraday
207
206
  connection by allowing you to just set your Data API connection settings:
208
207
 
209
208
  ```ruby
210
- class Kitty < Spyke::Base
209
+ class Honeybee < Spyke::Base
211
210
  include FmRest::Spyke
212
211
 
213
212
  self.fmrest_config = {
214
213
  host: "example.com",
215
- database: "database name",
216
- username: "username",
217
- password: "password"
214
+ database: "My Database",
215
+ username: "...",
216
+ password: "..."
218
217
  }
219
218
  end
220
219
  ```
@@ -227,19 +226,19 @@ does the initial connection setup and then inherit from it in models using that
227
226
  same connection. E.g.:
228
227
 
229
228
  ```ruby
230
- class KittyBase < Spyke::Base
229
+ class BeeBase < Spyke::Base
231
230
  include FmRest::Spyke
232
231
 
233
232
  self.fmrest_config = {
234
233
  host: "example.com",
235
234
  database: "My Database",
236
- username: "username",
237
- password: "password"
235
+ username: "...",
236
+ password: "..."
238
237
  }
239
238
  end
240
239
 
241
- class Kitty < KittyBase
242
- # This model will use the same connection as KittyBase
240
+ class Honeybee < BeeBase
241
+ # This model will use the same connection as BeeBase
243
242
  end
244
243
  ```
245
244
 
@@ -248,8 +247,8 @@ end
248
247
  Use `layout` to set the `:layout` part of API URLs, e.g.:
249
248
 
250
249
  ```ruby
251
- class Kitty < FmRest::Spyke::Base
252
- layout "FluffyKitty" # uri path will be "layouts/FluffyKitty/records(/:id)"
250
+ class Honeybee < FmRest::Spyke::Base
251
+ layout "Honeybees Web" # uri path will be "layouts/Honeybees%20Web/records(/:id)"
253
252
  end
254
253
  ```
255
254
 
@@ -268,7 +267,7 @@ fmrest-ruby extends `attributes`' functionality to allow you to map
268
267
  Ruby-friendly attribute names to FileMaker field names. E.g.:
269
268
 
270
269
  ```ruby
271
- class Kitty < FmRest::Spyke::Base
270
+ class Honeybee < FmRest::Spyke::Base
272
271
  attributes first_name: "First Name", last_name: "Last Name"
273
272
  end
274
273
  ```
@@ -277,14 +276,14 @@ You can then simply use the pretty attribute names whenever working with your
277
276
  model and they will get mapped to their FileMaker fields:
278
277
 
279
278
  ```ruby
280
- kitty = Kitty.find(1)
279
+ bee = Honeybee.find(1)
281
280
 
282
- kitty.first_name # => "Mr."
283
- kitty.last_name # => "Fluffers"
281
+ bee.first_name # => "Princess"
282
+ bee.last_name # => "Buzz"
284
283
 
285
- kitty.first_name = "Dr."
284
+ bee.first_name = "Queen"
286
285
 
287
- kitty.attributes # => { "First Name": "Dr.", "Last Name": "Fluffers" }
286
+ bee.attributes # => { "First Name": "Queen", "Last Name": "Buzz" }
288
287
  ```
289
288
 
290
289
  ### Model.has_portal
@@ -292,26 +291,26 @@ kitty.attributes # => { "First Name": "Dr.", "Last Name": "Fluffers" }
292
291
  You can define portal associations on your model as such:
293
292
 
294
293
  ```ruby
295
- class Kitty < FmRest::Spyke::Base
296
- has_portal :wool_yarns
294
+ class Honeybee < FmRest::Spyke::Base
295
+ has_portal :flowers
297
296
  end
298
297
 
299
- class WoolYarn < FmRest::Spyke::Base
300
- attributes :color, :thickness
298
+ class Flower < FmRest::Spyke::Base
299
+ attributes :color, :species
301
300
  end
302
301
  ```
303
302
 
304
303
  In this case fmrest-ruby will expect the portal table name and portal object
305
- name to be both "wool_yarns". E.g., the expected portal JSON portion should be
306
- look like this:
304
+ name to be both "flowers", i.e. the expected portal JSON portion should look
305
+ like this:
307
306
 
308
307
  ```json
309
308
  ...
310
309
  "portalData": {
311
- "wool_yarns": [
310
+ "flowers": [
312
311
  {
313
- "wool_yarns::color": "yellow",
314
- "wool_yarns::thickness": "thick",
312
+ "flowers::color": "red",
313
+ "flowers::species": "rose"
315
314
  }
316
315
  ]
317
316
  }
@@ -319,51 +318,46 @@ look like this:
319
318
 
320
319
  If you need to specify different values for them you can do so with
321
320
  `portal_key` for the portal table name, and `attribute_prefix` for the portal
322
- object name, e.g.:
321
+ object name, and `class_name`, e.g.:
323
322
 
324
323
  ```ruby
325
- class Kitty < FmRest::Spyke::Base
326
- has_portal :wool_yarns, portal_key: "Wool Yarn", attribute_prefix: "WoolYarn"
324
+ class Honeybee < FmRest::Spyke::Base
325
+ has_portal :pollinated_flowers, portal_key: "Bee Flowers",
326
+ attribute_prefix: "Flower",
327
+ class_name: "Flower"
327
328
  end
328
329
  ```
329
330
 
330
- The above expects the following portal JSON portion:
331
+ The above will use the `Flower` model class and expects the following portal JSON
332
+ portion:
331
333
 
332
334
  ```json
333
335
  ...
334
336
  "portalData": {
335
- "Wool Yarn": [
337
+ "Bee Flowers": [
336
338
  {
337
- "WoolYarn::color": "yellow",
338
- "WoolYarn::thickness": "thick",
339
+ "Flower::color": "white",
340
+ "Flower::species": "rose"
339
341
  }
340
342
  ]
341
343
  }
342
344
  ```
343
345
 
344
- You can also specify a different class name with the `class_name` option:
345
-
346
- ```ruby
347
- class Kitty < FmRest::Spyke::Base
348
- has_portal :wool_yarns, class_name: "FancyWoolYarn"
349
- end
350
- ```
351
-
352
346
  ### Dirty attributes
353
347
 
354
348
  fmrest-ruby includes support for ActiveModel's Dirty mixin out of the box,
355
349
  providing methods like:
356
350
 
357
351
  ```ruby
358
- kitty = Kitty.new
352
+ bee = Honeybee.new
359
353
 
360
- kitty.changed? # => false
354
+ bee.changed? # => false
361
355
 
362
- kitty.name = "Mr. Fluffers"
356
+ bee.name = "Maya"
363
357
 
364
- kitty.changed? # => true
358
+ bee.changed? # => true
365
359
 
366
- kitty.name_changed? # => true
360
+ bee.name_changed? # => true
367
361
  ```
368
362
 
369
363
  fmrest-ruby uses the Dirty functionality to only send changed attributes back
@@ -380,12 +374,12 @@ aware of its backend API, so it extends Spkye models with a bunch of useful
380
374
  querying methods.
381
375
 
382
376
  ```ruby
383
- class Kitty < Spyke::Base
377
+ class Honeybee < Spyke::Base
384
378
  include FmRest::Spyke
385
379
 
386
- attributes name: "CatName", age: "CatAge"
380
+ attributes name: "Bee Name", age: "Bee Age"
387
381
 
388
- has_portal :toys, portal_key: "CatToys"
382
+ has_portal :hives, portal_key: "Bee Hives"
389
383
  end
390
384
  ```
391
385
 
@@ -394,7 +388,7 @@ end
394
388
  `.limit` sets the limit for get and find request:
395
389
 
396
390
  ```ruby
397
- Kitty.limit(10)
391
+ Honeybee.limit(10)
398
392
  ```
399
393
 
400
394
  #### .offset
@@ -402,7 +396,7 @@ Kitty.limit(10)
402
396
  `.offset` sets the offset for get and find requests:
403
397
 
404
398
  ```ruby
405
- Kitty.offset(10)
399
+ Honeybee.offset(10)
406
400
  ```
407
401
 
408
402
  #### .sort
@@ -410,16 +404,16 @@ Kitty.offset(10)
410
404
  `.sort` (or `.order`) sets sorting options for get and find requests:
411
405
 
412
406
  ```ruby
413
- Kitty.sort(:name, :age)
414
- Kitty.order(:name, :age) # alias method
407
+ Honeybee.sort(:name, :age)
408
+ Honeybee.order(:name, :age) # alias method
415
409
  ```
416
410
 
417
411
  You can set descending sort order by appending either `!` or `__desc` to a sort
418
412
  attribute (defaults to ascending order):
419
413
 
420
414
  ```ruby
421
- Kitty.sort(:name, :age!)
422
- Kitty.sort(:name, :age__desc)
415
+ Honeybee.sort(:name, :age!)
416
+ Honeybee.sort(:name, :age__desc)
423
417
  ```
424
418
 
425
419
  #### .portal
@@ -428,8 +422,8 @@ Kitty.sort(:name, :age__desc)
428
422
  (this recognizes portals defined with `has_portal`):
429
423
 
430
424
  ```ruby
431
- Kitty.portal(:toys)
432
- Kitty.includes(:toys) # alias method
425
+ Honeybee.portal(:hives)
426
+ Honeybee.includes(:hives) # alias method
433
427
  ```
434
428
 
435
429
  #### .query
@@ -438,24 +432,24 @@ Kitty.includes(:toys) # alias method
438
432
  defined with `attributes`):
439
433
 
440
434
  ```ruby
441
- Kitty.query(name: "Mr. Fluffers")
442
- # JSON -> {"query": [{"CatName": "Mr. Fluffers"}]}
435
+ Honeybee.query(name: "Hutch")
436
+ # JSON -> {"query": [{"Bee Name": "Hutch"}]}
443
437
  ```
444
438
 
445
439
  Passing multiple attributes to `.query` will group them in the same JSON object:
446
440
 
447
441
  ```ruby
448
- Kitty.query(name: "Mr. Fluffers", age: 4)
449
- # JSON -> {"query": [{"CatName": "Foo", "CatAge": 4}]}
442
+ Honeybee.query(name: "Hutch", age: 4)
443
+ # JSON -> {"query": [{"Bee Name": "Hutch", "Bee Age": 4}]}
450
444
  ```
451
445
 
452
446
  Calling `.query` multiple times or passing it multiple hashes creates separate
453
447
  JSON objects (so you can define OR queries):
454
448
 
455
449
  ```ruby
456
- Kitty.query(name: "Mr. Fluffers").query(name: "Coronel Chai Latte")
457
- Kitty.query({ name: "Mr. Fluffers" }, { name: "Coronel Chai Latte" })
458
- # JSON -> {"query": [{"CatName": "Mr. Fluffers"}, {"CatName": "Coronel Chai Latte"}]}
450
+ Honeybee.query(name: "Hutch").query(name: "Maya")
451
+ Honeybee.query({ name: "Hutch" }, { name: "Maya" })
452
+ # JSON -> {"query": [{"Bee Name": "Hutch"}, {"Bee Name": "Maya"}]}
459
453
  ```
460
454
 
461
455
  #### .omit
@@ -463,15 +457,15 @@ Kitty.query({ name: "Mr. Fluffers" }, { name: "Coronel Chai Latte" })
463
457
  `.omit` works like `.query` but excludes matches:
464
458
 
465
459
  ```ruby
466
- Kitty.omit(name: "Captain Whiskers")
467
- # JSON -> {"query": [{"CatName": "Captain Whiskers", "omit": "true"}]}
460
+ Honeybee.omit(name: "Hutch")
461
+ # JSON -> {"query": [{"Bee Name": "Hutch", "omit": "true"}]}
468
462
  ```
469
463
 
470
464
  You can get the same effect by passing `omit: true` to `.query`:
471
465
 
472
466
  ```ruby
473
- Kitty.query(name: "Captain Whiskers", omit: true)
474
- # JSON -> {"query": [{"CatName": "Captain Whiskers", "omit": "true"}]}
467
+ Honeybee.query(name: "Hutch", omit: true)
468
+ # JSON -> {"query": [{"Bee Name": "Hutch", "omit": "true"}]}
475
469
  ```
476
470
 
477
471
  #### Other notes on querying
@@ -479,35 +473,35 @@ Kitty.query(name: "Captain Whiskers", omit: true)
479
473
  You can chain all query methods together:
480
474
 
481
475
  ```ruby
482
- Kitty.limit(10).offset(20).sort(:name, :age!).portal(:toys).query(name: "Mr. Fluffers")
476
+ Honeybee.limit(10).offset(20).sort(:name, :age!).portal(:hives).query(name: "Hutch")
483
477
  ```
484
478
 
485
479
  You can also set default values for limit and sort on the class:
486
480
 
487
481
  ```ruby
488
- Kitty.default_limit = 1000
489
- Kitty.default_sort = [:name, :age!]
482
+ Honeybee.default_limit = 1000
483
+ Honeybee.default_sort = [:name, :age!]
490
484
  ```
491
485
 
492
486
  Calling any `Enumerable` method on the resulting scope object will trigger a
493
487
  server request, so you can treat the scope as a collection:
494
488
 
495
489
  ```ruby
496
- Kitty.limit(10).sort(:name).each { |kitty| ... }
490
+ Honeybee.limit(10).sort(:name).each { |bee| ... }
497
491
  ```
498
492
 
499
493
  If you want to explicitly run the request instead you can use `.find_some` on
500
494
  the scope object:
501
495
 
502
496
  ```ruby
503
- Kitty.limit(10).sort(:name).find_some # => [<Kitty...>, ...]
497
+ Honeybee.limit(10).sort(:name).find_some # => [<Honeybee...>, ...]
504
498
  ```
505
499
 
506
500
  If you want just a single result you can use `.find_one` instead (this will
507
501
  force `.limit(1)`):
508
502
 
509
503
  ```ruby
510
- Kitty.query(name: "Mr. Fluffers").find_one # => <Kitty...>
504
+ Honeybee.query(name: "Hutch").find_one # => <Honeybee...>
511
505
  ```
512
506
 
513
507
  NOTE: If you know the id of the record you should use `.find(id)` instead of
@@ -515,7 +509,7 @@ NOTE: If you know the id of the record you should use `.find(id)` instead of
515
509
  instead of `POST ../:layout/_find`).
516
510
 
517
511
  ```ruby
518
- Kitty.find(89) # => <Kitty...>
512
+ Honeybee.find(89) # => <Honeybee...>
519
513
  ```
520
514
 
521
515
  ### Container fields
@@ -523,8 +517,8 @@ Kitty.find(89) # => <Kitty...>
523
517
  You can define container fields on your model class with `container`:
524
518
 
525
519
  ```ruby
526
- class Kitty < FmRest::Spyke::Base
527
- container :photo, field_name: "Vet Card Photo ID"
520
+ class Honeybee < FmRest::Spyke::Base
521
+ container :photo, field_name: "Beehive Photo ID"
528
522
  end
529
523
  ```
530
524
 
@@ -538,13 +532,13 @@ addition to the `container` definition.)
538
532
  This will provide you with the following instance methods:
539
533
 
540
534
  ```ruby
541
- kitty = Kitty.new
535
+ bee = Honeybee.new
542
536
 
543
- kitty.photo.url # The URL of the container file on the FileMaker server
537
+ bee.photo.url # The URL of the container file on the FileMaker server
544
538
 
545
- kitty.photo.download # Download the contents of the container as an IO object
539
+ bee.photo.download # Download the contents of the container as an IO object
546
540
 
547
- kitty.photo.upload(filename_or_io) # Upload a file to the container
541
+ bee.photo.upload(filename_or_io) # Upload a file to the container
548
542
  ```
549
543
 
550
544
  `upload` also accepts an options hash with the following options:
@@ -575,12 +569,12 @@ FmRest.config = {
575
569
  }
576
570
 
577
571
  # Or in your model
578
- class LoggyKitty < FmRest::Spyke::Base
572
+ class LoggyBee < FmRest::Spyke::Base
579
573
  self.fmrest_config = {
580
574
  host: "example.com",
581
575
  database: "My Database",
582
- username: "z3r0c00l",
583
- password: "abc123",
576
+ username: "...",
577
+ password: "...",
584
578
  log: true
585
579
  }
586
580
  end
@@ -593,7 +587,7 @@ If you need to set up more complex logging for your models can use the
593
587
  Faraday connection, e.g.:
594
588
 
595
589
  ```ruby
596
- class LoggyKitty < FmRest::Spyke::Base
590
+ class LoggyBee < FmRest::Spyke::Base
597
591
  faraday do |conn|
598
592
  conn.response :logger, MyApp.logger, bodies: true
599
593
  end
@@ -61,7 +61,7 @@ module FmRest
61
61
  where_options["#{prefix}limit"] = scope.limit_value if scope.limit_value
62
62
  where_options["#{prefix}offset"] = scope.offset_value if scope.offset_value
63
63
 
64
- if scope.sort_params.present? && scope.limit_value != 1
64
+ if scope.sort_params.present?
65
65
  where_options["#{prefix}sort"] =
66
66
  prefixed ? scope.sort_params.to_json : scope.sort_params
67
67
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module FmRest
4
- VERSION = "0.2.0"
4
+ VERSION = "0.2.1"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fmrest
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
  - Pedro Carbajal
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-06-19 00:00:00.000000000 Z
11
+ date: 2019-07-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday