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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a1889695468ff7c1a8250d9fa14e88d81167df6a
|
4
|
+
data.tar.gz: 5e6634f55c894b036d5580d8b31d9d5e8f207d13
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 81a56b64246f4b7bea76a0161d7d8c361090f643a8d0b2e8f0fa63c5dec0cc394560b940d0ba1d6b5d1e76f817bdf880fa61d63a99f6d121f21df50c04803ebb
|
7
|
+
data.tar.gz: 00d5ab1fb4dc4a68e4a97f421875c7b6d3422c0a2d5fe8255844b4e3cb70b3115ecc8640b18544c7329eb67f001edace299bcc87d96ccd940706a5dd3d0f0f98
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,27 @@
|
|
1
1
|
# Change Log
|
2
2
|
## Unreleased
|
3
3
|
|
4
|
+
## v1.1.0
|
5
|
+
### Removed
|
6
|
+
* Removed `init` command as `v1.0.0` refactor removed it's necessity
|
7
|
+
|
8
|
+
## v1.0.1 [YANKED]
|
9
|
+
### Fixed
|
10
|
+
* Release is now on `master`
|
11
|
+
|
12
|
+
## v1.0.0 [YANKED]
|
13
|
+
### Changed
|
14
|
+
* Changed namespace from `ContentfulBootstrap` to `Contentful::Bootstrap` to mimic other libraries
|
15
|
+
* Changed repository name from `contentful_bootstrap.rb` to `contentful-bootstrap.rb` to mimic other libraries
|
16
|
+
* Delivery API Token will always get created when using `contentful_bootstrap` commands to create a space
|
17
|
+
* Configuration now read from `~/.contentfulrc`
|
18
|
+
* Tool now requests user to allow to write configuration files
|
19
|
+
|
20
|
+
### Added
|
21
|
+
* `contentful-bootstrap.rb` version number to API Token description
|
22
|
+
* `inifile` as runtime dependency
|
23
|
+
* Add optional `--config CONFIG_PATH` parameter to commands
|
24
|
+
|
4
25
|
## v0.0.7
|
5
26
|
### Fixed
|
6
27
|
* Redirected Favicon fetch to Contentful's favicon, as some browsers would ping the server indefinitely
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -4,7 +4,7 @@ A small CLI tool for getting started with Contentful
|
|
4
4
|
|
5
5
|
## Contentful
|
6
6
|
[Contentful](http://www.contentful.com) is a content management platform for web applications,
|
7
|
-
mobile apps and connected devices. It allows you to create, edit &
|
7
|
+
mobile apps and connected devices. It allows you to create, edit & manage content in the cloud
|
8
8
|
and publish it anywhere via powerful API. Contentful offers tools for managing editorial
|
9
9
|
teams and enabling cooperation between organizations.
|
10
10
|
|
@@ -20,24 +20,19 @@ in a single command
|
|
20
20
|
$ gem install contentful_bootstrap
|
21
21
|
```
|
22
22
|
|
23
|
-
###
|
24
|
-
|
25
|
-
```bash
|
26
|
-
$ contentful_bootstrap init <space_name> [--template template_name]
|
27
|
-
```
|
23
|
+
### Usage
|
28
24
|
|
29
|
-
|
30
|
-
Then you can create other spaces by doing:
|
25
|
+
You can create spaces by doing
|
31
26
|
|
32
27
|
```bash
|
33
|
-
$ contentful_bootstrap create_space <space_name> [--template template_name]
|
28
|
+
$ contentful_bootstrap create_space <space_name> [--template template_name] [--config CONFIG_PATH]
|
34
29
|
```
|
35
30
|
|
36
31
|
|
37
32
|
You can also generate new Delivery API Tokens by doing:
|
38
33
|
|
39
34
|
```bash
|
40
|
-
$ contentful_bootstrap generate_token <space_id> [--name token_name]
|
35
|
+
$ contentful_bootstrap generate_token <space_id> [--name token_name] [--config CONFIG_PATH]
|
41
36
|
```
|
42
37
|
|
43
38
|
### Available templates
|
@@ -64,24 +59,38 @@ gem "contentful_bootstrap"
|
|
64
59
|
Require `contentful_bootstrap`
|
65
60
|
|
66
61
|
```ruby
|
67
|
-
require '
|
62
|
+
require 'contentful/bootstrap'
|
68
63
|
```
|
69
64
|
|
70
|
-
To
|
65
|
+
To Create a new Space
|
71
66
|
|
72
67
|
```ruby
|
73
|
-
|
68
|
+
Contentful::Bootstrap::Commands.new.create_space("space_name", "template_name") # Template Name is optional
|
74
69
|
```
|
75
70
|
|
76
|
-
|
77
|
-
To create a new Space or Token. *This operations require a CMA Token located in `File.join(Dir.pwd, '.contentful_token')`*
|
71
|
+
To Create a new Delivery API Token
|
78
72
|
|
79
73
|
```ruby
|
80
|
-
#
|
81
|
-
|
74
|
+
Contentful::Bootstrap::Commands.new.generate_token("space_id", "token_name") # Token Name is optional
|
75
|
+
```
|
76
|
+
|
77
|
+
Optionally, `Commands#new` will take a parameter for specifying a configuration path
|
78
|
+
|
79
|
+
### Configuration
|
80
|
+
|
81
|
+
Contentful Bootstrap will read by default from `~/.contentfulrc`, but you can provide your own
|
82
|
+
file by using the `--config CONFIG_PATH` parameter
|
83
|
+
|
84
|
+
If you don't have `~/.contentfulrc` created, you will be prompted if you want to create it
|
85
|
+
|
86
|
+
#### Configuration Format
|
87
|
+
|
88
|
+
The configuration file will be in `ini` format and looks like the following
|
82
89
|
|
83
|
-
|
84
|
-
|
90
|
+
```ini
|
91
|
+
[global]
|
92
|
+
CONTENTFUL_MANAGEMENT_ACCESS_TOKEN = a_management_access_token
|
93
|
+
CONTENTFUL_DELIVERY_ACCESS_TOKEN = a_delivery_acces_token ; Delivery Access Token is not required for this tool, but can be generated by it
|
85
94
|
```
|
86
95
|
|
87
96
|
## Contributing
|
data/bin/contentful_bootstrap
CHANGED
@@ -1,37 +1,37 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
require 'optparse'
|
4
|
-
require '
|
4
|
+
require 'contentful/bootstrap/commands'
|
5
5
|
|
6
6
|
options = {}
|
7
7
|
global = OptionParser.new do |opts|
|
8
|
-
opts.banner = "Usage: contentful_bootstrap <command> <space_name> [--template TEMPLATE_NAME]"
|
8
|
+
opts.banner = "Usage: contentful_bootstrap <command> <space_name> [--template TEMPLATE_NAME] [--config CONFIG_PATH]"
|
9
9
|
opts.separator ""
|
10
10
|
opts.separator <<-HELP
|
11
11
|
Available commands are:
|
12
|
-
init
|
13
12
|
create_space
|
13
|
+
generate_token
|
14
14
|
HELP
|
15
15
|
end
|
16
16
|
|
17
17
|
subcommands = {
|
18
|
-
'init' => OptionParser.new do |opts|
|
19
|
-
opts.banner = "Usage: init <space_name> [--template TEMPLATE_NAME]"
|
20
|
-
opts.on("-t TEMPLATE", "--template TEMPLATE", "Specify Template", "blog, catalogue, gallery") do |t|
|
21
|
-
options[:name] = t
|
22
|
-
end
|
23
|
-
end,
|
24
18
|
'create_space' => OptionParser.new do |opts|
|
25
19
|
opts.banner = "Usage: init <space_name> [--template TEMPLATE_NAME]"
|
26
20
|
opts.on("-t TEMPLATE", "--template TEMPLATE", "Specify Template", "blog, catalogue, gallery") do |t|
|
27
21
|
options[:name] = t
|
28
22
|
end
|
23
|
+
opts.on("-c CONFIG_PATH", "--config CONFIG_PATH", "Specify Configuration Path") do |c|
|
24
|
+
options[:config_path] = c
|
25
|
+
end
|
29
26
|
end,
|
30
27
|
'generate_token' => OptionParser.new do |opts|
|
31
28
|
opts.banner = "Usage: generate_token <space_id> [--name TOKEN_NAME]"
|
32
29
|
opts.on("-n NAME", "--name TEMPLATE", "Specify Token Name") do |n|
|
33
30
|
options[:name] = n
|
34
31
|
end
|
32
|
+
opts.on("-c CONFIG_PATH", "--config CONFIG_PATH", "Specify Configuration Path") do |c|
|
33
|
+
options[:config_path] = c
|
34
|
+
end
|
35
35
|
end
|
36
36
|
}
|
37
37
|
|
@@ -49,14 +49,13 @@ if subcommands.has_key? command
|
|
49
49
|
exit
|
50
50
|
end
|
51
51
|
|
52
|
-
|
52
|
+
Contentful::Bootstrap::Commands.new(options.fetch(:config_path, "")).send(command, space, options.fetch(:name, nil))
|
53
53
|
else
|
54
54
|
puts "Usage: contentful_bootstrap <command> <space> [options]"
|
55
55
|
puts
|
56
56
|
puts <<-HELP
|
57
57
|
Subcommand not available or missing
|
58
58
|
Available commands are:
|
59
|
-
init
|
60
59
|
create_space
|
61
60
|
generate_token
|
62
61
|
HELP
|
@@ -1,11 +1,11 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
lib = File.expand_path('../lib', __FILE__)
|
3
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require '
|
4
|
+
require 'contentful/bootstrap/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "contentful_bootstrap"
|
8
|
-
spec.version =
|
8
|
+
spec.version = Contentful::Bootstrap::VERSION
|
9
9
|
spec.authors = ["David Litvak Bruno"]
|
10
10
|
spec.email = ["david.litvakb@gmail.com"]
|
11
11
|
spec.summary = %q{Contentful CLI tool for getting started with Contentful}
|
@@ -21,4 +21,5 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.add_development_dependency "rake"
|
22
22
|
spec.add_runtime_dependency "launchy"
|
23
23
|
spec.add_runtime_dependency "contentful-management"
|
24
|
+
spec.add_runtime_dependency "inifile"
|
24
25
|
end
|
@@ -0,0 +1,135 @@
|
|
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
|
+
require "contentful/bootstrap/version"
|
10
|
+
|
11
|
+
module Contentful
|
12
|
+
module Bootstrap
|
13
|
+
class Commands
|
14
|
+
include Support
|
15
|
+
|
16
|
+
def initialize(config_path = "")
|
17
|
+
Token.set_path!(config_path)
|
18
|
+
end
|
19
|
+
|
20
|
+
def create_space(space_name, template_name = nil, from_command = true)
|
21
|
+
get_configuration if from_command
|
22
|
+
|
23
|
+
management_client_init
|
24
|
+
|
25
|
+
puts "Creating Space '#{space_name}'"
|
26
|
+
space = nil
|
27
|
+
begin
|
28
|
+
space = Contentful::Management::Space.create(name: space_name)
|
29
|
+
rescue Contentful::Management::NotFound
|
30
|
+
puts "Your account has multiple organizations"
|
31
|
+
print "Please insert the Organization ID you'd want to create the spaces for: "
|
32
|
+
organization_id = gets.chomp
|
33
|
+
space = Contentful::Management::Space.create(name: space_name, organization_id: organization_id)
|
34
|
+
end
|
35
|
+
|
36
|
+
puts "Space '#{space_name}' created!"
|
37
|
+
puts
|
38
|
+
|
39
|
+
unless template_name.nil?
|
40
|
+
if templates.has_key? template_name.to_sym
|
41
|
+
puts "Creating Template '#{template_name}'"
|
42
|
+
|
43
|
+
templates[template_name.to_sym].new(space).run
|
44
|
+
puts "Template '#{template_name}' created!"
|
45
|
+
else
|
46
|
+
puts "Template '#{template_name}' not found. Valid templates are '#{templates.keys.map(&:to_s).join('\', \'')}'"
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
token = generate_token(space, "Bootstrap Token", false)
|
51
|
+
puts
|
52
|
+
puts "Space ID: '#{space.id}'"
|
53
|
+
puts "Access Token: '#{token}'"
|
54
|
+
puts
|
55
|
+
puts "You can now insert those values into your configuration blocks"
|
56
|
+
end
|
57
|
+
|
58
|
+
def generate_token(space, token_name = "Bootstrap Token", from_command = true)
|
59
|
+
get_configuration if from_command
|
60
|
+
management_client_init if from_command
|
61
|
+
|
62
|
+
if space.is_a?(String)
|
63
|
+
space = Contentful::Management::Space.find(space)
|
64
|
+
end
|
65
|
+
|
66
|
+
puts
|
67
|
+
puts "Creating Delivery API Token"
|
68
|
+
|
69
|
+
response = Contentful::Management::Request.new(
|
70
|
+
"/#{space.id}/api_keys",
|
71
|
+
'name' => token_name,
|
72
|
+
'description' => "Created with 'contentful_bootstrap.rb v#{Contentful::Bootstrap::VERSION}'"
|
73
|
+
).post
|
74
|
+
fail response if response.object.is_a?(Contentful::Management::Error)
|
75
|
+
token = response.object["accessToken"]
|
76
|
+
|
77
|
+
puts "Token '#{token_name}' created! - '#{token}'"
|
78
|
+
print "Do you want to write the Delivery Token to your configuration file? (Y/n): "
|
79
|
+
Token.write_access_token(token) unless gets.chomp.downcase == "n"
|
80
|
+
|
81
|
+
token
|
82
|
+
end
|
83
|
+
|
84
|
+
private
|
85
|
+
def get_configuration
|
86
|
+
if !Token.present?
|
87
|
+
print "OAuth Token not found, do you want to create a new configuration file? (Y/n): "
|
88
|
+
if gets.chomp.downcase == "n"
|
89
|
+
puts "Exiting!"
|
90
|
+
return
|
91
|
+
end
|
92
|
+
puts "Configuration will be saved on #{Token.filename}"
|
93
|
+
|
94
|
+
puts "A new tab on your browser will open for requesting OAuth permissions"
|
95
|
+
get_token
|
96
|
+
else
|
97
|
+
puts "OAuth token found, moving on!"
|
98
|
+
end
|
99
|
+
puts
|
100
|
+
end
|
101
|
+
|
102
|
+
def management_client_init
|
103
|
+
Contentful::Management::Client.new(Token.read, raise_errors: true)
|
104
|
+
end
|
105
|
+
|
106
|
+
def get_token
|
107
|
+
silence_stderr do # Don't show any WEBrick related stuff
|
108
|
+
server = Server.new
|
109
|
+
|
110
|
+
server.start
|
111
|
+
|
112
|
+
while !server.running? # Wait for Server Init
|
113
|
+
sleep(1)
|
114
|
+
end
|
115
|
+
|
116
|
+
Net::HTTP.get(URI('http://localhost:5123'))
|
117
|
+
|
118
|
+
while !Token.present? # Wait for User to do OAuth cycle
|
119
|
+
sleep(1)
|
120
|
+
end
|
121
|
+
|
122
|
+
server.stop
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
def templates
|
127
|
+
{
|
128
|
+
blog: Templates::Blog,
|
129
|
+
gallery: Templates::Gallery,
|
130
|
+
catalogue: Templates::Catalogue
|
131
|
+
}
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
@@ -0,0 +1,97 @@
|
|
1
|
+
require "thread"
|
2
|
+
require "webrick"
|
3
|
+
require "launchy"
|
4
|
+
require "contentful/bootstrap/constants"
|
5
|
+
require "contentful/bootstrap/token"
|
6
|
+
|
7
|
+
module Contentful
|
8
|
+
module Bootstrap
|
9
|
+
class OAuthEchoView
|
10
|
+
def render
|
11
|
+
<<-JS
|
12
|
+
<html><head>
|
13
|
+
<link rel="shortcut icon" type="image/png" href="https://www.contentful.com/assets/images/favicons/favicon-47dc5f9d.png"/>
|
14
|
+
<link rel="shortcut icon" type="image/png" href="https://www.contentful.com/assets/images/favicons/favicon-47dc5f9d.png"/>
|
15
|
+
</head><body>
|
16
|
+
<script type="text/javascript">
|
17
|
+
(function() {
|
18
|
+
var access_token = window.location.hash.split('&')[0].split('=')[1];
|
19
|
+
window.location.replace('http://localhost:5123/save_token?token=' + access_token);
|
20
|
+
})();
|
21
|
+
</script>
|
22
|
+
</body></html>
|
23
|
+
JS
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
class ThanksView
|
28
|
+
def render
|
29
|
+
<<-HTML
|
30
|
+
<html><head>
|
31
|
+
<link rel="shortcut icon" type="image/png" href="https://www.contentful.com/assets/images/favicons/favicon-47dc5f9d.png"/>
|
32
|
+
<link rel="shortcut icon" type="image/png" href="https://www.contentful.com/assets/images/favicons/favicon-47dc5f9d.png"/>
|
33
|
+
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" />
|
34
|
+
</head><body>
|
35
|
+
<div class="container">
|
36
|
+
<div class="jumbotron">
|
37
|
+
<h1>Contentful Bootstrap</h1>
|
38
|
+
<h4>Thanks! The OAuth Token has been generated</h4>
|
39
|
+
<p>The Space you specified will now start to create. You can close this window freely</p>
|
40
|
+
</div>
|
41
|
+
</div>
|
42
|
+
</body></html>
|
43
|
+
HTML
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
class IndexController < WEBrick::HTTPServlet::AbstractServlet
|
48
|
+
def do_GET(request, response)
|
49
|
+
client_id = Contentful::Bootstrap::Constants::OAUTH_APP_ID
|
50
|
+
redirect_uri = Contentful::Bootstrap::Constants::OAUTH_CALLBACK_URL
|
51
|
+
scope = "content_management_manage"
|
52
|
+
Launchy.open("https://be.contentful.com/oauth/authorize?response_type=token&client_id=#{client_id}&redirect_uri=#{redirect_uri}&scope=#{scope}")
|
53
|
+
response.status = 200
|
54
|
+
response.body = ""
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
class OAuthCallbackController < WEBrick::HTTPServlet::AbstractServlet
|
59
|
+
def do_GET(request, response)
|
60
|
+
response.status = 200
|
61
|
+
response.content_type = "text/html"
|
62
|
+
response.body = OAuthEchoView.new.render
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
class SaveTokenController < WEBrick::HTTPServlet::AbstractServlet
|
67
|
+
def do_GET(request, response)
|
68
|
+
Token.write(request.query["token"])
|
69
|
+
response.status = 200
|
70
|
+
response.content_type = "text/html"
|
71
|
+
response.body = ThanksView.new.render
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
class Server
|
76
|
+
attr_reader :server
|
77
|
+
def initialize
|
78
|
+
@server = WEBrick::HTTPServer.new(:Port => 5123)
|
79
|
+
@server.mount "/", IndexController
|
80
|
+
@server.mount "/oauth_callback", OAuthCallbackController
|
81
|
+
@server.mount "/save_token", SaveTokenController
|
82
|
+
end
|
83
|
+
|
84
|
+
def start
|
85
|
+
Thread.new { @server.start }
|
86
|
+
end
|
87
|
+
|
88
|
+
def stop
|
89
|
+
@server.shutdown
|
90
|
+
end
|
91
|
+
|
92
|
+
def running?
|
93
|
+
@server.status != :Stop
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|