contentful_bootstrap 0.0.7 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +21 -0
- data/Gemfile +1 -0
- data/README.md +28 -19
- data/bin/contentful_bootstrap +10 -11
- data/contentful_bootstrap.gemspec +3 -2
- data/lib/contentful/bootstrap.rb +5 -0
- data/lib/contentful/bootstrap/commands.rb +135 -0
- data/lib/contentful/bootstrap/constants.rb +8 -0
- data/lib/contentful/bootstrap/server.rb +97 -0
- data/lib/contentful/bootstrap/support.rb +14 -0
- data/lib/contentful/bootstrap/templates.rb +3 -0
- data/lib/contentful/bootstrap/templates/base.rb +118 -0
- data/lib/contentful/bootstrap/templates/blog.rb +77 -0
- data/lib/contentful/bootstrap/templates/catalogue.rb +189 -0
- data/lib/contentful/bootstrap/templates/gallery.rb +119 -0
- data/lib/contentful/bootstrap/templates/links.rb +2 -0
- data/lib/contentful/bootstrap/templates/links/asset.rb +15 -0
- data/lib/contentful/bootstrap/templates/links/base.rb +18 -0
- data/lib/contentful/bootstrap/templates/links/entry.rb +15 -0
- data/lib/contentful/bootstrap/token.rb +58 -0
- data/lib/contentful/bootstrap/version.rb +5 -0
- metadata +32 -18
- data/lib/contentful_bootstrap.rb +0 -5
- data/lib/contentful_bootstrap/commands.rb +0 -120
- data/lib/contentful_bootstrap/constants.rb +0 -6
- data/lib/contentful_bootstrap/server.rb +0 -95
- data/lib/contentful_bootstrap/support.rb +0 -12
- data/lib/contentful_bootstrap/templates.rb +0 -3
- data/lib/contentful_bootstrap/templates/base.rb +0 -116
- data/lib/contentful_bootstrap/templates/blog.rb +0 -75
- data/lib/contentful_bootstrap/templates/catalogue.rb +0 -187
- data/lib/contentful_bootstrap/templates/gallery.rb +0 -117
- data/lib/contentful_bootstrap/templates/links.rb +0 -2
- data/lib/contentful_bootstrap/templates/links/asset.rb +0 -13
- data/lib/contentful_bootstrap/templates/links/base.rb +0 -16
- data/lib/contentful_bootstrap/templates/links/entry.rb +0 -13
- data/lib/contentful_bootstrap/token.rb +0 -23
- data/lib/contentful_bootstrap/version.rb +0 -3
@@ -0,0 +1,58 @@
|
|
1
|
+
require "inifile"
|
2
|
+
|
3
|
+
module Contentful
|
4
|
+
module Bootstrap
|
5
|
+
class Token
|
6
|
+
CONFIG_ENV = "CONTENTFUL_ENV".freeze
|
7
|
+
DEFAULT_SECTION = "global".freeze
|
8
|
+
DEFAULT_PATH = ".contentfulrc".freeze
|
9
|
+
MANAGEMENT_TOKEN = "CONTENTFUL_MANAGEMENT_ACCESS_TOKEN"
|
10
|
+
DELIVERY_TOKEN = "CONTENTFUL_DELIVERY_ACCESS_TOKEN"
|
11
|
+
|
12
|
+
def self.set_path!(config_path = "")
|
13
|
+
@@config_path = config_path
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.present?
|
17
|
+
return false unless File.exists? filename
|
18
|
+
config_file[config_section].has_key? MANAGEMENT_TOKEN
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.read
|
22
|
+
begin
|
23
|
+
config_file[config_section].fetch(MANAGEMENT_TOKEN)
|
24
|
+
rescue KeyError
|
25
|
+
fail "Token not found"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.write(token, key = MANAGEMENT_TOKEN)
|
30
|
+
file = config_file
|
31
|
+
file[config_section][key] = token
|
32
|
+
file.save
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.write_access_token(token)
|
36
|
+
write(token, DELIVERY_TOKEN)
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.filename
|
40
|
+
return config_path if File.exist?(config_path)
|
41
|
+
File.join(ENV['HOME'], DEFAULT_PATH)
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.config_section
|
45
|
+
return ENV[CONFIG_ENV] if config_file.has_section? ENV[CONFIG_ENV]
|
46
|
+
DEFAULT_SECTION
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.config_file
|
50
|
+
File.exist?(filename) ? IniFile.load(filename) : IniFile.new(filename: filename)
|
51
|
+
end
|
52
|
+
|
53
|
+
def self.config_path
|
54
|
+
@@config_path ||= ""
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: contentful_bootstrap
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Litvak Bruno
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-11-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -66,6 +66,20 @@ dependencies:
|
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: inifile
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
69
83
|
description:
|
70
84
|
email:
|
71
85
|
- david.litvakb@gmail.com
|
@@ -83,22 +97,22 @@ files:
|
|
83
97
|
- Rakefile
|
84
98
|
- bin/contentful_bootstrap
|
85
99
|
- contentful_bootstrap.gemspec
|
86
|
-
- lib/
|
87
|
-
- lib/
|
88
|
-
- lib/
|
89
|
-
- lib/
|
90
|
-
- lib/
|
91
|
-
- lib/
|
92
|
-
- lib/
|
93
|
-
- lib/
|
94
|
-
- lib/
|
95
|
-
- lib/
|
96
|
-
- lib/
|
97
|
-
- lib/
|
98
|
-
- lib/
|
99
|
-
- lib/
|
100
|
-
- lib/
|
101
|
-
- lib/
|
100
|
+
- lib/contentful/bootstrap.rb
|
101
|
+
- lib/contentful/bootstrap/commands.rb
|
102
|
+
- lib/contentful/bootstrap/constants.rb
|
103
|
+
- lib/contentful/bootstrap/server.rb
|
104
|
+
- lib/contentful/bootstrap/support.rb
|
105
|
+
- lib/contentful/bootstrap/templates.rb
|
106
|
+
- lib/contentful/bootstrap/templates/base.rb
|
107
|
+
- lib/contentful/bootstrap/templates/blog.rb
|
108
|
+
- lib/contentful/bootstrap/templates/catalogue.rb
|
109
|
+
- lib/contentful/bootstrap/templates/gallery.rb
|
110
|
+
- lib/contentful/bootstrap/templates/links.rb
|
111
|
+
- lib/contentful/bootstrap/templates/links/asset.rb
|
112
|
+
- lib/contentful/bootstrap/templates/links/base.rb
|
113
|
+
- lib/contentful/bootstrap/templates/links/entry.rb
|
114
|
+
- lib/contentful/bootstrap/token.rb
|
115
|
+
- lib/contentful/bootstrap/version.rb
|
102
116
|
homepage: https://www.contentful.com
|
103
117
|
licenses:
|
104
118
|
- MIT
|
data/lib/contentful_bootstrap.rb
DELETED
@@ -1,120 +0,0 @@
|
|
1
|
-
require "net/http"
|
2
|
-
require "contentful/management"
|
3
|
-
require "contentful/management/request"
|
4
|
-
require "contentful/management/error"
|
5
|
-
require "contentful_bootstrap/token"
|
6
|
-
require "contentful_bootstrap/server"
|
7
|
-
require "contentful_bootstrap/support"
|
8
|
-
require "contentful_bootstrap/templates"
|
9
|
-
|
10
|
-
module ContentfulBootstrap
|
11
|
-
class Commands
|
12
|
-
include Support
|
13
|
-
|
14
|
-
def init(space_name, template_name = nil)
|
15
|
-
if !Token.present?
|
16
|
-
puts "A new tab on your browser will open for requesting OAuth permissions"
|
17
|
-
get_token
|
18
|
-
puts "OAuth permissions successfully saved, your OAuth token is present in '.contentful_token'"
|
19
|
-
else
|
20
|
-
puts "OAuth token found, moving on!"
|
21
|
-
end
|
22
|
-
|
23
|
-
puts
|
24
|
-
|
25
|
-
create_space(space_name, template_name)
|
26
|
-
end
|
27
|
-
|
28
|
-
def create_space(space_name, template_name = nil)
|
29
|
-
management_client_init
|
30
|
-
|
31
|
-
puts "Creating Space '#{space_name}'"
|
32
|
-
space = nil
|
33
|
-
begin
|
34
|
-
space = Contentful::Management::Space.create(name: space_name)
|
35
|
-
rescue Contentful::Management::NotFound
|
36
|
-
puts "Your account has multiple organizations"
|
37
|
-
print "Please insert the Organization ID you'd want to create the spaces for: "
|
38
|
-
organization_id = gets.chomp
|
39
|
-
space = Contentful::Management::Space.create(name: space_name, organization_id: organization_id)
|
40
|
-
end
|
41
|
-
|
42
|
-
puts "Space '#{space_name}' created!"
|
43
|
-
puts
|
44
|
-
|
45
|
-
return if template_name.nil?
|
46
|
-
|
47
|
-
if templates.has_key? template_name.to_sym
|
48
|
-
puts "Creating Template '#{template_name}'"
|
49
|
-
|
50
|
-
templates[template_name.to_sym].new(space).run
|
51
|
-
puts "Template '#{template_name}' created!"
|
52
|
-
else
|
53
|
-
puts "Template '#{template_name}' not found. Valid templates are '#{templates.keys.map(&:to_s).join('\', \'')}'"
|
54
|
-
end
|
55
|
-
|
56
|
-
token = generate_token(space)
|
57
|
-
puts
|
58
|
-
puts "Space ID: '#{space.id}'"
|
59
|
-
puts "Access Token: '#{token}'"
|
60
|
-
puts
|
61
|
-
puts "You can now insert those values into your configuration blocks"
|
62
|
-
end
|
63
|
-
|
64
|
-
def generate_token(space, token_name = "Bootstrap Token")
|
65
|
-
management_client_init
|
66
|
-
|
67
|
-
if space.is_a?(String)
|
68
|
-
space = Contentful::Management::Space.find(space)
|
69
|
-
end
|
70
|
-
|
71
|
-
puts
|
72
|
-
puts "Creating Delivery API Token"
|
73
|
-
|
74
|
-
response = Contentful::Management::Request.new(
|
75
|
-
"/#{space.id}/api_keys",
|
76
|
-
'name' => token_name,
|
77
|
-
'description' => "Created with 'contentful_bootstrap.rb'"
|
78
|
-
).post
|
79
|
-
fail response if response.object.is_a?(Contentful::Management::Error)
|
80
|
-
token = response.object["accessToken"]
|
81
|
-
|
82
|
-
puts "Token '#{token_name}' created! - '#{token}'"
|
83
|
-
|
84
|
-
token
|
85
|
-
end
|
86
|
-
|
87
|
-
private
|
88
|
-
def management_client_init
|
89
|
-
Contentful::Management::Client.new(Token.read, raise_errors: true)
|
90
|
-
end
|
91
|
-
|
92
|
-
def get_token
|
93
|
-
silence_stderr do # Don't show any WEBrick related stuff
|
94
|
-
server = Server.new
|
95
|
-
|
96
|
-
server.start
|
97
|
-
|
98
|
-
while !server.running? # Wait for Server Init
|
99
|
-
sleep(1)
|
100
|
-
end
|
101
|
-
|
102
|
-
Net::HTTP.get(URI('http://localhost:5123'))
|
103
|
-
|
104
|
-
while !Token.present? # Wait for User to do OAuth cycle
|
105
|
-
sleep(1)
|
106
|
-
end
|
107
|
-
|
108
|
-
server.stop
|
109
|
-
end
|
110
|
-
end
|
111
|
-
|
112
|
-
def templates
|
113
|
-
{
|
114
|
-
blog: Templates::Blog,
|
115
|
-
gallery: Templates::Gallery,
|
116
|
-
catalogue: Templates::Catalogue
|
117
|
-
}
|
118
|
-
end
|
119
|
-
end
|
120
|
-
end
|
@@ -1,95 +0,0 @@
|
|
1
|
-
require "thread"
|
2
|
-
require "webrick"
|
3
|
-
require "launchy"
|
4
|
-
require "contentful_bootstrap/constants"
|
5
|
-
require "contentful_bootstrap/token"
|
6
|
-
|
7
|
-
module ContentfulBootstrap
|
8
|
-
class OAuthEchoView
|
9
|
-
def render
|
10
|
-
<<-JS
|
11
|
-
<html><head>
|
12
|
-
<link rel="shortcut icon" type="image/png" href="https://www.contentful.com/assets/images/favicons/favicon-47dc5f9d.png"/>
|
13
|
-
<link rel="shortcut icon" type="image/png" href="https://www.contentful.com/assets/images/favicons/favicon-47dc5f9d.png"/>
|
14
|
-
</head><body>
|
15
|
-
<script type="text/javascript">
|
16
|
-
(function() {
|
17
|
-
var access_token = window.location.hash.split('&')[0].split('=')[1];
|
18
|
-
window.location.replace('http://localhost:5123/save_token?token=' + access_token);
|
19
|
-
})();
|
20
|
-
</script>
|
21
|
-
</body></html>
|
22
|
-
JS
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
class ThanksView
|
27
|
-
def render
|
28
|
-
<<-HTML
|
29
|
-
<html><head>
|
30
|
-
<link rel="shortcut icon" type="image/png" href="https://www.contentful.com/assets/images/favicons/favicon-47dc5f9d.png"/>
|
31
|
-
<link rel="shortcut icon" type="image/png" href="https://www.contentful.com/assets/images/favicons/favicon-47dc5f9d.png"/>
|
32
|
-
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" />
|
33
|
-
</head><body>
|
34
|
-
<div class="container">
|
35
|
-
<div class="jumbotron">
|
36
|
-
<h1>Contentful Bootstrap</h1>
|
37
|
-
<h4>Thanks! The OAuth Token has been generated</h4>
|
38
|
-
<p>The Space you specified will now start to create. You can close this window freely</p>
|
39
|
-
</div>
|
40
|
-
</div>
|
41
|
-
</body></html>
|
42
|
-
HTML
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
class IndexController < WEBrick::HTTPServlet::AbstractServlet
|
47
|
-
def do_GET(request, response)
|
48
|
-
client_id = ContentfulBootstrap::Constants::OAUTH_APP_ID
|
49
|
-
redirect_uri = ContentfulBootstrap::Constants::OAUTH_CALLBACK_URL
|
50
|
-
scope = "content_management_manage"
|
51
|
-
Launchy.open("https://be.contentful.com/oauth/authorize?response_type=token&client_id=#{client_id}&redirect_uri=#{redirect_uri}&scope=#{scope}")
|
52
|
-
response.status = 200
|
53
|
-
response.body = ""
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
class OAuthCallbackController < WEBrick::HTTPServlet::AbstractServlet
|
58
|
-
def do_GET(request, response)
|
59
|
-
response.status = 200
|
60
|
-
response.content_type = "text/html"
|
61
|
-
response.body = OAuthEchoView.new.render
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
class SaveTokenController < WEBrick::HTTPServlet::AbstractServlet
|
66
|
-
def do_GET(request, response)
|
67
|
-
Token.write(request.query["token"])
|
68
|
-
response.status = 200
|
69
|
-
response.content_type = "text/html"
|
70
|
-
response.body = ThanksView.new.render
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
class Server
|
75
|
-
attr_reader :server
|
76
|
-
def initialize
|
77
|
-
@server = WEBrick::HTTPServer.new(:Port => 5123)
|
78
|
-
@server.mount "/", IndexController
|
79
|
-
@server.mount "/oauth_callback", OAuthCallbackController
|
80
|
-
@server.mount "/save_token", SaveTokenController
|
81
|
-
end
|
82
|
-
|
83
|
-
def start
|
84
|
-
Thread.new { @server.start }
|
85
|
-
end
|
86
|
-
|
87
|
-
def stop
|
88
|
-
@server.shutdown
|
89
|
-
end
|
90
|
-
|
91
|
-
def running?
|
92
|
-
@server.status != :Stop
|
93
|
-
end
|
94
|
-
end
|
95
|
-
end
|