storageroom-to-contentful 0.0.1

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.
@@ -0,0 +1,98 @@
1
+ require 'spec_helper'
2
+ require 'contentful_importer'
3
+ require 'contentful/management'
4
+ require 'yaml'
5
+
6
+ describe ContentfulImporter do
7
+
8
+ before do
9
+ stub_const('ContentfulImporter::STORAGE_ROOM_URL', 'http://api.storageroomapp.com/accounts/')
10
+ stub_const('ContentfulImporter::COLLECTIONS_DATA_DIR', 'spec/support/data/collections')
11
+ stub_const('ContentfulImporter::ENTRIES_DATA_DIR', 'spec/support/data/entries')
12
+ stub_const('ContentfulImporter::CREDENTIALS', YAML.load_file('spec/support/credentials_spec.yaml'))
13
+ end
14
+
15
+ it 'create_space' do
16
+ vcr('import/crate_space') do
17
+ ContentfulImporter.any_instance.stub(:gets).and_return('test')
18
+ space = subject.create_space
19
+ expect(space.name).to eq 'test'
20
+ end
21
+ end
22
+
23
+ it 'import_content_types' do
24
+ vcr('import/content_types') do
25
+ Contentful::Management::Client.new('<ACCESS_TOKEN>')
26
+ space = Contentful::Management::Space.find('ksbb7zto17p9')
27
+ ContentfulImporter.any_instance.stub(:space).and_return(space)
28
+ subject.import_content_types
29
+ content_type = space.content_types.all.first
30
+ expect(content_type.name).to eq 'Codequest'
31
+ expect(content_type.description).to eq 'Testing'
32
+ expect(content_type.fields.count).to eq 13
33
+ expect(content_type.active?).to be_truthy
34
+ end
35
+ end
36
+
37
+ it 'import_entries' do
38
+ vcr('import/entries') do
39
+ subject.import_entries
40
+ Contentful::Management::Client.new('<ACCESS_TOKEN>')
41
+ space = Contentful::Management::Space.find('ksbb7zto17p9')
42
+ entry = space.entries.find('540d6d961e29fa3559000d0d')
43
+ expect(entry.id).to eq '540d6d961e29fa3559000d0d'
44
+ expect(entry.number).to eq 11
45
+ expect(entry.float1).to eq 1.1
46
+ expect(entry.boolean).to eq true
47
+ expect(entry.fields[:array].first).to eq 'some value'
48
+ expect(entry.fields[:file]['sys']['id']).to eq 'LjiUYqF3k2SKkmEyQ2Yc0'
49
+ expect(entry.fields[:image]['sys']['id']).to eq '6GGpDNJTRCYeOGyWKmUqky'
50
+ expect(entry.fields[:entry]['sys']['id']).to eq '4d960919ba05617333000012'
51
+ expect(entry.fields[:entries].first['sys']['id']).to eq '4e2ea1674d085d46a7000021'
52
+ end
53
+ end
54
+
55
+ it 'find_symbol_params_in_collection' do
56
+ stub_const('ContentfulImporter::COLLECTIONS_DATA_DIR', 'spec/support/data/convert/collections')
57
+ stub_const('ContentfulImporter::ENTRIES_DATA_DIR', 'spec/support/data/convert/entries')
58
+ ContentfulImporter.any_instance.stub(:parse_symbol_value_to_string)
59
+ subject.find_symbol_type_in_collection
60
+ end
61
+
62
+ it 'parse_symbol_value_to_string' do
63
+ path = 'spec/support/data/convert/entries/symbol_test/symbol_entry.json'
64
+ entry_attributes = JSON.parse(File.read(path))
65
+ subject.send(:parse_symbol_value_to_string, path, 3, 'stars', entry_attributes)
66
+ end
67
+
68
+ it 'get_space_id' do
69
+ space_id = subject.send(:get_space_id, 'space_id' => '123456')
70
+ expect(space_id).to eq '123456'
71
+ end
72
+
73
+ it 'publish_all_entries' do
74
+ vcr('import/publish_entries') do
75
+ ContentfulImporter.any_instance.stub(:get_space_id).and_return('pwgzawloi92k')
76
+ subject.publish_all_entries
77
+ end
78
+ end
79
+
80
+ it 'map_entries_ids' do
81
+ subject.map_entries_ids
82
+ expect(ContentfulImporter::ENTRIES_IDS.first).to eq '540d6d961e29fa3559000d0d'
83
+ end
84
+
85
+ it 'create_entry' do
86
+ vcr('import/create_entry') do
87
+ Contentful::Management::Client.new('<ACCESS_TOKEN>')
88
+ stub_const('ContentfulImporter::ENTRIES_IDS', '4d960919ba05617333000012')
89
+ entry = {
90
+ '@type' => 'CollectionName',
91
+ 'url' => 'http://api.storageroomapp.com/accounts/account_id/collections/4d960916ba05617333000005/entries/4d960919ba05617333000012'
92
+ }
93
+ entry_object = subject.send(:create_entry, entry, 'jsdhlmknq7i6', '6x5iZOCWreIA4scme2sKwI')
94
+ expect(entry_object.id).to eq '4d960919ba05617333000012'
95
+ end
96
+ end
97
+
98
+ end
@@ -0,0 +1,152 @@
1
+ require 'spec_helper'
2
+ require 'storage_room_exporter'
3
+ require 'contentful/management'
4
+ require 'i18n'
5
+
6
+ describe StorageRoomExporter do
7
+
8
+ before do
9
+ stub_const('StorageRoomExporter::CONTENTFUL_TYPES', %w(Text Integer Number Boolean Symbol Array Entry Asset Date Location Object))
10
+ stub_const('StorageRoomExporter::STORAGE_ROOM_URL', 'http://api.storageroomapp.com/accounts/')
11
+ stub_const('StorageRoomExporter::COLLECTIONS_DATA_DIR', 'spec/support/data/collections')
12
+ stub_const('StorageRoomExporter::ENTRIES_DATA_DIR', 'spec/support/data/entries')
13
+ stub_const('StorageRoomExporter::CREDENTIALS', YAML.load_file('spec/support/credentials_spec.yaml'))
14
+ stub_const('APP_ROOT', File.expand_path('../../../', __FILE__))
15
+ I18n.load_path << "#{APP_ROOT}/contenftul_fields_types.yml"
16
+ end
17
+
18
+ context 'collections' do
19
+ it 'export_collections' do
20
+ vcr('collection/export_collections') do
21
+ StorageRoomExporter.any_instance.stub(:save_to_file)
22
+ collections = subject.export_collections
23
+ expect(collections.count).to eq 4
24
+ expect(collections.first['@type']).to eq 'Collection'
25
+ end
26
+ end
27
+
28
+ it 'get_request ' do
29
+ vcr('collection/get_request') do
30
+ request = subject.send(:get_request, 'collections')
31
+ expect(request['array']['resources'].count).to eq 4
32
+ expect(request['array']['resources'].first['@type']).to eq 'Collection'
33
+ expect(request['array']['resources'].first['entry_type']).to eq 'Announcement'
34
+ end
35
+ end
36
+ it 'collection_id ' do
37
+ collection = JSON.parse(File.read('spec/support/data/collections/codequest.json'))
38
+ collection_id = subject.send(:collection_id, collection)
39
+ expect(collection_id).to eq '540d6d001e29fa3541000d2d'
40
+ end
41
+ end
42
+ context 'entries' do
43
+ it 'export_entries' do
44
+ vcr('entries/export_entries') do
45
+ StorageRoomExporter.any_instance.stub(:save_to_file)
46
+ entries = subject.export_entries
47
+ request = subject.send(:entries, entries.first)
48
+ expect(request.count).to eq 8
49
+ expect(request.first['@type']).to eq 'Announcement'
50
+ expect(request.first['text']).to eq 'Welcome to our app. Try clicking around.'
51
+ end
52
+ end
53
+
54
+ it 'get all entries from storageroom' do
55
+ vcr('entries/entries') do
56
+ collection = JSON.parse(File.read('spec/support/data/collections/codequest.json'))
57
+ request = subject.send(:entries, collection)
58
+ expect(request.count).to eq 2
59
+ expect(request.first['@type']).to eq 'Codequest'
60
+ expect(request.first['name']).to eq 'Test'
61
+ expect(request.first['number']).to eq 11
62
+ end
63
+ end
64
+ end
65
+
66
+ it 'save_to_file' do
67
+ entry = File.read('spec/support/data/entries/codequest/540d6d961e29fa3559000d0d.json')
68
+ subject.send(:save_to_file, 'spec/support/data', 'save_to_file', entry)
69
+ end
70
+
71
+ it 'mapping_collections_input_types' do
72
+ stub_const('StorageRoomExporter::COLLECTIONS_DATA_DIR', 'spec/support/data/convert/mapping')
73
+ subject.mapping_collections_input_types
74
+ end
75
+
76
+ context 'mapping_array_fields' do
77
+ it 'add symbol link to array of symbols' do
78
+ field = {:@type => 'ArrayField'}
79
+ subject.send(:mapping_array_type, field)
80
+ expect(field['link']).to eq 'Symbol'
81
+ end
82
+ it 'add entry link_type to Array of Entries' do
83
+ field = {:@type => 'ManyAssociationField'}
84
+ subject.send(:mapping_array_type, field)
85
+ expect(field['link_type']).to eq 'Entry'
86
+ end
87
+ end
88
+
89
+ context 'translate input types' do
90
+ it 'StringField and text_field' do
91
+ field = {:@type => 'StringField', :input_type => 'text_field'}
92
+ subject.send(:translate_input_type, field)
93
+ expect(field[:input_type]).to eq 'Text'
94
+ end
95
+ it 'IntegerField and text_field' do
96
+ field = {:@type => 'IntegerField', :input_type => 'text_field'}
97
+ subject.send(:translate_input_type, field)
98
+ expect(field[:input_type]).to eq 'Integer'
99
+ end
100
+ it 'FloatFied and text_field' do
101
+ field = {:@type => 'FloatField', :input_type => 'text_field'}
102
+ subject.send(:translate_input_type, field)
103
+ expect(field[:input_type]).to eq 'Number'
104
+ end
105
+ it 'Location and text_field' do
106
+ field = {:@type => 'Location', :input_type => 'location'}
107
+ subject.send(:translate_input_type, field)
108
+ expect(field[:input_type]).to eq 'Location'
109
+ end
110
+ it 'BooleanField and radio' do
111
+ field = {:@type => 'BooleanField', :input_type => 'radio'}
112
+ subject.send(:translate_input_type, field)
113
+ expect(field[:input_type]).to eq 'Boolean'
114
+ end
115
+ it 'Select' do
116
+ field = {:@type => 'StringField', :input_type => 'select'}
117
+ subject.send(:translate_input_type, field)
118
+ expect(field[:input_type]).to eq 'Symbol'
119
+ end
120
+ it 'Image and File' do
121
+ field = {:@type => 'File', :input_type => 'file'}
122
+ subject.send(:translate_input_type, field)
123
+ expect(field[:input_type]).to eq 'Asset'
124
+ end
125
+
126
+ it 'OneAssociationField' do
127
+ field = {:@type => 'OneAssociationField', :input_type => 'association_field'}
128
+ subject.send(:translate_input_type, field)
129
+ expect(field[:input_type]).to eq 'Entry'
130
+ end
131
+
132
+ it 'OneAssociationField' do
133
+ field = {:@type => 'ManyAssociationField', :input_type => 'association_field'}
134
+ subject.send(:translate_input_type, field)
135
+ expect(field[:input_type]).to eq 'Array'
136
+ end
137
+
138
+ it 'Array_field' do
139
+ field = {:@type => 'ManyAssociationField', :input_type => 'array_field'}
140
+ subject.send(:translate_input_type, field)
141
+ expect(field[:input_type]).to eq 'Array'
142
+ end
143
+
144
+ it 'Json_field' do
145
+ field = {:@type => 'JsonField', :input_type => 'json_field'}
146
+ subject.send(:translate_input_type, field)
147
+ expect(field[:input_type]).to eq 'Object'
148
+ end
149
+
150
+ end
151
+
152
+ end
@@ -0,0 +1,14 @@
1
+ require 'simplecov'
2
+ SimpleCov.start
3
+ require 'rspec'
4
+
5
+ Dir[File.dirname(__FILE__) + '/support/**/*.rb'].each { |f| require f }
6
+
7
+ RSpec.configure do |config|
8
+ config.mock_with :rspec do |c|
9
+ c.syntax = [:should, :expect]
10
+ end
11
+ config.expect_with :rspec do |c|
12
+ c.syntax = [:should, :expect]
13
+ end
14
+ end
@@ -0,0 +1,7 @@
1
+ #Contentful
2
+ ACCESS_TOKEN: <ACCESS_TOKEN>
3
+ ORGANIZATION_ID: <ORGANIZATION_ID>
4
+
5
+ #Storageroom
6
+ ACCOUNT_ID: account_id
7
+ APPLICATION_API_KEY: application_api_key
@@ -0,0 +1,16 @@
1
+ require 'vcr'
2
+
3
+ VCR.configure do |c|
4
+ c.cassette_library_dir = 'spec/fixtures/vcr_cassettes'
5
+ c.ignore_localhost = true
6
+ c.hook_into :webmock
7
+ c.default_cassette_options = {record: :once}
8
+ end
9
+
10
+ def vcr(name, &block)
11
+ VCR.use_cassette(name, &block)
12
+ end
13
+
14
+ def expect_vcr(name, &block)
15
+ expect { VCR.use_cassette(name, &block) }
16
+ end
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ require File.expand_path('../lib/version', __FILE__)
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'storageroom-to-contentful'
9
+ spec.version = Version::VERSION
10
+ spec.authors = ['Andreas Tiefenthaler']
11
+ spec.email = ['at@an-ti.eu']
12
+ spec.description = 'Import data from StorageRoom to Contentful'
13
+ spec.summary = 'Import data from StorageRoom to Contentful'
14
+ spec.homepage = ''
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0")
18
+ spec.executables << 'storageroom-to-contentful'
19
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
+ spec.require_paths = ['lib']
21
+
22
+ spec.add_dependency 'http', '~> 0.6'
23
+ spec.add_dependency 'multi_json', '~> 1'
24
+ spec.add_dependency 'contentful-management', '~> 0.2'
25
+ spec.add_dependency 'i18n', '~> 0.6'
26
+
27
+ spec.add_development_dependency 'bundler', '~> 1.6'
28
+ spec.add_development_dependency 'rake'
29
+ end
metadata ADDED
@@ -0,0 +1,189 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: storageroom-to-contentful
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Andreas Tiefenthaler
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-09-22 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: http
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '0.6'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '0.6'
30
+ - !ruby/object:Gem::Dependency
31
+ name: multi_json
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '1'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '1'
46
+ - !ruby/object:Gem::Dependency
47
+ name: contentful-management
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: '0.2'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '0.2'
62
+ - !ruby/object:Gem::Dependency
63
+ name: i18n
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: '0.6'
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: '0.6'
78
+ - !ruby/object:Gem::Dependency
79
+ name: bundler
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ~>
84
+ - !ruby/object:Gem::Version
85
+ version: '1.6'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ~>
92
+ - !ruby/object:Gem::Version
93
+ version: '1.6'
94
+ - !ruby/object:Gem::Dependency
95
+ name: rake
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ description: Import data from StorageRoom to Contentful
111
+ email:
112
+ - at@an-ti.eu
113
+ executables:
114
+ - storageroom-to-contentful
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - .gitignore
119
+ - .rubocop.yml
120
+ - .travis.yml
121
+ - Gemfile
122
+ - Gemfile.lock
123
+ - LICENSE.txt
124
+ - README.md
125
+ - Rakefile
126
+ - bin/storageroom-to-contentful
127
+ - contenftul_fields_types.yml
128
+ - credentials.yml
129
+ - lib/contentful_importer.rb
130
+ - lib/migrator.rb
131
+ - lib/mime_content_type.rb
132
+ - lib/storage_room_exporter.rb
133
+ - lib/version.rb
134
+ - spec/fixtures/vcr_cassettes/collection/export_collections.yml
135
+ - spec/fixtures/vcr_cassettes/collection/get_request.yml
136
+ - spec/fixtures/vcr_cassettes/entries/entries.yml
137
+ - spec/fixtures/vcr_cassettes/entries/export_entries.yml
138
+ - spec/fixtures/vcr_cassettes/import/content_types.yml
139
+ - spec/fixtures/vcr_cassettes/import/crate_space.yml
140
+ - spec/fixtures/vcr_cassettes/import/create_entry.yml
141
+ - spec/fixtures/vcr_cassettes/import/entries.yml
142
+ - spec/fixtures/vcr_cassettes/import/publish_entries.yml
143
+ - spec/lib/contentful_importer_spec.rb
144
+ - spec/lib/storage_room_exporter_spec.rb
145
+ - spec/spec_helper.rb
146
+ - spec/support/credentials_spec.yaml
147
+ - spec/support/vcr.rb
148
+ - storageroom-to-contentful.gemspec
149
+ homepage: ''
150
+ licenses:
151
+ - MIT
152
+ post_install_message:
153
+ rdoc_options: []
154
+ require_paths:
155
+ - lib
156
+ required_ruby_version: !ruby/object:Gem::Requirement
157
+ none: false
158
+ requirements:
159
+ - - ! '>='
160
+ - !ruby/object:Gem::Version
161
+ version: '0'
162
+ required_rubygems_version: !ruby/object:Gem::Requirement
163
+ none: false
164
+ requirements:
165
+ - - ! '>='
166
+ - !ruby/object:Gem::Version
167
+ version: '0'
168
+ requirements: []
169
+ rubyforge_project:
170
+ rubygems_version: 1.8.23.2
171
+ signing_key:
172
+ specification_version: 3
173
+ summary: Import data from StorageRoom to Contentful
174
+ test_files:
175
+ - spec/fixtures/vcr_cassettes/collection/export_collections.yml
176
+ - spec/fixtures/vcr_cassettes/collection/get_request.yml
177
+ - spec/fixtures/vcr_cassettes/entries/entries.yml
178
+ - spec/fixtures/vcr_cassettes/entries/export_entries.yml
179
+ - spec/fixtures/vcr_cassettes/import/content_types.yml
180
+ - spec/fixtures/vcr_cassettes/import/crate_space.yml
181
+ - spec/fixtures/vcr_cassettes/import/create_entry.yml
182
+ - spec/fixtures/vcr_cassettes/import/entries.yml
183
+ - spec/fixtures/vcr_cassettes/import/publish_entries.yml
184
+ - spec/lib/contentful_importer_spec.rb
185
+ - spec/lib/storage_room_exporter_spec.rb
186
+ - spec/spec_helper.rb
187
+ - spec/support/credentials_spec.yaml
188
+ - spec/support/vcr.rb
189
+ has_rdoc: