delivery-sdk-ruby 0.14.6 → 0.14.13
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE.md +21 -21
- data/README.md +461 -461
- data/bin/console +14 -14
- data/bin/setup +8 -8
- data/lib/delivery-sdk-ruby.rb +17 -17
- data/lib/delivery/builders/image_transformation_builder.rb +141 -141
- data/lib/delivery/builders/url_builder.rb +73 -73
- data/lib/delivery/client/delivery_client.rb +85 -85
- data/lib/delivery/client/delivery_query.rb +183 -183
- data/lib/delivery/models/content_item.rb +96 -96
- data/lib/delivery/models/content_type.rb +26 -26
- data/lib/delivery/models/pagination.rb +13 -13
- data/lib/delivery/models/taxonomy_group.rb +24 -24
- data/lib/delivery/query_parameters/filters.rb +87 -87
- data/lib/delivery/query_parameters/parameter_base.rb +30 -30
- data/lib/delivery/query_parameters/query_string.rb +49 -49
- data/lib/delivery/resolvers/content_link_resolver.rb +62 -62
- data/lib/delivery/resolvers/inline_content_item_resolver.rb +50 -50
- data/lib/delivery/resolvers/linked_item_resolver.rb +27 -27
- data/lib/delivery/responses/delivery_element_response.rb +23 -23
- data/lib/delivery/responses/delivery_item_listing_response.rb +39 -39
- data/lib/delivery/responses/delivery_item_response.rb +29 -29
- data/lib/delivery/responses/delivery_taxonomy_listing_response.rb +32 -32
- data/lib/delivery/responses/delivery_taxonomy_response.rb +22 -22
- data/lib/delivery/responses/delivery_type_listing_response.rb +31 -31
- data/lib/delivery/responses/delivery_type_response.rb +21 -21
- data/lib/delivery/responses/response_base.rb +20 -20
- data/lib/delivery/version.rb +3 -3
- metadata +13 -14
@@ -1,85 +1,85 @@
|
|
1
|
-
require 'delivery/client/delivery_query'
|
2
|
-
require 'delivery/responses/delivery_item_listing_response'
|
3
|
-
require 'delivery/responses/delivery_item_response'
|
4
|
-
require 'json'
|
5
|
-
|
6
|
-
module Delivery
|
7
|
-
QUERY_TYPE_TYPES = 'QUERY_TYPE_TYPES'.freeze
|
8
|
-
QUERY_TYPE_ITEMS = 'QUERY_TYPE_ITEMS'.freeze
|
9
|
-
QUERY_TYPE_TAXONOMIES = 'QUERY_TYPE_TAXONOMIES'.freeze
|
10
|
-
QUERY_TYPE_ELEMENT = 'QUERY_TYPE_ELEMENT'.freeze
|
11
|
-
|
12
|
-
# Executes requests against the Kentico Cloud Delivery API.
|
13
|
-
class DeliveryClient
|
14
|
-
attr_accessor :use_preview
|
15
|
-
|
16
|
-
def initialize(config)
|
17
|
-
@project_id = config.fetch(:project_id)
|
18
|
-
@preview_key = config.fetch(:preview_key, nil)
|
19
|
-
@secure_key = config.fetch(:secure_key, nil)
|
20
|
-
@content_link_url_resolver = config.fetch(:content_link_url_resolver, nil)
|
21
|
-
@inline_content_item_resolver = config.fetch(:inline_content_item_resolver, nil)
|
22
|
-
self.use_preview = !@preview_key.nil?
|
23
|
-
end
|
24
|
-
|
25
|
-
def types
|
26
|
-
DeliveryQuery.new project_id: @project_id,
|
27
|
-
secure_key: @secure_key,
|
28
|
-
query_type: QUERY_TYPE_TYPES
|
29
|
-
end
|
30
|
-
|
31
|
-
def type(code_name)
|
32
|
-
DeliveryQuery.new project_id: @project_id,
|
33
|
-
secure_key: @secure_key,
|
34
|
-
code_name: code_name,
|
35
|
-
query_type: QUERY_TYPE_TYPES
|
36
|
-
end
|
37
|
-
|
38
|
-
def items(query_parameters = [])
|
39
|
-
q = DeliveryQuery.new project_id: @project_id,
|
40
|
-
secure_key: @secure_key,
|
41
|
-
qp: query_parameters,
|
42
|
-
content_link_url_resolver: @content_link_url_resolver,
|
43
|
-
inline_content_item_resolver: @inline_content_item_resolver,
|
44
|
-
query_type: QUERY_TYPE_ITEMS
|
45
|
-
q.use_preview = use_preview
|
46
|
-
q.preview_key = @preview_key
|
47
|
-
q
|
48
|
-
end
|
49
|
-
|
50
|
-
def item(code_name, query_parameters = [])
|
51
|
-
q = DeliveryQuery.new project_id: @project_id,
|
52
|
-
secure_key: @secure_key,
|
53
|
-
code_name: code_name,
|
54
|
-
qp: query_parameters,
|
55
|
-
content_link_url_resolver: @content_link_url_resolver,
|
56
|
-
inline_content_item_resolver: @inline_content_item_resolver,
|
57
|
-
query_type: QUERY_TYPE_ITEMS
|
58
|
-
q.use_preview = use_preview
|
59
|
-
q.preview_key = @preview_key
|
60
|
-
q
|
61
|
-
end
|
62
|
-
|
63
|
-
def taxonomies(query_parameters = [])
|
64
|
-
DeliveryQuery.new project_id: @project_id,
|
65
|
-
secure_key: @secure_key,
|
66
|
-
qp: query_parameters,
|
67
|
-
query_type: QUERY_TYPE_TAXONOMIES
|
68
|
-
end
|
69
|
-
|
70
|
-
def taxonomy(code_name)
|
71
|
-
DeliveryQuery.new project_id: @project_id,
|
72
|
-
secure_key: @secure_key,
|
73
|
-
code_name: code_name,
|
74
|
-
query_type: QUERY_TYPE_TAXONOMIES
|
75
|
-
end
|
76
|
-
|
77
|
-
def element(content_type, element)
|
78
|
-
DeliveryQuery.new project_id: @project_id,
|
79
|
-
secure_key: @secure_key,
|
80
|
-
code_name: element,
|
81
|
-
content_type: content_type,
|
82
|
-
query_type: QUERY_TYPE_ELEMENT
|
83
|
-
end
|
84
|
-
end
|
85
|
-
end
|
1
|
+
require 'delivery/client/delivery_query'
|
2
|
+
require 'delivery/responses/delivery_item_listing_response'
|
3
|
+
require 'delivery/responses/delivery_item_response'
|
4
|
+
require 'json'
|
5
|
+
|
6
|
+
module Delivery
|
7
|
+
QUERY_TYPE_TYPES = 'QUERY_TYPE_TYPES'.freeze
|
8
|
+
QUERY_TYPE_ITEMS = 'QUERY_TYPE_ITEMS'.freeze
|
9
|
+
QUERY_TYPE_TAXONOMIES = 'QUERY_TYPE_TAXONOMIES'.freeze
|
10
|
+
QUERY_TYPE_ELEMENT = 'QUERY_TYPE_ELEMENT'.freeze
|
11
|
+
|
12
|
+
# Executes requests against the Kentico Cloud Delivery API.
|
13
|
+
class DeliveryClient
|
14
|
+
attr_accessor :use_preview
|
15
|
+
|
16
|
+
def initialize(config)
|
17
|
+
@project_id = config.fetch(:project_id)
|
18
|
+
@preview_key = config.fetch(:preview_key, nil)
|
19
|
+
@secure_key = config.fetch(:secure_key, nil)
|
20
|
+
@content_link_url_resolver = config.fetch(:content_link_url_resolver, nil)
|
21
|
+
@inline_content_item_resolver = config.fetch(:inline_content_item_resolver, nil)
|
22
|
+
self.use_preview = !@preview_key.nil?
|
23
|
+
end
|
24
|
+
|
25
|
+
def types
|
26
|
+
DeliveryQuery.new project_id: @project_id,
|
27
|
+
secure_key: @secure_key,
|
28
|
+
query_type: QUERY_TYPE_TYPES
|
29
|
+
end
|
30
|
+
|
31
|
+
def type(code_name)
|
32
|
+
DeliveryQuery.new project_id: @project_id,
|
33
|
+
secure_key: @secure_key,
|
34
|
+
code_name: code_name,
|
35
|
+
query_type: QUERY_TYPE_TYPES
|
36
|
+
end
|
37
|
+
|
38
|
+
def items(query_parameters = [])
|
39
|
+
q = DeliveryQuery.new project_id: @project_id,
|
40
|
+
secure_key: @secure_key,
|
41
|
+
qp: query_parameters,
|
42
|
+
content_link_url_resolver: @content_link_url_resolver,
|
43
|
+
inline_content_item_resolver: @inline_content_item_resolver,
|
44
|
+
query_type: QUERY_TYPE_ITEMS
|
45
|
+
q.use_preview = use_preview
|
46
|
+
q.preview_key = @preview_key
|
47
|
+
q
|
48
|
+
end
|
49
|
+
|
50
|
+
def item(code_name, query_parameters = [])
|
51
|
+
q = DeliveryQuery.new project_id: @project_id,
|
52
|
+
secure_key: @secure_key,
|
53
|
+
code_name: code_name,
|
54
|
+
qp: query_parameters,
|
55
|
+
content_link_url_resolver: @content_link_url_resolver,
|
56
|
+
inline_content_item_resolver: @inline_content_item_resolver,
|
57
|
+
query_type: QUERY_TYPE_ITEMS
|
58
|
+
q.use_preview = use_preview
|
59
|
+
q.preview_key = @preview_key
|
60
|
+
q
|
61
|
+
end
|
62
|
+
|
63
|
+
def taxonomies(query_parameters = [])
|
64
|
+
DeliveryQuery.new project_id: @project_id,
|
65
|
+
secure_key: @secure_key,
|
66
|
+
qp: query_parameters,
|
67
|
+
query_type: QUERY_TYPE_TAXONOMIES
|
68
|
+
end
|
69
|
+
|
70
|
+
def taxonomy(code_name)
|
71
|
+
DeliveryQuery.new project_id: @project_id,
|
72
|
+
secure_key: @secure_key,
|
73
|
+
code_name: code_name,
|
74
|
+
query_type: QUERY_TYPE_TAXONOMIES
|
75
|
+
end
|
76
|
+
|
77
|
+
def element(content_type, element)
|
78
|
+
DeliveryQuery.new project_id: @project_id,
|
79
|
+
secure_key: @secure_key,
|
80
|
+
code_name: element,
|
81
|
+
content_type: content_type,
|
82
|
+
query_type: QUERY_TYPE_ELEMENT
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
@@ -1,183 +1,183 @@
|
|
1
|
-
require 'rest-client'
|
2
|
-
require 'delivery/builders/url_builder'
|
3
|
-
require 'delivery/query_parameters/query_string'
|
4
|
-
require 'delivery/version'
|
5
|
-
|
6
|
-
module Delivery
|
7
|
-
# Responsible for translating query parameters into the
|
8
|
-
# corresponding REST request to Kentico Cloud.
|
9
|
-
class DeliveryQuery
|
10
|
-
ERROR_PREVIEW = 'Preview is enabled for the query, but the key is null. '\
|
11
|
-
'You can set the preview_key attribute of the query, or '\
|
12
|
-
'when you initialize the client. See '\
|
13
|
-
'https://github.com/Kentico/delivery-sdk-ruby#previewing-unpublished-content'.freeze
|
14
|
-
ERROR_PARAMS = 'Only filters may be passed in the .item or .items methods'\
|
15
|
-
'. See https://github.com/Kentico/delivery-sdk-ruby#filtering'.freeze
|
16
|
-
attr_accessor :use_preview,
|
17
|
-
:preview_key,
|
18
|
-
:project_id,
|
19
|
-
:code_name,
|
20
|
-
:secure_key,
|
21
|
-
:content_link_url_resolver,
|
22
|
-
:inline_content_item_resolver,
|
23
|
-
:query_type,
|
24
|
-
:query_string,
|
25
|
-
:content_type
|
26
|
-
|
27
|
-
# Setter for url, returns self for chaining
|
28
|
-
# .url represents *manually* configured urls, otherwise final url is
|
29
|
-
# generated in .execute and this will return nil
|
30
|
-
def url(url = nil)
|
31
|
-
@url = url unless url.nil?
|
32
|
-
self
|
33
|
-
end
|
34
|
-
|
35
|
-
def initialize(config)
|
36
|
-
# Map each hash value to attr with corresponding key
|
37
|
-
# from https://stackoverflow.com/a/2681014/5656214
|
38
|
-
config.each do |k, v|
|
39
|
-
instance_variable_set("@#{k}", v) unless v.nil?
|
40
|
-
end
|
41
|
-
self.query_string = Delivery::QueryParameters::QueryString.new
|
42
|
-
return if config.fetch(:qp, nil).nil?
|
43
|
-
|
44
|
-
# Query parameters were passed, parse and validate
|
45
|
-
validate_params config.fetch(:qp)
|
46
|
-
end
|
47
|
-
|
48
|
-
def execute
|
49
|
-
provide_url
|
50
|
-
begin
|
51
|
-
resp = execute_rest
|
52
|
-
rescue RestClient::ExceptionWithResponse => err
|
53
|
-
resp = Delivery::Responses::ResponseBase.new err.http_code, err.response
|
54
|
-
rescue RestClient::SSLCertificateNotVerified => err
|
55
|
-
resp = Delivery::Responses::ResponseBase.new 500, err
|
56
|
-
rescue SocketError => err
|
57
|
-
resp = Delivery::Responses::ResponseBase.new 500, err.message
|
58
|
-
else
|
59
|
-
resp = make_response resp
|
60
|
-
ensure
|
61
|
-
yield resp if block_given?
|
62
|
-
resp
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
def with_link_resolver(resolver)
|
67
|
-
self.content_link_url_resolver = resolver
|
68
|
-
self
|
69
|
-
end
|
70
|
-
|
71
|
-
def with_inline_content_item_resolver(resolver)
|
72
|
-
self.inline_content_item_resolver = resolver
|
73
|
-
self
|
74
|
-
end
|
75
|
-
|
76
|
-
def order_by(value, sort = '[asc]')
|
77
|
-
query_string.set_param('order', value + sort)
|
78
|
-
self
|
79
|
-
end
|
80
|
-
|
81
|
-
def skip(value)
|
82
|
-
query_string.set_param('skip', value)
|
83
|
-
self
|
84
|
-
end
|
85
|
-
|
86
|
-
def language(value)
|
87
|
-
query_string.set_param('language', value)
|
88
|
-
end
|
89
|
-
|
90
|
-
def limit(value)
|
91
|
-
query_string.set_param('limit', value)
|
92
|
-
self
|
93
|
-
end
|
94
|
-
|
95
|
-
def elements(value)
|
96
|
-
query_string.set_param('elements', value)
|
97
|
-
self
|
98
|
-
end
|
99
|
-
|
100
|
-
def depth(value)
|
101
|
-
query_string.set_param('depth', value)
|
102
|
-
self
|
103
|
-
end
|
104
|
-
|
105
|
-
private
|
106
|
-
|
107
|
-
def provide_url
|
108
|
-
@url = Delivery::Builders::UrlBuilder.provide_url self if @url.nil?
|
109
|
-
Delivery::Builders::UrlBuilder.validate_url @url
|
110
|
-
end
|
111
|
-
|
112
|
-
def validate_params(query_parameters)
|
113
|
-
params = if query_parameters.is_a? Array
|
114
|
-
query_parameters
|
115
|
-
else
|
116
|
-
[query_parameters]
|
117
|
-
end
|
118
|
-
params.each do |p|
|
119
|
-
query_string.set_param p
|
120
|
-
unless p.is_a? Delivery::QueryParameters::Filter
|
121
|
-
raise ArgumentError, ERROR_PARAMS
|
122
|
-
end
|
123
|
-
end
|
124
|
-
end
|
125
|
-
|
126
|
-
# Returns true if this query should use preview mode. Raises an error if
|
127
|
-
# preview is enabled, but the key is nil
|
128
|
-
def should_preview
|
129
|
-
raise ERROR_PREVIEW if use_preview && preview_key.nil?
|
130
|
-
|
131
|
-
use_preview && !preview_key.nil?
|
132
|
-
end
|
133
|
-
|
134
|
-
def execute_rest
|
135
|
-
if should_preview
|
136
|
-
RestClient.get @url, 'X-KC-SDKID' => provide_sdk_header, Authorization: 'Bearer ' + preview_key
|
137
|
-
else
|
138
|
-
if secure_key.nil?
|
139
|
-
RestClient.get @url, 'X-KC-SDKID' => provide_sdk_header
|
140
|
-
else
|
141
|
-
RestClient.get @url, 'X-KC-SDKID' => provide_sdk_header, Authorization: 'Bearer ' + secure_key
|
142
|
-
end
|
143
|
-
end
|
144
|
-
end
|
145
|
-
|
146
|
-
def provide_sdk_header
|
147
|
-
"rubygems.org;delivery-sdk-ruby;#{Delivery::VERSION}"
|
148
|
-
end
|
149
|
-
|
150
|
-
def make_response(response)
|
151
|
-
case query_type
|
152
|
-
when Delivery::QUERY_TYPE_ITEMS
|
153
|
-
if code_name.nil?
|
154
|
-
Delivery::Responses::DeliveryItemListingResponse.new(
|
155
|
-
JSON.parse(response),
|
156
|
-
content_link_url_resolver,
|
157
|
-
inline_content_item_resolver
|
158
|
-
)
|
159
|
-
else
|
160
|
-
Delivery::Responses::DeliveryItemResponse.new(
|
161
|
-
JSON.parse(response),
|
162
|
-
content_link_url_resolver,
|
163
|
-
inline_content_item_resolver
|
164
|
-
)
|
165
|
-
end
|
166
|
-
when Delivery::QUERY_TYPE_TYPES
|
167
|
-
if code_name.nil?
|
168
|
-
Delivery::Responses::DeliveryTypeListingResponse.new JSON.parse(response)
|
169
|
-
else
|
170
|
-
Delivery::Responses::DeliveryTypeResponse.new JSON.parse(response)
|
171
|
-
end
|
172
|
-
when Delivery::QUERY_TYPE_TAXONOMIES
|
173
|
-
if code_name.nil?
|
174
|
-
Delivery::Responses::DeliveryTaxonomyListingResponse.new JSON.parse(response)
|
175
|
-
else
|
176
|
-
Delivery::Responses::DeliveryTaxonomyResponse.new JSON.parse(response)
|
177
|
-
end
|
178
|
-
when Delivery::QUERY_TYPE_ELEMENT
|
179
|
-
Delivery::Responses::DeliveryElementResponse.new JSON.parse(response)
|
180
|
-
end
|
181
|
-
end
|
182
|
-
end
|
183
|
-
end
|
1
|
+
require 'rest-client'
|
2
|
+
require 'delivery/builders/url_builder'
|
3
|
+
require 'delivery/query_parameters/query_string'
|
4
|
+
require 'delivery/version'
|
5
|
+
|
6
|
+
module Delivery
|
7
|
+
# Responsible for translating query parameters into the
|
8
|
+
# corresponding REST request to Kentico Cloud.
|
9
|
+
class DeliveryQuery
|
10
|
+
ERROR_PREVIEW = 'Preview is enabled for the query, but the key is null. '\
|
11
|
+
'You can set the preview_key attribute of the query, or '\
|
12
|
+
'when you initialize the client. See '\
|
13
|
+
'https://github.com/Kentico/delivery-sdk-ruby#previewing-unpublished-content'.freeze
|
14
|
+
ERROR_PARAMS = 'Only filters may be passed in the .item or .items methods'\
|
15
|
+
'. See https://github.com/Kentico/delivery-sdk-ruby#filtering'.freeze
|
16
|
+
attr_accessor :use_preview,
|
17
|
+
:preview_key,
|
18
|
+
:project_id,
|
19
|
+
:code_name,
|
20
|
+
:secure_key,
|
21
|
+
:content_link_url_resolver,
|
22
|
+
:inline_content_item_resolver,
|
23
|
+
:query_type,
|
24
|
+
:query_string,
|
25
|
+
:content_type
|
26
|
+
|
27
|
+
# Setter for url, returns self for chaining
|
28
|
+
# .url represents *manually* configured urls, otherwise final url is
|
29
|
+
# generated in .execute and this will return nil
|
30
|
+
def url(url = nil)
|
31
|
+
@url = url unless url.nil?
|
32
|
+
self
|
33
|
+
end
|
34
|
+
|
35
|
+
def initialize(config)
|
36
|
+
# Map each hash value to attr with corresponding key
|
37
|
+
# from https://stackoverflow.com/a/2681014/5656214
|
38
|
+
config.each do |k, v|
|
39
|
+
instance_variable_set("@#{k}", v) unless v.nil?
|
40
|
+
end
|
41
|
+
self.query_string = Delivery::QueryParameters::QueryString.new
|
42
|
+
return if config.fetch(:qp, nil).nil?
|
43
|
+
|
44
|
+
# Query parameters were passed, parse and validate
|
45
|
+
validate_params config.fetch(:qp)
|
46
|
+
end
|
47
|
+
|
48
|
+
def execute
|
49
|
+
provide_url
|
50
|
+
begin
|
51
|
+
resp = execute_rest
|
52
|
+
rescue RestClient::ExceptionWithResponse => err
|
53
|
+
resp = Delivery::Responses::ResponseBase.new err.http_code, err.response
|
54
|
+
rescue RestClient::SSLCertificateNotVerified => err
|
55
|
+
resp = Delivery::Responses::ResponseBase.new 500, err
|
56
|
+
rescue SocketError => err
|
57
|
+
resp = Delivery::Responses::ResponseBase.new 500, err.message
|
58
|
+
else
|
59
|
+
resp = make_response resp
|
60
|
+
ensure
|
61
|
+
yield resp if block_given?
|
62
|
+
resp
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def with_link_resolver(resolver)
|
67
|
+
self.content_link_url_resolver = resolver
|
68
|
+
self
|
69
|
+
end
|
70
|
+
|
71
|
+
def with_inline_content_item_resolver(resolver)
|
72
|
+
self.inline_content_item_resolver = resolver
|
73
|
+
self
|
74
|
+
end
|
75
|
+
|
76
|
+
def order_by(value, sort = '[asc]')
|
77
|
+
query_string.set_param('order', value + sort)
|
78
|
+
self
|
79
|
+
end
|
80
|
+
|
81
|
+
def skip(value)
|
82
|
+
query_string.set_param('skip', value)
|
83
|
+
self
|
84
|
+
end
|
85
|
+
|
86
|
+
def language(value)
|
87
|
+
query_string.set_param('language', value)
|
88
|
+
end
|
89
|
+
|
90
|
+
def limit(value)
|
91
|
+
query_string.set_param('limit', value)
|
92
|
+
self
|
93
|
+
end
|
94
|
+
|
95
|
+
def elements(value)
|
96
|
+
query_string.set_param('elements', value)
|
97
|
+
self
|
98
|
+
end
|
99
|
+
|
100
|
+
def depth(value)
|
101
|
+
query_string.set_param('depth', value)
|
102
|
+
self
|
103
|
+
end
|
104
|
+
|
105
|
+
private
|
106
|
+
|
107
|
+
def provide_url
|
108
|
+
@url = Delivery::Builders::UrlBuilder.provide_url self if @url.nil?
|
109
|
+
Delivery::Builders::UrlBuilder.validate_url @url
|
110
|
+
end
|
111
|
+
|
112
|
+
def validate_params(query_parameters)
|
113
|
+
params = if query_parameters.is_a? Array
|
114
|
+
query_parameters
|
115
|
+
else
|
116
|
+
[query_parameters]
|
117
|
+
end
|
118
|
+
params.each do |p|
|
119
|
+
query_string.set_param p
|
120
|
+
unless p.is_a? Delivery::QueryParameters::Filter
|
121
|
+
raise ArgumentError, ERROR_PARAMS
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
# Returns true if this query should use preview mode. Raises an error if
|
127
|
+
# preview is enabled, but the key is nil
|
128
|
+
def should_preview
|
129
|
+
raise ERROR_PREVIEW if use_preview && preview_key.nil?
|
130
|
+
|
131
|
+
use_preview && !preview_key.nil?
|
132
|
+
end
|
133
|
+
|
134
|
+
def execute_rest
|
135
|
+
if should_preview
|
136
|
+
RestClient.get @url, 'X-KC-SDKID' => provide_sdk_header, Authorization: 'Bearer ' + preview_key
|
137
|
+
else
|
138
|
+
if secure_key.nil?
|
139
|
+
RestClient.get @url, 'X-KC-SDKID' => provide_sdk_header
|
140
|
+
else
|
141
|
+
RestClient.get @url, 'X-KC-SDKID' => provide_sdk_header, Authorization: 'Bearer ' + secure_key
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
def provide_sdk_header
|
147
|
+
"rubygems.org;delivery-sdk-ruby;#{Delivery::VERSION}"
|
148
|
+
end
|
149
|
+
|
150
|
+
def make_response(response)
|
151
|
+
case query_type
|
152
|
+
when Delivery::QUERY_TYPE_ITEMS
|
153
|
+
if code_name.nil?
|
154
|
+
Delivery::Responses::DeliveryItemListingResponse.new(
|
155
|
+
JSON.parse(response),
|
156
|
+
content_link_url_resolver,
|
157
|
+
inline_content_item_resolver
|
158
|
+
)
|
159
|
+
else
|
160
|
+
Delivery::Responses::DeliveryItemResponse.new(
|
161
|
+
JSON.parse(response),
|
162
|
+
content_link_url_resolver,
|
163
|
+
inline_content_item_resolver
|
164
|
+
)
|
165
|
+
end
|
166
|
+
when Delivery::QUERY_TYPE_TYPES
|
167
|
+
if code_name.nil?
|
168
|
+
Delivery::Responses::DeliveryTypeListingResponse.new JSON.parse(response)
|
169
|
+
else
|
170
|
+
Delivery::Responses::DeliveryTypeResponse.new JSON.parse(response)
|
171
|
+
end
|
172
|
+
when Delivery::QUERY_TYPE_TAXONOMIES
|
173
|
+
if code_name.nil?
|
174
|
+
Delivery::Responses::DeliveryTaxonomyListingResponse.new JSON.parse(response)
|
175
|
+
else
|
176
|
+
Delivery::Responses::DeliveryTaxonomyResponse.new JSON.parse(response)
|
177
|
+
end
|
178
|
+
when Delivery::QUERY_TYPE_ELEMENT
|
179
|
+
Delivery::Responses::DeliveryElementResponse.new JSON.parse(response)
|
180
|
+
end
|
181
|
+
end
|
182
|
+
end
|
183
|
+
end
|