fmrest-core 0.15.2 → 0.16.0

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: 01ec00e52b9c84c094188e3b9b4e3f869063294ebf695364b9141dbce28a2e7c
4
- data.tar.gz: 00b228812583d4b256e0c2f9be8336db9d47b14fd2e1324ecdf6012c91af3c6f
3
+ metadata.gz: 02e8b51abdf2fc9a5b7df29cdad8d5acef8f04b5c6167d7ff94040a716117449
4
+ data.tar.gz: 6a78ce64f39cd5e41910114eb22948eb5c4f26d26a892ab2b09c0bdcaa6c3fb3
5
5
  SHA512:
6
- metadata.gz: cadaee1025630ff4e0e2110bc9d294262861a9baa578b84e88fca0c7ed15e8a73edba710232d535197f0c74cd0bb2af8758998710876f1ead48532bb0f69c27e
7
- data.tar.gz: 15e8c19893fc459e29f924352b1657dadfadc242201811719b1a2e871106af7616c99ab4f8adfd76f775021b288002c6d98d04ba64f30b549eb3802618e23b34
6
+ metadata.gz: 3bdd91f7e25de359a7a28746d4c7be4eae7a684b63d909eacae6dd48a7053666386ff6dd3b87895aaf315e6a6b923aadcf0b8713aefa696fadbef25656dbae3b
7
+ data.tar.gz: 37d292af43be4a6a42b4f4044d3078ec40edff189622e3d4390d4a9ec65e34b0b910b2542ca4293ea3d3925eea8c84f1c944a5d7c7cc22f47bf989113b1017d7
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  ## Changelog
2
2
 
3
+ ### 0.16.0
4
+
5
+ * Add `FmRest.logger=`
6
+ * Handle serialization of `nil`, `true` and `false` values
7
+
3
8
  ### 0.15.2
4
9
 
5
10
  * Fix autoloading of `FmRest::Layout`
data/README.md CHANGED
@@ -152,6 +152,7 @@ Option | Description | Format
152
152
  `:ssl` | SSL options to be forwarded to Faraday | Faraday SSL options | None
153
153
  `:proxy` | Proxy options to be forwarded to Faraday | Faraday proxy options | None
154
154
  `:log` | Log JSON responses to STDOUT | Boolean | `false`
155
+ `:log_level` | Which log level to log into | Values accepted by `Logger#level=` | `:debug`
155
156
  `:coerce_dates` | See section on [date fields](#date-fields-and-timezones) | Boolean \| `:hybrid` \| `:full` | `false`
156
157
  `:date_format` | Date parsing format | String (FM date format) | `"MM/dd/yyyy"`
157
158
  `:timestamp_format` | Timestmap parsing format | String (FM date format) | `"MM/dd/yyyy HH:mm:ss"`
@@ -457,7 +458,7 @@ If using `fmrest-spyke` with Rails then pretty log output will be set up for
457
458
  you automatically by Spyke (see [their
458
459
  README](https://github.com/balvig/spyke#log-output)).
459
460
 
460
- You can also enable simple Faraday STDOUT logging of raw requests (useful for
461
+ You can also enable simple Faraday logging of raw requests (useful for
461
462
  debugging) by passing `log: true` in the options hash for either
462
463
  `FmRest.default_connection_settings=` or your models' `fmrest_config=`, e.g.:
463
464
 
@@ -478,7 +479,17 @@ class LoggyBee < FmRest::Layout
478
479
  end
479
480
  ```
480
481
 
481
- If you need to set up more complex logging for your models can use the
482
+ You can also pass `log_level` to connection settings to change the severity of
483
+ log output (defaults to `:debug`).
484
+
485
+ By default fmrest-ruby logs to STDOUT or to Rails' logger object if available.
486
+ You can change this by providing your own logger object to `FmRest.logger=`:
487
+
488
+ ```ruby
489
+ FmRest.logger = Logger.new("fmrest.log")
490
+ ```
491
+
492
+ If you need to set up more complex logging for your models you can use the
482
493
  `faraday` block inside your class to inject your own logger middleware into the
483
494
  Faraday connection, e.g.:
484
495
 
data/lib/fmrest.rb CHANGED
@@ -15,9 +15,13 @@ module FmRest
15
15
 
16
16
  class << self
17
17
  attr_accessor :token_store
18
+ attr_writer :logger
18
19
 
19
20
  def default_connection_settings=(settings)
20
- @default_connection_settings = ConnectionSettings.wrap(settings, skip_validation: true)
21
+ # Skip validation since we may use the defaults for half-complete
22
+ # settings
23
+ @default_connection_settings =
24
+ ConnectionSettings.wrap(settings, skip_validation: true)
21
25
  end
22
26
 
23
27
  def default_connection_settings
@@ -34,6 +38,15 @@ module FmRest
34
38
  default_connection_settings
35
39
  end
36
40
 
41
+ def logger
42
+ @logger ||= if defined?(Rails)
43
+ Rails.logger
44
+ else
45
+ require "logger"
46
+ Logger.new($stdout)
47
+ end
48
+ end
49
+
37
50
  # Shortcut for FmRest::V1.escape_find_operators
38
51
  #
39
52
  # @param (see FmRest::V1.escape_find_operators
@@ -24,6 +24,7 @@ module FmRest
24
24
  ssl
25
25
  proxy
26
26
  log
27
+ log_level
27
28
  coerce_dates
28
29
  date_format
29
30
  timestamp_format
@@ -45,6 +46,7 @@ module FmRest
45
46
  DEFAULTS = {
46
47
  autologin: true,
47
48
  log: false,
49
+ log_level: :debug,
48
50
  date_format: DEFAULT_DATE_FORMAT,
49
51
  time_format: DEFAULT_TIME_FORMAT,
50
52
  timestamp_format: DEFAULT_TIMESTAMP_FORMAT,
@@ -41,7 +41,7 @@ module FmRest
41
41
  end
42
42
 
43
43
  if settings.log
44
- conn.response :logger, nil, bodies: true, headers: true
44
+ conn.response :logger, FmRest.logger, bodies: true, headers: true, log_level: settings.log_level
45
45
  end
46
46
 
47
47
  conn.adapter Faraday.default_adapter
@@ -61,7 +61,7 @@ module FmRest
61
61
  conn.basic_auth settings.username!, settings.password!
62
62
 
63
63
  if settings.log
64
- conn.response :logger, nil, bodies: true, headers: true
64
+ conn.response :logger, FmRest.logger, bodies: true, headers: true, log_level: settings.log_level
65
65
  end
66
66
 
67
67
  conn.response :json
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module FmRest
4
- VERSION = "0.15.2"
4
+ VERSION = "0.16.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.15.2
4
+ version: 0.16.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-04-06 00:00:00.000000000 Z
11
+ date: 2021-04-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday