kontent-delivery-sdk-ruby 2.0.7 → 2.0.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +10 -3
- data/lib/delivery/client/request_manager.rb +9 -7
- data/lib/delivery/query_parameters/parameter_base.rb +3 -1
- data/lib/delivery/responses/delivery_element_response.rb +3 -2
- data/lib/delivery/responses/delivery_item_listing_response.rb +3 -2
- data/lib/delivery/responses/delivery_item_response.rb +3 -2
- data/lib/delivery/responses/delivery_taxonomy_listing_response.rb +3 -2
- data/lib/delivery/responses/delivery_taxonomy_response.rb +3 -2
- data/lib/delivery/responses/delivery_type_listing_response.rb +3 -2
- data/lib/delivery/responses/delivery_type_response.rb +3 -2
- data/lib/delivery/responses/response_base.rb +4 -1
- data/lib/delivery/tests/fake_responder.rb +11 -3
- data/lib/delivery/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 06b0e73160343a8de41de7a8db925bc10aa4c41731408a23942f601852ec00bd
|
4
|
+
data.tar.gz: 1920f1c86c61b75b0e70178cfb77014b926d51414ac6376ce485b3ddaa196843
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 036a5de7909f8ac0be6a73193b1f8fbf934c42666ad83ef3ee819346d9b48c200cb5db5fe8006af17881ad058c21b10c1a437288a3d342996ffd7afadb303149
|
7
|
+
data.tar.gz: 2ebfa148a25fdb4585b8550e51ea0921338c79db07a6e8eff50e8a449e4a1c749f2f90044aefa5a97c27095b9b893292a6573725bc59029f7ee5228ae1329e02
|
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
[![Build Status](https://api.travis-ci.com/Kentico/kontent-delivery-sdk-ruby.svg?branch=master)](https://travis-ci.com/Kentico/kontent-delivery-sdk-ruby)
|
2
2
|
[![Join the chat at https://kentico-community.slack.com](https://img.shields.io/badge/join-slack-E6186D.svg)](https://kentico-community.slack.com)
|
3
3
|
[![Stack Overflow](https://img.shields.io/badge/Stack%20Overflow-ASK%20NOW-FE7A16.svg?logo=stackoverflow&logoColor=white)](https://stackoverflow.com/tags/kentico-kontent)
|
4
|
-
[![Version](https://img.shields.io/gem/v/delivery-sdk-ruby.svg?style=flat)](https://rubygems.org/gems/delivery-sdk-ruby)
|
4
|
+
[![Version](https://img.shields.io/gem/v/kontent-delivery-sdk-ruby.svg?style=flat)](https://rubygems.org/gems/kontent-delivery-sdk-ruby)
|
5
5
|
[![Maintainability](https://api.codeclimate.com/v1/badges/b2e3fae28a2b2601d815/maintainability)](https://codeclimate.com/github/Kentico/kontent-delivery-sdk-ruby/maintainability)
|
6
6
|
[![Test coverage](https://api.codeclimate.com/v1/badges/b2e3fae28a2b2601d815/test_coverage)](https://codeclimate.com/github/Kentico/delivery-sdk-ruby/test_coverage)
|
7
7
|
|
@@ -37,7 +37,7 @@ The site should be accessible at localhost:3000. You can also follow a step-by-s
|
|
37
37
|
To use the SDK in your own project, add the gem to your Gemfile:
|
38
38
|
|
39
39
|
```ruby
|
40
|
-
gem 'delivery-sdk-ruby'
|
40
|
+
gem 'kontent-delivery-sdk-ruby'
|
41
41
|
```
|
42
42
|
|
43
43
|
Then run `bundle install`. You can also download the gem from [RubyGems.org](https://rubygems.org/gems/delivery-sdk-ruby). To use the SDK in an `.rb` file, you need to require it:
|
@@ -213,7 +213,13 @@ delivery_client.items
|
|
213
213
|
|
214
214
|
### Responses
|
215
215
|
|
216
|
-
All responses from the `.execute` method will be/extend the `Kentico::Kontent::Delivery::Responses::ResponseBase` class which contains
|
216
|
+
All responses from the `.execute` method will be/extend the `Kentico::Kontent::Delivery::Responses::ResponseBase` class which contains the following attributes:
|
217
|
+
|
218
|
+
- **http_code**: The HTTP status code of the response
|
219
|
+
- **headers**: The headers of the response
|
220
|
+
- **json**: The full JSON body of the response
|
221
|
+
|
222
|
+
You can check the response code to determine if the request was successful:
|
217
223
|
|
218
224
|
```ruby
|
219
225
|
delivery_client.items.execute do |response|
|
@@ -223,6 +229,7 @@ delivery_client.items.execute do |response|
|
|
223
229
|
when 401
|
224
230
|
# Did you forget the secure key?
|
225
231
|
else
|
232
|
+
# to_s displays a friendly message with details of the response
|
226
233
|
puts response.to_s
|
227
234
|
end
|
228
235
|
end
|
@@ -66,36 +66,38 @@ module Kentico
|
|
66
66
|
when Kentico::Kontent::Delivery::QUERY_TYPE_TAXONOMIES
|
67
67
|
respond_taxonomy response
|
68
68
|
when Kentico::Kontent::Delivery::QUERY_TYPE_ELEMENT
|
69
|
-
Kentico::Kontent::Delivery::Responses::DeliveryElementResponse.new
|
69
|
+
Kentico::Kontent::Delivery::Responses::DeliveryElementResponse.new response.headers, response.body
|
70
70
|
end
|
71
71
|
end
|
72
72
|
|
73
73
|
def respond_type(response)
|
74
74
|
if @query.code_name.nil?
|
75
|
-
Kentico::Kontent::Delivery::Responses::DeliveryTypeListingResponse.new
|
75
|
+
Kentico::Kontent::Delivery::Responses::DeliveryTypeListingResponse.new response.headers, response.body
|
76
76
|
else
|
77
|
-
Kentico::Kontent::Delivery::Responses::DeliveryTypeResponse.new
|
77
|
+
Kentico::Kontent::Delivery::Responses::DeliveryTypeResponse.new response.headers, response.body
|
78
78
|
end
|
79
79
|
end
|
80
80
|
|
81
81
|
def respond_taxonomy(response)
|
82
82
|
if @query.code_name.nil?
|
83
|
-
Kentico::Kontent::Delivery::Responses::DeliveryTaxonomyListingResponse.new
|
83
|
+
Kentico::Kontent::Delivery::Responses::DeliveryTaxonomyListingResponse.new response.headers, response.body
|
84
84
|
else
|
85
|
-
Kentico::Kontent::Delivery::Responses::DeliveryTaxonomyResponse.new
|
85
|
+
Kentico::Kontent::Delivery::Responses::DeliveryTaxonomyResponse.new response.headers, response.body
|
86
86
|
end
|
87
87
|
end
|
88
88
|
|
89
89
|
def respond_item(response)
|
90
90
|
if @query.code_name.nil?
|
91
91
|
Kentico::Kontent::Delivery::Responses::DeliveryItemListingResponse.new(
|
92
|
-
|
92
|
+
response.headers,
|
93
|
+
response.body,
|
93
94
|
@query.content_link_url_resolver,
|
94
95
|
@query.inline_content_item_resolver
|
95
96
|
)
|
96
97
|
else
|
97
98
|
Kentico::Kontent::Delivery::Responses::DeliveryItemResponse.new(
|
98
|
-
|
99
|
+
response.headers,
|
100
|
+
response.body,
|
99
101
|
@query.content_link_url_resolver,
|
100
102
|
@query.inline_content_item_resolver
|
101
103
|
)
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'cgi'
|
2
|
+
|
1
3
|
module Kentico
|
2
4
|
module Kontent
|
3
5
|
module Delivery
|
@@ -6,7 +8,7 @@ module Kentico
|
|
6
8
|
# QueryParameters will appear in the query string.
|
7
9
|
class ParameterBase
|
8
10
|
attr_accessor :key
|
9
|
-
SEPARATOR = CGI
|
11
|
+
SEPARATOR = CGI::escape(',')
|
10
12
|
|
11
13
|
# Constructor.
|
12
14
|
#
|
@@ -20,10 +20,11 @@ module Kentico
|
|
20
20
|
)
|
21
21
|
end
|
22
22
|
|
23
|
-
def initialize(
|
24
|
-
@response =
|
23
|
+
def initialize(headers, body)
|
24
|
+
@response = JSON.parse(body)
|
25
25
|
super 200,
|
26
26
|
"Success, '#{element.codename}' returned",
|
27
|
+
headers,
|
27
28
|
JSON.generate(@response)
|
28
29
|
end
|
29
30
|
end
|
@@ -38,12 +38,13 @@ module Kentico
|
|
38
38
|
@items = items
|
39
39
|
end
|
40
40
|
|
41
|
-
def initialize(
|
42
|
-
@response =
|
41
|
+
def initialize(headers, body, content_link_url_resolver, inline_content_item_resolver)
|
42
|
+
@response = JSON.parse(body)
|
43
43
|
@content_link_url_resolver = content_link_url_resolver
|
44
44
|
@inline_content_item_resolver = inline_content_item_resolver
|
45
45
|
super 200,
|
46
46
|
"Success, #{items.length} items returned",
|
47
|
+
headers,
|
47
48
|
JSON.generate(@response)
|
48
49
|
end
|
49
50
|
end
|
@@ -24,12 +24,13 @@ module Kentico
|
|
24
24
|
)
|
25
25
|
end
|
26
26
|
|
27
|
-
def initialize(
|
28
|
-
@response =
|
27
|
+
def initialize(headers, body, content_link_url_resolver, inline_content_item_resolver)
|
28
|
+
@response = JSON.parse(body)
|
29
29
|
@content_link_url_resolver = content_link_url_resolver
|
30
30
|
@inline_content_item_resolver = inline_content_item_resolver
|
31
31
|
super 200,
|
32
32
|
"Success, '#{item.system.codename}' returned",
|
33
|
+
headers,
|
33
34
|
JSON.generate(@response)
|
34
35
|
end
|
35
36
|
end
|
@@ -32,11 +32,12 @@ module Kentico
|
|
32
32
|
@taxonomies = taxonomies
|
33
33
|
end
|
34
34
|
|
35
|
-
def initialize(
|
36
|
-
@response =
|
35
|
+
def initialize(headers, body)
|
36
|
+
@response = JSON.parse(body)
|
37
37
|
|
38
38
|
super 200,
|
39
39
|
"Success, #{taxonomies.length} taxonomies returned",
|
40
|
+
headers,
|
40
41
|
JSON.generate(@response)
|
41
42
|
end
|
42
43
|
end
|
@@ -18,11 +18,12 @@ module Kentico
|
|
18
18
|
@taxonomy = Kentico::Kontent::Delivery::TaxonomyGroup.new(@response)
|
19
19
|
end
|
20
20
|
|
21
|
-
def initialize(
|
22
|
-
@response =
|
21
|
+
def initialize(headers, body)
|
22
|
+
@response = JSON.parse(body)
|
23
23
|
|
24
24
|
super 200,
|
25
25
|
"Success, '#{taxonomy.system.codename}' returned",
|
26
|
+
headers,
|
26
27
|
JSON.generate(@response)
|
27
28
|
end
|
28
29
|
end
|
@@ -32,10 +32,11 @@ module Kentico
|
|
32
32
|
@types = types
|
33
33
|
end
|
34
34
|
|
35
|
-
def initialize(
|
36
|
-
@response =
|
35
|
+
def initialize(headers, body)
|
36
|
+
@response = JSON.parse(body)
|
37
37
|
super 200,
|
38
38
|
"Success, #{types.length} types returned",
|
39
|
+
headers,
|
39
40
|
JSON.generate(@response)
|
40
41
|
end
|
41
42
|
end
|
@@ -18,10 +18,11 @@ module Kentico
|
|
18
18
|
@type = Kentico::Kontent::Delivery::ContentType.new(@response)
|
19
19
|
end
|
20
20
|
|
21
|
-
def initialize(
|
22
|
-
@response =
|
21
|
+
def initialize(headers, body)
|
22
|
+
@response = JSON.parse(body)
|
23
23
|
super 200,
|
24
24
|
"Success, type '#{type.system.codename}' returned",
|
25
|
+
headers,
|
25
26
|
JSON.generate(@response)
|
26
27
|
end
|
27
28
|
end
|
@@ -7,6 +7,7 @@ module Kentico
|
|
7
7
|
class ResponseBase
|
8
8
|
attr_accessor :http_code,
|
9
9
|
:message,
|
10
|
+
:headers,
|
10
11
|
:json
|
11
12
|
|
12
13
|
# Constructor.
|
@@ -14,10 +15,12 @@ module Kentico
|
|
14
15
|
# * *Args*:
|
15
16
|
# - *http_code* (+integer+) The status code returned by the REST request
|
16
17
|
# - *message* (+string+) An informative message about the response, visible when calling +to_s+
|
18
|
+
# - *headers* (+hash+) The headers of the REST response
|
17
19
|
# - *json* (+string+) _optional_ The complete, unmodified JSON response from the server
|
18
|
-
def initialize(http_code, message, json = '')
|
20
|
+
def initialize(http_code, message, headers, json = '')
|
19
21
|
self.http_code = http_code
|
20
22
|
self.message = message
|
23
|
+
self.headers = headers
|
21
24
|
self.json = json
|
22
25
|
end
|
23
26
|
|
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'dotenv/load'
|
2
2
|
require 'pathname'
|
3
3
|
require 'cgi'
|
4
|
+
require 'ostruct'
|
4
5
|
|
5
6
|
module Kentico
|
6
7
|
module Kontent
|
@@ -39,7 +40,10 @@ module Kentico
|
|
39
40
|
|
40
41
|
def respond_generic(url)
|
41
42
|
path = Pathname.new(File.dirname(__FILE__) + "/generic#{url}.json")
|
42
|
-
|
43
|
+
OpenStruct.new(
|
44
|
+
headers: '',
|
45
|
+
body: path.read
|
46
|
+
)
|
43
47
|
end
|
44
48
|
|
45
49
|
def respond_filtering(query)
|
@@ -52,12 +56,16 @@ module Kentico
|
|
52
56
|
when 'elements.price[gt]=20&system.type=grinder'
|
53
57
|
Pathname.new(File.dirname(__FILE__) + '/filtering/multiple.json')
|
54
58
|
end
|
55
|
-
|
59
|
+
OpenStruct.new(
|
60
|
+
headers: '',
|
61
|
+
body: path.read
|
62
|
+
)
|
63
|
+
##Kentico::Kontent::Delivery::Responses::ResponseBase.new 200, '', '', path.read if path.exist?
|
56
64
|
end
|
57
65
|
|
58
66
|
def respond_401
|
59
67
|
path = Pathname.new(File.dirname(__FILE__) + '/401.json')
|
60
|
-
Kentico::Kontent::Delivery::Responses::ResponseBase.new 401, '', path.read if path.exist?
|
68
|
+
Kentico::Kontent::Delivery::Responses::ResponseBase.new 401, '', '', path.read if path.exist?
|
61
69
|
end
|
62
70
|
end
|
63
71
|
end
|
data/lib/delivery/version.rb
CHANGED