mojito_import 0.5.0 → 0.9.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.
- checksums.yaml +4 -4
- data/Gemfile.lock +83 -0
- data/Guardfile +50 -0
- data/changelog.md +16 -0
- data/lib/mojito_import.rb +1 -0
- data/lib/mojito_import/importer.rb +1 -1
- data/lib/mojito_import/report.rb +53 -26
- data/lib/mojito_import/session.rb +40 -0
- data/lib/mojito_import/version.rb +1 -1
- data/mojito_import.gemspec +1 -0
- metadata +24 -7
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 4e2ebb67aa976f2acedc64705b23572ede86d4e5fa2252972a81817ac50188a6
|
|
4
|
+
data.tar.gz: da5e7256e1be2f12c949b3246cd1258e80fe380f69e2daebfd8548fca311fea1
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 230a23804a9da9c33513d1b600a9876a6682533b3da662756ef6880ef89cf19c6e1f10f32646275c44931b95554ffd82aad0426f3b3f9bfc2849c5c76ebe0c1f
|
|
7
|
+
data.tar.gz: c79e4332592d103050ea6af75334ee3d5cb96577a66eca2f60a24c5247d98778a0c8812205566c87c723802526964934f0a46e36f3a90d101160705f243f3d1a
|
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
mojito_import (0.8.0)
|
|
5
|
+
rest-client (~> 2.0)
|
|
6
|
+
|
|
7
|
+
GEM
|
|
8
|
+
remote: https://rubygems.org/
|
|
9
|
+
specs:
|
|
10
|
+
coderay (1.1.2)
|
|
11
|
+
diff-lcs (1.3)
|
|
12
|
+
domain_name (0.5.20190701)
|
|
13
|
+
unf (>= 0.0.5, < 1.0.0)
|
|
14
|
+
ffi (1.11.1)
|
|
15
|
+
formatador (0.2.5)
|
|
16
|
+
guard (2.16.1)
|
|
17
|
+
formatador (>= 0.2.4)
|
|
18
|
+
listen (>= 2.7, < 4.0)
|
|
19
|
+
lumberjack (>= 1.0.12, < 2.0)
|
|
20
|
+
nenv (~> 0.1)
|
|
21
|
+
notiffany (~> 0.0)
|
|
22
|
+
pry (>= 0.9.12)
|
|
23
|
+
shellany (~> 0.0)
|
|
24
|
+
thor (>= 0.18.1)
|
|
25
|
+
http-accept (1.7.0)
|
|
26
|
+
http-cookie (1.0.3)
|
|
27
|
+
domain_name (~> 0.5)
|
|
28
|
+
listen (3.2.0)
|
|
29
|
+
rb-fsevent (~> 0.10, >= 0.10.3)
|
|
30
|
+
rb-inotify (~> 0.9, >= 0.9.10)
|
|
31
|
+
lumberjack (1.0.13)
|
|
32
|
+
method_source (0.9.2)
|
|
33
|
+
mime-types (3.3.1)
|
|
34
|
+
mime-types-data (~> 3.2015)
|
|
35
|
+
mime-types-data (3.2019.1009)
|
|
36
|
+
nenv (0.3.0)
|
|
37
|
+
netrc (0.11.0)
|
|
38
|
+
notiffany (0.1.3)
|
|
39
|
+
nenv (~> 0.1)
|
|
40
|
+
shellany (~> 0.0)
|
|
41
|
+
pry (0.12.2)
|
|
42
|
+
coderay (~> 1.1.0)
|
|
43
|
+
method_source (~> 0.9.0)
|
|
44
|
+
rake (12.3.3)
|
|
45
|
+
rb-fsevent (0.10.3)
|
|
46
|
+
rb-inotify (0.10.0)
|
|
47
|
+
ffi (~> 1.0)
|
|
48
|
+
rest-client (2.1.0)
|
|
49
|
+
http-accept (>= 1.7.0, < 2.0)
|
|
50
|
+
http-cookie (>= 1.0.2, < 2.0)
|
|
51
|
+
mime-types (>= 1.16, < 4.0)
|
|
52
|
+
netrc (~> 0.8)
|
|
53
|
+
rspec (3.9.0)
|
|
54
|
+
rspec-core (~> 3.9.0)
|
|
55
|
+
rspec-expectations (~> 3.9.0)
|
|
56
|
+
rspec-mocks (~> 3.9.0)
|
|
57
|
+
rspec-core (3.9.0)
|
|
58
|
+
rspec-support (~> 3.9.0)
|
|
59
|
+
rspec-expectations (3.9.0)
|
|
60
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
61
|
+
rspec-support (~> 3.9.0)
|
|
62
|
+
rspec-mocks (3.9.0)
|
|
63
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
64
|
+
rspec-support (~> 3.9.0)
|
|
65
|
+
rspec-support (3.9.0)
|
|
66
|
+
shellany (0.0.1)
|
|
67
|
+
thor (0.20.3)
|
|
68
|
+
unf (0.1.4)
|
|
69
|
+
unf_ext
|
|
70
|
+
unf_ext (0.0.7.6)
|
|
71
|
+
|
|
72
|
+
PLATFORMS
|
|
73
|
+
ruby
|
|
74
|
+
|
|
75
|
+
DEPENDENCIES
|
|
76
|
+
bundler (~> 1.17)
|
|
77
|
+
guard (~> 2.15)
|
|
78
|
+
mojito_import!
|
|
79
|
+
rake (~> 12.3)
|
|
80
|
+
rspec (~> 3.0)
|
|
81
|
+
|
|
82
|
+
BUNDLED WITH
|
|
83
|
+
1.17.3
|
data/Guardfile
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# A sample Guardfile
|
|
2
|
+
# More info at https://github.com/guard/guard#readme
|
|
3
|
+
|
|
4
|
+
## Uncomment and set this to only include directories you want to watch
|
|
5
|
+
# directories %w(app lib config test spec features) \
|
|
6
|
+
# .select{|d| Dir.exists?(d) ? d : UI.warning("Directory #{d} does not exist")}
|
|
7
|
+
|
|
8
|
+
## Note: if you are using the `directories` clause above and you are not
|
|
9
|
+
## watching the project directory ('.'), then you will want to move
|
|
10
|
+
## the Guardfile to a watched dir and symlink it back, e.g.
|
|
11
|
+
#
|
|
12
|
+
# $ mkdir config
|
|
13
|
+
# $ mv Guardfile config/
|
|
14
|
+
# $ ln -s config/Guardfile .
|
|
15
|
+
#
|
|
16
|
+
# and, you'll have to watch "config/Guardfile" instead of "Guardfile"
|
|
17
|
+
|
|
18
|
+
# Note: The cmd option is now required due to the increasing number of ways
|
|
19
|
+
# rspec may be run, below are examples of the most common uses.
|
|
20
|
+
# * bundler: 'bundle exec rspec'
|
|
21
|
+
# * bundler binstubs: 'bin/rspec'
|
|
22
|
+
# * spring: 'bin/rspec' (This will use spring if running and you have
|
|
23
|
+
# installed the spring binstubs per the docs)
|
|
24
|
+
# * zeus: 'zeus rspec' (requires the server to be started separately)
|
|
25
|
+
# * 'just' rspec: 'rspec'
|
|
26
|
+
|
|
27
|
+
guard :rspec, cmd: "bundle exec rspec" do
|
|
28
|
+
require "guard/rspec/dsl"
|
|
29
|
+
dsl = Guard::RSpec::Dsl.new(self)
|
|
30
|
+
|
|
31
|
+
directories %w(lib spec)
|
|
32
|
+
# We should also watch Guardfile
|
|
33
|
+
|
|
34
|
+
# Feel free to open issues for suggestions and improvements
|
|
35
|
+
|
|
36
|
+
# RSpec files
|
|
37
|
+
rspec = dsl.rspec
|
|
38
|
+
watch(rspec.spec_helper) { rspec.spec_dir }
|
|
39
|
+
watch(rspec.spec_support) { rspec.spec_dir }
|
|
40
|
+
watch(rspec.spec_files)
|
|
41
|
+
|
|
42
|
+
# Ruby files
|
|
43
|
+
ruby = dsl.ruby
|
|
44
|
+
dsl.watch_spec_files_for(ruby.lib_files)
|
|
45
|
+
|
|
46
|
+
# Watch lib
|
|
47
|
+
watch(%r{^lib/(?<path>.+)\.rb$}) { |m| "spec/#{m[:path]}_spec.rb" }
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
end
|
data/changelog.md
CHANGED
|
@@ -1,3 +1,19 @@
|
|
|
1
|
+
* MojitoImport 0.9.1
|
|
2
|
+
* Manage more errors
|
|
3
|
+
|
|
4
|
+
* MojitoImport 0.9.0
|
|
5
|
+
* Add history group
|
|
6
|
+
* Add operator identifier
|
|
7
|
+
|
|
8
|
+
* MojitoImport 0.8.0
|
|
9
|
+
* new json schema !
|
|
10
|
+
|
|
11
|
+
* MojitoImport 0.7.0
|
|
12
|
+
* iFrame with token auth
|
|
13
|
+
|
|
14
|
+
* MojitoImport 0.6.0
|
|
15
|
+
* Dry run imports
|
|
16
|
+
|
|
1
17
|
* MojitoImport 0.5.0
|
|
2
18
|
* Initial release
|
|
3
19
|
* Import sugar
|
data/lib/mojito_import.rb
CHANGED
|
@@ -55,7 +55,7 @@ module MojitoImport
|
|
|
55
55
|
# RestClient::Resource.new( , verify_ssl: false, log: Logger.new(STDOUT)).post "https://mojito-import.test/api/v1/new_import", data.to_json, {content_type: :json, accept: :json, :Authorization => "Bearer #{access_token}"}
|
|
56
56
|
|
|
57
57
|
remote_endpoint_url = "#{mojito_host}/api/v1/new_import"
|
|
58
|
-
|
|
58
|
+
Rails.logger.debug { "will contact : #{remote_endpoint_url}"}
|
|
59
59
|
RestClient::Resource.new( remote_endpoint_url, verify_ssl: false, log: Logger.new(STDOUT)).post data.to_json, {content_type: :json, accept: :json, :Authorization => "Bearer #{access_token}"}
|
|
60
60
|
end
|
|
61
61
|
end
|
data/lib/mojito_import/report.rb
CHANGED
|
@@ -1,43 +1,70 @@
|
|
|
1
|
+
require 'json'
|
|
2
|
+
|
|
1
3
|
module MojitoImport
|
|
2
4
|
class Report
|
|
3
|
-
|
|
4
|
-
attr_accessor :data_errors, :general_errors, :import_id
|
|
5
|
+
attr_accessor :object_errors, :request_errors, :object_updates, :import_id
|
|
5
6
|
|
|
6
7
|
def initialize(import_id)
|
|
7
8
|
self.import_id = import_id
|
|
8
|
-
self.
|
|
9
|
-
self.
|
|
9
|
+
self.object_errors = []
|
|
10
|
+
self.request_errors = []
|
|
11
|
+
self.object_updates = []
|
|
10
12
|
end
|
|
11
13
|
|
|
12
|
-
def
|
|
13
|
-
|
|
14
|
+
def to_json
|
|
15
|
+
{
|
|
16
|
+
"mojitoRequestId" => self.import_id,
|
|
17
|
+
"requestErrors" => self.request_errors,
|
|
18
|
+
"objectErrors" => self.object_errors,
|
|
19
|
+
"objectUpdates" => self.object_updates
|
|
20
|
+
}.to_json
|
|
14
21
|
end
|
|
15
22
|
|
|
16
|
-
def
|
|
17
|
-
|
|
18
|
-
hash_element = data_errors.detect { |error_hash| error_hash["mojitoId"] == mojito_id }
|
|
19
|
-
|
|
20
|
-
if hash_element.nil?
|
|
21
|
-
new_error_hash = {
|
|
22
|
-
"mojitoId" => mojito_id,
|
|
23
|
-
field => [error]
|
|
24
|
-
}
|
|
25
|
-
data_errors << new_error_hash
|
|
26
|
-
else
|
|
27
|
-
hash_element[field] ||= []
|
|
28
|
-
hash_element[field] << error
|
|
23
|
+
def add_request_error(error)
|
|
24
|
+
request_errors << error
|
|
29
25
|
end
|
|
30
|
-
end
|
|
31
26
|
|
|
32
|
-
|
|
33
|
-
data_error = data_errors.detect{|data| data["mojitoId"] == mojito_id}
|
|
34
|
-
return if data_error.nil?
|
|
27
|
+
def add_object_update(mojito_id, field, from, to: nil)
|
|
35
28
|
|
|
36
|
-
|
|
37
|
-
|
|
29
|
+
hash_element =
|
|
30
|
+
object_updates.detect { |error_hash| error_hash["mojitoObjectId"] == mojito_id }
|
|
38
31
|
|
|
32
|
+
update_hash = {"before" => from}
|
|
33
|
+
update_hash["after"] = to unless to.nil?
|
|
39
34
|
|
|
35
|
+
if hash_element.nil?
|
|
36
|
+
new_update_hash = { "mojitoObjectId" => mojito_id, field => update_hash }
|
|
37
|
+
object_updates << new_update_hash
|
|
38
|
+
else
|
|
39
|
+
hash_element[field] = update_hash
|
|
40
|
+
end
|
|
41
|
+
end
|
|
40
42
|
|
|
43
|
+
def add_object_error(mojito_id, error, field: nil)
|
|
41
44
|
|
|
42
|
-
|
|
45
|
+
hash_element =
|
|
46
|
+
object_errors.detect { |error_hash| error_hash["mojitoObjectId"] == mojito_id }
|
|
47
|
+
|
|
48
|
+
if hash_element.nil?
|
|
49
|
+
hash_element = { "mojitoObjectId" => mojito_id, "general" => [], "fields" => { } }
|
|
50
|
+
object_errors << hash_element
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
if field.nil? # it's a general error
|
|
54
|
+
hash_element["general"] << error
|
|
55
|
+
else
|
|
56
|
+
# The field has to be initialized to an array
|
|
57
|
+
# Else we got an error when adding an error to a 2nd field
|
|
58
|
+
hash_element["fields"][field] ||= []
|
|
59
|
+
hash_element["fields"][field] << error
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def find_errors_for_object(mojito_id)
|
|
64
|
+
object_error = object_errors.detect { |data| data["mojitoObjectId"] == mojito_id }
|
|
65
|
+
return if object_error.nil?
|
|
66
|
+
|
|
67
|
+
object_error.except("mojitoObjectId")
|
|
68
|
+
end
|
|
69
|
+
end
|
|
43
70
|
end
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
require "rest-client"
|
|
2
|
+
module MojitoImport
|
|
3
|
+
class Session
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def self.get_token(import_scenario_identifier, access_token, session_bucket, operator_identifier: nil, history_group: nil, use_dev_host: false, force_new: false)
|
|
7
|
+
data = { import_scenario_identifier: import_scenario_identifier, session_bucket: session_bucket, operator_identifier: operator_identifier, history_group: history_group, force_new: force_new }
|
|
8
|
+
|
|
9
|
+
mojito_host = use_dev_host ? 'http://www.mojito-import.test' : 'https://www.mojito-import.com'
|
|
10
|
+
|
|
11
|
+
request = RestClient::Resource.new(mojito_host, accept: :json,content_type: :json, Authorization: "Bearer #{access_token}", verify_ssl: false)
|
|
12
|
+
|
|
13
|
+
begin
|
|
14
|
+
path = "api/v1/import_session_token?access_token=#{access_token}"
|
|
15
|
+
response = request[path].post(data, timeout: 5) { |response, request, result|
|
|
16
|
+
case response.code
|
|
17
|
+
when 200, 201
|
|
18
|
+
token = JSON.parse(response)["token"]
|
|
19
|
+
if token.blank?
|
|
20
|
+
return {"error when retrieving token" => response.body.inspect}
|
|
21
|
+
else
|
|
22
|
+
return token
|
|
23
|
+
end
|
|
24
|
+
when 500
|
|
25
|
+
return {"error when retrieving token" => response.body.inspect}
|
|
26
|
+
else
|
|
27
|
+
return "Unexpected response code : #{response.code} #{response.body.inspect}"
|
|
28
|
+
end
|
|
29
|
+
}
|
|
30
|
+
rescue Net::ReadTimeout => e
|
|
31
|
+
return "error when retrieving token got a Timeout from the server."
|
|
32
|
+
rescue Exception => e
|
|
33
|
+
return "Unkown error : #{e}"
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
end
|
|
40
|
+
end
|
data/mojito_import.gemspec
CHANGED
|
@@ -32,5 +32,6 @@ Gem::Specification.new do |spec|
|
|
|
32
32
|
spec.add_dependency "rest-client", "~> 2.0"
|
|
33
33
|
spec.add_development_dependency "bundler", "~> 1.17"
|
|
34
34
|
spec.add_development_dependency "rake", "~> 12.3"
|
|
35
|
+
spec.add_development_dependency "guard", "~> 2.15"
|
|
35
36
|
spec.add_development_dependency "rspec", "~> 3.0"
|
|
36
37
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: mojito_import
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.9.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Thomas Darde
|
|
8
|
-
autorequire:
|
|
8
|
+
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2020-10-27 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rest-client
|
|
@@ -52,6 +52,20 @@ dependencies:
|
|
|
52
52
|
- - "~>"
|
|
53
53
|
- !ruby/object:Gem::Version
|
|
54
54
|
version: '12.3'
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: guard
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - "~>"
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: '2.15'
|
|
62
|
+
type: :development
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - "~>"
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: '2.15'
|
|
55
69
|
- !ruby/object:Gem::Dependency
|
|
56
70
|
name: rspec
|
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -66,7 +80,7 @@ dependencies:
|
|
|
66
80
|
- - "~>"
|
|
67
81
|
- !ruby/object:Gem::Version
|
|
68
82
|
version: '3.0'
|
|
69
|
-
description:
|
|
83
|
+
description:
|
|
70
84
|
email:
|
|
71
85
|
- thomas@rougecardinal.fr
|
|
72
86
|
executables: []
|
|
@@ -78,6 +92,8 @@ files:
|
|
|
78
92
|
- ".travis.yml"
|
|
79
93
|
- CODE_OF_CONDUCT.md
|
|
80
94
|
- Gemfile
|
|
95
|
+
- Gemfile.lock
|
|
96
|
+
- Guardfile
|
|
81
97
|
- LICENSE.txt
|
|
82
98
|
- README.md
|
|
83
99
|
- Rakefile
|
|
@@ -87,6 +103,7 @@ files:
|
|
|
87
103
|
- lib/mojito_import.rb
|
|
88
104
|
- lib/mojito_import/importer.rb
|
|
89
105
|
- lib/mojito_import/report.rb
|
|
106
|
+
- lib/mojito_import/session.rb
|
|
90
107
|
- lib/mojito_import/version.rb
|
|
91
108
|
- mojito_import.gemspec
|
|
92
109
|
homepage: https://www.mojito-import.com
|
|
@@ -96,7 +113,7 @@ metadata:
|
|
|
96
113
|
homepage_uri: https://www.mojito-import.com
|
|
97
114
|
source_code_uri: https://github.com/thomasdarde/mojito_import_gem
|
|
98
115
|
changelog_uri: https://raw.githubusercontent.com/thomasdarde/mojito_import_gem/master/changelog.md
|
|
99
|
-
post_install_message:
|
|
116
|
+
post_install_message:
|
|
100
117
|
rdoc_options: []
|
|
101
118
|
require_paths:
|
|
102
119
|
- lib
|
|
@@ -111,8 +128,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
111
128
|
- !ruby/object:Gem::Version
|
|
112
129
|
version: '0'
|
|
113
130
|
requirements: []
|
|
114
|
-
rubygems_version: 3.
|
|
115
|
-
signing_key:
|
|
131
|
+
rubygems_version: 3.1.4
|
|
132
|
+
signing_key:
|
|
116
133
|
specification_version: 4
|
|
117
134
|
summary: Mojito Import, so fresh.
|
|
118
135
|
test_files: []
|