contentstack 0.0.2 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: ee5dd72d68bfd14e2292a7dd9bd18f0f11fe6091
4
- data.tar.gz: 9903cbb89a02c2775a24a238727203c4d9ec9e10
2
+ SHA256:
3
+ metadata.gz: 71f7d4a812c67dc37dba0ef98229566ea5b4d340b87f0389e45cfe041c173400
4
+ data.tar.gz: c49301d479315648103c8eb84771558a7475579e9d277d857ff700927ac87f3d
5
5
  SHA512:
6
- metadata.gz: df87832f6264b3ac38745dd5cd4364e89c61c50f817f1321c979fae7f9d38d1b32a560784abfaf2ceaf9e558b30ebe033290d778b1eeae4bae408e5b03a609aa
7
- data.tar.gz: 9d98b68aae934eef4b344e1d19022d3c2b0ed795013f1023a322182588478d40f73fd6387d3b5887e22921d2620aceb5960b54bf4e9dff1e5caac6c9e32b7b4b
6
+ metadata.gz: b3f188fe61e9d35a1c9626b8f2fd15a1196abd1b547eacef2c24147ab7369d75c0d1c09b0f9e288ad94bb89068948e72dadf15a540539f5605d011cbcccfeaf5
7
+ data.tar.gz: 040c5271bda413fa05a96c9bba8fa1a399c4fd74ce0b83aaff610830e1aa586093e269e03c4be089e0f8717d405dcc85bec9b1e1ac7eba2d20b77ae1fd78344a
data/.gitignore CHANGED
@@ -5,3 +5,6 @@ doc
5
5
  spec-integration
6
6
  coverage
7
7
  \.yardoc
8
+ .DS_Store
9
+ .bundle/
10
+ */rspec_results.html
@@ -0,0 +1,48 @@
1
+ ## CHANGELOG
2
+ ------------------------------------------------
3
+
4
+ ## Version 0.2.0
5
+
6
+ ### New Features
7
+ - Entry
8
+ - locale - function for passing locale is added
9
+ - only - function for getting only specified field
10
+ - except - function for getting field except specified field
11
+ - include_reference - function for including reference in entry
12
+ - include_schema - function for including schema along with entry added
13
+ - include_content_type - function for including content type details along with entry added
14
+ - include_owner - function for getting owner of entry
15
+ - include_fallback - function for getting published fallback locale content, if specified locale content is not published
16
+
17
+ - Query
18
+ - include_fallback - function for getting published fallback locale content, if specified locale content is not published
19
+
20
+
21
+ ------------------------------------------------
22
+
23
+ ## Version 0.1.0
24
+
25
+ ### Bug
26
+ - Stack Tokens Moved to Headers
27
+
28
+ ------------------------------------------------
29
+
30
+ ## Version 0.0.4
31
+
32
+ ### Enhancement
33
+ - Region support added
34
+
35
+ ------------------------------------------------
36
+
37
+ ## Version 0.0.3
38
+
39
+ ### Enhancement
40
+ - Query - function for passing locale is added.
41
+
42
+ ------------------------------------------------
43
+
44
+ ## Version 0.0.1
45
+
46
+ - Initial release
47
+
48
+ ------------------------------------------------
@@ -22,8 +22,7 @@ include:
22
22
 
23
23
  Examples of unacceptable behavior by participants include:
24
24
 
25
- * The use of sexualized language or imagery and unwelcome sexual attention or
26
- advances
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or advances
27
26
  * Trolling, insulting/derogatory comments, and personal or political attacks
28
27
  * Public or private harassment
29
28
  * Publishing others' private information, such as a physical or electronic
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ # Gemfile
2
+ source "https://rubygems.org"
3
+
4
+ gem "rspec"
5
+ gem "webmock"
6
+ gem "simplecov"
7
+ gem "activesupport"
8
+ gem "yard"
@@ -0,0 +1,61 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ activesupport (6.0.3.1)
5
+ concurrent-ruby (~> 1.0, >= 1.0.2)
6
+ i18n (>= 0.7, < 2)
7
+ minitest (~> 5.1)
8
+ tzinfo (~> 1.1)
9
+ zeitwerk (~> 2.2, >= 2.2.2)
10
+ addressable (2.7.0)
11
+ public_suffix (>= 2.0.2, < 5.0)
12
+ concurrent-ruby (1.1.6)
13
+ crack (0.4.3)
14
+ safe_yaml (~> 1.0.0)
15
+ diff-lcs (1.3)
16
+ docile (1.3.2)
17
+ hashdiff (1.0.1)
18
+ i18n (1.8.2)
19
+ concurrent-ruby (~> 1.0)
20
+ minitest (5.14.1)
21
+ public_suffix (4.0.4)
22
+ rspec (3.9.0)
23
+ rspec-core (~> 3.9.0)
24
+ rspec-expectations (~> 3.9.0)
25
+ rspec-mocks (~> 3.9.0)
26
+ rspec-core (3.9.1)
27
+ rspec-support (~> 3.9.1)
28
+ rspec-expectations (3.9.1)
29
+ diff-lcs (>= 1.2.0, < 2.0)
30
+ rspec-support (~> 3.9.0)
31
+ rspec-mocks (3.9.1)
32
+ diff-lcs (>= 1.2.0, < 2.0)
33
+ rspec-support (~> 3.9.0)
34
+ rspec-support (3.9.2)
35
+ safe_yaml (1.0.5)
36
+ simplecov (0.18.5)
37
+ docile (~> 1.1)
38
+ simplecov-html (~> 0.11)
39
+ simplecov-html (0.12.2)
40
+ thread_safe (0.3.6)
41
+ tzinfo (1.2.7)
42
+ thread_safe (~> 0.1)
43
+ webmock (3.8.3)
44
+ addressable (>= 2.3.6)
45
+ crack (>= 0.3.2)
46
+ hashdiff (>= 0.4.0, < 2.0.0)
47
+ yard (0.9.25)
48
+ zeitwerk (2.3.0)
49
+
50
+ PLATFORMS
51
+ ruby
52
+
53
+ DEPENDENCIES
54
+ activesupport
55
+ rspec
56
+ simplecov
57
+ webmock
58
+ yard
59
+
60
+ BUNDLED WITH
61
+ 2.1.4
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2016 amite
3
+ Copyright (c) 2012-2019 Contentstack. All Rights Reserved
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
@@ -0,0 +1,134 @@
1
+ # **Ruby SDK for Contentstack**
2
+
3
+ Contentstack is a headless CMS with an API-first approach. It is a CMS that developers can use to build powerful cross-platform applications in their favorite languages. Build your application frontend, and Contentstack will take care of the rest. [Read More](https://www.contentstack.com/).
4
+
5
+ Contentstack provides Ruby SDK to build application on top of Ruby on Rails. Given below is the detailed guide and helpful resources to get started with our Ruby SDK.
6
+
7
+ ## **Prerequisite**
8
+
9
+ You need ruby v2.0 or later installed to use the Contentstack Ruby SDK.
10
+
11
+ ## **Setup and Installation**
12
+
13
+ Add the following code to your application's Gemfile and bundle:
14
+
15
+ gem 'contentstack'
16
+
17
+ Or you can run this command in your terminal (you might need administrator privileges to perform this installation):
18
+
19
+ gem install contentstack
20
+
21
+ To start using the SDK in your application, you will need to initialize the stack by providing the values for the keys given in the code snippet below.
22
+
23
+ # with default region
24
+ client = Contentstack::Client.new("api_key", "delivery_token", "enviroment_name")
25
+
26
+ # with specific region
27
+ client = Contentstack::Client.new("api_key", "delivery_token", "enviroment_name",{"region": Contentstack::Region::EU})
28
+
29
+ # with custom host
30
+ client = Contentstack::Client.new("api_key", "delivery_token", "enviroment_name",{"host": "https://custom-cdn.contentstack.com"})
31
+
32
+ ## **Key Concepts for using Contentstack**
33
+
34
+ ### **Stack**
35
+
36
+ A stack is like a container that holds the content of your app. Learn more about [stacks](https://www.contentstack.com/docs/guide/stack).
37
+
38
+ ### **Content Type**
39
+
40
+ Content type lets you define the structure or blueprint of a page or a section of your digital property. It is a form-like page that gives Content Managers an interface to input and upload content. [Read more](https://www.contentstack.com/docs/guide/content-types).
41
+
42
+ ### **Entry**
43
+
44
+ An entry is the actual piece of content created using one of the defined content types. Learn more about [Entries](https://www.contentstack.com/docs/guide/content-management#working-with-entries).
45
+
46
+ ### **Asset**
47
+
48
+ Assets refer to all the media files (images, videos, PDFs, audio files, and so on) uploaded to Contentstack. These files can be used in multiple entries. Read more about [Assets](https://www.contentstack.com/docs/guide/content-management#working-with-assets).
49
+
50
+ ### **Environment**
51
+
52
+ A publishing environment corresponds to one or more deployment servers or a content delivery destination where the entries need to be published. Learn how to work with [Environments](https://www.contentstack.com/docs/guide/environments).
53
+
54
+ ## **Contentstack Ruby SDK: 5-minute Quickstart**
55
+
56
+ ### **Initializing your SDK**
57
+
58
+ To initialize the SDK, you need to provide values for the keys given in the snippet below:
59
+
60
+ stack = Contentstack::Client.new("api_key", "delivery_token", "enviroment_name")
61
+
62
+ To get the API credentials mentioned above, log in to your Contentstack account and then in your top panel navigation, go to Settings > Stack to view the API Key and Access Token.
63
+
64
+ ### **Querying content from your stack**
65
+
66
+ To fetch all entries of of a content type, use the query given below:
67
+
68
+ entry = stack.content_type(<<CONTENT_TYPE_UID>>).query();
69
+
70
+ To fetch a specific entry from a content type, use the following query:
71
+
72
+ entry = stack.content_type(<<CONTENT_TYPE_UID>>).entry(<<ENTRY_UID>>);
73
+
74
+ ### Get Multiple Entries
75
+ To retrieve multiple entries of a content type, specify the content type UID. You can also specify search parameters to filter results:
76
+
77
+ @query = @stack.content_type('blog').query
78
+ @entries = @query.where('title', 'welcome')
79
+ .include_schema
80
+ .include_count
81
+ .fetch
82
+ puts "Total Entries -- #{@entries.count}"
83
+ @entries.each{|entry| puts "#{entry.get('title')}" }
84
+ To retrieve localized versions of entries, you can use the query attribute:
85
+
86
+ entry = @stack.content_type('content_type_uid').query.locale('locale_code').fetch()
87
+
88
+ > Note: Currently, the above query works in case of retrieving localized versions of multiple entries only.
89
+
90
+ ## **Advanced Queries**
91
+
92
+ You can query for content types, entries, assets and more using our Ruby API Reference.
93
+
94
+ [Ruby API Reference Doc](http://www.rubydoc.info/gems/contentstack)
95
+
96
+ ### Paginating Responses
97
+ In a single instance, the [Get Multiple Entries](https://www.contentstack.com/docs/developers/ruby/get-started-with-ruby-sdk/#get-multiple-entries) query will retrieve only the first 100 items of the specified content type. You can paginate and retrieve the rest of the items in batches using the [skip](https://www.rubydoc.info/gems/contentstack/Contentstack/Query#skip-instance_method) and [limit](https://www.rubydoc.info/gems/contentstack/Contentstack/Query#limit-instance_method) parameters in subsequent requests.
98
+
99
+ @stack = Contentstack::Client.new("api_key", "delivery_token", "environment")
100
+ @entries = @stack.content_type('category').query
101
+ .limit(20)
102
+ .skip(50)
103
+ .fetch
104
+
105
+ > Note: Currently, the Ruby SDK does not support multiple content types referencing in a single query. For more information on how to query entries and assets, refer the Queries section of our Content Delivery API documentation.
106
+
107
+ ## **Working with Images**
108
+
109
+ We have introduced Image Delivery APIs that let you retrieve images and then manipulate and optimize them for your digital properties. It lets you perform a host of other actions such as crop, trim, resize, rotate, overlay, and so on.
110
+
111
+ For example, if you want to crop an image (with width as 300 and height as 400), you simply need to append query parameters at the end of the image URL, such as, https://images.contentstack.io/v3/assets/blteae40eb499811073/bltc5064f36b5855343/59e0c41ac0eddd140d5a8e3e/download?crop=300,400. There are several more parameters that you can use for your images.
112
+
113
+ [Read Image Delivery API documentation](https://www.contentstack.com/docs/apis/image-delivery-api/).
114
+
115
+ SDK functions for Image Delivery API coming soon.
116
+
117
+ ## **Helpful Links**
118
+
119
+ * [Contentstack Website](https://www.contentstack.com)
120
+
121
+ * [Official Documentation](http://contentstack.com/docs)
122
+
123
+ * [Content Delivery API Docs](https://contentstack.com/docs/apis/content-delivery-api/)
124
+
125
+ ## **The MIT License (MIT)**
126
+
127
+ Copyright © 2012-2020 [Contentstack](https://www.contentstack.com). All Rights Reserved
128
+
129
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
130
+
131
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
132
+
133
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
134
+
@@ -6,11 +6,13 @@ Gem::Specification.new do |s|
6
6
  s.name = %q{contentstack}
7
7
  s.version = Contentstack::VERSION.dup
8
8
  s.date = Time.now
9
- s.authors = [%q{Rohit Sharma}]
10
- s.email = ["rubygems@contentstack.com"]
9
+ s.authors = [%q{Contentstack}]
10
+ s.email = ["support@contentstack.com"]
11
+
12
+ s.required_ruby_version = '>= 2.0'
11
13
 
12
14
  s.license = "MIT"
13
- s.homepage = "https://github.com/builtio-contentstack/contentstack-ruby"
15
+ s.homepage = "https://github.com/contentstack/contentstack-ruby"
14
16
 
15
17
  s.summary = %q{Contentstack Ruby client for the Content Delivery API}
16
18
  s.description = %q{Contentstack Ruby client for the Content Delivery API}
@@ -2,15 +2,20 @@ $LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
2
2
 
3
3
  require "contentstack/version"
4
4
  require "contentstack/client"
5
+ require "contentstack/region"
5
6
  require "util"
6
7
 
7
8
 
8
- # == Built.io Contentstack - Ruby SDK
9
- # Built.io Contentstack is a content management system that facilitates the process of publication by separating the content from site-related programming and design.
9
+ # == Contentstack - Ruby SDK
10
+ # Contentstack is a content management system that facilitates the process of publication by separating the content from site-related programming and design.
10
11
  # == Installation
11
12
  # gem install contentstack
12
13
  # == Initialize the Stack
13
- # @stack = Contentstack::Client.new("site_api_key", "access_token", "enviroment_name")
14
+ # @stack = Contentstack::Client.new("site_api_key", "delivery_token", "enviroment_name")
15
+ # == Initialize the Stack for EU region
16
+ # @stack = Contentstack::Client.new("site_api_key", "delivery_token", "enviroment_name", {"region": Contentstack::Region::EU })
17
+ # == Initialize the Stack for custom host
18
+ # @stack = Contentstack::Client.new("site_api_key", "delivery_token", "enviroment_name", {"host": "https://custom-cdn.contentstack.com" })
14
19
  # == Usage
15
20
  # ==== Get single entry
16
21
  # @stack.content_type('blog').entry('<entry_uid_here>').fetch
@@ -6,11 +6,13 @@ require 'open-uri'
6
6
 
7
7
  module Contentstack
8
8
  class API
9
- def self.init_api(api_key, access_token, environment)
10
- @host = "https://cdn.contentstack.io"
9
+ def self.init_api(api_key, delivery_token, environment,host)
10
+ @host = host
11
11
  @api_version = '/v3'
12
12
  @environment = environment
13
- @headers = {api_key: api_key, access_token: access_token, user_agent: "ruby-sdk/#{Contentstack::VERSION}", environment: @environment}
13
+ @api_key = api_key
14
+ @access_token = delivery_token
15
+ @headers = {environment: @environment}
14
16
  end
15
17
 
16
18
  def self.fetch_content_types(uid="")
@@ -27,9 +29,9 @@ module Contentstack
27
29
  send_request(path, query)
28
30
  end
29
31
 
30
- def self.fetch_entry(content_type, entry_uid)
32
+ def self.fetch_entry(content_type, entry_uid, query)
31
33
  path = "/content_types/#{content_type}/entries/#{entry_uid}"
32
- send_request(path)
34
+ send_request(path, query)
33
35
  end
34
36
 
35
37
  def self.get_assets(asset_uid=nil)
@@ -43,12 +45,15 @@ module Contentstack
43
45
  q ||= {}
44
46
 
45
47
  q.merge!(@headers)
46
- q.merge!({timestamp: Time.now.to_i})
47
48
 
48
49
  query = "?" + q.to_query
49
50
  # puts "Request URL:- #{@host}#{@api_version}#{path}#{query} \n\n"
50
51
 
51
- ActiveSupport::JSON.decode(open("#{@host}#{@api_version}#{path}#{query}").read)
52
+ ActiveSupport::JSON.decode(open("#{@host}#{@api_version}#{path}#{query}",
53
+ "api_key" => @api_key,
54
+ "access_token"=> @access_token,
55
+ "user_agent"=> "ruby-sdk/#{Contentstack::VERSION}",
56
+ "x-user-agent" => "ruby-sdk/#{Contentstack::VERSION}").read)
52
57
  end
53
58
  end
54
- end
59
+ end
@@ -4,9 +4,12 @@ require 'contentstack/asset_collection'
4
4
 
5
5
  module Contentstack
6
6
  class Client
7
- # Initialize "Built.io Contentstack" Client instance
8
- def initialize(api_key, access_token, environment)
9
- API.init_api(api_key, access_token, environment)
7
+ attr_reader :region, :host
8
+ # Initialize "Contentstack" Client instance
9
+ def initialize(api_key, delivery_token, environment, options={})
10
+ @region = options[:region].nil? ? Contentstack::Region::US : options[:region]
11
+ @host = options[:host].nil? ? get_default_region_hosts(@region) : options[:host]
12
+ API.init_api(api_key, delivery_token, environment, @host)
10
13
  end
11
14
 
12
15
 
@@ -25,5 +28,16 @@ module Contentstack
25
28
  def asset(uid)
26
29
  Asset.new(uid)
27
30
  end
31
+
32
+ private
33
+ def get_default_region_hosts(region='us')
34
+ case region
35
+ when "us"
36
+ host = "https://cdn.contentstack.io"
37
+ when "eu"
38
+ host = "https://eu-cdn.contentstack.com"
39
+ end
40
+ host
41
+ end
28
42
  end
29
43
  end
@@ -44,7 +44,7 @@ module Contentstack
44
44
  end
45
45
  end
46
46
 
47
- def self.find_by_uid(uid)
47
+ def fetch
48
48
  content_type = API.fetch_content_types(uid)["content_type"]
49
49
  ContentType.new(content_type.inject({}){|clone,(k,v)| clone[k.to_sym] = v; clone})
50
50
  end
@@ -1,13 +1,179 @@
1
+ require 'active_support/core_ext'
2
+
1
3
  module Contentstack
2
4
  class Entry
3
- attr_reader :fields, :content_type, :uid, :owner
5
+ attr_reader :fields, :content_type, :uid, :owner, :query, :schema, :content_type
4
6
  def initialize(attrs, content_type_uid=nil)
5
7
  setup(attrs, content_type_uid)
6
8
  end
7
9
 
10
+ # Get entries from the specified locale.
11
+ #
12
+ # @param [String] code The locale code of the entry
13
+ #
14
+ # Example
15
+ # @entry = @stack.content_type('category').entry(entry_uid)
16
+ # @entry.locale('en-us')
17
+ #
18
+ # @return [Contentstack::Entry]
19
+ def locale(code)
20
+ @query[:locale] = code
21
+ self
22
+ end
23
+
24
+ # Specifies an array of 'only' keys in BASE object that would be 'included' in the response.
25
+ #
26
+ # @param [Array] fields Array of the 'only' reference keys to be included in response.
27
+ # @param [Array] fields_with_base Can be used to denote 'only' fields of the reference class
28
+ #
29
+ # Example
30
+ # # Include only title and description field in response
31
+ # @entry = @stack.content_type('category').entry(entry_uid)
32
+ # @entry.only(['title', 'description'])
33
+ #
34
+ # # Query product and include only the title and description from category reference
35
+ # @entry = @stack.content_type('product').entry(entry_uid)
36
+ # @entry.include_reference('category')
37
+ # .only('category', ['title', 'description'])
38
+ #
39
+ # @return [Contentstack::Entry]
40
+ def only(fields, fields_with_base=nil)
41
+ q = {}
42
+ if [Array, String].include?(fields_with_base.class)
43
+ fields_with_base = [fields_with_base] if fields_with_base.class == String
44
+ q[fields.to_sym] = fields_with_base
45
+ else
46
+ fields = [fields] if fields.class == String
47
+ q = {BASE: fields}
48
+ end
49
+
50
+ @query[:only] = q
51
+ self
52
+ end
53
+
54
+ # Specifies list of field uids that would be 'excluded' from the response.
55
+ #
56
+ # @param [Array] fields Array of field uid which get 'excluded' from the response.
57
+ # @param [Array] fields_with_base Can be used to denote 'except' fields of the reference class
58
+ #
59
+ # Example
60
+ # # Exclude 'description' field in response
61
+ # @entry = @stack.content_type('category').entry(entry_uid)
62
+ # @entry.except(['description'])
63
+ #
64
+ # # Query product and exclude the 'description' from category reference
65
+ # @entry = @stack.content_type('product').entry(entry_uid)
66
+ # @entry.include_reference('category')
67
+ # .except('category', ['description'])
68
+ #
69
+ # @return [Contentstack::Entry]
70
+ def except(fields, fields_with_base=nil)
71
+ q = {}
72
+ if [Array, String].include?(fields_with_base.class)
73
+ fields_with_base = [fields_with_base] if fields_with_base.class == String
74
+ q[fields.to_sym] = fields_with_base
75
+ else
76
+ fields = [fields] if fields.class == String
77
+ q = {BASE: fields}
78
+ end
79
+
80
+ @query[:except] = q
81
+ self
82
+ end
83
+
84
+ # Add a constraint that requires a particular reference key details.
85
+ #
86
+ # @param [String/Array] reference_field_uids Pass string or array of reference fields that must be included in the response
87
+ #
88
+ # Example
89
+ #
90
+ # # Include reference of 'category'
91
+ # @entry = @stack.content_type('product').entry(entry_uid)
92
+ # @entry.include_reference('category')
93
+ #
94
+ # # Include reference of 'category' and 'reviews'
95
+ # @entry = @stack.content_type('product').entry(entry_uid)
96
+ # @entry.include_reference(['category', 'reviews'])
97
+ #
98
+ # @return [Contentstack::Entry]
99
+ def include_reference(reference_field_uids)
100
+ self.include(reference_field_uids)
101
+ end
102
+
103
+ # Include schemas of all returned objects along with objects themselves.
104
+ #
105
+ # Example
106
+ #
107
+ # @entry = @stack.content_type('product').entry(entry_uid)
108
+ # @entry.include_schema
109
+ #
110
+ # @return [Contentstack::Entry]
111
+ def include_schema(flag=true)
112
+ @query[:include_schema] = flag
113
+ self
114
+ end
115
+
116
+ # Include object owner's profile in the objects data.
117
+ #
118
+ # Example
119
+ #
120
+ # @entry = @stack.content_type('product').entry(entry_uid)
121
+ # @entry.include_owner
122
+ #
123
+ # @return [Contentstack::Entry]
124
+ def include_owner(flag=true)
125
+ @query[:include_owner] = flag
126
+ self
127
+ end
128
+
129
+ # Include object's content_type in response
130
+ #
131
+ # Example
132
+ #
133
+ # @entry = @stack.content_type('product').entry(entry_uid)
134
+ # @entry.include_content_type
135
+ #
136
+ # @return [Contentstack::Entry]
137
+ def include_content_type(flag=true)
138
+ @query[:include_content_type] = flag
139
+ self
140
+ end
141
+
142
+ # Include the fallback locale publish content, if specified locale content is not publish.
143
+ #
144
+ # Example
145
+ #
146
+ # @entry = @stack.content_type('product').entry(entry_uid)
147
+ # @entry.include_fallback
148
+ #
149
+ # @return [Contentstack::Entry]
150
+ def include_fallback(flag=true)
151
+ @query[:include_fallback] = flag
152
+ self
153
+ end
154
+
155
+ #
156
+ # @return [Contentstack::Query]
157
+ def include(field_uids)
158
+ field_uids = [field_uids] if field_uids.class == String
159
+ @query[:include] ||= []
160
+ @query[:include] = @query[:include] | field_uids
161
+ self
162
+ end
163
+
164
+ # Execute entry
165
+ #
166
+ # Example
167
+ #
168
+ # @entry = @stack.content_type('product').entry(entry_uid)
169
+ # @entry.fetch
170
+ #
171
+ # @return [Contentstack::EntryCollection]
8
172
  def fetch
9
- entry = API.fetch_entry(@content_type, self.fields[:uid])
173
+ entry = API.fetch_entry(@content_type, self.fields[:uid], @query)
10
174
  setup(entry["entry"])
175
+ @schema = entry["schema"].symbolize_keys if entry["schema"]
176
+ @content_type = entry["content_type"].symbolize_keys if entry["content_type"]
11
177
  self
12
178
  end
13
179
 
@@ -22,6 +188,7 @@ module Contentstack
22
188
  @content_type = content_type_uid if !content_type_uid.blank?
23
189
  @owner = attrs[:_owner] if attrs[:_owner]
24
190
  @uid = attrs[:uid]
191
+ @query = {}
25
192
  end
26
193
  end
27
194
  end
@@ -370,6 +370,20 @@ module Contentstack
370
370
  self
371
371
  end
372
372
 
373
+ # Get entries from the specified locale.
374
+ #
375
+ # @param [String] code The locale code of the entry
376
+ #
377
+ # Example
378
+ # @query = @stack.content_type('category').query
379
+ # @query.locale('en-us')
380
+ #
381
+ # @return [Contentstack::Query]
382
+ def locale(code)
383
+ @query[:locale] = code
384
+ self
385
+ end
386
+
373
387
  # Specifies an array of 'only' keys in BASE object that would be 'included' in the response.
374
388
  #
375
389
  # @param [Array] fields Array of the 'only' reference keys to be included in response.
@@ -488,6 +502,20 @@ module Contentstack
488
502
  self
489
503
  end
490
504
 
505
+
506
+ # Include the fallback locale publish content, if specified locale content is not publish.
507
+ #
508
+ # Example
509
+ #
510
+ # @query = @stack.content_type('product').query
511
+ # @query.include_fallback
512
+ #
513
+ # @return [Contentstack::Query]
514
+ def include_fallback(flag=true)
515
+ @query[:include_fallback] = flag
516
+ self
517
+ end
518
+
491
519
  # Include objects in 'Draft' mode in response
492
520
  #
493
521
  # Example
@@ -0,0 +1,6 @@
1
+ module Contentstack
2
+ class Region
3
+ EU='eu'
4
+ US='us'
5
+ end
6
+ end
@@ -1,3 +1,3 @@
1
1
  module Contentstack
2
- VERSION = "0.0.2"
2
+ VERSION = "0.2.1"
3
3
  end
@@ -3,6 +3,8 @@ require_relative '../lib/contentstack.rb'
3
3
 
4
4
  describe Contentstack::ContentType do
5
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"}) }
6
8
 
7
9
  describe "Fetch data from API" do
8
10
  it "has class as Contentstack::ContentType" do
@@ -14,6 +16,16 @@ describe Contentstack::ContentType do
14
16
  @data = client.content_types.first
15
17
  expect(@data.title).not_to be nil
16
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
17
29
 
18
30
  it "has method called uid with data" do
19
31
  @data = client.content_types.first
@@ -34,6 +46,11 @@ describe Contentstack::ContentType do
34
46
  @data = client.content_types.first
35
47
  expect(@data.attributes).not_to be nil
36
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
37
54
  end
38
55
 
39
56
  describe "Initialized using class" do
@@ -3,8 +3,30 @@ require_relative '../lib/contentstack.rb'
3
3
 
4
4
  describe Contentstack do
5
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"}) }
6
8
 
7
9
  it "has a version number" do
8
10
  expect(Contentstack::VERSION).not_to be nil
9
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
+
10
32
  end
@@ -3,6 +3,10 @@ require_relative '../lib/contentstack.rb'
3
3
 
4
4
  describe Contentstack::Entry do
5
5
  let(:client) { create_client }
6
+ let(:uid) { "blt05056a2f5e0ebf76" }
7
+
8
+ let(:category) {client.content_type("category").entry(uid)}
9
+ let(:product) {client.content_type("product").entry(uid)}
6
10
 
7
11
  it "Contentstack::EntryCollection should have Contentstack::Entry instance" do
8
12
  data = client.content_type("category").query.fetch
@@ -11,13 +15,75 @@ describe Contentstack::Entry do
11
15
  end
12
16
 
13
17
  it "is an instance of Contentstack::Entry if single entry is fetched" do
14
- data = client.content_type("category").entry("blt05056a2f5e0ebf76").fetch
18
+ data = category.fetch
15
19
  expect(data.class).to eq Contentstack::Entry
16
20
  end
17
21
 
18
22
  it 'has a method `get` to get attributes data' do
19
- uid = "blt05056a2f5e0ebf76"
20
- data = client.content_type("category").entry(uid).fetch
23
+ data = category.fetch
21
24
  expect(data.get('uid')).to eq uid
22
25
  end
26
+
27
+ it "should set locale the in the request entry" do
28
+ data = category.locale('en-us')
29
+ expect(data.query[:locale]).to eq 'en-us'
30
+ end
31
+
32
+ it "should get data using `only` method with string parameter" do
33
+ data = category.fetch
34
+ expect(data.fields[:title]).not_to be nil
35
+ expect(data.fields[:uid]).not_to be nil
36
+ end
37
+
38
+ it "should get data using `only` method with array parameter" do
39
+ data = category.only(["title"]).fetch
40
+ expect(data.fields[:title]).not_to be nil
41
+ expect(data.fields[:uid]).not_to be nil
42
+ end
43
+
44
+ it "should get data using `except` method with string parameter" do
45
+ data = category.except("category_tags").fetch
46
+ expect(data.fields[:category_tags]).to be nil
47
+ end
48
+
49
+ it "should get data using `except` method with array parameter" do
50
+ data = category.except(["description"]).fetch
51
+ expect(data.fields[:description]).to be nil
52
+ end
53
+
54
+ it "should get data using `only` method for reference fields" do
55
+ data = product.include_reference('categories').only("categories", ["title", "description"]).fetch
56
+ expect(data.fields[:categories][0][:title]).to eq "Smartphones"
57
+ end
58
+
59
+ it "should get data using `except` method for reference fields" do
60
+ data = product.include_reference('categories').except("categories", "title").fetch
61
+ expect(data.fields[:categories][0][:title]).to eq 'Smartphones'
62
+ end
63
+
64
+ it "should get data using `include_schema` method" do
65
+ data = category.include_schema.fetch
66
+ expect(data.schema).not_to be nil
67
+ end
68
+
69
+ it "should get data using `include_owner` method" do
70
+ data = product.include_owner.fetch
71
+ expect(data.fields[:_owner]).not_to be nil
72
+ end
73
+
74
+ it "should get data using `include_owner` method" do
75
+ data = product.include_fallback.fetch
76
+ expect(data.fields[:locale]).not_to be nil
77
+ end
78
+
79
+ it "should get data using `include_content_type` method" do
80
+ data = category.include_content_type.fetch
81
+ expect(data.content_type).not_to be nil
82
+ end
83
+
84
+ it "should get data using `include_reference` method" do
85
+ data = product.include_reference('categories').fetch
86
+ puts data.get("categories.title")
87
+ expect(data.fields[:categories][0][:title]).not_to be nil
88
+ end
23
89
  end
@@ -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":"blt922581483b3573b4","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":"blt249905a2fc79092e","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":"bltdbf78d599f92b0c9","read":true,"create":false,"update":false,"delete":false,"sub_acl":{"read":true,"create":true,"update":true,"delete":true,"publish":true}},{"uid":"blt344db9f3f8011ce2","read":true,"create":true,"update":true,"delete":true,"sub_acl":{"read":true,"create":true,"update":true,"delete":true,"publish":true}}]}}}
@@ -1 +1 @@
1
- {"entry":{"title":"Apple Products","tags":[],"locale":"en-us","uid":"blt05056a2f5e0ebf76","created_by":"sys_bltcbfe73b68603b243","updated_by":"sys_bltcbfe73b68603b243","created_at":"2017-09-28T06:08:21.276Z","updated_at":"2017-09-28T06:08:21.276Z","ACL":{},"_version":1}}
1
+ {"entry":{"title":"Apple Products","tags":[],"locale":"en-us","uid":"blt05056a2f5e0ebf76","created_by":"sys_bltcbfe73b68603b243","updated_by":"sys_bltcbfe73b68603b243","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":"bltc5173a61bc94f944","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":"blt8360496f808a5408","read":true,"sub_acl":{"read":true}}]}}}
@@ -1 +1 @@
1
- {"entry":{"title":"Motorola Moto X4","url":"/products/blt70d3d8c86c566079","price":"500","discounted_price":"450","featured_image":{"uid":"bltcf9489a3cf1eaa00","created_at":"2017-09-28T07:02:20.745Z","updated_at":"2017-09-28T07:02:20.745Z","created_by":"sys_bltcbfe73b68603b243","updated_by":"sys_bltcbfe73b68603b243","content_type":"image/jpeg","file_size":"311812","tags":[],"filename":"1.jpg","url":"https://images.contentstack.io/v3/assets/bltc46be1ce6b7e1e24/bltcf9489a3cf1eaa00/59cc9e7c75d9f7760dfc33eb/download","ACL":{},"is_dir":false,"_version":1,"title":"1.jpg","publish_details":{"environment":"blt922581483b3573b4","locale":"en-us","time":"2017-09-28T09:28:47.919Z","user":"sys_bltcbfe73b68603b243"}},"product_images":[{"uid":"bltcf9489a3cf1eaa00","created_at":"2017-09-28T07:02:20.745Z","updated_at":"2017-09-28T07:02:20.745Z","created_by":"sys_bltcbfe73b68603b243","updated_by":"sys_bltcbfe73b68603b243","content_type":"image/jpeg","file_size":"311812","tags":[],"filename":"1.jpg","url":"https://images.contentstack.io/v3/assets/bltc46be1ce6b7e1e24/bltcf9489a3cf1eaa00/59cc9e7c75d9f7760dfc33eb/download","ACL":{},"is_dir":false,"_version":1,"title":"1.jpg","publish_details":{"environment":"blt922581483b3573b4","locale":"en-us","time":"2017-09-28T09:28:47.919Z","user":"sys_bltcbfe73b68603b243"}},{"uid":"blt49a8b46c6839be12","created_at":"2017-09-28T07:02:30.108Z","updated_at":"2017-09-28T07:02:30.108Z","created_by":"sys_bltcbfe73b68603b243","updated_by":"sys_bltcbfe73b68603b243","content_type":"image/jpeg","file_size":"4226","tags":[],"filename":"2.jpg","url":"https://images.contentstack.io/v3/assets/bltc46be1ce6b7e1e24/blt49a8b46c6839be12/59cc9e86462a293417404402/download","ACL":{},"is_dir":false,"_version":1,"title":"2.jpg","publish_details":{"environment":"blt922581483b3573b4","locale":"en-us","time":"2017-09-28T09:28:47.919Z","user":"sys_bltcbfe73b68603b243"}},{"uid":"bltb545ae58b0ab72bb","created_at":"2017-09-28T07:02:32.375Z","updated_at":"2017-09-28T07:02:32.375Z","created_by":"sys_bltcbfe73b68603b243","updated_by":"sys_bltcbfe73b68603b243","content_type":"image/jpeg","file_size":"5755","tags":[],"filename":"3.jpg","url":"https://images.contentstack.io/v3/assets/bltc46be1ce6b7e1e24/bltb545ae58b0ab72bb/59cc9e8895fd2a0a0daa742a/download","ACL":{},"is_dir":false,"_version":1,"title":"3.jpg","publish_details":{"environment":"blt922581483b3573b4","locale":"en-us","time":"2017-09-28T09:28:47.919Z","user":"sys_bltcbfe73b68603b243"}},{"uid":"blt6af2dddde9d35e3c","created_at":"2017-09-28T07:02:36.507Z","updated_at":"2017-09-28T07:02:36.507Z","created_by":"sys_bltcbfe73b68603b243","updated_by":"sys_bltcbfe73b68603b243","content_type":"image/jpeg","file_size":"312464","tags":[],"filename":"4.jpg","url":"https://images.contentstack.io/v3/assets/bltc46be1ce6b7e1e24/blt6af2dddde9d35e3c/59cc9e8c75d9f7760dfc33f1/download","ACL":{},"is_dir":false,"_version":1,"title":"4.jpg","publish_details":{"environment":"blt922581483b3573b4","locale":"en-us","time":"2017-09-28T09:28:47.919Z","user":"sys_bltcbfe73b68603b243"}}],"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":"bltccd0ea06c1da94fd","created_by":"sys_bltcbfe73b68603b243","updated_by":"sys_bltcbfe73b68603b243","created_at":"2017-09-28T06:07:37.132Z","updated_at":"2017-09-28T06:07:37.132Z","ACL":{},"_version":1,"publish_details":{"environment":"blt922581483b3573b4","locale":"en-us","time":"2017-09-28T09:28:47.932Z","user":"sys_bltcbfe73b68603b243"},"_publish_environment":"blt922581483b3573b4","_publish_locale":"en-us","_publish_scheduled":false}],"related_products":[{"title":"OnePlus 3T A3000 64GB Gunmetal","url":"/products/bltc37f44d9bc85f3ec","price":"539","discounted_price":"499","featured_image":{"uid":"blt2f02748d62b5d9df","created_at":"2017-09-28T06:56:13.016Z","updated_at":"2017-09-28T06:56:13.016Z","created_by":"sys_bltcbfe73b68603b243","updated_by":"sys_bltcbfe73b68603b243","content_type":"image/jpeg","file_size":"40674","tags":[],"filename":"one-plus-three-1x.jpg","url":"https://images.contentstack.io/v3/assets/bltc46be1ce6b7e1e24/blt2f02748d62b5d9df/59cc9d0d95fd2a0a0daa7424/download","ACL":{},"is_dir":false,"_version":1,"title":"one-plus-three-1x.jpg","publish_details":{"environment":"blt922581483b3573b4","locale":"en-us","time":"2017-09-28T09:42:37.885Z","user":"sys_bltcbfe73b68603b243"}},"product_images":[{"uid":"blt2f02748d62b5d9df","created_at":"2017-09-28T06:56:13.016Z","updated_at":"2017-09-28T06:56:13.016Z","created_by":"sys_bltcbfe73b68603b243","updated_by":"sys_bltcbfe73b68603b243","content_type":"image/jpeg","file_size":"40674","tags":[],"filename":"one-plus-three-1x.jpg","url":"https://images.contentstack.io/v3/assets/bltc46be1ce6b7e1e24/blt2f02748d62b5d9df/59cc9d0d95fd2a0a0daa7424/download","ACL":{},"is_dir":false,"_version":1,"title":"one-plus-three-1x.jpg","publish_details":{"environment":"blt922581483b3573b4","locale":"en-us","time":"2017-09-28T09:42:37.885Z","user":"sys_bltcbfe73b68603b243"}},{"uid":"bltf061d797179b0013","created_at":"2017-09-28T06:56:20.954Z","updated_at":"2017-09-28T06:56:20.954Z","created_by":"sys_bltcbfe73b68603b243","updated_by":"sys_bltcbfe73b68603b243","content_type":"image/jpeg","file_size":"13187","tags":[],"filename":"one-plus-3-2.jpg","url":"https://images.contentstack.io/v3/assets/bltc46be1ce6b7e1e24/bltf061d797179b0013/59cc9d1475d9f7760dfc33e5/download","ACL":{},"is_dir":false,"_version":1,"title":"one-plus-3-2.jpg","publish_details":{"environment":"blt922581483b3573b4","locale":"en-us","time":"2017-09-28T09:42:31.431Z","user":"sys_bltcbfe73b68603b243"}},{"uid":"blt7469869415aa6d33","created_at":"2017-09-28T06:56:24.656Z","updated_at":"2017-09-28T06:56:24.656Z","created_by":"sys_bltcbfe73b68603b243","updated_by":"sys_bltcbfe73b68603b243","content_type":"image/jpeg","file_size":"27485","tags":[],"filename":"one-plus-3-3.jpg","url":"https://images.contentstack.io/v3/assets/bltc46be1ce6b7e1e24/blt7469869415aa6d33/59cc9d183ef8e08c0d90ce29/download","ACL":{},"is_dir":false,"_version":1,"title":"one-plus-3-3.jpg","publish_details":{"environment":"blt922581483b3573b4","locale":"en-us","time":"2017-09-28T09:42:26.882Z","user":"sys_bltcbfe73b68603b243"}}],"description":"Snapdragon 821 6gb RAM Unlocked Smartphone","categories":["bltccd0ea06c1da94fd"],"related_products":["blt6c4014da5a782a25"],"tags":[],"locale":"en-us","uid":"bltc37f44d9bc85f3ec","created_by":"sys_bltcbfe73b68603b243","updated_by":"sys_bltcbfe73b68603b243","created_at":"2017-09-28T06:57:55.574Z","updated_at":"2017-09-28T06:57:55.574Z","ACL":{},"_version":1,"publish_details":{"environment":"blt922581483b3573b4","locale":"en-us","time":"2017-09-28T09:28:47.933Z","user":"sys_bltcbfe73b68603b243"},"_publish_environment":"blt922581483b3573b4","_publish_locale":"en-us","_publish_scheduled":false}],"tags":[],"locale":"en-us","uid":"blt70d3d8c86c566079","created_by":"sys_bltcbfe73b68603b243","updated_by":"sys_bltcbfe73b68603b243","created_at":"2017-09-28T07:03:11.350Z","updated_at":"2017-09-28T07:03:11.350Z","ACL":{},"_version":1}}
1
+ {"entry":{"title":"Motorola Moto X4","url":"/products/blt70d3d8c86c566079","price":"500","discounted_price":"450","featured_image":{"uid":"bltcf9489a3cf1eaa00","created_at":"2017-09-28T07:02:20.745Z","updated_at":"2017-09-28T07:02:20.745Z","created_by":"sys_bltcbfe73b68603b243","updated_by":"sys_bltcbfe73b68603b243","content_type":"image/jpeg","file_size":"311812","tags":[],"filename":"1.jpg","url":"https://images.contentstack.io/v3/assets/bltc46be1ce6b7e1e24/bltcf9489a3cf1eaa00/59cc9e7c75d9f7760dfc33eb/download","ACL":{},"is_dir":false,"_version":1,"title":"1.jpg","publish_details":{"environment":"blt922581483b3573b4","locale":"en-us","time":"2017-09-28T09:28:47.919Z","user":"sys_bltcbfe73b68603b243"}},"product_images":[{"uid":"bltcf9489a3cf1eaa00","created_at":"2017-09-28T07:02:20.745Z","updated_at":"2017-09-28T07:02:20.745Z","created_by":"sys_bltcbfe73b68603b243","updated_by":"sys_bltcbfe73b68603b243","content_type":"image/jpeg","file_size":"311812","tags":[],"filename":"1.jpg","url":"https://images.contentstack.io/v3/assets/bltc46be1ce6b7e1e24/bltcf9489a3cf1eaa00/59cc9e7c75d9f7760dfc33eb/download","ACL":{},"is_dir":false,"_version":1,"title":"1.jpg","publish_details":{"environment":"blt922581483b3573b4","locale":"en-us","time":"2017-09-28T09:28:47.919Z","user":"sys_bltcbfe73b68603b243"}},{"uid":"blt49a8b46c6839be12","created_at":"2017-09-28T07:02:30.108Z","updated_at":"2017-09-28T07:02:30.108Z","created_by":"sys_bltcbfe73b68603b243","updated_by":"sys_bltcbfe73b68603b243","content_type":"image/jpeg","file_size":"4226","tags":[],"filename":"2.jpg","url":"https://images.contentstack.io/v3/assets/bltc46be1ce6b7e1e24/blt49a8b46c6839be12/59cc9e86462a293417404402/download","ACL":{},"is_dir":false,"_version":1,"title":"2.jpg","publish_details":{"environment":"blt922581483b3573b4","locale":"en-us","time":"2017-09-28T09:28:47.919Z","user":"sys_bltcbfe73b68603b243"}},{"uid":"bltb545ae58b0ab72bb","created_at":"2017-09-28T07:02:32.375Z","updated_at":"2017-09-28T07:02:32.375Z","created_by":"sys_bltcbfe73b68603b243","updated_by":"sys_bltcbfe73b68603b243","content_type":"image/jpeg","file_size":"5755","tags":[],"filename":"3.jpg","url":"https://images.contentstack.io/v3/assets/bltc46be1ce6b7e1e24/bltb545ae58b0ab72bb/59cc9e8895fd2a0a0daa742a/download","ACL":{},"is_dir":false,"_version":1,"title":"3.jpg","publish_details":{"environment":"blt922581483b3573b4","locale":"en-us","time":"2017-09-28T09:28:47.919Z","user":"sys_bltcbfe73b68603b243"}},{"uid":"blt6af2dddde9d35e3c","created_at":"2017-09-28T07:02:36.507Z","updated_at":"2017-09-28T07:02:36.507Z","created_by":"sys_bltcbfe73b68603b243","updated_by":"sys_bltcbfe73b68603b243","content_type":"image/jpeg","file_size":"312464","tags":[],"filename":"4.jpg","url":"https://images.contentstack.io/v3/assets/bltc46be1ce6b7e1e24/blt6af2dddde9d35e3c/59cc9e8c75d9f7760dfc33f1/download","ACL":{},"is_dir":false,"_version":1,"title":"4.jpg","publish_details":{"environment":"blt922581483b3573b4","locale":"en-us","time":"2017-09-28T09:28:47.919Z","user":"sys_bltcbfe73b68603b243"}}],"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":"bltccd0ea06c1da94fd","created_by":"sys_bltcbfe73b68603b243","updated_by":"sys_bltcbfe73b68603b243","created_at":"2017-09-28T06:07:37.132Z","updated_at":"2017-09-28T06:07:37.132Z","ACL":{},"_version":1,"publish_details":{"environment":"blt922581483b3573b4","locale":"en-us","time":"2017-09-28T09:28:47.932Z","user":"sys_bltcbfe73b68603b243"},"_publish_environment":"blt922581483b3573b4","_publish_locale":"en-us","_publish_scheduled":false}],"related_products":[{"title":"OnePlus 3T A3000 64GB Gunmetal","url":"/products/bltc37f44d9bc85f3ec","price":"539","discounted_price":"499","featured_image":{"uid":"blt2f02748d62b5d9df","created_at":"2017-09-28T06:56:13.016Z","updated_at":"2017-09-28T06:56:13.016Z","created_by":"sys_bltcbfe73b68603b243","updated_by":"sys_bltcbfe73b68603b243","content_type":"image/jpeg","file_size":"40674","tags":[],"filename":"one-plus-three-1x.jpg","url":"https://images.contentstack.io/v3/assets/bltc46be1ce6b7e1e24/blt2f02748d62b5d9df/59cc9d0d95fd2a0a0daa7424/download","ACL":{},"is_dir":false,"_version":1,"title":"one-plus-three-1x.jpg","publish_details":{"environment":"blt922581483b3573b4","locale":"en-us","time":"2017-09-28T09:42:37.885Z","user":"sys_bltcbfe73b68603b243"}},"product_images":[{"uid":"blt2f02748d62b5d9df","created_at":"2017-09-28T06:56:13.016Z","updated_at":"2017-09-28T06:56:13.016Z","created_by":"sys_bltcbfe73b68603b243","updated_by":"sys_bltcbfe73b68603b243","content_type":"image/jpeg","file_size":"40674","tags":[],"filename":"one-plus-three-1x.jpg","url":"https://images.contentstack.io/v3/assets/bltc46be1ce6b7e1e24/blt2f02748d62b5d9df/59cc9d0d95fd2a0a0daa7424/download","ACL":{},"is_dir":false,"_version":1,"title":"one-plus-three-1x.jpg","publish_details":{"environment":"blt922581483b3573b4","locale":"en-us","time":"2017-09-28T09:42:37.885Z","user":"sys_bltcbfe73b68603b243"}},{"uid":"bltf061d797179b0013","created_at":"2017-09-28T06:56:20.954Z","updated_at":"2017-09-28T06:56:20.954Z","created_by":"sys_bltcbfe73b68603b243","updated_by":"sys_bltcbfe73b68603b243","content_type":"image/jpeg","file_size":"13187","tags":[],"filename":"one-plus-3-2.jpg","url":"https://images.contentstack.io/v3/assets/bltc46be1ce6b7e1e24/bltf061d797179b0013/59cc9d1475d9f7760dfc33e5/download","ACL":{},"is_dir":false,"_version":1,"title":"one-plus-3-2.jpg","publish_details":{"environment":"blt922581483b3573b4","locale":"en-us","time":"2017-09-28T09:42:31.431Z","user":"sys_bltcbfe73b68603b243"}},{"uid":"blt7469869415aa6d33","created_at":"2017-09-28T06:56:24.656Z","updated_at":"2017-09-28T06:56:24.656Z","created_by":"sys_bltcbfe73b68603b243","updated_by":"sys_bltcbfe73b68603b243","content_type":"image/jpeg","file_size":"27485","tags":[],"filename":"one-plus-3-3.jpg","url":"https://images.contentstack.io/v3/assets/bltc46be1ce6b7e1e24/blt7469869415aa6d33/59cc9d183ef8e08c0d90ce29/download","ACL":{},"is_dir":false,"_version":1,"title":"one-plus-3-3.jpg","publish_details":{"environment":"blt922581483b3573b4","locale":"en-us","time":"2017-09-28T09:42:26.882Z","user":"sys_bltcbfe73b68603b243"}}],"description":"Snapdragon 821 6gb RAM Unlocked Smartphone","categories":["bltccd0ea06c1da94fd"],"related_products":["blt6c4014da5a782a25"],"tags":[],"locale":"en-us","uid":"bltc37f44d9bc85f3ec","created_by":"sys_bltcbfe73b68603b243","updated_by":"sys_bltcbfe73b68603b243","created_at":"2017-09-28T06:57:55.574Z","updated_at":"2017-09-28T06:57:55.574Z","ACL":{},"_version":1,"publish_details":{"environment":"blt922581483b3573b4","locale":"en-us","time":"2017-09-28T09:28:47.933Z","user":"sys_bltcbfe73b68603b243"},"_publish_environment":"blt922581483b3573b4","_publish_locale":"en-us","_publish_scheduled":false}],"tags":[],"locale":"en-us","uid":"blt70d3d8c86c566079","created_by":"sys_bltcbfe73b68603b243","updated_by":"sys_bltcbfe73b68603b243","created_at":"2017-09-28T07:03:11.350Z","updated_at":"2017-09-28T07:03:11.350Z","ACL":{},"_version":1, "_owner":{"uid":"sys_bltcbfe73b68603b243","created_at":"2012-11-26T09:45:10.000Z","updated_at":"2017-09-15T16:06:07.920Z","email":"rohit.sharma@raweng.com","username":"rohit.sharma_blt50c79ab1","first_name":"Rohit","last_name":"Sharma","company":"raw engineering inc.","plan_id":["cms_plan"],"org_uid":["blt821f82ffcc171fed"]}}}
@@ -54,7 +54,7 @@ describe Contentstack::Query do
54
54
  it "should get data using `include_count` method" do
55
55
  data = category_query.include_count.fetch
56
56
  expect(data.count).not_to be nil
57
- expect(data.count.class).to be Integer
57
+ expect(data.count).to eq 5
58
58
  end
59
59
 
60
60
  it "should get data using `only` method with string parameter" do
@@ -147,6 +147,11 @@ describe Contentstack::Query do
147
147
  expect(data.first.fields[:_owner]).not_to be nil
148
148
  end
149
149
 
150
+ it "should get data using `include_owner` method" do
151
+ data = product_query.include_fallback.fetch
152
+ expect(data.first.fields[:locale]).not_to be nil
153
+ end
154
+
150
155
  it "should get data using `include_draft` method" do
151
156
  data = category_query.include_draft.fetch
152
157
  expect(data.length).to eq 5
@@ -185,4 +190,9 @@ describe Contentstack::Query do
185
190
  data = category_query.or([q1,q2]).fetch
186
191
  expect(data.length).to eq 5
187
192
  end
193
+
194
+ it "should set locale the in the request query" do
195
+ data = product_query.locale('en-us')
196
+ expect(data.query[:locale]).to eq 'en-us'
197
+ end
188
198
  end
@@ -107,10 +107,22 @@ RSpec.configure do |config|
107
107
  =end
108
108
 
109
109
  config.before(:each) do
110
- stub_request(:get, /cdn.contentstack.io\/v3\/content_types/).
110
+ stub_request(:get, /custom-cdn.contentstack.com\/v3\/content_types/).
111
+ with(headers: {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Ruby'}).
112
+ to_return(:status => 200, :body => File.read(File.dirname(__FILE__) + '/fixtures/content_types.json'), :headers => {})
113
+
114
+ stub_request(:get, /eu-cdn.contentstack.com\/v3\/content_types/).
111
115
  with(headers: {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Ruby'}).
112
116
  to_return(:status => 200, :body => File.read(File.dirname(__FILE__) + '/fixtures/content_types.json'), :headers => {})
113
117
 
118
+ stub_request(:get, /cdn.contentstack.io\/v3\/content_types/).
119
+ with(headers: {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Ruby'}).
120
+ to_return(:status => 200, :body => File.read(File.dirname(__FILE__) + '/fixtures/content_types.json'), :headers => {})
121
+
122
+ stub_request(:get, /cdn.contentstack.io\/v3\/content_types\/category/).
123
+ with(headers: {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Ruby'}).
124
+ to_return(:status => 200, :body => File.read(File.dirname(__FILE__) + '/fixtures/category_content_type.json'), :headers => {})
125
+
114
126
  stub_request(:get, /cdn.contentstack.io\/v3\/assets/).
115
127
  with(headers: {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Ruby'}).
116
128
  to_return(:status => 200, :body => File.read(File.dirname(__FILE__) + '/fixtures/asset_collection.json'), :headers => {})
@@ -140,7 +152,7 @@ RSpec.configure do |config|
140
152
  to_return(:status => 200, :body => File.read(File.dirname(__FILE__) + '/fixtures/category_entry.json'), :headers => {})
141
153
  end
142
154
 
143
- def create_client(access_token = ENV['ACCESS_TOKEN'], api_key = ENV['API_KEY'], environment = ENV['STACK_ENV'])
144
- Contentstack::Client.new(access_token, api_key, environment)
155
+ def create_client(delivery_token = ENV['ACCESS_TOKEN'], api_key = ENV['API_KEY'], environment = ENV['STACK_ENV'], options = {})
156
+ Contentstack::Client.new(delivery_token, api_key, environment, options)
145
157
  end
146
158
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: contentstack
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
- - Rohit Sharma
8
- autorequire:
7
+ - Contentstack
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-10-11 00:00:00.000000000 Z
11
+ date: 2020-12-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -68,44 +68,23 @@ dependencies:
68
68
  version: '0'
69
69
  description: Contentstack Ruby client for the Content Delivery API
70
70
  email:
71
- - rubygems@contentstack.com
71
+ - support@contentstack.com
72
72
  executables: []
73
73
  extensions: []
74
74
  extra_rdoc_files: []
75
75
  files:
76
76
  - ".gitignore"
77
77
  - ".yardopts"
78
+ - CHANGELOG.md
78
79
  - CODE_OF_CONDUCT.md
80
+ - Gemfile
81
+ - Gemfile.lock
79
82
  - LICENSE.txt
80
- - README.rdoc
83
+ - README.md
81
84
  - contentstack.gemspec
82
85
  - coverage/.last_run.json
83
86
  - coverage/.resultset.json
84
87
  - coverage/.resultset.json.lock
85
- - coverage/assets/0.10.2/application.css
86
- - coverage/assets/0.10.2/application.js
87
- - coverage/assets/0.10.2/colorbox/border.png
88
- - coverage/assets/0.10.2/colorbox/controls.png
89
- - coverage/assets/0.10.2/colorbox/loading.gif
90
- - coverage/assets/0.10.2/colorbox/loading_background.png
91
- - coverage/assets/0.10.2/favicon_green.png
92
- - coverage/assets/0.10.2/favicon_red.png
93
- - coverage/assets/0.10.2/favicon_yellow.png
94
- - coverage/assets/0.10.2/loading.gif
95
- - coverage/assets/0.10.2/magnify.png
96
- - coverage/assets/0.10.2/smoothness/images/ui-bg_flat_0_aaaaaa_40x100.png
97
- - coverage/assets/0.10.2/smoothness/images/ui-bg_flat_75_ffffff_40x100.png
98
- - coverage/assets/0.10.2/smoothness/images/ui-bg_glass_55_fbf9ee_1x400.png
99
- - coverage/assets/0.10.2/smoothness/images/ui-bg_glass_65_ffffff_1x400.png
100
- - coverage/assets/0.10.2/smoothness/images/ui-bg_glass_75_dadada_1x400.png
101
- - coverage/assets/0.10.2/smoothness/images/ui-bg_glass_75_e6e6e6_1x400.png
102
- - coverage/assets/0.10.2/smoothness/images/ui-bg_glass_95_fef1ec_1x400.png
103
- - coverage/assets/0.10.2/smoothness/images/ui-bg_highlight-soft_75_cccccc_1x100.png
104
- - coverage/assets/0.10.2/smoothness/images/ui-icons_222222_256x240.png
105
- - coverage/assets/0.10.2/smoothness/images/ui-icons_2e83ff_256x240.png
106
- - coverage/assets/0.10.2/smoothness/images/ui-icons_454545_256x240.png
107
- - coverage/assets/0.10.2/smoothness/images/ui-icons_888888_256x240.png
108
- - coverage/assets/0.10.2/smoothness/images/ui-icons_cd0a0a_256x240.png
109
88
  - coverage/index.html
110
89
  - lib/contentstack.rb
111
90
  - lib/contentstack/api.rb
@@ -117,6 +96,7 @@ files:
117
96
  - lib/contentstack/entry_collection.rb
118
97
  - lib/contentstack/error.rb
119
98
  - lib/contentstack/query.rb
99
+ - lib/contentstack/region.rb
120
100
  - lib/contentstack/version.rb
121
101
  - lib/util.rb
122
102
  - rakefile.rb
@@ -128,6 +108,7 @@ files:
128
108
  - spec/entry_spec.rb
129
109
  - spec/fixtures/asset.json
130
110
  - spec/fixtures/asset_collection.json
111
+ - spec/fixtures/category_content_type.json
131
112
  - spec/fixtures/category_entry.json
132
113
  - spec/fixtures/category_entry_collection.json
133
114
  - spec/fixtures/category_entry_collection_without_count.json
@@ -136,11 +117,11 @@ files:
136
117
  - spec/fixtures/product_entry_collection.json
137
118
  - spec/query_spec.rb
138
119
  - spec/spec_helper.rb
139
- homepage: https://github.com/builtio-contentstack/contentstack-ruby
120
+ homepage: https://github.com/contentstack/contentstack-ruby
140
121
  licenses:
141
122
  - MIT
142
123
  metadata: {}
143
- post_install_message:
124
+ post_install_message:
144
125
  rdoc_options: []
145
126
  require_paths:
146
127
  - lib
@@ -148,16 +129,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
148
129
  requirements:
149
130
  - - ">="
150
131
  - !ruby/object:Gem::Version
151
- version: '0'
132
+ version: '2.0'
152
133
  required_rubygems_version: !ruby/object:Gem::Requirement
153
134
  requirements:
154
135
  - - ">="
155
136
  - !ruby/object:Gem::Version
156
137
  version: '0'
157
138
  requirements: []
158
- rubyforge_project:
159
- rubygems_version: 2.6.11
160
- signing_key:
139
+ rubygems_version: 3.1.2
140
+ signing_key:
161
141
  specification_version: 4
162
142
  summary: Contentstack Ruby client for the Content Delivery API
163
143
  test_files: []
@@ -1,61 +0,0 @@
1
- = Contentstack Ruby SDK
2
-
3
- <i>Use Built.io Contentstack to power content for your Ruby projects</i>
4
-
5
- Create Ruby based applications and use the Ruby SDK to fetch and deliver content from Built.io Contentstack. The SDK uses Content Delivery APIs.
6
-
7
- == Getting Started
8
-
9
- This guide will help you get started with our Ruby SDK to build apps powered by Built.io Contentstack.
10
-
11
- === SDK Installation and Setup
12
-
13
- To use the Ruby SDK, download it using the gem install command
14
-
15
- $ gem install contentstack
16
-
17
- === Initialize SDK
18
-
19
- You will need to specify the API key, Access token, and Environment Name of your stack to initialize the SDK:
20
-
21
- @stack = Contentstack::Client.new("site_api_key", "access_token", "enviroment_name")
22
-
23
- Once you have initialized the SDK, you can start getting content in your app.
24
-
25
- === Basic Queries
26
-
27
- ==== Get a Single Entry
28
-
29
- To get a single entry, you need to specify the content type as well as the uid of the entry.
30
-
31
- entry = @stack.content_type('content_type_uid').entry("entry_uid").fetch
32
- puts entry.get('title') # Use `get` method to retrieve field value by providing a field's unique ID
33
-
34
- ==== Get Multiple Entries
35
-
36
- To retrieve multiple entries of a content type, you need to specify the content type uid. You can also specify search parameters to filter results.
37
-
38
- @query = @stack.content_type('blog').query
39
- @entries = @query.where('title', 'welcome')
40
- .include_schema
41
- .include_count
42
- .fetch
43
-
44
- puts "Total Entries -- #{@entries.count}"
45
- @entries.each{|entry| puts "#{entry.get('title')}" }
46
-
47
-
48
- == API Reference
49
-
50
- Go through our SDK API Reference guide to know about the methods that can be used to query your content in Built.io Contentstack.
51
-
52
- {Read Ruby SDK API Reference Guide}[http://www.rubydoc.info/gems/contentstack/0.0.1]
53
-
54
-
55
- == Example Apps
56
-
57
- To help you get started, we have created some sample applications that are powered by Built.io Contentstack Ruby SDK. Click on any of the links below to read the tutorials of the app, view app demo, or download the code from GitHub.
58
-
59
- {Product Catalog}[#]
60
-
61
- Built.io Contentstack provides Ruby SDK using which you can create applications based on Ruby, or any other web frameworks created using Ruby.