ievkit 0.1.0

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.
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.3
4
+ before_install: gem install bundler -v 1.10.6
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+ ruby '2.3.0'
3
+ # Specify your gem's dependencies in ievkit.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,59 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ ievkit (0.1.0)
5
+ faraday_middleware (~> 0.10.0)
6
+ figaro (~> 1.1.1)
7
+ rest-client (~> 1.8.0)
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ diff-lcs (1.2.5)
13
+ domain_name (0.5.25)
14
+ unf (>= 0.0.5, < 1.0.0)
15
+ faraday (0.9.2)
16
+ multipart-post (>= 1.2, < 3)
17
+ faraday_middleware (0.10.0)
18
+ faraday (>= 0.7.4, < 0.10)
19
+ figaro (1.1.1)
20
+ thor (~> 0.14)
21
+ http-cookie (1.0.2)
22
+ domain_name (~> 0.5)
23
+ mime-types (2.99)
24
+ multipart-post (2.0.0)
25
+ netrc (0.11.0)
26
+ rake (10.4.2)
27
+ rest-client (1.8.0)
28
+ http-cookie (>= 1.0.2, < 2.0)
29
+ mime-types (>= 1.16, < 3.0)
30
+ netrc (~> 0.7)
31
+ rspec (3.4.0)
32
+ rspec-core (~> 3.4.0)
33
+ rspec-expectations (~> 3.4.0)
34
+ rspec-mocks (~> 3.4.0)
35
+ rspec-core (3.4.1)
36
+ rspec-support (~> 3.4.0)
37
+ rspec-expectations (3.4.0)
38
+ diff-lcs (>= 1.2.0, < 2.0)
39
+ rspec-support (~> 3.4.0)
40
+ rspec-mocks (3.4.0)
41
+ diff-lcs (>= 1.2.0, < 2.0)
42
+ rspec-support (~> 3.4.0)
43
+ rspec-support (3.4.1)
44
+ thor (0.19.1)
45
+ unf (0.1.4)
46
+ unf_ext
47
+ unf_ext (0.0.7.1)
48
+
49
+ PLATFORMS
50
+ ruby
51
+
52
+ DEPENDENCIES
53
+ bundler (~> 1.10)
54
+ ievkit!
55
+ rake (~> 10.0)
56
+ rspec
57
+
58
+ BUNDLED WITH
59
+ 1.11.2
data/LICENSE.md ADDED
@@ -0,0 +1,25 @@
1
+ # Licence
2
+
3
+ Copyright [AFIMB](http://www.developpement-durable.gouv.fr/Presentation-de-l-AFIMB.html)
4
+
5
+ contributeurs / contributors :
6
+ * [Cityway](http://www.cityway.fr)
7
+
8
+
9
+ Ce logiciel est régi par la licence CeCILL-B soumise au droit français et respectant les principes de diffusion des logiciels libres. Vous pouvez utiliser, modifier et/ou redistribuer ce programme sous les conditions de la licence CeCILL-B telle que diffusée par le CEA, le CNRS et l'INRIA sur le site [http://www.cecill.info](http://www.cecill.info).
10
+
11
+ En contrepartie de l'accessibilité au code source et des droits de copie, de modification et de redistribution accordés par cette licence, il n'est offert aux utilisateurs qu'une garantie limitée. Pour les mêmes raisons, seule une responsabilité restreinte pèse sur l'auteur du programme, le titulaire des droits patrimoniaux et les concédants successifs.
12
+
13
+ A cet égard l'attention de l'utilisateur est attirée sur les risques associés au chargement, à l'utilisation, à la modification et/ou au développement et à la reproduction du logiciel par l'utilisateur étant donné sa spécificité de logiciel libre, qui peut le rendre complexe à manipuler et qui le réserve donc à des développeurs et des professionnels avertis possédant des connaissances informatiques approfondies. Les utilisateurs sont donc invités à charger et tester l'adéquation du logiciel à leurs besoins dans des conditions permettant d'assurer la sécurité de leurs systèmes et ou de leurs données et, plus généralement, à l'utiliser et l'exploiter dans les mêmes conditions de sécurité.
14
+
15
+ Le fait que vous puissiez accéder à cet en-tête signifie que vous avez pris connaissance de la licence CeCILL-B, et que vous en avez accepté les termes.
16
+
17
+ --------------------------------------------------------------
18
+
19
+ This software is governed by the CeCILL-B license under French law and abiding by the rules of distribution of free software. You can use, modify and/ or redistribute the software under the terms of the CeCILL-B license as circulated by CEA, CNRS and INRIA at the following URL [http://www.cecill.info](http://www.cecill.info).
20
+
21
+ As a counterpart to the access to the source code and rights to copy, modify and redistribute granted by the license, users are provided only with a limited warranty and the software's author, the holder of the economic rights, and the successive licensors have only limited liability.
22
+
23
+ In this respect, the user's attention is drawn to the risks associated with loading, using, modifying and/or developing or reproducing the software by the user in light of its specific status of free software, that may mean that it is complicated to manipulate,and that also therefore means that it is reserved for developers and experienced professionals having in-depth computer knowledge. Users are therefore encouraged to load and test the software's suitability as regards their requirements in conditions enabling the security of their systems and/or data to be ensured and, more generally, to use and operate it in the same conditions as regards security.
24
+
25
+ The fact that you are presently reading this means that you have had knowledge of the CeCILL-B license and that you accept its terms.
data/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # Ievkit
2
+
3
+ [![Code Climate](https://codeclimate.com/github/afimb/ievkit/badges/gpa.svg)](https://codeclimate.com/github/afimb/ievkit)
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'ievkit'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install ievkit
20
+
21
+ ## Usage
22
+
23
+
24
+ ## Development
25
+
26
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run
27
+ `rake iev_import_file='metz-gtfs_current.zip' iev_import_params='importgtfs.json' iev_export_params='exportneptune.json' iev_validate_params='validategtfs.json'`
28
+ to run the tests.
29
+ You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/ievkit.
36
+
37
+
38
+ ## License
39
+
40
+ This project is licensed under the CeCILL-B license, a copy of which can be found in the [LICENSE](./LICENSE.md) file.
41
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "ievkit"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,4 @@
1
+ IEV_VERSION: '1.0'
2
+ IEV_HOST:
3
+ IEV_PORT:
4
+ IEV_PATH:
@@ -0,0 +1 @@
1
+ Figaro.require_keys('IEV_VERSION', 'IEV_HOST', 'IEV_PORT', 'IEV_PATH')
data/ievkit.gemspec ADDED
@@ -0,0 +1,37 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ievkit/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'ievkit'
8
+ spec.version = Ievkit::VERSION
9
+ spec.authors = ['Bruno Perles']
10
+ spec.email = ['bruno@atnos.com']
11
+
12
+ spec.summary = ''
13
+ spec.description = ''
14
+ spec.homepage = 'https://github.com/afimb/ievkit'
15
+ spec.license = 'CECILL-B'
16
+
17
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
18
+ # delete this section to allow pushing this gem to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org'
21
+ else
22
+ raise 'RubyGems 2.0 or newer is required to protect against public gem pushes.'
23
+ end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ spec.bindir = 'exe'
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ['lib']
29
+
30
+ spec.add_dependency 'figaro', '~> 1.1.1'
31
+ spec.add_dependency 'faraday_middleware', '~> 0.10.0'
32
+ spec.add_dependency 'rest-client', '~> 1.8.0'
33
+
34
+ spec.add_development_dependency 'bundler', '~> 1.10'
35
+ spec.add_development_dependency 'rake', '~> 10.0'
36
+ spec.add_development_dependency 'rspec'
37
+ end
@@ -0,0 +1,116 @@
1
+ module Ievkit
2
+ class Client
3
+ attr_reader :iev_url_prefix, :iev_url_suffix, :iev_url_jobs, :referential
4
+
5
+ def initialize(referential)
6
+ @payload = {}
7
+ @referential = referential
8
+ @iev_url_prefix = init_iev_url_prefix
9
+ @iev_url_jobs = init_iev_url_jobs
10
+ end
11
+
12
+ def prepare_post_request(type, options)
13
+ init_files(options)
14
+ @iev_url_suffix = init_iev_url_suffix(type)
15
+ init_connection(iev_url_prefix)
16
+ begin
17
+ response = @connection.post(@iev_url_suffix, @payload)
18
+ parse_response(response)
19
+ rescue => e
20
+ Ievkit::Log.logger.fatal("Unable to contact IEV server: #{e.message}")
21
+ return false
22
+ end
23
+ end
24
+
25
+ def prepare_request(url, http_method)
26
+ init_connection(url)
27
+ begin
28
+ response = @connection.send(http_method)
29
+ parse_response(response)
30
+ rescue => e
31
+ Ievkit::Log.logger.fatal("Unable to contact IEV server: #{e.message}")
32
+ return false
33
+ end
34
+ end
35
+
36
+ def init_connection(url)
37
+ @connection = Faraday.new(url: url) do |conn|
38
+ conn.request :multipart if @payload.any?
39
+ conn.headers = headers
40
+ conn.response :json, content_type: 'application/json'
41
+ conn.adapter Faraday.default_adapter
42
+ end
43
+ end
44
+
45
+ def init_files(options)
46
+ return unless options
47
+ iev_file = options[:iev_file]
48
+ @payload[:file[0]] = Faraday::UploadIO.new(options[:iev_params], 'application/json', 'parameters.json')
49
+ return unless iev_file
50
+ filename = File.basename(iev_file)
51
+ @payload[:file[1]] = Faraday::UploadIO.new(iev_file, 'application/zip', filename)
52
+ end
53
+
54
+ protected
55
+
56
+ def headers
57
+ {}.merge(init_iev_version)
58
+ end
59
+
60
+ def parse_links_headers(response)
61
+ return response.body if response.headers['link'].to_s.empty?
62
+ {}.tap do |hash|
63
+ response.headers['link'].split(',').each do |part|
64
+ section = part.split(';')
65
+ name = section[1][/rel="(.*)"/, 1].to_sym
66
+ hash[name] = section[0][/<(.*)>/, 1]
67
+ end
68
+ end
69
+ end
70
+
71
+ def parse_response(response)
72
+ case response.status
73
+ when 202
74
+ response.headers['location']
75
+ when 303
76
+ response.headers['location']
77
+ when 200
78
+ parse_links_headers(response)
79
+ when 404
80
+ raise 'IEV not accessible'
81
+ else
82
+ response.body
83
+ end
84
+ rescue => e
85
+ Ievkit::Log.logger.fatal("Unable to parse response: #{e.message}")
86
+ return false
87
+ end
88
+
89
+ private
90
+
91
+ def init_iev_url_prefix
92
+ [
93
+ "#{ENV['IEV_HOST']}:#{ENV['IEV_PORT']}",
94
+ ENV['IEV_PATH'],
95
+ 'referentials',
96
+ @referential,
97
+ ''
98
+ ].compact * '/'
99
+ end
100
+
101
+ def init_iev_url_suffix(type = nil)
102
+ [
103
+ caller_locations(2, 2)[0].label,
104
+ type
105
+ ].compact * '/'
106
+ end
107
+
108
+ def init_iev_url_jobs
109
+ [@iev_url_prefix, 'jobs'].join
110
+ end
111
+
112
+ def init_iev_version
113
+ { 'Accept-Version': ENV['IEV_VERSION'] }
114
+ end
115
+ end
116
+ end
data/lib/ievkit/job.rb ADDED
@@ -0,0 +1,51 @@
1
+ module Ievkit
2
+ class Job
3
+ attr_reader :client, :response
4
+
5
+ def initialize(referential_id)
6
+ @client = Ievkit::Client.new(referential_id)
7
+ end
8
+
9
+ def post_job(action, type = nil, options = {})
10
+ send(action, type, options)
11
+ end
12
+
13
+ def get_job(url)
14
+ do_job(url, :get)
15
+ end
16
+
17
+ def delete_job(url)
18
+ do_job(url, :delete)
19
+ end
20
+
21
+ def delete_jobs
22
+ do_job(@client.iev_url_jobs, :delete)
23
+ end
24
+
25
+ def terminated_job?(url)
26
+ get_job(url).to_s.include?('terminated_jobs')
27
+ end
28
+
29
+ protected
30
+
31
+ def do_job(url, http_method)
32
+ @client.prepare_request(url, http_method)
33
+ end
34
+
35
+ def importer(type, options)
36
+ @client.prepare_post_request(type, options)
37
+ end
38
+
39
+ def exporter(type, options)
40
+ @client.prepare_post_request(type, options)
41
+ end
42
+
43
+ def converter(type, options)
44
+ @client.prepare_post_request(type, options)
45
+ end
46
+
47
+ def validator(type, options)
48
+ @client.prepare_post_request(type, options)
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ievkit
4
+ class Railtie < Rails::Railtie
5
+ initializer 'ievkit' do
6
+ Ievkit::Log.logger = Rails.logger
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,3 @@
1
+ module Ievkit
2
+ VERSION = '0.1.0'
3
+ end
data/lib/ievkit.rb ADDED
@@ -0,0 +1,19 @@
1
+ require 'figaro'
2
+ require 'faraday_middleware'
3
+ require 'logger'
4
+ require 'ievkit/version'
5
+ require 'ievkit/job'
6
+ require 'ievkit/client'
7
+ require 'ievkit/railtie' if defined?(Rails)
8
+
9
+ module Ievkit
10
+ class Log
11
+ class << self
12
+ attr_accessor :logger
13
+ end
14
+ self.logger = Logger.new(STDOUT)
15
+ end
16
+
17
+ Figaro.application = Figaro::Application.new(path: 'config/application.yml')
18
+ Figaro.application.load
19
+ end
metadata ADDED
@@ -0,0 +1,150 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ievkit
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Bruno Perles
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-03-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: figaro
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 1.1.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 1.1.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: faraday_middleware
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.10.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.10.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: rest-client
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 1.8.0
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 1.8.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.10'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.10'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '10.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '10.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: ''
98
+ email:
99
+ - bruno@atnos.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".codeclimate.yml"
105
+ - ".gitignore"
106
+ - ".rspec"
107
+ - ".rubocop.yml"
108
+ - ".travis.yml"
109
+ - Gemfile
110
+ - Gemfile.lock
111
+ - LICENSE.md
112
+ - README.md
113
+ - Rakefile
114
+ - bin/console
115
+ - bin/setup
116
+ - config/application.example.yml
117
+ - config/initializers/figaro.rb
118
+ - ievkit.gemspec
119
+ - lib/ievkit.rb
120
+ - lib/ievkit/client.rb
121
+ - lib/ievkit/job.rb
122
+ - lib/ievkit/railtie.rb
123
+ - lib/ievkit/version.rb
124
+ homepage: https://github.com/afimb/ievkit
125
+ licenses:
126
+ - CECILL-B
127
+ metadata:
128
+ allowed_push_host: https://rubygems.org
129
+ post_install_message:
130
+ rdoc_options: []
131
+ require_paths:
132
+ - lib
133
+ required_ruby_version: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - ">="
136
+ - !ruby/object:Gem::Version
137
+ version: '0'
138
+ required_rubygems_version: !ruby/object:Gem::Requirement
139
+ requirements:
140
+ - - ">="
141
+ - !ruby/object:Gem::Version
142
+ version: '0'
143
+ requirements: []
144
+ rubyforge_project:
145
+ rubygems_version: 2.5.1
146
+ signing_key:
147
+ specification_version: 4
148
+ summary: ''
149
+ test_files: []
150
+ has_rdoc: