delivery-sdk-ruby 1.0.4 → 1.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -0
- data/lib/delivery/client/delivery_query.rb +13 -13
- data/lib/delivery/client/request_manager.rb +19 -9
- data/lib/delivery/tests/401.json +6 -0
- data/lib/delivery/tests/fake_responder.rb +65 -0
- data/lib/delivery/tests/filtering/items_gt.json +566 -0
- data/lib/delivery/tests/filtering/multiple.json +283 -0
- data/lib/delivery/tests/filtering/pagination_about_us.json +647 -0
- data/lib/delivery/tests/generic/items/about_us.json +228 -0
- data/lib/delivery/tests/generic/items/aeropress_filters.json +139 -0
- data/lib/delivery/tests/generic/items/coffee_processing_techniques.json +169 -0
- data/lib/delivery/tests/generic/items/where_does_coffee_come_from_.json +621 -0
- data/lib/delivery/tests/generic/items.json +4985 -0
- data/lib/delivery/tests/generic/taxonomies.json +127 -0
- data/lib/delivery/tests/generic/types/brewer/elements/product_status.json +6 -0
- data/lib/delivery/tests/generic/types.json +781 -0
- data/lib/delivery/version.rb +1 -1
- data/lib/delivery-sdk-ruby.rb +1 -0
- metadata +15 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dca4c3262d547c5c78bc08b50bae3eac4c5648c47d504b7e84eb275898dcf15b
|
4
|
+
data.tar.gz: b69230e0daeab4020129b5468828cd335cda552c178a17789a421b44b810cafd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6ebb05000adcca618e7380b85ebed9be8ed0cd5485381297a918adef67e79e60430f86f8b10615be4d570a574a9ba9b8ab35166946f65134757ccb2023265e50
|
7
|
+
data.tar.gz: 37c0838a7dc73f6465424422f936e79b7f72a63bd1c8756b54b3755b332682deca5d9018d311d50991e470ddca105a50eb7a238d4456b742978c1ded2f05d4ff
|
data/README.md
CHANGED
@@ -6,6 +6,8 @@
|
|
6
6
|
|
7
7
|
# Delivery Ruby SDK
|
8
8
|
|
9
|
+
![Banner](https://github.com/Kentico/delivery-sdk-ruby/blob/master/banner.png)
|
10
|
+
|
9
11
|
The Delivery Ruby SDK can be used in Ruby/Rails projects to retrieve content from Kentico Cloud. This is a community project and not an official Kentico SDK. If you find a bug in the SDK or have a feature request, please submit a GitHub issue.
|
10
12
|
|
11
13
|
See [How to setup a development environment on Windows](https://github.com/Kentico/delivery-sdk-ruby/wiki/How-to-setup-development-environment-on-Windows) for local development.
|
@@ -71,6 +71,19 @@ module KenticoCloud
|
|
71
71
|
resp
|
72
72
|
end
|
73
73
|
|
74
|
+
# Determines whether the query should use preview mode.
|
75
|
+
#
|
76
|
+
# * *Returns*:
|
77
|
+
# - +boolean+ Whether preview mode should be used for the query
|
78
|
+
#
|
79
|
+
# * *Raises*:
|
80
|
+
# - +StandardError+ if +use_preview+ is true, but +preview_key+ is +nil+
|
81
|
+
def should_preview
|
82
|
+
raise ERROR_PREVIEW if use_preview && preview_key.nil?
|
83
|
+
|
84
|
+
use_preview && !preview_key.nil?
|
85
|
+
end
|
86
|
+
|
74
87
|
# Sets a content link resolver to render links contained in rich text. See
|
75
88
|
# https://github.com/Kentico/delivery-sdk-ruby#resolving-links
|
76
89
|
#
|
@@ -226,19 +239,6 @@ module KenticoCloud
|
|
226
239
|
end
|
227
240
|
end
|
228
241
|
|
229
|
-
# Determines whether the query should use preview mode.
|
230
|
-
#
|
231
|
-
# * *Returns*:
|
232
|
-
# - +boolean+ Whether preview mode should be used for the query
|
233
|
-
#
|
234
|
-
# * *Raises*:
|
235
|
-
# - +StandardError+ if +use_preview+ is true, but +preview_key+ is +nil+
|
236
|
-
def should_preview
|
237
|
-
raise ERROR_PREVIEW if use_preview && preview_key.nil?
|
238
|
-
|
239
|
-
use_preview && !preview_key.nil?
|
240
|
-
end
|
241
|
-
|
242
242
|
def provide_sdk_header
|
243
243
|
"rubygems.org;delivery-sdk-ruby;#{KenticoCloud::Delivery::VERSION}"
|
244
244
|
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'rest-client'
|
2
|
+
require 'dotenv/load'
|
2
3
|
|
3
4
|
module KenticoCloud
|
4
5
|
module Delivery
|
@@ -31,15 +32,24 @@ module KenticoCloud
|
|
31
32
|
end
|
32
33
|
|
33
34
|
def continue
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
35
|
+
if ENV['TEST'] == '1'
|
36
|
+
resp = KenticoCloud::Delivery::Tests::FakeResponder.get_response @query, @url, @headers
|
37
|
+
return resp if resp.is_a? KenticoCloud::Delivery::Responses::ResponseBase
|
38
|
+
|
39
|
+
make_response resp # resp is pure JSON
|
40
|
+
else
|
41
|
+
begin
|
42
|
+
resp = RestClient.get @url, @headers
|
43
|
+
rescue RestClient::ExceptionWithResponse => err
|
44
|
+
should_retry KenticoCloud::Delivery::Responses::ResponseBase.new err.http_code, err.response
|
45
|
+
rescue RestClient::SSLCertificateNotVerified => err
|
46
|
+
should_retry KenticoCloud::Delivery::Responses::ResponseBase.new 500, err
|
47
|
+
rescue SocketError => err
|
48
|
+
should_retry KenticoCloud::Delivery::Responses::ResponseBase.new 500, err.message
|
49
|
+
else
|
50
|
+
make_response resp
|
51
|
+
end
|
52
|
+
end
|
43
53
|
end
|
44
54
|
|
45
55
|
# Converts a standard REST response based on the type of query.
|
@@ -0,0 +1,6 @@
|
|
1
|
+
{
|
2
|
+
"message": "Missing or invalid access token. Please include the valid access token value in the Authorization header field as an HTTP bearer authorization scheme.",
|
3
|
+
"request_id": "|89bb1503b14c254a91bd57c135329822.d31c99c5_",
|
4
|
+
"error_code": 3,
|
5
|
+
"specific_code": 0
|
6
|
+
}
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'dotenv/load'
|
2
|
+
require 'pathname'
|
3
|
+
require 'cgi'
|
4
|
+
|
5
|
+
module KenticoCloud
|
6
|
+
module Delivery
|
7
|
+
module Tests
|
8
|
+
class FakeResponder
|
9
|
+
PROJECT_ID = ENV['PROJECT_ID']
|
10
|
+
IS_SECURE = ENV['TEST_SECURE_API_ENABLED']
|
11
|
+
SECURE_KEY = ENV['SECURE_KEY']
|
12
|
+
PREVIEW_KEY = ENV['PREVIEW_KEY']
|
13
|
+
BASE_URL = "https://deliver.kenticocloud.com/#{PROJECT_ID}".freeze
|
14
|
+
PREVIEW_URL = "https://preview-deliver.kenticocloud.com/#{PROJECT_ID}".freeze
|
15
|
+
|
16
|
+
class << self
|
17
|
+
def get_response(query, url, headers)
|
18
|
+
@query = query
|
19
|
+
if IS_SECURE && !(
|
20
|
+
headers['Authorization'] == "Bearer #{SECURE_KEY}" ||
|
21
|
+
headers['Authorization'] == "Bearer #{PREVIEW_KEY}"
|
22
|
+
)
|
23
|
+
return respond_401
|
24
|
+
end
|
25
|
+
|
26
|
+
url =
|
27
|
+
if @query.should_preview
|
28
|
+
url[PREVIEW_URL.length...url.length]
|
29
|
+
else
|
30
|
+
url[BASE_URL.length...url.length]
|
31
|
+
end
|
32
|
+
|
33
|
+
qs = url.contains('?') ? url.split('?')[1] : nil
|
34
|
+
return respond_filtering qs unless qs.nil? # e.g. /items/about_us?skip=0&limit=5
|
35
|
+
|
36
|
+
respond_generic url # Didn't match other clauses, so response should be located in corresponding filepath
|
37
|
+
end
|
38
|
+
|
39
|
+
def respond_generic(url)
|
40
|
+
path = Pathname.new(File.dirname(__FILE__) + "/generic#{url}.json")
|
41
|
+
path.read if path.exist?
|
42
|
+
end
|
43
|
+
|
44
|
+
def respond_filtering(query)
|
45
|
+
path =
|
46
|
+
case CGI.unescape query
|
47
|
+
when 'skip=0&limit=5'
|
48
|
+
Pathname.new(File.dirname(__FILE__) + '/filtering/pagination_about_us.json')
|
49
|
+
when 'elements.price[gt]=20'
|
50
|
+
Pathname.new(File.dirname(__FILE__) + '/filtering/items_gt.json')
|
51
|
+
when 'elements.price[gt]=20&system.type=grinder'
|
52
|
+
Pathname.new(File.dirname(__FILE__) + '/filtering/multiple.json')
|
53
|
+
end
|
54
|
+
path.read unless path.nil? && !path.exist?
|
55
|
+
end
|
56
|
+
|
57
|
+
def respond_401
|
58
|
+
path = Pathname.new(File.dirname(__FILE__) + '/401.json')
|
59
|
+
KenticoCloud::Delivery::Responses::ResponseBase.new 401, '', path.read if path.exist?
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|