contentful_bootstrap 0.0.4 → 0.0.5

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
2
  SHA1:
3
- metadata.gz: 53b22cc778c5ea2cc284ae20b28fdeddeb23ab41
4
- data.tar.gz: b2da6f2928e023c29e03832b534e210ecdb42cdc
3
+ metadata.gz: 6e77ad4fd678b1dc7f168dc9335cccf1acd8284d
4
+ data.tar.gz: 94f63823bd9899ef377501f6600a6640a8a34000
5
5
  SHA512:
6
- metadata.gz: 1d9632fac3308458ddce48349c96c193de969a0ae5a77cee06811db6119088100d9405051f8d9320cc3e49abd1746bba4ab7993d0bb5440141f9fe831d096820
7
- data.tar.gz: 7e3f14690da03181e200651d4ebecf95cfd436a9c0580f722ff9b59909826e0b20f9c2726b46fe11975287434f53af22e7977e4f5440c7193c906f301c267112
6
+ metadata.gz: 2cc6feca791ae952b4cec20beab02c16fd09b5158a88b79ec7fa0a94f5096b6536ab420201b422ec23f3f74340e9ae4ee168aaf4becd60beab86186d258751dd
7
+ data.tar.gz: 5cc98562634701de40c3cc480f9b5d809df25e235b4d43cc95fae90da6798b664d30c070865e5368680a2fbac347b4a7b0bd775e929c33f8a55264f232696f3e
data/CHANGELOG.md CHANGED
@@ -1,6 +1,13 @@
1
1
  # Change Log
2
2
  ## Unreleased
3
3
 
4
+ ## v0.0.5
5
+ ### Added
6
+ * API Token Generation
7
+ * `generate_token` command added to binary
8
+ * Better Formatting of current steps
9
+ * Space and Access Token Values displayed at end of command
10
+
4
11
  ## v0.0.4
5
12
  ### Added
6
13
  * Added support for users with multiple Organizations
@@ -17,40 +17,47 @@ end
17
17
  subcommands = {
18
18
  'init' => OptionParser.new do |opts|
19
19
  opts.banner = "Usage: init <space_name> [--template TEMPLATE_NAME]"
20
- opts.on("-t", "--template TEMPLATE", "Specify Template", "blog, catalogue, gallery") do |t|
21
- options[:template] = t
20
+ opts.on("-t TEMPLATE", "--template TEMPLATE", "Specify Template", "blog, catalogue, gallery") do |t|
21
+ options[:name] = t
22
22
  end
23
23
  end,
24
24
  'create_space' => OptionParser.new do |opts|
25
25
  opts.banner = "Usage: init <space_name> [--template TEMPLATE_NAME]"
26
- opts.on("-t", "--template TEMPLATE", "Specify Template", "blog, catalogue, gallery") do |t|
27
- options[:template] = t
26
+ opts.on("-t TEMPLATE", "--template TEMPLATE", "Specify Template", "blog, catalogue, gallery") do |t|
27
+ options[:name] = t
28
+ end
29
+ end,
30
+ 'generate_token' => OptionParser.new do |opts|
31
+ opts.banner = "Usage: generate_token <space_id> [--name TOKEN_NAME]"
32
+ opts.on("-n NAME", "--name TEMPLATE", "Specify Token Name") do |n|
33
+ options[:name] = n
28
34
  end
29
35
  end
30
36
  }
31
37
 
32
38
  global.order!
33
39
  command = ARGV.shift
34
- space_name = ARGV.shift
40
+ space = ARGV.shift
35
41
 
36
42
  if subcommands.has_key? command
37
43
  subcommands[command].order!
38
44
 
39
- if space_name.nil? || space_name.empty?
45
+ if space.nil? || space.empty?
40
46
  puts "Usage: contentful_bootstrap <command> <space_name> [--template TEMPLATE_NAME]"
41
47
  puts
42
48
  puts "You must provide a valid space name. Exiting!"
43
49
  exit
44
50
  end
45
51
 
46
- ContentfulBootstrap::Commands.new.send(command, space_name, options.fetch(:template, nil))
52
+ ContentfulBootstrap::Commands.new.send(command, space, options.fetch(:name, nil))
47
53
  else
48
- puts "Usage: contentful_bootstrap <command> <space_name> [--template TEMPLATE_NAME]"
54
+ puts "Usage: contentful_bootstrap <command> <space> [options]"
49
55
  puts
50
56
  puts <<-HELP
51
57
  Subcommand not available or missing
52
58
  Available commands are:
53
59
  init
54
60
  create_space
61
+ generate_token
55
62
  HELP
56
63
  end
@@ -1,5 +1,7 @@
1
1
  require "net/http"
2
2
  require "contentful/management"
3
+ require "contentful/management/request"
4
+ require "contentful/management/error"
3
5
  require "contentful_bootstrap/token"
4
6
  require "contentful_bootstrap/server"
5
7
  require "contentful_bootstrap/support"
@@ -18,6 +20,8 @@ module ContentfulBootstrap
18
20
  puts "OAuth token found, moving on!"
19
21
  end
20
22
 
23
+ puts
24
+
21
25
  create_space(space_name, template_name)
22
26
  end
23
27
 
@@ -34,7 +38,9 @@ module ContentfulBootstrap
34
38
  organization_id = gets.chomp
35
39
  space = Contentful::Management::Space.create(name: space_name, organization_id: organization_id)
36
40
  end
41
+
37
42
  puts "Space '#{space_name}' created!"
43
+ puts
38
44
 
39
45
  return if template_name.nil?
40
46
 
@@ -46,6 +52,33 @@ module ContentfulBootstrap
46
52
  else
47
53
  puts "Template '#{template_name}' not found. Valid templates are '#{templates.keys.map(&:to_s).join('\', \'')}'"
48
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 "Creating Delivery API Token"
72
+
73
+ response = Contentful::Management::Request.new(
74
+ "/#{space.id}/api_keys",
75
+ 'name' => token_name,
76
+ 'description' => "Created with 'contentful_bootstrap.rb'"
77
+ ).post
78
+ fail response if response.object.is_a?(Contentful::Management::Error)
79
+ token = response.object["accessToken"]
80
+
81
+ puts "Token '#{token_name}' created! - '#{token}'"
49
82
  end
50
83
 
51
84
  private
@@ -54,7 +87,7 @@ module ContentfulBootstrap
54
87
  end
55
88
 
56
89
  def get_token
57
- silence_stderr do # Don't show any Sinatra related stuff
90
+ silence_stderr do # Don't show any WEBrick related stuff
58
91
  server = Server.new
59
92
 
60
93
  server.start
@@ -1,3 +1,3 @@
1
1
  module ContentfulBootstrap
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  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: 0.0.4
4
+ version: 0.0.5
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-10-29 00:00:00.000000000 Z
11
+ date: 2015-10-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler