storageroom-to-contentful 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,41 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /test/tmp/
9
+ /test/version_tmp/
10
+ /tmp/
11
+
12
+ ## Specific to RubyMotion:
13
+ .dat*
14
+ .repl_history
15
+ build/
16
+
17
+ ## Documentation cache and generated files:
18
+ /.yardoc/
19
+ /_yardoc/
20
+ /doc/
21
+ /rdoc/
22
+
23
+ ## Environment normalisation:
24
+ /.bundle/
25
+ /lib/bundler/man/
26
+
27
+ # for a library or gem, you might want to ignore these files since the code is
28
+ # intended to run in multiple environments; otherwise, check them in:
29
+ # Gemfile.lock
30
+ # .ruby-version
31
+ # .ruby-gemset
32
+
33
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
34
+ .rvmrc
35
+
36
+ #RubyMine
37
+ .idea
38
+
39
+
40
+
41
+ data
data/.rubocop.yml ADDED
@@ -0,0 +1,40 @@
1
+ Encoding:
2
+ Enabled: false
3
+
4
+ Documentation:
5
+ Enabled: false
6
+
7
+ ClassLength:
8
+ Enabled: false
9
+
10
+ AllCops:
11
+ Exclude:
12
+ - contentful-management.gemspec
13
+ - bin/cma-console
14
+
15
+ LineLength:
16
+ Max: 135
17
+ Style/MethodLength:
18
+ Max: 15
19
+
20
+ Style/SpaceInsideBrackets:
21
+ Enabled: false
22
+
23
+ Style/CyclomaticComplexity:
24
+ Max: 8
25
+
26
+ Style/SpaceInsideHashLiteralBraces:
27
+ EnforcedStyle: no_space
28
+ EnforcedStyleForEmptyBraces: no_space
29
+
30
+ Style/CaseIndentation:
31
+ Enabled: false
32
+
33
+ Lint/UselessAssignment:
34
+ Enabled: false
35
+
36
+ Style/IndentationWidth:
37
+ Enabled: false
38
+
39
+ Style/GuardClause:
40
+ Enabled: false
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ - 1.9.3
5
+ - jruby-19mode
6
+ - rbx-2
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ source 'https://rubygems.org'
2
+ # Specify your gem's dependencies in storageroom-to-contentful.gemspec
3
+ gemspec
4
+
5
+ group :test do
6
+ gem 'rspec'
7
+ gem 'vcr'
8
+ gem 'webmock'
9
+ gem 'simplecov', require: false
10
+ gem 'rubocop'
11
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,77 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ storageroom-to-contentful (0.0.1)
5
+ contentful-management (~> 0.2)
6
+ http (~> 0.6)
7
+ i18n (~> 0.6)
8
+ multi_json (~> 1)
9
+
10
+ GEM
11
+ remote: https://rubygems.org/
12
+ specs:
13
+ addressable (2.3.6)
14
+ ast (2.0.0)
15
+ astrolabe (1.3.0)
16
+ parser (>= 2.2.0.pre.3, < 3.0)
17
+ contentful-management (0.2.1)
18
+ http (~> 0.6)
19
+ multi_json (~> 1)
20
+ crack (0.4.2)
21
+ safe_yaml (~> 1.0.0)
22
+ diff-lcs (1.2.5)
23
+ docile (1.1.5)
24
+ http (0.6.2)
25
+ http_parser.rb (~> 0.6.0)
26
+ http_parser.rb (0.6.0)
27
+ i18n (0.6.11)
28
+ multi_json (1.10.1)
29
+ parser (2.2.0.pre.4)
30
+ ast (>= 1.1, < 3.0)
31
+ slop (~> 3.4, >= 3.4.5)
32
+ powerpack (0.0.9)
33
+ rainbow (2.0.0)
34
+ rake (10.3.2)
35
+ rspec (3.1.0)
36
+ rspec-core (~> 3.1.0)
37
+ rspec-expectations (~> 3.1.0)
38
+ rspec-mocks (~> 3.1.0)
39
+ rspec-core (3.1.4)
40
+ rspec-support (~> 3.1.0)
41
+ rspec-expectations (3.1.1)
42
+ diff-lcs (>= 1.2.0, < 2.0)
43
+ rspec-support (~> 3.1.0)
44
+ rspec-mocks (3.1.1)
45
+ rspec-support (~> 3.1.0)
46
+ rspec-support (3.1.0)
47
+ rubocop (0.26.1)
48
+ astrolabe (~> 1.3)
49
+ parser (>= 2.2.0.pre.4, < 3.0)
50
+ powerpack (~> 0.0.6)
51
+ rainbow (>= 1.99.1, < 3.0)
52
+ ruby-progressbar (~> 1.4)
53
+ ruby-progressbar (1.6.0)
54
+ safe_yaml (1.0.3)
55
+ simplecov (0.9.1)
56
+ docile (~> 1.1.0)
57
+ multi_json (~> 1.0)
58
+ simplecov-html (~> 0.8.0)
59
+ simplecov-html (0.8.0)
60
+ slop (3.6.0)
61
+ vcr (2.9.3)
62
+ webmock (1.18.0)
63
+ addressable (>= 2.3.6)
64
+ crack (>= 0.3.2)
65
+
66
+ PLATFORMS
67
+ ruby
68
+
69
+ DEPENDENCIES
70
+ bundler (~> 1.6)
71
+ rake
72
+ rspec
73
+ rubocop
74
+ simplecov
75
+ storageroom-to-contentful!
76
+ vcr
77
+ webmock
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 Contentful GmbH
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,208 @@
1
+ StorageRoom to Contentful
2
+ =================
3
+
4
+ ## Description
5
+ This tool can be used to migrate data from [StorageRoom](http://storageroomapp.com/) to the [Contentful](https://www.contentful.com) platform.
6
+
7
+ It exports the data from StorageRoom as JSON to the local hard drive, tries to convert the data to the Contentful data types and allows to recreate the data on Contentful.
8
+
9
+
10
+ ## Installation
11
+
12
+ ``` bash
13
+ gem install storageroom-to-contentful
14
+ ```
15
+
16
+ This will install a ```storageroom-to-contentful``` executable.
17
+
18
+ ## Usage
19
+
20
+ To use the tool you need to specify your StorageRoom and Contentful credentials in a YAML file.
21
+ For example in a ```credentials.yml``` file:
22
+
23
+ ``` yaml
24
+ #Contentful
25
+ ACCESS_TOKEN: access_token
26
+ ORGANIZATION_ID: organization_id
27
+
28
+ #StorageRoom
29
+ ACCOUNT_ID: account_id
30
+ APPLICATION_API_KEY: application_key_id%
31
+ ```
32
+
33
+ Your Contentful access token can be easiest created using the [Contentful Management API - documentation](https://www.contentful.com/developers/documentation/content-management-api/#getting-started)
34
+
35
+ Once you installed the Gem and created the YAML file with the credentials you can invoke the tool using:
36
+
37
+ ``` bash
38
+ storageroom-to-contentful credentials.yml
39
+ ```
40
+
41
+ You will be presented with a bunch of options:
42
+
43
+ ```
44
+ Actions:
45
+ 1. Export data from StorageRoom to JSON files.
46
+ 2. Convert Storageroom field types to Contentful.
47
+ 3. Import collections to Contentful.
48
+ 4. Import entries to Contentful.
49
+ 5. Publish all entries on Contentful.
50
+ ```
51
+
52
+
53
+
54
+ ##Step 1 - Export data from StorageRoom to JSON files:
55
+
56
+ Downloads all data from StorageRoom and saves it locally as JSON files.
57
+ The data will be copied to the current working directory in a sub folder called `data`.
58
+
59
+ You either manually adjust the data types or try an automatic translation.
60
+ In either case we suggest to put the `data` directory under version control like git and commit after each change.
61
+
62
+
63
+ Available types of field on Contentful:
64
+ ```
65
+ 1. 'Symbol'
66
+ 2. 'Text'
67
+ 3. 'Integer'
68
+ 4. 'Number'
69
+ 5. 'Date'
70
+ 6. 'Boolean'
71
+ 7. 'Link'
72
+ 8. 'Array'
73
+ 9. 'Object'
74
+ 10. 'Location'
75
+ ```
76
+
77
+ All files in ```data/collections``` must be inspected and changed.
78
+ Any occurrence of the *input_type* attribute must changed to a type that is available on Contentful.
79
+
80
+ #### File & Image
81
+
82
+ File and Image are equivalent to ```Asset``` in Contentful.
83
+ To create Asset type in Contentful, you must change ```input_type``` to ```Asset```.
84
+
85
+ #### Select
86
+
87
+ StorageRoom has a field type: ```select``` which is not directly referred in Contentful.
88
+ As an equivalent it can be treated as a Symbol.
89
+ To create a single ```Symbol``` you must change ```input_type``` to ```Symbol```
90
+
91
+ Example:
92
+ ```
93
+ "name": "Symbols",
94
+ "identifier": "symbol_tag",
95
+ "input_type": "Symbol",
96
+ ```
97
+ #### Array
98
+ StorageRoom has a field type: ```Array``` that can not directly be mapped to Contentful.
99
+ As n equivalent it can be treated as a ```Multiple Symbols```.
100
+ To create a multiple ```Symbols``` you must change ```input_type``` to ```Array``` and add an additional parameter:
101
+ ```"link": "Symbol"```
102
+
103
+
104
+ Example:
105
+ ```
106
+ "name": "Symbols",
107
+ "identifier": "symbol_tag",
108
+ "input_type": "Array",
109
+ "link": "Symbol"
110
+ ```
111
+
112
+ #### Locale
113
+ Entries in Contentful can be localized.
114
+ When importing Entries from StorageRoom to Contentful, some may have attributes that are named as 'locale'.
115
+ Is the value of this attribute not the same as locale ```code``` on Contentful creating the entries will fail.
116
+ You always need to create the locales on Contentful before you start the import.
117
+
118
+
119
+ ##Association
120
+ ```
121
+ 1. OneAssociationField (To-One)
122
+ 2. ManyAssociationField (To-Many)
123
+ ```
124
+
125
+ #### OneAssociationField (To-One)
126
+
127
+ To create an ```Entry``` or ```Asset``` Link type, you must change the ```input_type``` to ```Asset``` or ```Entry```.
128
+
129
+ #### ManyAssociationField (To-Many)
130
+
131
+ * Entries
132
+
133
+ To create multiple ```Entries``` Link type, you must change the ```link_type``` to ```Array``` and add an additional parameter:
134
+ ```"link_type": "Entry"```
135
+
136
+ Example:
137
+ ```
138
+ "name": "Entries",
139
+ "identifier": "entries",
140
+ "input_type": "Array",
141
+ "required": true,
142
+ "unique": null,
143
+ "link_type": "Entry"
144
+ ```
145
+ ##Step 2 - Convert Storageroom field types to Contentful:
146
+
147
+ To convert values of ​​input_type in each collection file (``` data/collections/ ```), select action '2' from the menu.
148
+
149
+ ##Step 3 - Import collections to Contentful:
150
+ Once the exported StorageRoom data is transformed to be compatible with Contentful you can start the import.
151
+
152
+ Run script again and select action '3' from the menu.
153
+ Enter the name of the new space on Contentful and import the collections as content types.
154
+
155
+ Once the exported StorageRoom data is transformed to be compatible with Contentful you can start the import.
156
+
157
+ Run script again and select action '3' from the menu.
158
+ Enter the name of the new space on Contentful and import the collections as content types.
159
+
160
+ ## Convert symbol values to String:
161
+ If the collection has a field of type ```Symbol```, the value of the entry must be strings.
162
+
163
+ Example:
164
+ #### Field in Collection
165
+ ```
166
+ {
167
+ "@type": "IntegerField",
168
+ "name": "Price Range",
169
+ "identifier": "price_range",
170
+ "input_type": "Symbol",
171
+ "required": true,
172
+ "include_blank_choice": false,
173
+ "choices": [
174
+ 1,
175
+ 2,
176
+ 3
177
+ ]
178
+ },
179
+ ```
180
+ #### Entry
181
+ ```
182
+ {
183
+ "@type": "Restaurant",
184
+ "price_range": 2,
185
+ }
186
+ ```
187
+
188
+ ##Step 4 - Import entries to Contentful:
189
+ To import all the entries from the exported data to the Contentful platform, select action '4' from the menu.
190
+
191
+ Each entry will be created with the same StorageRoom id.
192
+
193
+ #### [Links](https://www.contentful.com/developers/documentation/content-management-api/#links)
194
+
195
+ If two or more entries are linked the import tool will recreate those relationships.
196
+
197
+ The entries will be valid once all the required relations are created on Contentful.
198
+
199
+ ##Step 5 - Publish all entries on Contentful:
200
+ To publish all entries, select action '5' from the menu.
201
+
202
+ If an entry can not be published the tool will print an error message containing the reason(eg. Invalid, ...)
203
+
204
+ ##Script execution:
205
+
206
+ ```
207
+ $ storageroom-to-contentful credentials.yml
208
+ ```
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require 'bundler/gem_tasks'
2
+
3
+ require 'rspec/core/rake_task'
4
+
5
+ RSpec::Core::RakeTask.new(:spec)
6
+
7
+ task default: :spec
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env ruby
2
+ require 'yaml'
3
+ require 'i18n'
4
+
5
+ require_relative '../lib/migrator'
6
+
7
+ yaml_path = ARGV.shift
8
+ fail 'Missing credentials.yml file, `storageroom-to-contentful credentials.yml`' unless yaml_path
9
+
10
+ spec = Gem::Specification.find_by_name('storageroom-to-contentful')
11
+ gem_root = spec.gem_dir
12
+
13
+ puts gem_root
14
+ APP_ROOT = Dir.pwd
15
+ DATA_DIR = "#{APP_ROOT}/data"
16
+ COLLECTIONS_DATA_DIR = "#{DATA_DIR}/collections"
17
+ ENTRIES_DATA_DIR = "#{DATA_DIR}/entries"
18
+ STORAGE_ROOM_URL = 'http://api.storageroomapp.com/accounts/'
19
+ CONTENTFUL_TYPES = %w(Text Integer Number Boolean Symbol Array Entry Asset Date Location Object)
20
+
21
+ CREDENTIALS = YAML.load_file(File.expand_path(yaml_path))
22
+
23
+ translations = "#{gem_root}/contenftul_fields_types.yml"
24
+ I18n.load_path << translations
25
+ I18n.enforce_available_locales = false
26
+
27
+ Migrator.new.run