contentstack 0.0.3 → 0.0.4
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 +4 -4
- data/LICENSE.txt +1 -1
- data/README.md +12 -1
- data/lib/contentstack.rb +5 -0
- data/lib/contentstack/api.rb +2 -3
- data/lib/contentstack/client.rb +16 -2
- data/lib/contentstack/region.rb +6 -0
- data/lib/contentstack/version.rb +1 -1
- data/spec/content_type_spec.rb +12 -0
- data/spec/contentstack_spec.rb +22 -0
- data/spec/query_spec.rb +1 -1
- data/spec/spec_helper.rb +10 -2
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2c05a60239a20793be053c9afa3684e579f1b744
|
4
|
+
data.tar.gz: 002d29d76b307264a6353cb13b6a7d07a5372d35
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3fa5770932d3c6e4de5dbb6c90790f3ae889802863403c45a4aff7338d1ca591ec72e6920798fb81f85c3c745ef33e770898e852e3ad68bf9c490b356a957a17
|
7
|
+
data.tar.gz: 63b98d912dcbf97dc4b1e34f326ef125a53fcccdb1748211126ff4a3f311ab5d65d762216703a8fdda46cb8c3a2871d16d210c323561373bdad6cdf76cd76f31
|
data/LICENSE.txt
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
The MIT License (MIT)
|
2
2
|
|
3
|
-
Copyright (c)
|
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
|
data/README.md
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
|
1
2
|
# **Ruby SDK for Contentstack**
|
2
3
|
|
3
4
|
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/).
|
@@ -20,7 +21,17 @@ Or you can run this command in your terminal (you might need administrator privi
|
|
20
21
|
|
21
22
|
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
|
|
24
|
+
# with default region
|
23
25
|
client = Contentstack::Client.new("site_api_key", "access_token", "enviroment_name")
|
26
|
+
|
27
|
+
# with specific region
|
28
|
+
client = Contentstack::Client.new("site_api_key", "access_token", "enviroment_name",{"region": Contentstack::Region::EU})
|
29
|
+
|
30
|
+
# with custom host
|
31
|
+
client = Contentstack::Client.new("site_api_key", "access_token", "enviroment_name",{"host": "https://custom-cdn.contentstack.com"})
|
32
|
+
|
33
|
+
|
34
|
+
|
24
35
|
|
25
36
|
## **Key Concepts for using Contentstack**
|
26
37
|
|
@@ -90,7 +101,7 @@ SDK functions for Image Delivery API coming soon.
|
|
90
101
|
|
91
102
|
## **The MIT License (MIT)**
|
92
103
|
|
93
|
-
Copyright © 2012-
|
104
|
+
Copyright © 2012-2019 [Contentstack](https://www.contentstack.com). All Rights Reserved
|
94
105
|
|
95
106
|
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:
|
96
107
|
|
data/lib/contentstack.rb
CHANGED
@@ -2,6 +2,7 @@ $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
|
|
@@ -11,6 +12,10 @@ require "util"
|
|
11
12
|
# gem install contentstack
|
12
13
|
# == Initialize the Stack
|
13
14
|
# @stack = Contentstack::Client.new("site_api_key", "access_token", "enviroment_name")
|
15
|
+
# == Initialize the Stack for EU region
|
16
|
+
# @stack = Contentstack::Client.new("site_api_key", "access_token", "enviroment_name", {"region": Contentstack::Region::EU })
|
17
|
+
# == Initialize the Stack for custom host
|
18
|
+
# @stack = Contentstack::Client.new("site_api_key", "access_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
|
data/lib/contentstack/api.rb
CHANGED
@@ -6,8 +6,8 @@ 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 =
|
9
|
+
def self.init_api(api_key, access_token, environment,host)
|
10
|
+
@host = host
|
11
11
|
@api_version = '/v3'
|
12
12
|
@environment = environment
|
13
13
|
@headers = {api_key: api_key, access_token: access_token, user_agent: "ruby-sdk/#{Contentstack::VERSION}", environment: @environment}
|
@@ -43,7 +43,6 @@ module Contentstack
|
|
43
43
|
q ||= {}
|
44
44
|
|
45
45
|
q.merge!(@headers)
|
46
|
-
q.merge!({timestamp: Time.now.to_i})
|
47
46
|
|
48
47
|
query = "?" + q.to_query
|
49
48
|
# puts "Request URL:- #{@host}#{@api_version}#{path}#{query} \n\n"
|
data/lib/contentstack/client.rb
CHANGED
@@ -4,9 +4,12 @@ require 'contentstack/asset_collection'
|
|
4
4
|
|
5
5
|
module Contentstack
|
6
6
|
class Client
|
7
|
+
attr_reader :region, :host
|
7
8
|
# Initialize "Built.io Contentstack" Client instance
|
8
|
-
def initialize(api_key, access_token, environment)
|
9
|
-
|
9
|
+
def initialize(api_key, access_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, access_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
|
data/lib/contentstack/version.rb
CHANGED
data/spec/content_type_spec.rb
CHANGED
@@ -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('ACCESS_TOKEN', 'API_KEY', 'STACK_ENV', {region: Contentstack::Region::EU}) }
|
7
|
+
let(:custom_host_client) { create_client('ACCESS_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
|
data/spec/contentstack_spec.rb
CHANGED
@@ -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('ACCESS_TOKEN', 'API_KEY', 'STACK_ENV', {region: Contentstack::Region::EU}) }
|
7
|
+
let(:custom_host_client) { create_client('ACCESS_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
|
data/spec/query_spec.rb
CHANGED
@@ -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
|
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
|
data/spec/spec_helper.rb
CHANGED
@@ -107,6 +107,14 @@ RSpec.configure do |config|
|
|
107
107
|
=end
|
108
108
|
|
109
109
|
config.before(:each) do
|
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/).
|
115
|
+
with(headers: {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Ruby'}).
|
116
|
+
to_return(:status => 200, :body => File.read(File.dirname(__FILE__) + '/fixtures/content_types.json'), :headers => {})
|
117
|
+
|
110
118
|
stub_request(:get, /cdn.contentstack.io\/v3\/content_types/).
|
111
119
|
with(headers: {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Ruby'}).
|
112
120
|
to_return(:status => 200, :body => File.read(File.dirname(__FILE__) + '/fixtures/content_types.json'), :headers => {})
|
@@ -140,7 +148,7 @@ RSpec.configure do |config|
|
|
140
148
|
to_return(:status => 200, :body => File.read(File.dirname(__FILE__) + '/fixtures/category_entry.json'), :headers => {})
|
141
149
|
end
|
142
150
|
|
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)
|
151
|
+
def create_client(access_token = ENV['ACCESS_TOKEN'], api_key = ENV['API_KEY'], environment = ENV['STACK_ENV'], options = {})
|
152
|
+
Contentstack::Client.new(access_token, api_key, environment, options)
|
145
153
|
end
|
146
154
|
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.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Contentstack
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-09-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -117,6 +117,7 @@ files:
|
|
117
117
|
- lib/contentstack/entry_collection.rb
|
118
118
|
- lib/contentstack/error.rb
|
119
119
|
- lib/contentstack/query.rb
|
120
|
+
- lib/contentstack/region.rb
|
120
121
|
- lib/contentstack/version.rb
|
121
122
|
- lib/util.rb
|
122
123
|
- rakefile.rb
|
@@ -156,7 +157,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
156
157
|
version: '0'
|
157
158
|
requirements: []
|
158
159
|
rubyforge_project:
|
159
|
-
rubygems_version: 2.
|
160
|
+
rubygems_version: 2.5.2.3
|
160
161
|
signing_key:
|
161
162
|
specification_version: 4
|
162
163
|
summary: Contentstack Ruby client for the Content Delivery API
|