Skip to content

Commit d408bd1

Browse files
authored
Merge pull request #9 from contentstack/hotfix_token
Stack Tokens Moved to Headers
2 parents 0949e94 + cf6b5d0 commit d408bd1

10 files changed

Lines changed: 95 additions & 18 deletions

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,6 @@ doc
55
spec-integration
66
coverage
77
\.yardoc
8+
.DS_Store
9+
.bundle/
10+
*/rspec_results.html

Gemfile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Gemfile
2+
source "https://rubygems.org"
3+
4+
gem "rspec"
5+
gem "webmock"
6+
gem "simplecov"
7+
gem "activesupport"

Gemfile.lock

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
GEM
2+
remote: https://rubygems.org/
3+
specs:
4+
activesupport (6.0.2.2)
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)
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.0)
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+
zeitwerk (2.3.0)
48+
49+
PLATFORMS
50+
ruby
51+
52+
DEPENDENCIES
53+
activesupport
54+
rspec
55+
simplecov
56+
webmock
57+
58+
BUNDLED WITH
59+
2.1.4

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ Or you can run this command in your terminal (you might need administrator privi
2222
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.
2323

2424
# with default region
25-
client = Contentstack::Client.new("site_api_key", "access_token", "enviroment_name")
25+
client = Contentstack::Client.new("site_api_key", "delivery_token", "enviroment_name")
2626

2727
# with specific region
28-
client = Contentstack::Client.new("site_api_key", "access_token", "enviroment_name",{"region": Contentstack::Region::EU})
28+
client = Contentstack::Client.new("site_api_key", "delivery_token", "enviroment_name",{"region": Contentstack::Region::EU})
2929

3030
# with custom host
31-
client = Contentstack::Client.new("site_api_key", "access_token", "enviroment_name",{"host": "https://custom-cdn.contentstack.com"})
31+
client = Contentstack::Client.new("site_api_key", "delivery_token", "enviroment_name",{"host": "https://custom-cdn.contentstack.com"})
3232

3333

3434

@@ -61,7 +61,7 @@ A publishing environment corresponds to one or more deployment servers or a cont
6161

6262
To initialize the SDK, you need to provide values for the keys given in the snippet below:
6363

64-
stack = Contentstack::Client.new("site_api_key", "access_token", "enviroment_name")
64+
stack = Contentstack::Client.new("site_api_key", "delivery_token", "enviroment_name")
6565

6666
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.
6767

contentstack.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Gem::Specification.new do |s|
1212
s.required_ruby_version = '>= 2.0'
1313

1414
s.license = "MIT"
15-
s.homepage = "https://github.com/builtio-contentstack/contentstack-ruby"
15+
s.homepage = "https://github.com/contentstack/contentstack-ruby"
1616

1717
s.summary = %q{Contentstack Ruby client for the Content Delivery API}
1818
s.description = %q{Contentstack Ruby client for the Content Delivery API}

lib/contentstack.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@
66
require "util"
77

88

9-
# == Built.io Contentstack - Ruby SDK
10-
# 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.
1111
# == Installation
1212
# gem install contentstack
1313
# == Initialize the Stack
14-
# @stack = Contentstack::Client.new("site_api_key", "access_token", "enviroment_name")
14+
# @stack = Contentstack::Client.new("site_api_key", "delivery_token", "enviroment_name")
1515
# == Initialize the Stack for EU region
16-
# @stack = Contentstack::Client.new("site_api_key", "access_token", "enviroment_name", {"region": Contentstack::Region::EU })
16+
# @stack = Contentstack::Client.new("site_api_key", "delivery_token", "enviroment_name", {"region": Contentstack::Region::EU })
1717
# == Initialize the Stack for custom host
18-
# @stack = Contentstack::Client.new("site_api_key", "access_token", "enviroment_name", {"host": "https://custom-cdn.contentstack.com" })
18+
# @stack = Contentstack::Client.new("site_api_key", "delivery_token", "enviroment_name", {"host": "https://custom-cdn.contentstack.com" })
1919
# == Usage
2020
# ==== Get single entry
2121
# @stack.content_type('blog').entry('<entry_uid_here>').fetch

lib/contentstack/api.rb

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@
66

77
module Contentstack
88
class API
9-
def self.init_api(api_key, access_token, environment,host)
9+
def self.init_api(api_key, delivery_token, environment,host)
1010
@host = host
1111
@api_version = '/v3'
1212
@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}
1416
end
1517

1618
def self.fetch_content_types(uid="")
@@ -47,7 +49,11 @@ def self.send_request(path, q=nil)
4749
query = "?" + q.to_query
4850
# puts "Request URL:- #{@host}#{@api_version}#{path}#{query} \n\n"
4951

50-
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)
5157
end
5258
end
53-
end
59+
end

lib/contentstack/client.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
module Contentstack
66
class Client
77
attr_reader :region, :host
8-
# Initialize "Built.io Contentstack" Client instance
9-
def initialize(api_key, access_token, environment, options={})
8+
# Initialize "Contentstack" Client instance
9+
def initialize(api_key, delivery_token, environment, options={})
1010
@region = options[:region].nil? ? Contentstack::Region::US : options[:region]
1111
@host = options[:host].nil? ? get_default_region_hosts(@region) : options[:host]
12-
API.init_api(api_key, access_token, environment, @host)
12+
API.init_api(api_key, delivery_token, environment, @host)
1313
end
1414

1515

lib/contentstack/entry.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
require 'active_support/core_ext'
2+
13
module Contentstack
24
class Entry
35
attr_reader :fields, :content_type, :uid, :owner

lib/contentstack/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module Contentstack
2-
VERSION = "0.0.4"
2+
VERSION = "0.1.0"
33
end

0 commit comments

Comments
 (0)