delivery-sdk-ruby 0.14.1 → 0.14.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +8 -1
- data/lib/delivery-sdk-ruby.rb +1 -0
- data/lib/delivery/models/content_item.rb +6 -15
- data/lib/delivery/resolvers/linked_item_resolver.rb +28 -0
- data/lib/delivery/responses/delivery_item_listing_response.rb +2 -1
- data/lib/delivery/responses/delivery_item_response.rb +3 -1
- data/lib/delivery/version.rb +1 -1
- metadata +17 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b78db9a74f7389d472bbc2ccb4e2abba26285835999c09bbe4a01bf5886b371e
|
4
|
+
data.tar.gz: fd1c7b62a50e45245569d48e136252011d780186ff15d2e1a972f7b032c40fce
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 45395875e18f12f54946d5c0638b1fbe6f9ceec2f1b5e47e168d604e1e566be77ba83cfca69ce829e0ce258003148a6bf0decdd23e96a9d7967dc01fb509156f
|
7
|
+
data.tar.gz: 208f83cb6e927c857a37cd6a152cdecb58715eb9055248453410ff44b17ca603b82743c0785a7301c028e76d3337859af451c1d7af5459d507705c2d0bc6cb52
|
data/README.md
CHANGED
@@ -1,9 +1,16 @@
|
|
1
|
-
|
1
|
+
[![Build Status](https://api.travis-ci.org/Kentico/delivery-sdk-ruby.svg?branch=master)](https://travis-ci.org/Kentico/delivery-sdk-ruby)
|
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
|
+
[![Stack Overflow](https://img.shields.io/badge/Stack%20Overflow-ASK%20NOW-FE7A16.svg?logo=stackoverflow&logoColor=white)](https://stackoverflow.com/tags/kentico-cloud)
|
4
|
+
[![Version](https://img.shields.io/gem/v/delivery-sdk-ruby.svg?style=flat)](https://rubygems.org/gems/delivery-sdk-ruby)
|
5
|
+
[![Maintainability](https://api.codeclimate.com/v1/badges/b2e3fae28a2b2601d815/maintainability)](https://codeclimate.com/github/Kentico/delivery-sdk-ruby/maintainability)
|
2
6
|
|
3
7
|
# Delivery Ruby SDK
|
4
8
|
|
5
9
|
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.
|
6
10
|
|
11
|
+
See [environment setup fo Windows](https://github.com/Kentico/delivery-sdk-ruby/wiki/How-to-setup-development-environment-on-Windows) for local development.
|
12
|
+
|
13
|
+
|
7
14
|
## Demo Rails application
|
8
15
|
|
9
16
|
This repository contains a very basic Rails application that you can run locally to see how the SDK can be used. To run the Dancing Goat demo application, clone this repository and open `/dancing_goat/app/controllers/application_controller.rb`. Add your project ID to the file here:
|
data/lib/delivery-sdk-ruby.rb
CHANGED
@@ -13,4 +13,5 @@ require File.dirname(__FILE__) + '/delivery/responses/delivery_taxonomy_response
|
|
13
13
|
require File.dirname(__FILE__) + '/delivery/responses/delivery_element_response'
|
14
14
|
require File.dirname(__FILE__) + '/delivery/resolvers/content_link_resolver'
|
15
15
|
require File.dirname(__FILE__) + '/delivery/resolvers/inline_content_item_resolver'
|
16
|
+
require File.dirname(__FILE__) + '/delivery/resolvers/linked_item_resolver'
|
16
17
|
require File.dirname(__FILE__) + '/delivery/builders/image_transformation_builder'
|
@@ -23,21 +23,14 @@ module Delivery
|
|
23
23
|
)
|
24
24
|
end
|
25
25
|
|
26
|
-
def initialize(source, content_link_url_resolver, inline_content_item_resolver,
|
26
|
+
def initialize(source, content_link_url_resolver, inline_content_item_resolver, linked_items_resolver)
|
27
27
|
@source =
|
28
28
|
if source['item'].nil?
|
29
29
|
source
|
30
30
|
else
|
31
31
|
source['item']
|
32
32
|
end
|
33
|
-
|
34
|
-
# responses have modular content in the item
|
35
|
-
@modular_content =
|
36
|
-
if modular_content.nil?
|
37
|
-
source['modular_content']
|
38
|
-
else
|
39
|
-
modular_content
|
40
|
-
end
|
33
|
+
@linked_items_resolver = linked_items_resolver
|
41
34
|
self.content_link_url_resolver = content_link_url_resolver
|
42
35
|
self.inline_content_item_resolver = inline_content_item_resolver
|
43
36
|
end
|
@@ -64,16 +57,14 @@ module Delivery
|
|
64
57
|
# element with items from request's modular_content
|
65
58
|
def get_links(code_name)
|
66
59
|
element = get_element code_name
|
67
|
-
|
68
|
-
filtered.map { |n| ContentItem.new JSON.parse(JSON.generate(n)), content_link_url_resolver, inline_content_item_resolver }
|
60
|
+
get_linked_items element['value']
|
69
61
|
end
|
70
62
|
|
71
63
|
# Returns an array of ContentItems by comparing code names stored in the
|
72
64
|
# modular_content object with items from request's modular_content
|
73
65
|
def get_inline_items(code_name)
|
74
66
|
element = get_element code_name
|
75
|
-
|
76
|
-
filtered.map { |n| ContentItem.new JSON.parse(JSON.generate(n)), content_link_url_resolver, inline_content_item_resolver }
|
67
|
+
get_linked_items element['modular_content']
|
77
68
|
end
|
78
69
|
|
79
70
|
private
|
@@ -93,11 +84,11 @@ module Delivery
|
|
93
84
|
@source['elements'][code_name]
|
94
85
|
end
|
95
86
|
|
96
|
-
def
|
87
|
+
def get_linked_items(codenames)
|
97
88
|
return [] unless codenames.class == Array
|
98
89
|
|
99
90
|
codenames.each_with_object([]) do |codename, items|
|
100
|
-
item = @
|
91
|
+
item = @linked_items_resolver.resolve codename
|
101
92
|
items << item if item
|
102
93
|
end
|
103
94
|
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Delivery
|
2
|
+
# Resolves a content item by its codename
|
3
|
+
# It contains the modular content of item/items response
|
4
|
+
class LinkedItemResolver
|
5
|
+
def initialize(modular_content, content_link_url_resolver, inline_content_item_resolver)
|
6
|
+
@modular_content = modular_content
|
7
|
+
@content_link_url_resolver = content_link_url_resolver
|
8
|
+
@inline_content_item_resolver = inline_content_item_resolver
|
9
|
+
@resolved_items = {}
|
10
|
+
end
|
11
|
+
|
12
|
+
# Resolves a content item
|
13
|
+
# If the link for a codename was resolved before,
|
14
|
+
# it returns the same instance of Content Item
|
15
|
+
# @param [String] codename Codename of the content item
|
16
|
+
# @return [ContentItem]
|
17
|
+
def resolve(codename)
|
18
|
+
@resolved_items[codename] ||= resolve_item(codename)
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def resolve_item(codename)
|
24
|
+
item = @modular_content.values.find { |i| i['system']['codename'] == codename }
|
25
|
+
ContentItem.new JSON.parse(JSON.generate(item)), @content_link_url_resolver, @inline_content_item_resolver, self
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -13,13 +13,14 @@ module Delivery
|
|
13
13
|
|
14
14
|
def items
|
15
15
|
@items unless @items.nil?
|
16
|
+
linked_items_resolver = LinkedItemResolver.new @response['modular_content'], @content_link_url_resolver, @inline_content_item_resolver
|
16
17
|
items = []
|
17
18
|
@response['items'].each do |n|
|
18
19
|
items << Delivery::ContentItem.new(
|
19
20
|
n,
|
20
21
|
@content_link_url_resolver,
|
21
22
|
@inline_content_item_resolver,
|
22
|
-
|
23
|
+
linked_items_resolver
|
23
24
|
)
|
24
25
|
end
|
25
26
|
@items = items
|
@@ -7,10 +7,12 @@ module Delivery
|
|
7
7
|
class DeliveryItemResponse < ResponseBase
|
8
8
|
def item
|
9
9
|
@item unless @item.nil?
|
10
|
+
linked_items_resolver = LinkedItemResolver.new @response['modular_content'], @content_link_url_resolver, @inline_content_item_resolver
|
10
11
|
@item = Delivery::ContentItem.new(
|
11
12
|
@response,
|
12
13
|
@content_link_url_resolver,
|
13
|
-
@inline_content_item_resolver
|
14
|
+
@inline_content_item_resolver,
|
15
|
+
linked_items_resolver
|
14
16
|
)
|
15
17
|
end
|
16
18
|
|
data/lib/delivery/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: delivery-sdk-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.14.
|
4
|
+
version: 0.14.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eric Dugre
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-03-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|
@@ -50,6 +50,20 @@ dependencies:
|
|
50
50
|
- - ">="
|
51
51
|
- !ruby/object:Gem::Version
|
52
52
|
version: 2.1.0.rc1
|
53
|
+
- !ruby/object:Gem::Dependency
|
54
|
+
name: dotenv
|
55
|
+
requirement: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - "~>"
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: 2.7.0
|
60
|
+
type: :development
|
61
|
+
prerelease: false
|
62
|
+
version_requirements: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - "~>"
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: 2.7.0
|
53
67
|
- !ruby/object:Gem::Dependency
|
54
68
|
name: bundler
|
55
69
|
requirement: !ruby/object:Gem::Requirement
|
@@ -117,6 +131,7 @@ files:
|
|
117
131
|
- lib/delivery/query_parameters/query_string.rb
|
118
132
|
- lib/delivery/resolvers/content_link_resolver.rb
|
119
133
|
- lib/delivery/resolvers/inline_content_item_resolver.rb
|
134
|
+
- lib/delivery/resolvers/linked_item_resolver.rb
|
120
135
|
- lib/delivery/responses/delivery_element_response.rb
|
121
136
|
- lib/delivery/responses/delivery_item_listing_response.rb
|
122
137
|
- lib/delivery/responses/delivery_item_response.rb
|