sunil 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.github/workflows/gem-push.yml +33 -0
- data/.gitignore +12 -0
- data/.talismanrc +1 -0
- data/.yardopts +6 -0
- data/CHANGELOG.md +79 -0
- data/CODEOWNERS +1 -0
- data/CODE_OF_CONDUCT.md +73 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +77 -0
- data/LICENSE.txt +21 -0
- data/README.md +197 -0
- data/SECURITY.md +27 -0
- data/lib/contentstack/api.rb +191 -0
- data/lib/contentstack/asset.rb +69 -0
- data/lib/contentstack/asset_collection.rb +28 -0
- data/lib/contentstack/client.rb +92 -0
- data/lib/contentstack/content_type.rb +54 -0
- data/lib/contentstack/entry.rb +222 -0
- data/lib/contentstack/entry_collection.rb +45 -0
- data/lib/contentstack/error.rb +7 -0
- data/lib/contentstack/query.rb +654 -0
- data/lib/contentstack/region.rb +6 -0
- data/lib/contentstack/sync_result.rb +30 -0
- data/lib/contentstack/version.rb +3 -0
- data/lib/contentstack.rb +32 -0
- data/lib/util.rb +111 -0
- data/rakefile.rb +4 -0
- data/spec/asset_collection_spec.rb +16 -0
- data/spec/asset_spec.rb +48 -0
- data/spec/content_type_spec.rb +81 -0
- data/spec/contentstack_spec.rb +39 -0
- data/spec/entry_collection_spec.rb +42 -0
- data/spec/entry_spec.rb +102 -0
- data/spec/fixtures/asset.json +1 -0
- data/spec/fixtures/asset_collection.json +1 -0
- data/spec/fixtures/category_content_type.json +1 -0
- data/spec/fixtures/category_entry.json +1 -0
- data/spec/fixtures/category_entry_collection.json +1 -0
- data/spec/fixtures/category_entry_collection_without_count.json +1 -0
- data/spec/fixtures/content_types.json +1 -0
- data/spec/fixtures/product_entry.json +1 -0
- data/spec/fixtures/product_entry_collection.json +1 -0
- data/spec/fixtures/sync_init.json +2975 -0
- data/spec/query_spec.rb +206 -0
- data/spec/spec_helper.rb +181 -0
- data/spec/sync_spec.rb +27 -0
- data/sunil.gemspec +30 -0
- metadata +186 -0
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'active_support/core_ext'
|
2
|
+
|
3
|
+
module Contentstack
|
4
|
+
class SyncResult
|
5
|
+
attr_reader :items
|
6
|
+
attr_reader :sync_token
|
7
|
+
attr_reader :pagination_token
|
8
|
+
attr_reader :total_count
|
9
|
+
attr_reader :skip
|
10
|
+
attr_reader :limit
|
11
|
+
|
12
|
+
def initialize(sync_result)
|
13
|
+
if sync_result.nil?
|
14
|
+
@items = []
|
15
|
+
@sync_token = nil
|
16
|
+
@pagination_token = nil
|
17
|
+
@total_count = 0
|
18
|
+
@skip = 0
|
19
|
+
@limit = 100
|
20
|
+
else
|
21
|
+
@items = sync_result["items"] || []
|
22
|
+
@sync_token = sync_result["sync_token"] || nil
|
23
|
+
@pagination_token = sync_result["pagination_token"] || nil
|
24
|
+
@total_count = sync_result["total_count"] || 0
|
25
|
+
@skip = sync_result["skip"] || 0
|
26
|
+
@limit = sync_result["limit"] || 100
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/lib/contentstack.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
$LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
|
2
|
+
|
3
|
+
require "contentstack/version"
|
4
|
+
require "contentstack/client"
|
5
|
+
require "contentstack/region"
|
6
|
+
require "contentstack_utils"
|
7
|
+
|
8
|
+
# == Contentstack - Ruby SDK
|
9
|
+
# Contentstack is a content management system that facilitates the process of publication by separating the content from site-related programming and design.
|
10
|
+
# == Installation
|
11
|
+
# gem install contentstack
|
12
|
+
# == Initialize the Stack
|
13
|
+
# @stack = Contentstack::Client.new("site_api_key", "delivery_token", "enviroment_name")
|
14
|
+
# == Initialize the Stack for EU region
|
15
|
+
# @stack = Contentstack::Client.new("site_api_key", "delivery_token", "enviroment_name", {"region": Contentstack::Region::EU })
|
16
|
+
# == Initialize the Stack for custom host
|
17
|
+
# @stack = Contentstack::Client.new("site_api_key", "delivery_token", "enviroment_name", {"host": "https://custom-cdn.contentstack.com" })
|
18
|
+
# == Initialize the Stack for EU region
|
19
|
+
# @stack = Contentstack::Client.new("site_api_key", "delivery_token", "enviroment_name", {"branch":"branch_name" })
|
20
|
+
# == Usage
|
21
|
+
# ==== Get single entry
|
22
|
+
# @stack.content_type('blog').entry('<entry_uid_here>').fetch
|
23
|
+
# ==== Query entries
|
24
|
+
# @stack.content_type('blog').query.regex('title', '.*hello.*').fetch
|
25
|
+
module Contentstack
|
26
|
+
def self.render_content(content, options)
|
27
|
+
ContentstackUtils.render_content(content, options)
|
28
|
+
end
|
29
|
+
def self.json_to_html(content, options)
|
30
|
+
ContentstackUtils.json_to_html(content, options)
|
31
|
+
end
|
32
|
+
end
|
data/lib/util.rb
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
module Contentstack
|
2
|
+
module Utility
|
3
|
+
refine Hash do
|
4
|
+
def to_query(namespace = nil)
|
5
|
+
collect do |key, value|
|
6
|
+
value.to_query(namespace ? "#{namespace}[#{key}]" : key)
|
7
|
+
end.sort * '&'
|
8
|
+
end
|
9
|
+
|
10
|
+
def symbolize_keys
|
11
|
+
new_hash = {}
|
12
|
+
self.each do |key,value|
|
13
|
+
if [Hash, Array].include?(value.class)
|
14
|
+
new_hash[key.to_sym] = value.symbolize_keys
|
15
|
+
else
|
16
|
+
new_hash[key.to_sym] = value
|
17
|
+
end
|
18
|
+
end
|
19
|
+
new_hash
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
refine Array do
|
24
|
+
def to_query(key)
|
25
|
+
prefix = "#{key}[]"
|
26
|
+
collect { |value| value.to_query(prefix) }.join '&'
|
27
|
+
end
|
28
|
+
|
29
|
+
def symbolize_keys
|
30
|
+
collect do |entry|
|
31
|
+
if entry.class == Hash
|
32
|
+
entry.symbolize_keys
|
33
|
+
else
|
34
|
+
entry
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
refine String do
|
41
|
+
def to_query(key)
|
42
|
+
require 'cgi' unless defined?(CGI) && defined?(CGI::escape)
|
43
|
+
"#{CGI.escape(key.to_param)}=#{CGI.escape(to_param.to_s)}"
|
44
|
+
end
|
45
|
+
|
46
|
+
def to_param
|
47
|
+
to_s
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
refine Symbol do
|
52
|
+
def to_query(key)
|
53
|
+
to_s.to_query(key)
|
54
|
+
end
|
55
|
+
|
56
|
+
def to_param
|
57
|
+
to_s
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
refine NilClass do
|
62
|
+
def to_query(key)
|
63
|
+
to_s.to_query(key)
|
64
|
+
end
|
65
|
+
|
66
|
+
def to_param
|
67
|
+
to_s
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
refine TrueClass do
|
72
|
+
def to_query(key)
|
73
|
+
to_s.to_query(key)
|
74
|
+
end
|
75
|
+
|
76
|
+
def to_query(val)
|
77
|
+
"#{CGI.escape(val.to_param)}=#{CGI.escape(to_s)}"
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
refine FalseClass do
|
82
|
+
def to_query(key)
|
83
|
+
to_s.to_query(key)
|
84
|
+
end
|
85
|
+
|
86
|
+
def to_query(val)
|
87
|
+
"#{CGI.escape(val.to_param)}=#{CGI.escape(to_s)}"
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
refine Integer do
|
92
|
+
def to_query(key)
|
93
|
+
to_s.to_query(key)
|
94
|
+
end
|
95
|
+
|
96
|
+
def to_query(val)
|
97
|
+
"#{CGI.escape(val.to_param)}=#{CGI.escape(to_s)}"
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
refine Numeric do
|
102
|
+
def to_query(key)
|
103
|
+
to_s.to_query(key)
|
104
|
+
end
|
105
|
+
|
106
|
+
def to_query(val)
|
107
|
+
"#{CGI.escape(val.to_param)}=#{CGI.escape(to_s)}"
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
data/rakefile.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require_relative '../lib/contentstack.rb'
|
3
|
+
|
4
|
+
describe Contentstack::AssetCollection do
|
5
|
+
let(:client) { create_client }
|
6
|
+
|
7
|
+
it "has attribute called `assets`" do
|
8
|
+
data = client.assets.fetch
|
9
|
+
expect(data.assets).not_to be nil
|
10
|
+
end
|
11
|
+
|
12
|
+
it "is instance of `Contentstack::AssetCollection`" do
|
13
|
+
data = client.assets.fetch
|
14
|
+
expect(data.class).to be Contentstack::AssetCollection
|
15
|
+
end
|
16
|
+
end
|
data/spec/asset_spec.rb
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require_relative '../lib/contentstack.rb'
|
3
|
+
|
4
|
+
describe Contentstack::Asset do
|
5
|
+
let(:client) { create_client }
|
6
|
+
|
7
|
+
it "has attribute called `uid`" do
|
8
|
+
@uid = "image_1"
|
9
|
+
@asset = client.asset(@uid).fetch
|
10
|
+
expect(@asset.uid).not_to be nil
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should match uid" do
|
14
|
+
@uid = "image_1"
|
15
|
+
@asset = client.asset(@uid).fetch
|
16
|
+
expect(@asset.uid).to eq @uid
|
17
|
+
end
|
18
|
+
|
19
|
+
it "has attribute called `url`" do
|
20
|
+
@uid = "image_1"
|
21
|
+
@asset = client.asset(@uid).fetch
|
22
|
+
expect(@asset.url).not_to be nil
|
23
|
+
end
|
24
|
+
|
25
|
+
it "has attribute called `tags`" do
|
26
|
+
@uid = "image_1"
|
27
|
+
@asset = client.asset(@uid).fetch
|
28
|
+
expect(@asset.tags).not_to be nil
|
29
|
+
end
|
30
|
+
|
31
|
+
it "has attribute called `file_size`" do
|
32
|
+
@uid = "image_1"
|
33
|
+
@asset = client.asset(@uid).fetch
|
34
|
+
expect(@asset.file_size).not_to be nil
|
35
|
+
end
|
36
|
+
|
37
|
+
it "has attribute called `filename`" do
|
38
|
+
@uid = "image_1"
|
39
|
+
@asset = client.asset(@uid).fetch
|
40
|
+
expect(@asset.filename).not_to be nil
|
41
|
+
end
|
42
|
+
|
43
|
+
it "has attribute called `content_type`" do
|
44
|
+
@uid = "image_1"
|
45
|
+
@asset = client.asset(@uid).fetch
|
46
|
+
expect(@asset.content_type).not_to be nil
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require_relative '../lib/contentstack.rb'
|
3
|
+
|
4
|
+
describe Contentstack::ContentType do
|
5
|
+
let(:client) { create_client }
|
6
|
+
let(:eu_client) { create_client('DELIVERY_TOKEN', 'API_KEY', 'STACK_ENV', {region: Contentstack::Region::EU}) }
|
7
|
+
let(:custom_host_client) { create_client('DELIVERY_TOKEN', 'API_KEY', 'STACK_ENV', {host: "https://custom-cdn.contentstack.com"}) }
|
8
|
+
|
9
|
+
describe "Fetch data from API" do
|
10
|
+
it "has class as Contentstack::ContentType" do
|
11
|
+
@data = client.content_types.first
|
12
|
+
expect(@data.class).to eq Contentstack::ContentType
|
13
|
+
end
|
14
|
+
|
15
|
+
it "has method called title with data" do
|
16
|
+
@data = client.content_types.first
|
17
|
+
expect(@data.title).not_to be nil
|
18
|
+
end
|
19
|
+
|
20
|
+
it "has method called title with data from eu" do
|
21
|
+
@data = eu_client.content_types.first
|
22
|
+
expect(@data.title).not_to be nil
|
23
|
+
end
|
24
|
+
|
25
|
+
it "has method called title with data from custom client" do
|
26
|
+
@data = custom_host_client.content_types.first
|
27
|
+
expect(@data.title).not_to be nil
|
28
|
+
end
|
29
|
+
|
30
|
+
it "has method called uid with data" do
|
31
|
+
@data = client.content_types.first
|
32
|
+
expect(@data.uid).not_to be nil
|
33
|
+
end
|
34
|
+
|
35
|
+
it "has method called created_at with data" do
|
36
|
+
@data = client.content_types.first
|
37
|
+
expect(@data.created_at).not_to be nil
|
38
|
+
end
|
39
|
+
|
40
|
+
it "has method called updated_at with data" do
|
41
|
+
@data = client.content_types.first
|
42
|
+
expect(@data.updated_at).not_to be nil
|
43
|
+
end
|
44
|
+
|
45
|
+
it "has method called attributes with data" do
|
46
|
+
@data = client.content_types.first
|
47
|
+
expect(@data.attributes).not_to be nil
|
48
|
+
end
|
49
|
+
|
50
|
+
it "Should get content type from uid" do
|
51
|
+
@data = client.content_type("category").fetch
|
52
|
+
expect(@data.attributes).not_to be nil
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
describe "Initialized using class" do
|
57
|
+
before(:each) do
|
58
|
+
@data = Contentstack::ContentType.new({uid: "DummyUID"})
|
59
|
+
end
|
60
|
+
|
61
|
+
it "has method called title without data" do
|
62
|
+
expect(@data.title).to be nil
|
63
|
+
end
|
64
|
+
|
65
|
+
it "has method called uid with data" do
|
66
|
+
expect(@data.uid).not_to be nil
|
67
|
+
end
|
68
|
+
|
69
|
+
it "has method called created_at without data" do
|
70
|
+
expect(@data.created_at).to be nil
|
71
|
+
end
|
72
|
+
|
73
|
+
it "has method called updated_at without data" do
|
74
|
+
expect(@data.updated_at).to be nil
|
75
|
+
end
|
76
|
+
|
77
|
+
it "has method called attributes without data" do
|
78
|
+
expect(@data.attributes).not_to be nil
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require_relative '../lib/contentstack.rb'
|
3
|
+
|
4
|
+
describe Contentstack do
|
5
|
+
let(:client) { create_client }
|
6
|
+
let(:eu_client) { create_client('DELIVERY_TOKEN_TOKEN', 'API_KEY', 'STACK_ENV', {region: Contentstack::Region::EU}) }
|
7
|
+
let(:custom_host_client) { create_client('DELIVERY_TOKEN_TOKEN', 'API_KEY', 'STACK_ENV', {host: "https://custom-cdn.contentstack.com"}) }
|
8
|
+
|
9
|
+
it "has a version number" do
|
10
|
+
expect(Contentstack::VERSION).not_to be nil
|
11
|
+
end
|
12
|
+
|
13
|
+
it "has region data" do
|
14
|
+
expect(Contentstack::Region::EU).not_to be 'eu'
|
15
|
+
expect(Contentstack::Region::US).not_to be 'us'
|
16
|
+
end
|
17
|
+
|
18
|
+
it "has default host and region" do
|
19
|
+
expect(client.region).to eq Contentstack::Region::US
|
20
|
+
expect(client.host).to eq 'https://cdn.contentstack.io'
|
21
|
+
end
|
22
|
+
|
23
|
+
it "has custom region with region host" do
|
24
|
+
expect(eu_client.region).to eq Contentstack::Region::EU
|
25
|
+
expect(eu_client.host).to eq 'https://eu-cdn.contentstack.com'
|
26
|
+
end
|
27
|
+
|
28
|
+
it "has custom host" do
|
29
|
+
expect(custom_host_client.host).to eq 'https://custom-cdn.contentstack.com'
|
30
|
+
end
|
31
|
+
|
32
|
+
it "JSON to HTML" do
|
33
|
+
expect(Contentstack::json_to_html({}, ContentstackUtils::Model::Options.new())).to eq ''
|
34
|
+
end
|
35
|
+
|
36
|
+
it "JSON to HTML" do
|
37
|
+
expect(Contentstack::render_content('', ContentstackUtils::Model::Options.new())).to eq ''
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require_relative '../lib/contentstack.rb'
|
3
|
+
|
4
|
+
describe Contentstack::EntryCollection do
|
5
|
+
let(:client) { create_client }
|
6
|
+
|
7
|
+
it "has no instance variable `count`" do
|
8
|
+
@data = client.content_type("category").query.fetch
|
9
|
+
@countdata = client.content_type("category").query.include_count.fetch
|
10
|
+
expect(@data.count).to be nil
|
11
|
+
end
|
12
|
+
|
13
|
+
it "has instance variable `count`" do
|
14
|
+
@data = client.content_type("category").query.fetch
|
15
|
+
@countdata = client.content_type("category").query.include_count.fetch
|
16
|
+
expect(@countdata.count).not_to be nil
|
17
|
+
end
|
18
|
+
|
19
|
+
it "has instance variable `entries`" do
|
20
|
+
@data = client.content_type("category").query.fetch
|
21
|
+
@countdata = client.content_type("category").query.include_count.fetch
|
22
|
+
expect(@data.entries).not_to be nil
|
23
|
+
end
|
24
|
+
|
25
|
+
it "has the same entry using `first` method" do
|
26
|
+
@data = client.content_type("category").query.fetch
|
27
|
+
@countdata = client.content_type("category").query.include_count.fetch
|
28
|
+
expect(@data.entries[0].uid).to eq @data.first.uid
|
29
|
+
end
|
30
|
+
|
31
|
+
it "has the same entry using `last` method" do
|
32
|
+
@data = client.content_type("category").query.fetch
|
33
|
+
@countdata = client.content_type("category").query.include_count.fetch
|
34
|
+
expect(@data.entries[-1].uid).to eq @data.last.uid
|
35
|
+
end
|
36
|
+
|
37
|
+
it "has the same entry using `get` method" do
|
38
|
+
@data = client.content_type("category").query.fetch
|
39
|
+
@countdata = client.content_type("category").query.include_count.fetch
|
40
|
+
expect(@data.entries[3].uid).to eq @data.get(3).uid
|
41
|
+
end
|
42
|
+
end
|
data/spec/entry_spec.rb
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require_relative '../lib/contentstack.rb'
|
3
|
+
|
4
|
+
describe Contentstack::Entry do
|
5
|
+
let(:client) { create_client }
|
6
|
+
let(:preview_client) { create_preview_client }
|
7
|
+
let(:uid) { "uid" }
|
8
|
+
let(:category) {client.content_type("category").entry(uid)}
|
9
|
+
let(:preview_category) {preview_client.content_type("category").entry(uid)}
|
10
|
+
let(:product) {client.content_type("product").entry(uid)}
|
11
|
+
|
12
|
+
it "Contentstack::EntryCollection should have Contentstack::Entry instance" do
|
13
|
+
data = client.content_type("category").query.fetch
|
14
|
+
expect(data.class).to eq Contentstack::EntryCollection
|
15
|
+
expect(data.first.class).to eq Contentstack::Entry
|
16
|
+
end
|
17
|
+
|
18
|
+
it "is an instance of Contentstack::Entry if single entry is fetched" do
|
19
|
+
data = category.fetch
|
20
|
+
expect(data.class).to eq Contentstack::Entry
|
21
|
+
end
|
22
|
+
|
23
|
+
it "is preview entry featch" do
|
24
|
+
preview_client.live_preview_query({hash: 'hash', content_type_uid: 'category'})
|
25
|
+
data = preview_category.fetch
|
26
|
+
expect(data.class).to eq Contentstack::Entry
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'has a method `get` to get attributes data' do
|
30
|
+
data = category.fetch
|
31
|
+
expect(data.get('uid')).to eq uid
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should set locale the in the request entry" do
|
35
|
+
data = category.locale('en-us')
|
36
|
+
expect(data.query[:locale]).to eq 'en-us'
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should get data using `only` method with string parameter" do
|
40
|
+
data = category.fetch
|
41
|
+
expect(data.fields[:title]).not_to be nil
|
42
|
+
expect(data.fields[:uid]).not_to be nil
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should get data using `only` method with array parameter" do
|
46
|
+
data = category.only(["title"]).fetch
|
47
|
+
expect(data.fields[:title]).not_to be nil
|
48
|
+
expect(data.fields[:uid]).not_to be nil
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should get data using `except` method with string parameter" do
|
52
|
+
data = category.except("category_tags").fetch
|
53
|
+
expect(data.fields[:category_tags]).to be nil
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should get data using `except` method with array parameter" do
|
57
|
+
data = category.except(["description"]).fetch
|
58
|
+
expect(data.fields[:description]).to be nil
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should get data using `only` method for reference fields" do
|
62
|
+
data = product.include_reference('categories').only("categories", ["title", "description"]).fetch
|
63
|
+
expect(data.fields[:categories][0][:title]).to eq "Smartphones"
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should get data using `except` method for reference fields" do
|
67
|
+
data = product.include_reference('categories').except("categories", "title").fetch
|
68
|
+
expect(data.fields[:categories][0][:title]).to eq 'Smartphones'
|
69
|
+
end
|
70
|
+
|
71
|
+
it "should get data using `include_schema` method" do
|
72
|
+
data = category.include_schema.fetch
|
73
|
+
expect(data.schema).not_to be nil
|
74
|
+
end
|
75
|
+
|
76
|
+
it "should get data using `include_owner` method" do
|
77
|
+
data = product.include_owner.fetch
|
78
|
+
expect(data.fields[:_owner]).not_to be nil
|
79
|
+
end
|
80
|
+
|
81
|
+
it "should get data using `include_owner` method" do
|
82
|
+
data = product.include_fallback.fetch
|
83
|
+
expect(data.fields[:locale]).not_to be nil
|
84
|
+
end
|
85
|
+
|
86
|
+
it "should get data using `include_content_type` method" do
|
87
|
+
data = category.include_content_type.fetch
|
88
|
+
expect(data.content_type).not_to be nil
|
89
|
+
end
|
90
|
+
|
91
|
+
it "should get data using `include_reference` method" do
|
92
|
+
data = product.include_reference('categories').fetch
|
93
|
+
puts data.get("categories.title")
|
94
|
+
expect(data.fields[:categories][0][:title]).not_to be nil
|
95
|
+
end
|
96
|
+
|
97
|
+
it "should get data using `include_embedded_items` method" do
|
98
|
+
data = product.include_embedded_items().fetch
|
99
|
+
puts data.get("categories.title")
|
100
|
+
expect(data.fields[:categories][0][:title]).not_to be nil
|
101
|
+
end
|
102
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
{"asset":{"uid":"image_1","created_at":"2017-09-07T01:31:59.139Z","updated_at":"2017-09-07T01:31:59.139Z","created_by":"user","updated_by":"user","content_type":"image/png","file_size":"241691","tags":["tag1","tag2"],"filename":"maybe.png","url":"url","ACL":{},"is_dir":false,"parent_uid":null,"_version":1,"title":"maybe.png","description":""}}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"assets":[{"uid":"image_1","created_at":"2017-09-10T20:27:00.488Z","updated_at":"2017-09-10T20:27:00.488Z","created_by":"user","updated_by":"user","content_type":"image/jpeg","file_size":"115545","tags":[],"filename":"Win Against Dortmund.jpg","url":"image_url_1","ACL":{},"is_dir":false,"_version":1,"title":"Win Against Dortmund.jpg"},{"uid":"image_2","created_at":"2017-09-07T01:31:59.139Z","updated_at":"2017-09-07T01:31:59.139Z","created_by":"user","updated_by":"user","content_type":"image/png","file_size":"241691","tags":["tag1","tag2"],"filename":"maybe.png","url":"image_url_2","ACL":{},"is_dir":false,"parent_uid":null,"_version":1,"title":"maybe.png","description":""}]}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"content_type":{"created_at":"2017-09-28T06:04:02.500Z","updated_at":"2017-09-28T07:13:13.612Z","title":"Product","uid":"product","inbuilt_class":false,"schema":[{"display_name":"Title","uid":"title","data_type":"text","mandatory":true,"unique":true,"field_metadata":{"_default":true},"multiple":false},{"display_name":"URL","uid":"url","data_type":"text","mandatory":false,"field_metadata":{"_default":true},"multiple":false,"unique":false},{"data_type":"text","display_name":"Price","uid":"price","field_metadata":{"description":"","default_value":""},"format":"","error_messages":{"format":""},"multiple":false,"mandatory":false,"unique":false},{"data_type":"text","display_name":"Discounted Price","uid":"discounted_price","field_metadata":{"description":"","default_value":""},"format":"","error_messages":{"format":""},"multiple":false,"mandatory":false,"unique":false},{"data_type":"file","display_name":"Featured Image","uid":"featured_image","extensions":[],"field_metadata":{"description":"","rich_text_type":"standard"},"multiple":false,"mandatory":false,"unique":false},{"data_type":"file","display_name":"Product Images","uid":"product_images","extensions":[],"field_metadata":{"description":"","rich_text_type":"standard"},"multiple":true,"mandatory":false,"unique":false},{"data_type":"text","display_name":"Description","uid":"description","field_metadata":{"description":"","default_value":"","multiline":true},"format":"","error_messages":{"format":""},"multiple":false,"mandatory":false,"unique":false},{"data_type":"reference","display_name":"Categories","reference_to":"category","field_metadata":{"ref_multiple":true},"uid":"categories","multiple":false,"mandatory":false,"unique":false},{"data_type":"reference","display_name":"Related Products","reference_to":"product","field_metadata":{"ref_multiple":true},"uid":"related_products","mandatory":false,"multiple":false,"unique":false}],"last_activity":{"environments":[{"uid":"env","details":[{"locale":"en-us","time":"2017-09-28T09:43:24.028Z"}]}]},"maintain_revisions":true,"description":"","options":{"is_page":true,"singleton":false,"title":"title","sub_title":[],"url_pattern":"/:unique_id","url_prefix":"/products/"},"abilities":{"get_one_object":true,"get_all_objects":true,"create_object":true,"update_object":true,"delete_object":true,"delete_all_objects":true},"DEFAULT_ACL":{"others":{"read":false,"create":false},"users":[{"uid":"user","read":true,"sub_acl":{"read":true}}]},"SYS_ACL":{"others":{"read":false,"create":false,"update":false,"delete":false,"sub_acl":{"read":false,"create":false,"update":false,"delete":false,"publish":false}},"roles":[{"uid":"role","read":true,"create":false,"update":false,"delete":false,"sub_acl":{"read":true,"create":true,"update":true,"delete":true,"publish":true}},{"uid":"role2","read":true,"create":true,"update":true,"delete":true,"sub_acl":{"read":true,"create":true,"update":true,"delete":true,"publish":true}}]}}}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"entry":{"title":"Apple Products","tags":[],"locale":"en-us","uid":"uid","created_by":"user","updated_by":"user","created_at":"2017-09-28T06:08:21.276Z","updated_at":"2017-09-28T06:08:21.276Z","ACL":{},"_version":1}, "schema":[{"display_name":"Title","uid":"title","data_type":"text","mandatory":true,"unique":true,"field_metadata":{"_default":true},"multiple":false},{"data_type":"text","display_name":"Description","uid":"description","field_metadata":{"description":"","default_value":"","multiline":true},"format":"","error_messages":{"format":""},"multiple":false,"mandatory":false,"unique":false}],"content_type":{"created_at":"2017-08-28T11:26:16.005Z","updated_at":"2017-08-28T11:26:28.217Z","title":"Category","uid":"category","inbuilt_class":false,"schema":[{"display_name":"Title","uid":"title","data_type":"text","mandatory":true,"unique":true,"field_metadata":{"_default":true},"multiple":false},{"data_type":"text","display_name":"Description","uid":"description","field_metadata":{"description":"","default_value":"","multiline":true},"format":"","error_messages":{"format":""},"multiple":false,"mandatory":false,"unique":false}],"last_activity":{"environments":[{"uid":"environment","details":[{"locale":"en-us","time":"2017-09-28T09:37:14.441Z"}]}]},"maintain_revisions":true,"description":"","options":{"is_page":false,"singleton":false,"title":"title","sub_title":[]},"abilities":{"get_one_object":true,"get_all_objects":true,"create_object":true,"update_object":true,"delete_object":true,"delete_all_objects":true},"DEFAULT_ACL":{"others":{"read":false,"create":false},"users":[{"uid":"user","read":true,"sub_acl":{"read":true}}]}}}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"entries":[{"title":"Home & Appliances","tags":[],"locale":"en-us","uid":"uid_1","created_by":"user","updated_by":"user","created_at":"2017-09-28T06:08:32.914Z","updated_at":"2017-09-28T06:08:32.914Z","ACL":{},"_version":1,"_owner":{}},{"title":"Apple Products","tags":[],"locale":"en-us","uid":"uid_2","created_by":"user","updated_by":"user","created_at":"2017-09-28T06:08:21.276Z","updated_at":"2017-09-28T06:08:21.276Z","ACL":{},"_version":1,"_owner":{}},{"title":"Smartphones","tags":[],"locale":"en-us","uid":"uid_3","created_by":"user","updated_by":"user","created_at":"2017-09-28T06:07:37.132Z","updated_at":"2017-09-28T06:07:37.132Z","ACL":{},"_version":1,"_owner":{}},{"title":"Tablets","tags":[],"locale":"en-us","uid":"uid_4","created_by":"user","updated_by":"user","created_at":"2017-09-28T06:07:20.740Z","updated_at":"2017-09-28T06:07:20.740Z","ACL":{},"_version":1,"_owner":{}},{"title":"Headphones","tags":[],"locale":"en-us","uid":"uid_5","created_by":"user","updated_by":"user","created_at":"2017-09-28T06:07:07.673Z","updated_at":"2017-09-28T06:07:07.673Z","ACL":{},"_version":1,"_owner":{}}],"count":5,"content_type":{"created_at":"2017-09-28T06:06:44.057Z","updated_at":"2017-09-28T06:06:49.125Z","title":"Category","uid":"category","inbuilt_class":false,"schema":[{"display_name":"Title","uid":"title","data_type":"text","mandatory":true,"unique":true,"field_metadata":{"_default":true},"multiple":false}],"last_activity":{"environments":[{"uid":"environment","details":[{"locale":"en-us","time":"2017-09-28T09:43:24.027Z"}]}]},"maintain_revisions":true,"description":"","options":{"is_page":false,"singleton":false,"title":"title","sub_title":[]},"abilities":{"get_one_object":true,"get_all_objects":true,"create_object":true,"update_object":true,"delete_object":true,"delete_all_objects":true},"DEFAULT_ACL":{"others":{"read":false,"create":false},"users":[{"uid":"user","read":true,"sub_acl":{"read":true}}]}},"schema":[{"display_name":"Title","uid":"title","data_type":"text","mandatory":true,"unique":true,"field_metadata":{"_default":true},"multiple":false},{"data_type":"text","display_name":"Description","uid":"description","field_metadata":{"description":"","default_value":"","multiline":true},"format":"","error_messages":{"format":""},"multiple":false,"mandatory":false,"unique":false}],"content_type":{"created_at":"2017-08-28T11:26:16.005Z","updated_at":"2017-08-28T11:26:28.217Z","title":"Category","uid":"category","inbuilt_class":false,"schema":[{"display_name":"Title","uid":"title","data_type":"text","mandatory":true,"unique":true,"field_metadata":{"_default":true},"multiple":false},{"data_type":"text","display_name":"Description","uid":"description","field_metadata":{"description":"","default_value":"","multiline":true},"format":"","error_messages":{"format":""},"multiple":false,"mandatory":false,"unique":false}],"last_activity":{"environments":[{"uid":"environment","details":[{"locale":"en-us","time":"2017-09-28T09:37:14.441Z"}]}]},"maintain_revisions":true,"description":"","options":{"is_page":false,"singleton":false,"title":"title","sub_title":[]},"abilities":{"get_one_object":true,"get_all_objects":true,"create_object":true,"update_object":true,"delete_object":true,"delete_all_objects":true},"DEFAULT_ACL":{"others":{"read":false,"create":false},"users":[{"uid":"user","read":true,"sub_acl":{"read":true}}]}}}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"entries":[{"title":"Home & Appliances","tags":[],"locale":"en-us","uid":"uid_1","created_by":"user","updated_by":"user","created_at":"2017-09-28T06:08:32.914Z","updated_at":"2017-09-28T06:08:32.914Z","ACL":{},"_version":1},{"title":"Apple Products","tags":[],"locale":"en-us","uid":"uid_2","created_by":"user","updated_by":"user","created_at":"2017-09-28T06:08:21.276Z","updated_at":"2017-09-28T06:08:21.276Z","ACL":{},"_version":1},{"title":"Smartphones","tags":[],"locale":"en-us","uid":"uid_3","created_by":"user","updated_by":"user","created_at":"2017-09-28T06:07:37.132Z","updated_at":"2017-09-28T06:07:37.132Z","ACL":{},"_version":1},{"title":"Tablets","tags":[],"locale":"en-us","uid":"uid_4","created_by":"user","updated_by":"user","created_at":"2017-09-28T06:07:20.740Z","updated_at":"2017-09-28T06:07:20.740Z","ACL":{},"_version":1},{"title":"Headphones","tags":[],"locale":"en-us","uid":"uid5","created_by":"user","updated_by":"user","created_at":"2017-09-28T06:07:07.673Z","updated_at":"2017-09-28T06:07:07.673Z","ACL":{},"_version":1}],"schema":[{"display_name":"Title","uid":"title","data_type":"text","mandatory":true,"unique":true,"field_metadata":{"_default":true},"multiple":false},{"data_type":"text","display_name":"Description","uid":"description","field_metadata":{"description":"","default_value":"","multiline":true},"format":"","error_messages":{"format":""},"multiple":false,"mandatory":false,"unique":false}],"content_type":{"created_at":"2017-08-28T11:26:16.005Z","updated_at":"2017-08-28T11:26:28.217Z","title":"Category","uid":"category","inbuilt_class":false,"schema":[{"display_name":"Title","uid":"title","data_type":"text","mandatory":true,"unique":true,"field_metadata":{"_default":true},"multiple":false},{"data_type":"text","display_name":"Description","uid":"description","field_metadata":{"description":"","default_value":"","multiline":true},"format":"","error_messages":{"format":""},"multiple":false,"mandatory":false,"unique":false}],"last_activity":{"environments":[{"uid":"uid6","details":[{"locale":"en-us","time":"2017-09-28T09:37:14.441Z"}]}]},"maintain_revisions":true,"description":"","options":{"is_page":false,"singleton":false,"title":"title","sub_title":[]},"abilities":{"get_one_object":true,"get_all_objects":true,"create_object":true,"update_object":true,"delete_object":true,"delete_all_objects":true},"DEFAULT_ACL":{"others":{"read":false,"create":false},"users":[{"uid":"uid_7","read":true,"sub_acl":{"read":true}}]}}}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"content_types":[{"created_at":"2017-09-28T06:04:02.500Z","updated_at":"2017-09-28T07:13:13.612Z","title":"Product","uid":"product","inbuilt_class":false,"schema":[{"display_name":"Title","uid":"title","data_type":"text","mandatory":true,"unique":true,"field_metadata":{"_default":true},"multiple":false},{"display_name":"URL","uid":"url","data_type":"text","mandatory":false,"field_metadata":{"_default":true},"multiple":false,"unique":false},{"data_type":"text","display_name":"Price","uid":"price","field_metadata":{"description":"","default_value":""},"format":"","error_messages":{"format":""},"multiple":false,"mandatory":false,"unique":false},{"data_type":"text","display_name":"Discounted Price","uid":"discounted_price","field_metadata":{"description":"","default_value":""},"format":"","error_messages":{"format":""},"multiple":false,"mandatory":false,"unique":false},{"data_type":"file","display_name":"Featured Image","uid":"featured_image","extensions":[],"field_metadata":{"description":"","rich_text_type":"standard"},"multiple":false,"mandatory":false,"unique":false},{"data_type":"file","display_name":"Product Images","uid":"product_images","extensions":[],"field_metadata":{"description":"","rich_text_type":"standard"},"multiple":true,"mandatory":false,"unique":false},{"data_type":"text","display_name":"Description","uid":"description","field_metadata":{"description":"","default_value":"","multiline":true},"format":"","error_messages":{"format":""},"multiple":false,"mandatory":false,"unique":false},{"data_type":"reference","display_name":"Categories","reference_to":"category","field_metadata":{"ref_multiple":true},"uid":"categories","multiple":false,"mandatory":false,"unique":false},{"data_type":"reference","display_name":"Related Products","reference_to":"product","field_metadata":{"ref_multiple":true},"uid":"related_products","mandatory":false,"multiple":false,"unique":false}],"last_activity":{"environments":[{"uid":"environment","details":[{"locale":"en-us","time":"2017-09-28T09:43:24.028Z"}]}]},"maintain_revisions":true,"description":"","options":{"is_page":true,"singleton":false,"title":"title","sub_title":[],"url_pattern":"/:unique_id","url_prefix":"/products/"},"abilities":{"get_one_object":true,"get_all_objects":true,"create_object":true,"update_object":true,"delete_object":true,"delete_all_objects":true},"DEFAULT_ACL":{"others":{"read":false,"create":false},"users":[{"uid":"user","read":true,"sub_acl":{"read":true}}]},"SYS_ACL":{"others":{"read":false,"create":false,"update":false,"delete":false,"sub_acl":{"read":false,"create":false,"update":false,"delete":false,"publish":false}},"roles":[{"uid":"role","read":true,"create":false,"update":false,"delete":false,"sub_acl":{"read":true,"create":true,"update":true,"delete":true,"publish":true}},{"uid":"role2","read":true,"create":true,"update":true,"delete":true,"sub_acl":{"read":true,"create":true,"update":true,"delete":true,"publish":true}}]}},{"created_at":"2017-09-28T06:06:44.057Z","updated_at":"2017-09-28T06:06:49.125Z","title":"Category","uid":"category","inbuilt_class":false,"schema":[{"display_name":"Title","uid":"title","data_type":"text","mandatory":true,"unique":true,"field_metadata":{"_default":true},"multiple":false}],"last_activity":{"environments":[{"uid":"environment","details":[{"locale":"en-us","time":"2017-09-28T09:43:24.027Z"}]}]},"maintain_revisions":true,"description":"","options":{"is_page":false,"singleton":false,"title":"title","sub_title":[]},"abilities":{"get_one_object":true,"get_all_objects":true,"create_object":true,"update_object":true,"delete_object":true,"delete_all_objects":true},"DEFAULT_ACL":{"others":{"read":false,"create":false},"users":[{"uid":"user","read":true,"sub_acl":{"read":true}}]},"SYS_ACL":{"others":{"read":false,"create":false,"update":false,"delete":false,"sub_acl":{"read":false,"create":false,"update":false,"delete":false,"publish":false}},"roles":[{"uid":"role","read":true,"create":false,"update":false,"delete":false,"sub_acl":{"read":true,"create":true,"update":true,"delete":true,"publish":true}},{"uid":"role2","read":true,"create":true,"update":true,"delete":true,"sub_acl":{"read":true,"create":true,"update":true,"delete":true,"publish":true}}]}}]}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"entry":{"title":"Motorola Moto X4","url":"/products/product_1_uid","price":"500","discounted_price":"450","featured_image":{"uid":"product_2_uid","created_at":"2017-09-28T07:02:20.745Z","updated_at":"2017-09-28T07:02:20.745Z","created_by":"created_by_string","updated_by":"created_by_string","content_type":"image/jpeg","file_size":"311812","tags":[],"filename":"1.jpg","url":"image_url","ACL":{},"is_dir":false,"_version":1,"title":"1.jpg","publish_details":{"environment":"environment_uid","locale":"en-us","time":"2017-09-28T09:28:47.919Z","user":"created_by_string"}},"product_images":[{"uid":"product_2_uid","created_at":"2017-09-28T07:02:20.745Z","updated_at":"2017-09-28T07:02:20.745Z","created_by":"created_by_string","updated_by":"created_by_string","content_type":"image/jpeg","file_size":"311812","tags":[],"filename":"1.jpg","url":"image_url","ACL":{},"is_dir":false,"_version":1,"title":"1.jpg","publish_details":{"environment":"environment_uid","locale":"en-us","time":"2017-09-28T09:28:47.919Z","user":"created_by_string"}},{"uid":"product_3_uid","created_at":"2017-09-28T07:02:30.108Z","updated_at":"2017-09-28T07:02:30.108Z","created_by":"created_by_string","updated_by":"created_by_string","content_type":"image/jpeg","file_size":"4226","tags":[],"filename":"2.jpg","url":"image_2_url","ACL":{},"is_dir":false,"_version":1,"title":"2.jpg","publish_details":{"environment":"environment_uid","locale":"en-us","time":"2017-09-28T09:28:47.919Z","user":"created_by_string"}},{"uid":"product_4_uid","created_at":"2017-09-28T07:02:32.375Z","updated_at":"2017-09-28T07:02:32.375Z","created_by":"created_by_string","updated_by":"created_by_string","content_type":"image/jpeg","file_size":"5755","tags":[],"filename":"3.jpg","url":"image_3_url","ACL":{},"is_dir":false,"_version":1,"title":"3.jpg","publish_details":{"environment":"environment_uid","locale":"en-us","time":"2017-09-28T09:28:47.919Z","user":"created_by_string"}},{"uid":"product_4_uid","created_at":"2017-09-28T07:02:36.507Z","updated_at":"2017-09-28T07:02:36.507Z","created_by":"created_by_string","updated_by":"created_by_string","content_type":"image/jpeg","file_size":"312464","tags":[],"filename":"4.jpg","url":"image_4_url","ACL":{},"is_dir":false,"_version":1,"title":"4.jpg","publish_details":{"environment":"environment_uid","locale":"en-us","time":"2017-09-28T09:28:47.919Z","user":"created_by_string"}}],"description":"dual cameras.\nsingular design.\nAdvanced dual rear cameras for your best photos yet. Plus, a beautiful contoured glass and metal frame with an IP68 water resistance rating.* Coming soon.","categories":[{"title":"Smartphones","tags":[],"locale":"en-us","uid":"product_5_uid","created_by":"created_by_string","updated_by":"created_by_string","created_at":"2017-09-28T06:07:37.132Z","updated_at":"2017-09-28T06:07:37.132Z","ACL":{},"_version":1,"publish_details":{"environment":"environment_uid","locale":"en-us","time":"2017-09-28T09:28:47.932Z","user":"created_by_string"},"_publish_environment":"environment_uid","_publish_locale":"en-us","_publish_scheduled":false}],"related_products":[{"title":"OnePlus 3T A3000 64GB Gunmetal","url":"/products/product_9_uid","price":"539","discounted_price":"499","featured_image":{"uid":"product_6_uid","created_at":"2017-09-28T06:56:13.016Z","updated_at":"2017-09-28T06:56:13.016Z","created_by":"created_by_string","updated_by":"created_by_string","content_type":"image/jpeg","file_size":"40674","tags":[],"filename":"one-plus-three-1x.jpg","url":"image_5_url","ACL":{},"is_dir":false,"_version":1,"title":"one-plus-three-1x.jpg","publish_details":{"environment":"environment_uid","locale":"en-us","time":"2017-09-28T09:42:37.885Z","user":"created_by_string"}},"product_images":[{"uid":"product_6_uid","created_at":"2017-09-28T06:56:13.016Z","updated_at":"2017-09-28T06:56:13.016Z","created_by":"created_by_string","updated_by":"created_by_string","content_type":"image/jpeg","file_size":"40674","tags":[],"filename":"one-plus-three-1x.jpg","url":"image_5_url","ACL":{},"is_dir":false,"_version":1,"title":"one-plus-three-1x.jpg","publish_details":{"environment":"environment_uid","locale":"en-us","time":"2017-09-28T09:42:37.885Z","user":"created_by_string"}},{"uid":"product_7_uid","created_at":"2017-09-28T06:56:20.954Z","updated_at":"2017-09-28T06:56:20.954Z","created_by":"created_by_string","updated_by":"created_by_string","content_type":"image/jpeg","file_size":"13187","tags":[],"filename":"one-plus-3-2.jpg","url":"image_6_url","ACL":{},"is_dir":false,"_version":1,"title":"one-plus-3-2.jpg","publish_details":{"environment":"environment_uid","locale":"en-us","time":"2017-09-28T09:42:31.431Z","user":"created_by_string"}},{"uid":"product_8_uid","created_at":"2017-09-28T06:56:24.656Z","updated_at":"2017-09-28T06:56:24.656Z","created_by":"created_by_string","updated_by":"created_by_string","content_type":"image/jpeg","file_size":"27485","tags":[],"filename":"one-plus-3-3.jpg","url":"image_7_url","ACL":{},"is_dir":false,"_version":1,"title":"one-plus-3-3.jpg","publish_details":{"environment":"environment_uid","locale":"en-us","time":"2017-09-28T09:42:26.882Z","user":"created_by_string"}}],"description":"Snapdragon 821 6gb RAM Unlocked Smartphone","categories":["product_5_uid"],"related_products":["product_related_uid"],"tags":[],"locale":"en-us","uid":"product_9_uid","created_by":"created_by_string","updated_by":"created_by_string","created_at":"2017-09-28T06:57:55.574Z","updated_at":"2017-09-28T06:57:55.574Z","ACL":{},"_version":1,"publish_details":{"environment":"environment_uid","locale":"en-us","time":"2017-09-28T09:28:47.933Z","user":"created_by_string"},"_publish_environment":"environment_uid","_publish_locale":"en-us","_publish_scheduled":false}],"tags":[],"locale":"en-us","uid":"product_1_uid","created_by":"created_by_string","updated_by":"created_by_string","created_at":"2017-09-28T07:03:11.350Z","updated_at":"2017-09-28T07:03:11.350Z","ACL":{},"_version":1, "_owner":{}}}
|