fmrest-core 0.14.0 → 0.15.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 +5 -0
- data/README.md +27 -11
- data/lib/fmrest.rb +8 -0
- data/lib/fmrest/v1/dates.rb +38 -2
- data/lib/fmrest/v1/utils.rb +13 -0
- data/lib/fmrest/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ffafc2aecdab7b90059a7cc7a9a3687fbb557178d1cba164ca98feccf675cad1
|
4
|
+
data.tar.gz: df5a41ca5a2601a0bf4f9635ba42b14240aaeea10ced1b035a376fff12c0327e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: effc1532b7060e3167c726771bf057fa9154fd61e77517628e2d4ae9da716555e6bf0aa0a3fac29a1d5a7bbd6c6f53b9db138472af64b19b685e00d3a49ff52b
|
7
|
+
data.tar.gz: 3dc285d1ed51eb1a12203f90ad27655e8c24810391c0dbcb9223cbff80c0ed694c32ff86f6dd9f41f4170e399ec4aeabd79b7b4119b578fa3e1f9ef7e24ad500
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,10 @@
|
|
1
1
|
## Changelog
|
2
2
|
|
3
|
+
### 0.15.0
|
4
|
+
|
5
|
+
* Much improved querying API (see documentation on querying), adding new
|
6
|
+
`.query` capabilities, as well as two new methods: `.match` and `.or`
|
7
|
+
|
3
8
|
### 0.14.0
|
4
9
|
|
5
10
|
* Aliased `FmRest::Spyke::Base` as `FmRest::Layout` (now preferred), and
|
data/README.md
CHANGED
@@ -54,13 +54,28 @@ class Honeybee < FmRest::Layout("Honeybees Web")
|
|
54
54
|
}
|
55
55
|
|
56
56
|
# Mapped attributes
|
57
|
-
attributes name: "Bee Name", age: "Bee Age"
|
57
|
+
attributes name: "Bee Name", age: "Bee Age", created_on: "Created On"
|
58
58
|
|
59
|
-
#
|
60
|
-
has_portal :
|
59
|
+
# Portal associations
|
60
|
+
has_portal :tasks
|
61
61
|
|
62
|
-
# File
|
62
|
+
# File containers
|
63
63
|
container :photo, field_name: "Bee Photo"
|
64
|
+
|
65
|
+
# Scopes
|
66
|
+
scope :can_legally_fly, -> { query(age: ">18") }
|
67
|
+
|
68
|
+
# Client-side validations
|
69
|
+
validates :name, presence: true
|
70
|
+
|
71
|
+
# Callbacks
|
72
|
+
before_save :set_created_on
|
73
|
+
|
74
|
+
private
|
75
|
+
|
76
|
+
def set_created_on
|
77
|
+
self.created_on = Date.today
|
78
|
+
end
|
64
79
|
end
|
65
80
|
|
66
81
|
# Find a record by id
|
@@ -69,7 +84,7 @@ bee = Honeybee.find(9)
|
|
69
84
|
bee.name = "Hutch"
|
70
85
|
|
71
86
|
# Add a new record to portal
|
72
|
-
bee.
|
87
|
+
bee.tasks.build(urgency: "Today")
|
73
88
|
|
74
89
|
bee.save
|
75
90
|
```
|
@@ -129,9 +144,9 @@ You can also pass a `:log` option for basic request logging, see the section on
|
|
129
144
|
Option | Description | Format | Default
|
130
145
|
--------------------|--------------------------------------------|-----------------------------|--------
|
131
146
|
`:host` | Hostname with optional port, e.g. `"example.com:9000"` | String | None
|
132
|
-
`:database` |
|
133
|
-
`:username` |
|
134
|
-
`:password` |
|
147
|
+
`:database` | The name of the database to connect to | String | None
|
148
|
+
`:username` | A Data API-ready account | String | None
|
149
|
+
`:password` | Your password | String | None
|
135
150
|
`:account_name` | Alias of `:username` | String | None
|
136
151
|
`:ssl` | SSL options to be forwarded to Faraday | Faraday SSL options | None
|
137
152
|
`:proxy` | Proxy options to be forwarded to Faraday | Faraday proxy options | None
|
@@ -288,7 +303,8 @@ class Honeybee < FmRest::Layout
|
|
288
303
|
end
|
289
304
|
```
|
290
305
|
|
291
|
-
Alternatively, you
|
306
|
+
Alternatively, if you're inheriting from `FmRest::Layout` directly you can set
|
307
|
+
the layout name in the class definition line:
|
292
308
|
|
293
309
|
```ruby
|
294
310
|
class Honeybee < FmRest::Layout("Honeybees Web")
|
@@ -388,8 +404,8 @@ Guides](https://guides.rubyonrails.org/active_model_basics.html#dirty).
|
|
388
404
|
Since Spyke is API-agnostic it only provides a wide-purpose `.where` method for
|
389
405
|
passing arbitrary parameters to the REST backend. fmrest-ruby however is well
|
390
406
|
aware of its backend API, so it extends Spkye models with a bunch of useful
|
391
|
-
querying methods: `.query`, `.
|
392
|
-
etc.
|
407
|
+
querying methods: `.query`, `.match`, `.omit`, `.limit`, `.offset`, `.sort`,
|
408
|
+
`.portal`, `.script`, etc.
|
393
409
|
|
394
410
|
See the [main document on querying](docs/Querying.md) for detailed information
|
395
411
|
on the query API methods.
|
data/lib/fmrest.rb
CHANGED
@@ -32,5 +32,13 @@ module FmRest
|
|
32
32
|
warn "[DEPRECATION] `FmRest.config` is deprecated, use `FmRest.default_connection_settings` instead"
|
33
33
|
default_connection_settings
|
34
34
|
end
|
35
|
+
|
36
|
+
# Shortcut for FmRest::V1.escape_find_operators
|
37
|
+
#
|
38
|
+
# @param (see FmRest::V1.escape_find_operators
|
39
|
+
# @return (see FmRest::V1.escape_find_operators
|
40
|
+
def e(s)
|
41
|
+
V1.escape_find_operators(s)
|
42
|
+
end
|
35
43
|
end
|
36
44
|
end
|
data/lib/fmrest/v1/dates.rb
CHANGED
@@ -3,6 +3,8 @@
|
|
3
3
|
module FmRest
|
4
4
|
module V1
|
5
5
|
module Dates
|
6
|
+
FM_DATE_FORMAT = "%m/%d/%Y"
|
7
|
+
FM_DATETIME_FORMAT = "#{FM_DATE_FORMAT} %H:%M:%S"
|
6
8
|
FM_DATETIME_FORMAT_MATCHER = /MM|mm|dd|HH|ss|yyyy/.freeze
|
7
9
|
|
8
10
|
FM_DATE_TO_STRPTIME_SUBSTITUTIONS = {
|
@@ -55,8 +57,8 @@ module FmRest
|
|
55
57
|
# Takes a DateTime dt, and returns the correct local offset for that dt,
|
56
58
|
# daylight savings included, in fraction of a day.
|
57
59
|
#
|
58
|
-
# By default, if ActiveSupport's Time.zone is set it will be used
|
59
|
-
# of the system timezone.
|
60
|
+
# By default, if ActiveSupport's `Time.zone` is set it will be used
|
61
|
+
# instead of the system timezone.
|
60
62
|
#
|
61
63
|
# @param dt [DateTime] The DateTime to get the offset for
|
62
64
|
# @param zone [nil, String, TimeZone] The timezone to use to calculate
|
@@ -76,6 +78,40 @@ module FmRest
|
|
76
78
|
|
77
79
|
Rational(time.utc_offset, 86400) # seconds in one day (24*60*60)
|
78
80
|
end
|
81
|
+
|
82
|
+
# Returns a list of all datetime classes recognized by fmrest-ruby,
|
83
|
+
# including `FmRest::StringDateTime` if defined. Useful for using in a
|
84
|
+
# `case .. when` statement.
|
85
|
+
#
|
86
|
+
def datetime_classes
|
87
|
+
[DateTime, Time, defined?(FmRest::StringDateTime) && FmRest::StringDateTime].compact.freeze
|
88
|
+
end
|
89
|
+
|
90
|
+
# Returns a list of all date classes recognized by fmrest-ruby, including
|
91
|
+
# `FmRest::StringDate` if defined. Useful for using in a `case .. when`
|
92
|
+
# statement.
|
93
|
+
#
|
94
|
+
def date_classes
|
95
|
+
[Date, defined?(FmRest::StringDate) && FmRest::StringDate].compact.freeze
|
96
|
+
end
|
97
|
+
|
98
|
+
# Converts the given DateTime dt to the specified timezone setting offset,
|
99
|
+
# leaving everything else intact.
|
100
|
+
#
|
101
|
+
# @param dt [DateTime] The datetime to convert
|
102
|
+
# @param timezone [nil, Symbol, String] Accepted values are `:utc`,
|
103
|
+
# `:local`, or `nil` (in which case it leaves the given datetime intact)
|
104
|
+
# @return [DateTime] A new datetime with converted timezone
|
105
|
+
def convert_datetime_timezone(dt, timezone)
|
106
|
+
case timezone
|
107
|
+
when :utc, "utc"
|
108
|
+
dt.new_offset(0)
|
109
|
+
when :local, "local"
|
110
|
+
dt.new_offset(FmRest::V1.local_offset_for_datetime(dt))
|
111
|
+
when nil
|
112
|
+
dt
|
113
|
+
end
|
114
|
+
end
|
79
115
|
end
|
80
116
|
end
|
81
117
|
end
|
data/lib/fmrest/v1/utils.rb
CHANGED
@@ -5,6 +5,9 @@ module FmRest
|
|
5
5
|
module Utils
|
6
6
|
VALID_SCRIPT_KEYS = [:prerequest, :presort, :after].freeze
|
7
7
|
|
8
|
+
# See https://help.claris.com/en/pro-help/content/finding-text.html
|
9
|
+
FM_FIND_OPERATORS_RE = /([@\*#\?!=<>"])/
|
10
|
+
|
8
11
|
# Converts custom script options to a hash with the Data API's expected
|
9
12
|
# JSON script format.
|
10
13
|
#
|
@@ -91,6 +94,16 @@ module FmRest
|
|
91
94
|
}
|
92
95
|
end
|
93
96
|
|
97
|
+
# Escapes FileMaker find operators from the given string in order to use
|
98
|
+
# it in a find request.
|
99
|
+
#
|
100
|
+
# @param s [String] The string to escape
|
101
|
+
# @return [String] A new string with find operators escaped with
|
102
|
+
# backslashes
|
103
|
+
def escape_find_operators(s)
|
104
|
+
s.gsub(FM_FIND_OPERATORS_RE, "\\\\\\1")
|
105
|
+
end
|
106
|
+
|
94
107
|
private
|
95
108
|
|
96
109
|
def convert_script_arguments(script_arguments, suffix = nil)
|
data/lib/fmrest/version.rb
CHANGED
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.
|
4
|
+
version: 0.15.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-
|
11
|
+
date: 2021-04-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|