desk_api 0.6.1 → 0.6.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE.txt +1 -1
- data/README.md +26 -8
- data/lib/desk.rb +1 -1
- data/lib/desk_api.rb +2 -3
- data/lib/desk_api/client.rb +6 -6
- data/lib/desk_api/configuration.rb +5 -2
- data/lib/desk_api/default.rb +2 -2
- data/lib/desk_api/error.rb +2 -2
- data/lib/desk_api/error/bad_gateway.rb +1 -1
- data/lib/desk_api/error/bad_request.rb +1 -1
- data/lib/desk_api/error/client_error.rb +1 -1
- data/lib/desk_api/error/configuration_error.rb +1 -1
- data/lib/desk_api/error/conflict.rb +1 -1
- data/lib/desk_api/error/follow_redirect_error.rb +1 -1
- data/lib/desk_api/error/forbidden.rb +1 -1
- data/lib/desk_api/error/gateway_timeout.rb +1 -1
- data/lib/desk_api/error/internal_server_error.rb +1 -1
- data/lib/desk_api/error/method_not_allowed.rb +1 -1
- data/lib/desk_api/error/not_acceptable.rb +1 -1
- data/lib/desk_api/error/not_found.rb +1 -1
- data/lib/desk_api/error/parser_error.rb +1 -1
- data/lib/desk_api/error/server_error.rb +1 -1
- data/lib/desk_api/error/service_unavailable.rb +1 -1
- data/lib/desk_api/error/too_many_requests.rb +1 -1
- data/lib/desk_api/error/unauthorized.rb +1 -1
- data/lib/desk_api/error/unprocessable_entity.rb +1 -1
- data/lib/desk_api/error/unsupported_media_type.rb +1 -1
- data/lib/desk_api/rate_limit.rb +2 -2
- data/lib/desk_api/request/encode_dates.rb +73 -0
- data/lib/desk_api/request/encode_json.rb +2 -2
- data/lib/desk_api/request/oauth.rb +2 -2
- data/lib/desk_api/request/retry.rb +4 -3
- data/lib/desk_api/resource.rb +22 -194
- data/lib/desk_api/resource/download.rb +57 -0
- data/lib/desk_api/resource/pagination.rb +77 -0
- data/lib/desk_api/resource/query_params.rb +106 -0
- data/lib/desk_api/resource/scrud.rb +145 -0
- data/lib/desk_api/response/follow_redirects.rb +2 -2
- data/lib/desk_api/response/parse_dates.rb +2 -2
- data/lib/desk_api/response/parse_json.rb +2 -2
- data/lib/desk_api/response/raise_error.rb +2 -2
- data/lib/desk_api/version.rb +2 -2
- data/spec/cassettes/DeskApi_Resource/_next_/returns_nil_on_non-page_resources.yml +207 -0
- data/spec/cassettes/DeskApi_Resource/_next_/throws_an_error_on_non-page_resources.yml +207 -0
- data/spec/cassettes/DeskApi_Resource_Download/downloads_the_attachment.yml +238 -0
- data/spec/cassettes/DeskApi_Resource_Download/throws_an_error_on_non_attachment_resources.yml +47 -0
- data/spec/cassettes/DeskApi_Resource_Pagination/_all/iterates_over_each_resource_on_each_page.yml +13538 -0
- data/spec/cassettes/DeskApi_Resource_Pagination/_each_page/iterates_over_each_page.yml +13538 -0
- data/spec/cassettes/DeskApi_Resource_Pagination/_each_page/raises_NoMethodError_is_called_on_non-page_resources.yml +2093 -0
- data/spec/cassettes/DeskApi_Resource_Pagination/_each_page/uses_a_default_per_page_of_1000.yml +13538 -0
- data/spec/cassettes/DeskApi_Resource_QueryParams/_page/keeps_the_resource_as_loaded.yml +2093 -0
- data/spec/cassettes/DeskApi_Resource_QueryParams/_page/returns_the_current_page_and_loads_if_page_not_defined.yml +1207 -0
- data/spec/cassettes/DeskApi_Resource_QueryParams/_page/sets_the_resource_to_not_loaded.yml +2093 -0
- data/spec/cassettes/{DeskApi_Resource → DeskApi_Resource_SCRUD}/_create/creates_a_new_topic.yml +0 -0
- data/spec/cassettes/{DeskApi_Resource → DeskApi_Resource_SCRUD}/_create/throws_an_error_creating_a_user.yml +0 -0
- data/spec/cassettes/{DeskApi_Resource → DeskApi_Resource_SCRUD}/_delete/deletes_a_resource.yml +0 -0
- data/spec/cassettes/{DeskApi_Resource → DeskApi_Resource_SCRUD}/_delete/throws_an_error_deleting_a_non_deletalbe_resource.yml +0 -0
- data/spec/cassettes/{DeskApi_Resource → DeskApi_Resource_SCRUD}/_find/has_an_alias_by_id.yml +0 -0
- data/spec/cassettes/{DeskApi_Resource → DeskApi_Resource_SCRUD}/_find/loads_the_requested_resource.yml +0 -0
- data/spec/cassettes/{DeskApi_Resource → DeskApi_Resource_SCRUD}/_search/allows_searching_on_search_enabled_resources.yml +0 -0
- data/spec/cassettes/{DeskApi_Resource → DeskApi_Resource_SCRUD}/_search/throws_an_error_if_search_is_not_enabled.yml +0 -0
- data/spec/cassettes/{DeskApi_Resource → DeskApi_Resource_SCRUD}/_update/can_handle_action_params.yml +0 -0
- data/spec/cassettes/{DeskApi_Resource → DeskApi_Resource_SCRUD}/_update/can_handle_links.yml +0 -0
- data/spec/cassettes/{DeskApi_Resource → DeskApi_Resource_SCRUD}/_update/can_handle_update_action_params.yml +0 -0
- data/spec/cassettes/{DeskApi_Resource → DeskApi_Resource_SCRUD}/_update/can_replace_instead_of_append.yml +0 -0
- data/spec/cassettes/{DeskApi_Resource → DeskApi_Resource_SCRUD}/_update/can_update_without_a_hash.yml +0 -0
- data/spec/cassettes/{DeskApi_Resource → DeskApi_Resource_SCRUD}/_update/throws_an_error_updating_a_user.yml +0 -0
- data/spec/cassettes/{DeskApi_Resource → DeskApi_Resource_SCRUD}/_update/updates_a_topic.yml +0 -0
- data/spec/desk_api/client_spec.rb +33 -7
- data/spec/desk_api/configuration_spec.rb +4 -4
- data/spec/desk_api/default_spec.rb +1 -1
- data/spec/desk_api/error_spec.rb +1 -1
- data/spec/desk_api/rate_limit_spec.rb +1 -1
- data/spec/desk_api/request/encode_dates_spec.rb +63 -0
- data/spec/desk_api/request/encode_json_spec.rb +4 -4
- data/spec/desk_api/request/oauth_spec.rb +1 -1
- data/spec/desk_api/request/retry_spec.rb +1 -1
- data/spec/desk_api/resource/download_spec.rb +45 -0
- data/spec/desk_api/resource/pagination_spec.rb +77 -0
- data/spec/desk_api/resource/query_params_spec.rb +145 -0
- data/spec/desk_api/resource/scrud_spec.rb +216 -0
- data/spec/desk_api/resource_spec.rb +14 -321
- data/spec/desk_api/response/follow_redirects_spec.rb +1 -1
- data/spec/desk_api/response/parse_dates_spec.rb +1 -1
- data/spec/desk_api/response/parse_json_spec.rb +1 -1
- data/spec/desk_api/response/raise_error_spec.rb +1 -1
- data/spec/desk_api_spec.rb +1 -1
- data/spec/spec_helper.rb +1 -2
- data/spec/stubs/file.jpg +0 -0
- metadata +128 -104
- data/spec/cassettes/DeskApi_Resource/_all/iterates_over_each_resource_on_each_page.yml +0 -1953
- data/spec/cassettes/DeskApi_Resource/_each_page/iterates_over_each_page.yml +0 -1953
- data/spec/cassettes/DeskApi_Resource/_each_page/raises_NoMethodError_is_called_on_non-page_resources.yml +0 -207
- data/spec/cassettes/DeskApi_Resource/_each_page/uses_a_default_per_page_of_1000.yml +0 -1953
- data/spec/cassettes/DeskApi_Resource/_page/keeps_the_resource_as_loaded.yml +0 -113
- data/spec/cassettes/DeskApi_Resource/_page/returns_the_current_page_and_loads_if_page_not_defined.yml +0 -62
- data/spec/cassettes/DeskApi_Resource/_page/sets_the_resource_to_not_loaded.yml +0 -113
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7cef419cb4804c1a1d30d99063b5f3bba9e3d552
|
4
|
+
data.tar.gz: 67d6895e8a527ac9be61d64271bc65756e856fe1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 81d57dd47f416ddb525e88aec774a323990dd3ac195cd825d5513ba69c35e76ddba6fdd453f7b7b9f223aea8d8acea9f04b0a9d0c8f1f9e12fc3507b30785fb0
|
7
|
+
data.tar.gz: 4ce97b7989cc00c14c29b4e0ae3b79a1d9d348069f6d5b336efa5ebc7eb3b78115c1405d24d6daf32cc302945b3eee58221949047a9d6b005222b31df15fee88
|
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
# DeskApi a client for
|
2
|
-
## An
|
1
|
+
# DeskApi a client for API v2
|
2
|
+
## An official Desk API Client
|
3
3
|
|
4
4
|
DeskApi takes the capabilities of the Desk.com API and wraps them up in a Ruby
|
5
5
|
client so that it's easy-as-pie to get working with your support site's API.
|
6
6
|
|
7
|
-
Desk publishes a
|
7
|
+
Desk.com publishes a change log monthly, which you can keep up with at
|
8
8
|
[dev.desk.com/API/changelog](http://dev.desk.com/API/changelog).
|
9
9
|
|
10
10
|
We do our best to keep DeskApi, but please don't hesitate to open an
|
@@ -25,7 +25,7 @@ gem install desk_api
|
|
25
25
|
|
26
26
|
#### Authentication Mechanism
|
27
27
|
|
28
|
-
The
|
28
|
+
The Desk.com API allows you to access data using two authentication mechanisms:
|
29
29
|
|
30
30
|
##### Basic Authentication
|
31
31
|
|
@@ -185,7 +185,7 @@ updated_customer = customer.update title: 'Master of the Universe'
|
|
185
185
|
# users are not updatable
|
186
186
|
begin
|
187
187
|
user = DeskApi.users.first
|
188
|
-
user.update name: 'Not
|
188
|
+
user.update name: 'Not updatable'
|
189
189
|
rescue DeskApi::Error::MethodNotAllowed
|
190
190
|
# too bad
|
191
191
|
end
|
@@ -193,7 +193,7 @@ end
|
|
193
193
|
|
194
194
|
### Find
|
195
195
|
|
196
|
-
The method `by_url` can be called on the client, for backwards
|
196
|
+
The method `by_url` can be called on the client, for backwards compatibility we
|
197
197
|
haven't yet removed it from the `DeskApi::Resource` but it will be removed once
|
198
198
|
we release v1 of this client. `by_url` will return a lazy loaded instance of the
|
199
199
|
resource.
|
@@ -345,7 +345,7 @@ DeskApi.cases.page(10).per_page(50).entries.each do |my_case|
|
|
345
345
|
# in this method chain, no HTTP request is fired until `.entries'
|
346
346
|
end
|
347
347
|
|
348
|
-
# however if you request the current page
|
348
|
+
# however if you request the current page number and the resource is not loaded
|
349
349
|
# it'll send a request
|
350
350
|
DeskApi.cases.page == 1
|
351
351
|
```
|
@@ -394,6 +394,24 @@ assigned_user = my_case.assigned_user
|
|
394
394
|
assigned_group = my_case.assigned_group
|
395
395
|
```
|
396
396
|
|
397
|
+
### Downloading Attachments
|
398
|
+
|
399
|
+
Attachment resources can be downloaded directly, a `Tempfile` is returned that can either be read or moved to the final location.
|
400
|
+
|
401
|
+
```ruby
|
402
|
+
ticket = DeskApi.cases.find(123)
|
403
|
+
attachment = ticket.attachments.entries.first
|
404
|
+
file = attachment.download
|
405
|
+
|
406
|
+
# Read the file
|
407
|
+
content = file.read
|
408
|
+
|
409
|
+
# Save the file
|
410
|
+
File.open('/path/to/my/storage', 'w') do |f|
|
411
|
+
f.write(content)
|
412
|
+
end
|
413
|
+
```
|
414
|
+
|
397
415
|
### API Errors
|
398
416
|
|
399
417
|
Sometimes the API is going to return errors, eg. Validation Error. In these
|
@@ -418,7 +436,7 @@ their respective meanings.
|
|
418
436
|
|
419
437
|
## License
|
420
438
|
|
421
|
-
Copyright (c) 2013-
|
439
|
+
Copyright (c) 2013-2016, Salesforce.com, Inc.
|
422
440
|
All rights reserved.
|
423
441
|
|
424
442
|
Redistribution and use in source and binary forms, with or without modification,
|
data/lib/desk.rb
CHANGED
data/lib/desk_api.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (c) 2013-
|
1
|
+
# Copyright (c) 2013-2016, Salesforce.com, Inc.
|
2
2
|
# All rights reserved.
|
3
3
|
#
|
4
4
|
# Redistribution and use in source and binary forms, with or without modification,
|
@@ -29,7 +29,6 @@
|
|
29
29
|
require 'uri'
|
30
30
|
require 'faraday'
|
31
31
|
require 'forwardable'
|
32
|
-
require 'addressable/uri'
|
33
32
|
|
34
33
|
# {DeskApi} allows for easy interaction with Desk.com's API.
|
35
34
|
# It is the top level namespace and delegates all missing
|
@@ -38,7 +37,7 @@ require 'addressable/uri'
|
|
38
37
|
# if you have to connect to multiple Desk.com sites.
|
39
38
|
#
|
40
39
|
# @author Thomas Stachl <tstachl@salesforce.com>
|
41
|
-
# @copyright Copyright (c) 2013-
|
40
|
+
# @copyright Copyright (c) 2013-2016 Salesforce.com
|
42
41
|
# @license BSD 3-Clause License
|
43
42
|
#
|
44
43
|
# @example configure the {DeskApi} client
|
data/lib/desk_api/client.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (c) 2013-
|
1
|
+
# Copyright (c) 2013-2016, Salesforce.com, Inc.
|
2
2
|
# All rights reserved.
|
3
3
|
#
|
4
4
|
# Redistribution and use in source and binary forms, with or without modification,
|
@@ -36,7 +36,7 @@ module DeskApi
|
|
36
36
|
# the configuration module.
|
37
37
|
#
|
38
38
|
# @author Thomas Stachl <tstachl@salesforce.com>
|
39
|
-
# @copyright Copyright (c) 2013-
|
39
|
+
# @copyright Copyright (c) 2013-2016 Salesforce.com
|
40
40
|
# @license BSD 3-Clause License
|
41
41
|
class Client
|
42
42
|
include DeskApi::Configuration
|
@@ -103,10 +103,10 @@ module DeskApi
|
|
103
103
|
# @raises [DeskApi::Error::ParserError]
|
104
104
|
def request(method, path, params = {}, &block)
|
105
105
|
connection.send(method, path, params, &block)
|
106
|
-
rescue Faraday::Error::ClientError
|
107
|
-
raise DeskApi::Error::ClientError
|
108
|
-
rescue JSON::ParserError
|
109
|
-
raise DeskApi::Error::ParserError
|
106
|
+
rescue Faraday::Error::ClientError => err
|
107
|
+
raise DeskApi::Error::ClientError.new(err)
|
108
|
+
rescue JSON::ParserError => err
|
109
|
+
raise DeskApi::Error::ParserError.new(err)
|
110
110
|
end
|
111
111
|
|
112
112
|
# Builds and/or returns the Faraday client.
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (c) 2013-
|
1
|
+
# Copyright (c) 2013-2016, Salesforce.com, Inc.
|
2
2
|
# All rights reserved.
|
3
3
|
#
|
4
4
|
# Redistribution and use in source and binary forms, with or without modification,
|
@@ -32,6 +32,7 @@ require 'desk_api/default'
|
|
32
32
|
require 'desk_api/request/retry'
|
33
33
|
require 'desk_api/request/oauth'
|
34
34
|
require 'desk_api/request/encode_json'
|
35
|
+
require 'desk_api/request/encode_dates'
|
35
36
|
require 'desk_api/response/parse_dates'
|
36
37
|
require 'desk_api/response/parse_json'
|
37
38
|
require 'desk_api/response/raise_error'
|
@@ -46,7 +47,7 @@ module DeskApi
|
|
46
47
|
# makes sure secrets are only readable by the client.
|
47
48
|
#
|
48
49
|
# @author Thomas Stachl <tstachl@salesforce.com>
|
49
|
-
# @copyright Copyright (c) 2013-
|
50
|
+
# @copyright Copyright (c) 2013-2016 Salesforce.com
|
50
51
|
# @license BSD 3-Clause License
|
51
52
|
module Configuration
|
52
53
|
extend Forwardable
|
@@ -84,6 +85,7 @@ module DeskApi
|
|
84
85
|
|
85
86
|
# Registers the middleware when the module is included.
|
86
87
|
def included(_base)
|
88
|
+
register_middleware :request, :desk_encode_dates, :EncodeDates
|
87
89
|
register_middleware :request, :desk_encode_json, :EncodeJson
|
88
90
|
register_middleware :request, :desk_oauth, :OAuth
|
89
91
|
register_middleware :request, :desk_retry, :Retry
|
@@ -106,6 +108,7 @@ module DeskApi
|
|
106
108
|
# @return [Proc]
|
107
109
|
def middleware
|
108
110
|
@middleware ||= proc do |builder|
|
111
|
+
builder.request(:desk_encode_dates)
|
109
112
|
builder.request(:desk_encode_json)
|
110
113
|
builder.request(*authorize_request)
|
111
114
|
builder.request(:desk_retry)
|
data/lib/desk_api/default.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (c) 2013-
|
1
|
+
# Copyright (c) 2013-2016, Salesforce.com, Inc.
|
2
2
|
# All rights reserved.
|
3
3
|
#
|
4
4
|
# Redistribution and use in source and binary forms, with or without modification,
|
@@ -31,7 +31,7 @@ module DeskApi
|
|
31
31
|
# {DeskApi::Client}.
|
32
32
|
#
|
33
33
|
# @author Thomas Stachl <tstachl@salesforce.com>
|
34
|
-
# @copyright Copyright (c) 2013-
|
34
|
+
# @copyright Copyright (c) 2013-2016 Salesforce.com
|
35
35
|
# @license BSD 3-Clause License
|
36
36
|
module Default
|
37
37
|
CONNECTION_OPTIONS = {
|
data/lib/desk_api/error.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (c) 2013-
|
1
|
+
# Copyright (c) 2013-2016, Salesforce.com, Inc.
|
2
2
|
# All rights reserved.
|
3
3
|
#
|
4
4
|
# Redistribution and use in source and binary forms, with or without modification,
|
@@ -32,7 +32,7 @@ module DeskApi
|
|
32
32
|
# {DeskApi::Error} is the base error for all {DeskApi} errors.
|
33
33
|
#
|
34
34
|
# @author Thomas Stachl <tstachl@salesforce.com>
|
35
|
-
# @copyright Copyright (c) 2013-
|
35
|
+
# @copyright Copyright (c) 2013-2016 Salesforce.com
|
36
36
|
# @license BSD 3-Clause License
|
37
37
|
class Error < StandardError
|
38
38
|
attr_reader :rate_limit
|
data/lib/desk_api/rate_limit.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (c) 2013-
|
1
|
+
# Copyright (c) 2013-2016, Salesforce.com, Inc.
|
2
2
|
# All rights reserved.
|
3
3
|
#
|
4
4
|
# Redistribution and use in source and binary forms, with or without modification,
|
@@ -31,7 +31,7 @@ module DeskApi
|
|
31
31
|
# responses from desk.com API.
|
32
32
|
#
|
33
33
|
# @author Thomas Stachl <tstachl@salesforce.com>
|
34
|
-
# @copyright Copyright (c) 2013-
|
34
|
+
# @copyright Copyright (c) 2013-2016 Salesforce.com
|
35
35
|
# @license BSD 3-Clause License
|
36
36
|
class RateLimit
|
37
37
|
def initialize(attrs = {})
|
@@ -0,0 +1,73 @@
|
|
1
|
+
# Copyright (c) 2013-2016, Salesforce.com, Inc.
|
2
|
+
# All rights reserved.
|
3
|
+
#
|
4
|
+
# Redistribution and use in source and binary forms, with or without modification,
|
5
|
+
# are permitted provided that the following conditions are met:
|
6
|
+
#
|
7
|
+
# * Redistributions of source code must retain the above copyright notice, this
|
8
|
+
# list of conditions and the following disclaimer.
|
9
|
+
#
|
10
|
+
# * Redistributions in binary form must reproduce the above copyright notice,
|
11
|
+
# this list of conditions and the following disclaimer in the documentation
|
12
|
+
# and/or other materials provided with the distribution.
|
13
|
+
#
|
14
|
+
# * Neither the name of Salesforce.com nor the names of its contributors may be
|
15
|
+
# used to endorse or promote products derived from this software without
|
16
|
+
# specific prior written permission.
|
17
|
+
#
|
18
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
19
|
+
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
20
|
+
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
21
|
+
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
22
|
+
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
23
|
+
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
24
|
+
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
25
|
+
# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
26
|
+
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
27
|
+
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
28
|
+
|
29
|
+
module DeskApi
|
30
|
+
module Request
|
31
|
+
# {DeskApi::Request::EncodeJson} is the Faraday middleware
|
32
|
+
# that dumps a json string from whatever is specified in
|
33
|
+
# the request body. It also sets the "Content-Type" header.
|
34
|
+
#
|
35
|
+
# @author Thomas Stachl <tstachl@salesforce.com>
|
36
|
+
# @copyright Copyright (c) 2013-2016 Salesforce.com
|
37
|
+
# @license BSD 3-Clause License
|
38
|
+
class EncodeDates < Faraday::Middleware
|
39
|
+
# Changes the request before it gets sent
|
40
|
+
#
|
41
|
+
# @param env [Hash] the request hash
|
42
|
+
def call(env)
|
43
|
+
if env[:body] && !env[:body].to_s.empty?
|
44
|
+
env[:body] = encode_dates(env[:body])
|
45
|
+
end
|
46
|
+
@app.call env
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
# Encodes all {Date}, {DateTime} and {Time} values
|
52
|
+
# to iso8601
|
53
|
+
#
|
54
|
+
# @param value [Mixed] the current body
|
55
|
+
def encode_dates(value)
|
56
|
+
case value
|
57
|
+
when Hash
|
58
|
+
value.each_pair do |key, element|
|
59
|
+
value[key] = encode_dates element
|
60
|
+
end
|
61
|
+
when Array
|
62
|
+
value.each_with_index do |element, index|
|
63
|
+
value[index] = encode_dates element
|
64
|
+
end
|
65
|
+
when DateTime, Date, Time
|
66
|
+
value.to_time.utc.iso8601
|
67
|
+
else
|
68
|
+
value
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|