contentful_bootstrap 1.6.0 → 2.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +26 -0
  3. data/.rubocop_todo.yml +123 -0
  4. data/.travis.yml +6 -0
  5. data/CHANGELOG.md +25 -0
  6. data/Gemfile +1 -0
  7. data/Guardfile +5 -0
  8. data/README.md +40 -14
  9. data/Rakefile +7 -0
  10. data/bin/contentful_bootstrap +33 -22
  11. data/contentful_bootstrap.gemspec +7 -0
  12. data/lib/contentful/bootstrap.rb +7 -5
  13. data/lib/contentful/bootstrap/command_runner.rb +45 -0
  14. data/lib/contentful/bootstrap/commands.rb +3 -168
  15. data/lib/contentful/bootstrap/commands/base.rb +66 -0
  16. data/lib/contentful/bootstrap/commands/create_space.rb +111 -0
  17. data/lib/contentful/bootstrap/commands/generate_json.rb +41 -0
  18. data/lib/contentful/bootstrap/commands/generate_token.rb +52 -0
  19. data/lib/contentful/bootstrap/constants.rb +2 -2
  20. data/lib/contentful/bootstrap/generator.rb +94 -0
  21. data/lib/contentful/bootstrap/server.rb +25 -17
  22. data/lib/contentful/bootstrap/support.rb +3 -2
  23. data/lib/contentful/bootstrap/templates.rb +4 -4
  24. data/lib/contentful/bootstrap/templates/base.rb +51 -30
  25. data/lib/contentful/bootstrap/templates/blog.rb +33 -33
  26. data/lib/contentful/bootstrap/templates/catalogue.rb +103 -103
  27. data/lib/contentful/bootstrap/templates/gallery.rb +55 -56
  28. data/lib/contentful/bootstrap/templates/json_template.rb +22 -16
  29. data/lib/contentful/bootstrap/templates/links.rb +2 -2
  30. data/lib/contentful/bootstrap/templates/links/asset.rb +2 -2
  31. data/lib/contentful/bootstrap/templates/links/base.rb +3 -3
  32. data/lib/contentful/bootstrap/templates/links/entry.rb +2 -2
  33. data/lib/contentful/bootstrap/token.rb +32 -31
  34. data/lib/contentful/bootstrap/version.rb +1 -1
  35. data/spec/contentful/bootstrap/command_runner_spec.rb +111 -0
  36. data/spec/contentful/bootstrap/commands/base_spec.rb +102 -0
  37. data/spec/contentful/bootstrap/commands/create_space_spec.rb +72 -0
  38. data/spec/contentful/bootstrap/commands/generate_json_spec.rb +64 -0
  39. data/spec/contentful/bootstrap/commands/generate_token_spec.rb +82 -0
  40. data/spec/contentful/bootstrap/generator_spec.rb +15 -0
  41. data/spec/contentful/bootstrap/server_spec.rb +154 -0
  42. data/spec/contentful/bootstrap/support_spec.rb +27 -0
  43. data/spec/contentful/bootstrap/templates/base_spec.rb +34 -0
  44. data/spec/contentful/bootstrap/templates/blog_spec.rb +32 -0
  45. data/spec/contentful/bootstrap/templates/catalogue_spec.rb +40 -0
  46. data/spec/contentful/bootstrap/templates/gallery_spec.rb +40 -0
  47. data/spec/contentful/bootstrap/templates/json_template_spec.rb +52 -0
  48. data/spec/contentful/bootstrap/templates/links/asset_spec.rb +23 -0
  49. data/spec/contentful/bootstrap/templates/links/base_spec.rb +31 -0
  50. data/spec/contentful/bootstrap/templates/links/entry_spec.rb +23 -0
  51. data/spec/contentful/bootstrap/token_spec.rb +143 -0
  52. data/spec/fixtures/ini_fixtures/contentfulrc.ini +2 -0
  53. data/spec/fixtures/ini_fixtures/no_global.ini +2 -0
  54. data/spec/fixtures/ini_fixtures/no_token.ini +1 -0
  55. data/spec/fixtures/ini_fixtures/sections.ini +5 -0
  56. data/spec/fixtures/json_fixtures/issue_22.json +77 -0
  57. data/spec/fixtures/json_fixtures/simple.json +34 -0
  58. data/spec/fixtures/json_fixtures/wl1z0pal05vy.json +437 -0
  59. data/spec/fixtures/vcr_fixtures/generate_json.yml +384 -0
  60. data/spec/fixtures/vcr_fixtures/issue_22.yml +2488 -0
  61. data/spec/spec_helper.rb +51 -0
  62. metadata +167 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 350dcf7465b5d8ccd0efcdbb8351e6504bf653c0
4
- data.tar.gz: 1c554d4d7ec3606eb026d671660dae89aad58b28
3
+ metadata.gz: c454afb5aa1257e813b5f668b67c49538091812f
4
+ data.tar.gz: dc137c43d045a69be4dd75102b7b6389a41be490
5
5
  SHA512:
6
- metadata.gz: 623d664fcd58c48df3b1067c18ae757d5e831c827f24acc4f01c59a5b7926af1f5681b4b85f9d764c66700043862af4d940620a4c52520f398c189a0e39d3358
7
- data.tar.gz: 4fba258364e79b46261f7ef7e5584c6b64090678c5725e9ad0720b5d671cb96704abbfed658d2db94c27ea3a223708248893eb0357c9f960cf89cd0690247fd8
6
+ metadata.gz: 9890d7da94353a39bf694cba99921f660513490a362d23bd0134ba68eb39253b9ae761f3d96ccf496df1b920717217186b57972923af244be2831578b127f7c4
7
+ data.tar.gz: 48b153d5610352f98ab2291b63cc87fe6a52cc283163be42babfea205376418d362e6bd5116683dcdf09a646bebd9cd1c641738305c18abf777dc1112e2cf788
data/.rubocop.yml ADDED
@@ -0,0 +1,26 @@
1
+ Metrics/LineLength:
2
+ Max: 120
3
+ Exclude:
4
+ - 'lib/contentful/bootstrap/templates/blog.rb'
5
+ - 'lib/contentful/bootstrap/templates/catalogue.rb'
6
+ - 'lib/contentful/bootstrap/templates/gallery.rb'
7
+
8
+ Style/Documentation:
9
+ Exclude:
10
+ - 'spec/**/*'
11
+ - 'test/**/*'
12
+ - 'lib/contentful/bootstrap/commands.rb'
13
+ - 'lib/contentful/bootstrap/constants.rb'
14
+ - 'lib/contentful/bootstrap/generator.rb'
15
+ - 'lib/contentful/bootstrap/server.rb'
16
+ - 'lib/contentful/bootstrap/support.rb'
17
+ - 'lib/contentful/bootstrap/templates/base.rb'
18
+ - 'lib/contentful/bootstrap/templates/blog.rb'
19
+ - 'lib/contentful/bootstrap/templates/catalogue.rb'
20
+ - 'lib/contentful/bootstrap/templates/gallery.rb'
21
+ - 'lib/contentful/bootstrap/templates/json_template.rb'
22
+ - 'lib/contentful/bootstrap/templates/links/asset.rb'
23
+ - 'lib/contentful/bootstrap/templates/links/base.rb'
24
+ - 'lib/contentful/bootstrap/templates/links/entry.rb'
25
+ - 'lib/contentful/bootstrap/token.rb'
26
+ - 'lib/contentful/bootstrap/version.rb'
data/.rubocop_todo.yml ADDED
@@ -0,0 +1,123 @@
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config`
3
+ # on 2015-11-12 15:38:57 -0300 using RuboCop version 0.35.1.
4
+ # The point is for the user to remove these configuration records
5
+ # one by one as the offenses are removed from the code base.
6
+ # Note that changes in the inspected code, or installation of new
7
+ # versions of RuboCop, may require this file to be generated again.
8
+
9
+ # Offense count: 8
10
+ Metrics/AbcSize:
11
+ Max: 52
12
+
13
+ # Offense count: 4
14
+ # Configuration parameters: CountComments.
15
+ Metrics/ClassLength:
16
+ Max: 176
17
+
18
+ # Offense count: 1
19
+ Metrics/CyclomaticComplexity:
20
+ Max: 7
21
+
22
+ # Offense count: 16
23
+ # Configuration parameters: AllowURI, URISchemes.
24
+ Metrics/LineLength:
25
+ Max: 316
26
+
27
+ # Offense count: 19
28
+ # Configuration parameters: CountComments.
29
+ Metrics/MethodLength:
30
+ Max: 88
31
+
32
+ # Offense count: 1
33
+ Metrics/PerceivedComplexity:
34
+ Max: 9
35
+
36
+ # Offense count: 2
37
+ # Cop supports --auto-correct.
38
+ # Configuration parameters: EnforcedStyle, SupportedStyles, ProceduralMethods, FunctionalMethods, IgnoredMethods.
39
+ Style/BlockDelimiters:
40
+ Exclude:
41
+ - 'spec/contentful/bootstrap/generator_spec.rb'
42
+
43
+ # Offense count: 2
44
+ Style/ClassVars:
45
+ Exclude:
46
+ - 'lib/contentful/bootstrap/token.rb'
47
+
48
+ # Offense count: 1
49
+ # Cop supports --auto-correct.
50
+ Style/DeprecatedHashMethods:
51
+ Exclude:
52
+ - 'bin/contentful_bootstrap'
53
+
54
+ # Offense count: 20
55
+ # Configuration parameters: Exclude.
56
+ Style/Documentation:
57
+ Exclude:
58
+ - 'spec/**/*'
59
+ - 'test/**/*'
60
+ - 'lib/contentful/bootstrap/commands.rb'
61
+ - 'lib/contentful/bootstrap/constants.rb'
62
+ - 'lib/contentful/bootstrap/generator.rb'
63
+ - 'lib/contentful/bootstrap/server.rb'
64
+ - 'lib/contentful/bootstrap/support.rb'
65
+ - 'lib/contentful/bootstrap/templates/base.rb'
66
+ - 'lib/contentful/bootstrap/templates/blog.rb'
67
+ - 'lib/contentful/bootstrap/templates/catalogue.rb'
68
+ - 'lib/contentful/bootstrap/templates/gallery.rb'
69
+ - 'lib/contentful/bootstrap/templates/json_template.rb'
70
+ - 'lib/contentful/bootstrap/templates/links/asset.rb'
71
+ - 'lib/contentful/bootstrap/templates/links/base.rb'
72
+ - 'lib/contentful/bootstrap/templates/links/entry.rb'
73
+ - 'lib/contentful/bootstrap/token.rb'
74
+ - 'lib/contentful/bootstrap/version.rb'
75
+
76
+ # Offense count: 1
77
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
78
+ Style/FormatString:
79
+ Exclude:
80
+ - 'lib/contentful/bootstrap/commands.rb'
81
+
82
+ # Offense count: 1
83
+ # Cop supports --auto-correct.
84
+ # Configuration parameters: MaxLineLength.
85
+ Style/IfUnlessModifier:
86
+ Exclude:
87
+ - 'bin/contentful_bootstrap'
88
+
89
+ # Offense count: 3
90
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
91
+ Style/MethodName:
92
+ Enabled: false
93
+
94
+ # Offense count: 2
95
+ Style/MultilineBlockChain:
96
+ Exclude:
97
+ - 'lib/contentful/bootstrap/generator.rb'
98
+
99
+ # Offense count: 1
100
+ # Cop supports --auto-correct.
101
+ # Configuration parameters: PreferredDelimiters.
102
+ Style/PercentLiteralDelimiters:
103
+ Exclude:
104
+ - 'contentful_bootstrap.gemspec'
105
+
106
+ # Offense count: 68
107
+ # Cop supports --auto-correct.
108
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
109
+ Style/StringLiterals:
110
+ Enabled: false
111
+
112
+ # Offense count: 1
113
+ # Cop supports --auto-correct.
114
+ # Configuration parameters: EnforcedStyleForMultiline, SupportedStyles.
115
+ Style/TrailingComma:
116
+ Exclude:
117
+ - 'bin/contentful_bootstrap'
118
+
119
+ # Offense count: 1
120
+ # Cop supports --auto-correct.
121
+ Style/UnneededPercentQ:
122
+ Exclude:
123
+ - 'contentful_bootstrap.gemspec'
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.1.7
5
+ - 2.2.3
6
+ - 2.0.0
data/CHANGELOG.md CHANGED
@@ -1,6 +1,31 @@
1
1
  # Change Log
2
+
2
3
  ## Unreleased
3
4
 
5
+ ## v2.0.2
6
+ ### Fixed
7
+ * Array and Link handling
8
+
9
+ ### Changed
10
+ * Command now provide better help on incomplete command
11
+
12
+ ## v2.0.1 [YANKED]
13
+ ### Changed
14
+ * Scoped File Usage on GenerateJson Command
15
+
16
+ ## v2.0.0 [YANKED]
17
+ ### Changed
18
+ * Refactored `Commands` into new classes
19
+ * Renamed `Commands` to `CommandRunner`, kept external interface, moved internal logic to new `Commands` classes
20
+ * Refactored `Token` to be an Object instead of a collection of static behavior
21
+ * General code refactoring and cleanup
22
+
23
+ ### Added
24
+ * More robust mechanism for waiting on processed assets
25
+ * JSON Template generator `generate_json` command
26
+ * Added Specs for almost all the code
27
+ * Applied Rubocop Style guide
28
+
4
29
  ## v1.6.0
5
30
  ### Added
6
31
  * Support for Symbols in Array fields
data/Gemfile CHANGED
@@ -6,3 +6,4 @@ gemspec
6
6
  gem "launchy"
7
7
  gem "inifile"
8
8
  gem "contentful-management"
9
+ gem "contentful", "~> 0.7"
data/Guardfile ADDED
@@ -0,0 +1,5 @@
1
+ guard :rspec, cmd: 'rspec --format documentation --color' do
2
+ watch(%r{^spec/.+_spec\.rb$})
3
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
4
+ watch('spec/spec_helper.rb') { "spec" }
5
+ end
data/README.md CHANGED
@@ -1,3 +1,5 @@
1
+ [![Build Status](https://travis-ci.org/contentful-labs/contentful-bootstrap.rb.svg)](https://travis-ci.org/contentful-labs/contentful-bootstrap.rb)
2
+
1
3
  # Contentful Bootstrap
2
4
 
3
5
  A small CLI tool for getting started with Contentful
@@ -9,8 +11,7 @@ and publish it anywhere via powerful API. Contentful offers tools for managing e
9
11
  teams and enabling cooperation between organizations.
10
12
 
11
13
  ## What does `contentful_bootstrap` do?
12
- The aim of `contentful_bootstrap` is to have developers setting up their Contentful environment
13
- in a single command
14
+ `contentful_bootstrap` let's you set up a new Contentful environment with a single command.
14
15
 
15
16
  ## How to Use
16
17
 
@@ -22,22 +23,27 @@ $ gem install contentful_bootstrap
22
23
 
23
24
  ### Usage
24
25
 
25
- You can create spaces by doing
26
+ You can create spaces by doing:
26
27
 
27
28
  ```bash
28
29
  $ contentful_bootstrap create_space <space_name> [--template template_name] [--json-template template_path] [--config CONFIG_PATH]
29
30
  ```
30
31
 
31
-
32
32
  You can also generate new Delivery API Tokens by doing:
33
33
 
34
34
  ```bash
35
35
  $ contentful_bootstrap generate_token <space_id> [--name token_name] [--config CONFIG_PATH]
36
36
  ```
37
37
 
38
- ### Available templates
38
+ You can also generate JSON Templates from existing spaces by doing:
39
+
40
+ ```bash
41
+ $ contentful_bootstrap generate_json <space_id> <access_token> [--output-file OUTPUT PATH]
42
+ ```
39
43
 
40
- The available templates for your spaces are:
44
+ ### Built-in templates
45
+
46
+ Just getting started with Contentful? We have included the following built-in templates:
41
47
 
42
48
  ```
43
49
  blog
@@ -45,8 +51,9 @@ gallery
45
51
  catalogue
46
52
  ```
47
53
 
48
- This will get you started with Contentful by setting up a Space with some Demo Data to get you
49
- started as soon as possible with development using our API.
54
+ You can use these with the `--template` option to create some demo data and start developing
55
+ against our APIs right away. Once you've gotten comfortable, you can
56
+ [create your own templates](#json-templates) for quickly replicating testing & development spaces.
50
57
 
51
58
  ### Using from within other applications
52
59
 
@@ -65,7 +72,7 @@ require 'contentful/bootstrap'
65
72
  To Create a new Space
66
73
 
67
74
  ```ruby
68
- Contentful::Bootstrap::Commands.new.create_space("space_name")
75
+ Contentful::Bootstrap::CommandRunner.new.create_space("space_name")
69
76
  ```
70
77
 
71
78
  Additionally, you can send an options hash with the following keys:
@@ -76,13 +83,13 @@ options = {
76
83
  json_template: "/path/to/template.json", # Will use the JSON file specified as a Template
77
84
  trigger_oauth: true # if true will trigger OAuth process
78
85
  }
79
- Contentful::Bootstrap::Commands.new.create_space("space_name", options)
86
+ Contentful::Bootstrap::CommandRunner.new.create_space("space_name", options)
80
87
  ```
81
88
 
82
89
  To Create a new Delivery API Token
83
90
 
84
91
  ```ruby
85
- Contentful::Bootstrap::Commands.new.generate_token("space_id")
92
+ Contentful::Bootstrap::CommandRunner.new.generate_token("space_id")
86
93
  ```
87
94
 
88
95
  Additionally, you can send an options hash with the following keys:
@@ -92,10 +99,27 @@ options = {
92
99
  name: "Some Nice Token Name", # Will Create the Delivery API Token with the specified name
93
100
  trigger_oauth: true # if true will trigger OAuth process
94
101
  }
95
- Contentful::Bootstrap::Commands.new.create_space("space_name", options)
102
+ Contentful::Bootstrap::CommandRunner.new.generate_token("space_id", options)
103
+ ```
104
+
105
+ To Generate a JSON Template from an exising Space
106
+
107
+ ```ruby
108
+ Contentful::Bootstrap::CommandRunner.new.generate_json("space_id", access_token: "access_token")
109
+ ```
110
+
111
+ Additionally, you can send an options hash with the following keys:
112
+ **NOTE**: The `:access_token` key is required in the options hash
113
+
114
+ ```ruby
115
+ options = {
116
+ access_token: "access_token" # REQUIRED
117
+ filename: "template.json" # Will save the JSON to the specified file
118
+ }
119
+ Contentful::Bootstrap::CommandRunner.new.generate_json("space_id", options)
96
120
  ```
97
121
 
98
- Optionally, `Commands#new` will take a parameter for specifying a configuration path
122
+ Optionally, `CommandRunner#new` will take a parameter for specifying a configuration path
99
123
 
100
124
  ### Configuration
101
125
 
@@ -119,7 +143,9 @@ CONTENTFUL_DELIVERY_ACCESS_TOKEN = a_delivery_acces_token ; Delivery Access
119
143
 
120
144
  ### JSON Templates
121
145
 
122
- You can find a complete example [here](./examples/templates/catalogue.json)
146
+ Using the `--json-template` option, you can create spaces with your own predefined content.
147
+ This can be useful for creating testing & development spaces or just starting new projects from
148
+ a common baseline. You can find a complete example [here](./examples/templates/catalogue.json)
123
149
 
124
150
  ## Contributing
125
151
 
data/Rakefile CHANGED
@@ -1,2 +1,9 @@
1
1
  require "bundler/gem_tasks"
2
2
 
3
+ require 'rspec/core/rake_task'
4
+ RSpec::Core::RakeTask.new do |t|
5
+ t.rspec_opts = '--format documentation --color'
6
+ end
7
+
8
+ task test: :spec
9
+ task default: :spec
@@ -1,22 +1,13 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require 'optparse'
4
- require 'contentful/bootstrap/commands'
4
+ require 'contentful/bootstrap/command_runner'
5
5
 
6
6
  options = {}
7
- global = OptionParser.new do |opts|
8
- opts.banner = "Usage: contentful_bootstrap <command> <space_name> [options]"
9
- opts.separator ""
10
- opts.separator <<-HELP
11
- Available commands are:
12
- create_space
13
- generate_token
14
- HELP
15
- end
16
7
 
17
8
  subcommands = {
18
9
  'create_space' => OptionParser.new do |opts|
19
- opts.banner = "Usage: init <space_name> [--template TEMPLATE_NAME] [--json-template JSON_PATH] [--config CONFIG_PATH]"
10
+ opts.banner = "Usage: create_space <space_name> [--template TEMPLATE_NAME] [--json-template JSON_PATH] [--config CONFIG_PATH]"
20
11
  opts.on("-t TEMPLATE", "--template TEMPLATE", "Specify Template", "Available Templates: blog, catalogue, gallery") do |t|
21
12
  options[:template] = t
22
13
  end
@@ -41,45 +32,65 @@ subcommands = {
41
32
  opts.on_tail("-h", "--help", "Print this message") do
42
33
  puts opts
43
34
  end
44
- end
35
+ end,
36
+ 'generate_json' => OptionParser.new do |opts|
37
+ opts.banner = "Usage: generate_json <space_id> <access_token> [--output-file OUTPUT_PATH]"
38
+ opts.on("-o OUTPUT_PATH", "--output-file OUTPUT_PATH", "Specify Output File") do |f|
39
+ options[:filename] = f
40
+ end
41
+ opts.on_tail("-h", "--help", "Print this message") do
42
+ puts opts
43
+ end
44
+ end,
45
45
  }
46
46
 
47
+ global = OptionParser.new do |opts|
48
+ opts.banner = "Usage: contentful_bootstrap <command> <space_name> [options]"
49
+ opts.separator ""
50
+ opts.separator <<-HELP
51
+ Available commands are:
52
+ \t#{subcommands.keys.sort.join("\n\t")}
53
+ HELP
54
+ end
55
+
47
56
  global.order!
48
57
  command = ARGV.shift
49
58
 
50
59
  is_help = ARGV.include?("-h") || ARGV.include?("--help")
51
60
  space = ARGV.shift unless is_help
52
61
 
53
- unless STDIN.tty? && STDOUT.tty?
54
- $stderr.write "This tool requires user interaction\n"
55
- $stderr.write "Exiting!\n"
56
- exit
57
- end
62
+ options[:access_token] = ARGV.shift if command == "generate_json" && !is_help
58
63
 
59
64
  if subcommands.has_key? command
60
65
  subcommands[command].order!
61
66
 
67
+ unless STDIN.tty? && STDOUT.tty?
68
+ $stderr.write "This tool requires user interaction\n"
69
+ $stderr.write "Exiting!\n"
70
+ exit
71
+ end
72
+
62
73
  if is_help
63
74
  exit
64
75
  end
65
76
 
66
77
  if space.nil? || space.empty?
67
- puts "Usage: contentful_bootstrap <command> <space> [options]"
78
+ ARGV << '-h'
79
+ subcommands[command].order!
68
80
  puts
69
- puts "You must provide a valid space name. Exiting!"
81
+ puts "Required Arguments not specified. Exiting!"
70
82
  exit
71
83
  end
72
84
 
73
85
  options[:trigger_oauth] = true
74
86
 
75
- Contentful::Bootstrap::Commands.new(options.fetch(:config_path, "")).send(command, space, options)
87
+ Contentful::Bootstrap::CommandRunner.new(options.fetch(:config_path, "")).send(command, space, options)
76
88
  else
77
89
  puts "Usage: contentful_bootstrap <command> <space> [options]"
78
90
  puts
79
91
  puts <<-HELP
80
92
  Subcommand not available or missing
81
93
  Available commands are:
82
- create_space
83
- generate_token
84
94
  HELP
95
+ puts "\t#{subcommands.keys.sort.join("\n\t")}"
85
96
  end