broker 0.0.9

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 22906356dab990f2e1791980fd4259d5c915c1e1
4
+ data.tar.gz: b509f861be4137165f8b92e5f7667dbb891fdca7
5
+ SHA512:
6
+ metadata.gz: ed637b3ac16bbb1346fbee41f7bd52e456441cf4b74a47a4a2bfe66423bde82e6876b879657f841e13c1abaf925a25970cda27fe0b07f81e1fb6e9849c4ffd86
7
+ data.tar.gz: 12de6c2ad9ddc465aed4423e8c4d5eaec4f1bd503e9b49eb57384f029254bea79248b3e654452c86cab6166dd75bedd64da4bbfcbf1b0d03d71b4a259ad76923
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ *.DS_Store
4
+ .bundle
5
+ .config
6
+ .yardoc
7
+ Gemfile.lock
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
3
+
4
+ gem 'thor'
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Shawn Henley
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,47 @@
1
+ # Broker
2
+
3
+ Automate importing of data to Quickbase applications using a file queue
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem broker
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ ```ruby
16
+ $ bundle
17
+ ```
18
+
19
+ Or install it yourself as:
20
+
21
+ ```ruby
22
+ $ gem install broker
23
+ ```
24
+
25
+ ## Setup
26
+
27
+ Setup the initializers, config files, and structure by:
28
+
29
+ ```ruby
30
+ $ broker install
31
+ ```
32
+
33
+ The following files will be generated for you:
34
+
35
+ ```ruby
36
+ /config/secrets.yml
37
+ /config/quickbase_tables
38
+ /config/initializers/broker.rb
39
+ ````
40
+
41
+ ## Contributing
42
+
43
+ 1. Fork it
44
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
45
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
46
+ 4. Push to the branch (`git push origin my-new-feature`)
47
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/broker ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+
5
+ begin
6
+ require 'broker/cli'
7
+ rescue LoadError => e
8
+ warn 'Could not load "broker/cli"'
9
+ exit -1
10
+ end
11
+
12
+ Broker::CLI.start
13
+
14
+
15
+
16
+
data/broker.gemspec ADDED
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'broker/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "broker"
8
+ gem.version = Broker::VERSION
9
+ gem.authors = ["Shawn Henley"]
10
+ gem.email = ["shawn@luckysailor.net"]
11
+ gem.description = gem.summary = "Automate the importing and exporting of data with Quickbase applications, using post requests."
12
+ gem.homepage = "https://github.com/luckysailor/broker"
13
+ gem.license = "MIT"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = ["broker"]#gem.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_development_dependency 'bundler', '~> 1.3'
21
+ gem.add_development_dependency 'rake'
22
+ gem.add_development_dependency 'sinatra'
23
+ end
data/config.ru ADDED
@@ -0,0 +1,5 @@
1
+ require 'broker'
2
+ require 'broker/web'
3
+
4
+ Broker::Application.boot!
5
+ run Broker::Web
@@ -0,0 +1,16 @@
1
+ begin
2
+ require File.expand_path('../../../config/initializers/broker', __FILE__)
3
+ rescue LoadError => e
4
+ warn 'Could not load "initializers/broker"'
5
+ end
6
+
7
+ module Broker
8
+ class Application
9
+
10
+ def self.boot!
11
+ puts "starting up"
12
+ puts "watching for files in #{Broker.queue}"
13
+ end
14
+
15
+ end
16
+ end
data/lib/broker/cli.rb ADDED
@@ -0,0 +1,198 @@
1
+ require 'thor'
2
+
3
+ module Broker
4
+ class CLI < Thor
5
+ include Thor::Actions
6
+
7
+ def self.source_root
8
+ File.dirname(__FILE__) + "/templates"
9
+ end
10
+
11
+ desc "install", "install and configure broker"
12
+ def install
13
+ require 'broker'
14
+ unless already_installed?
15
+ inject_initializer
16
+ inject_secrets
17
+ inject_tables
18
+ welcome
19
+ else
20
+ say "Broker is already Installed/Setup!"
21
+ end
22
+ end
23
+
24
+ desc "queue", "make and update your queue"
25
+ method_option :create,
26
+ type: :boolean,
27
+ default: false,
28
+ aliases: "-c",
29
+ banner: "Generate your queue folder structure"
30
+ method_option :delete,
31
+ type: :boolean,
32
+ default: false,
33
+ aliases: "-d",
34
+ banner: "Delete your queue folder structure"
35
+ method_option :update,
36
+ type: :boolean,
37
+ default: false,
38
+ aliases: "-u",
39
+ banner: "Generate your queue folder structure"
40
+ def queue
41
+ require 'broker'
42
+ empty_dir = !Dir.exists?(Broker.queue)
43
+
44
+ if options[:create] && empty_dir
45
+ FileUtils.mkdir Broker.queue
46
+ say "Your Q has been created at:"
47
+ puts "#{Broker.queue}"
48
+ end
49
+
50
+ if options[:update] && !empty_dir
51
+ base_path = "#{Broker.queue}"
52
+ roots = Broker.tables.keys
53
+ tables = []
54
+
55
+ make_tree(base_path, roots)
56
+
57
+ Broker.tables.each do |key, val|
58
+ tables = val['tables'].keys
59
+ make_tree("#{base_path}/#{key}", tables)
60
+ end
61
+ end
62
+ end
63
+
64
+ desc "inject_initializer", "add initializer"
65
+ def inject_initializer
66
+ puts 'add initializer for broker configuration'
67
+ copy_file "broker.rb", "config/initializers/broker.rb"
68
+ end
69
+
70
+ desc "inject_secrets", "add secrets"
71
+ def inject_secrets
72
+ puts 'add secrets yaml for broker authentication environment variables'
73
+ copy_file "secrets.yml", "config/secrets.yml"
74
+ end
75
+
76
+ desc "inject_tables", "add table mapping"
77
+ def inject_tables
78
+ puts 'add broker_tables for setting up table mappings'
79
+ copy_file "quickbase_tables.yml", "config/quickbase_tables.yml"
80
+ end
81
+
82
+ desc "start", "boot up broker service"
83
+ method_option :standalone,
84
+ type: :boolean,
85
+ default: false,
86
+ aliases: "-s",
87
+ banner: "Boots w/out web service"
88
+ method_option :web,
89
+ type: :boolean,
90
+ default: false,
91
+ aliases: "-w",
92
+ banner: "Boots w/ web service"
93
+ def start
94
+
95
+ require 'broker'
96
+
97
+ if options[:standalone]
98
+
99
+ io_read, io_write = IO.pipe
100
+
101
+ %w(INT TERM USR1 USR2 TTIN).each do |sig|
102
+ begin
103
+ Signal.trap(sig) do
104
+ io_write.puts(sig)
105
+ end
106
+ rescue ArgumentError
107
+ puts "Signal #{sig} not valid"
108
+ end
109
+ end
110
+
111
+ require 'broker/launcher'
112
+ @launcher = Broker::Launcher.new
113
+
114
+ begin
115
+ puts "launched with PID #{Process.pid}"
116
+ @launcher.run
117
+
118
+ while readable_io = IO.select([io_read])
119
+ signal = readable_io.first[0].gets.strip
120
+ catch_signal(signal)
121
+ end
122
+ rescue Interrupt
123
+ puts "Shutting down"
124
+ @launcher.stop
125
+ exit(0)
126
+ end
127
+
128
+ elsif options[:web]
129
+ puts "web service not implemented yet"
130
+ end
131
+ end
132
+
133
+ desc "welcome", "invite to broker"
134
+ def welcome
135
+ say ""
136
+ say ""
137
+ say ""
138
+ say "*************************************************"
139
+ say "*************************************************"
140
+ say "Broker Successfully Installed!"
141
+ say "*************************************************"
142
+ say ""
143
+ say "Default Config files created for you"
144
+ say ""
145
+ say "You can change the config paths in:"
146
+ say "config/initializers/broker.rb"
147
+ say ""
148
+ say "1. Enter your Quickbase credentials in:"
149
+ say "/config/secrets.yml"
150
+ say ""
151
+ say "2. Set up your Table Mappings in:"
152
+ say "/config/quickbase_tables.yml"
153
+ say ""
154
+ say "*************************************************"
155
+ say ""
156
+ say "Update your Broker Q by running:"
157
+ say ""
158
+ say "$ broker update_q"
159
+ say ""
160
+ end
161
+
162
+ private
163
+
164
+ def catch_signal(sig)
165
+ case sig
166
+ when 'INT'
167
+ raise Interrupt
168
+ when 'TERM'
169
+ raise Interrupt
170
+ when 'USR1'
171
+ when 'USR2'
172
+ when 'TTIN'
173
+ end
174
+ end
175
+
176
+ def make_tree(base_path, folders=[])
177
+ folders.each do |f|
178
+ unless valid_path?("#{base_path}/#{f}")
179
+ Dir.mkdir("#{base_path}/#{f}")
180
+ say "created: #{base_path}/#{f}"
181
+ end
182
+ end
183
+ end
184
+
185
+ def valid_path?(path)
186
+ Dir.exists?(path)
187
+ end
188
+
189
+ def already_installed?
190
+ files = Broker.config_files
191
+ files.each do |f|
192
+ return false unless File.exists?(f)
193
+ end && true
194
+ end
195
+
196
+
197
+ end
198
+ end