qbo-sandbox 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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5f8f44d9da2d869cddbfbd1deef375987615efc1
4
+ data.tar.gz: 9ac1f9d22f019b8e78e81b2daf821b1e9fce662a
5
+ SHA512:
6
+ metadata.gz: fbfb63682e57d1f59db199d2b72e3e447a3be258f92330c4c2b65110873ebe7a8e5f3cee269b8a7875968894cc76bd3d63b5d5879d536245d779047db78d3414
7
+ data.tar.gz: 82e6f4f0d509240e56ae0ddc752d31c98ec4cefa903aa0d1944f459918342087c4ed3e7ae48384b80d0a4f4d31273a546233df1ac50828e0de54d58bf25196f9
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ .env
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.2.2
5
+ before_install: gem install bundler -v 1.13.5
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in qbo-sandbox.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Christian
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
13
+ all 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
21
+ THE SOFTWARE.
@@ -0,0 +1,45 @@
1
+ # Qbo::Sandbox
2
+
3
+ Copy QuickBooks Online production entities to a sandbox in a single command
4
+
5
+ ## Requirements
6
+
7
+ Ruby 2.2.2 or greater
8
+
9
+ ## Usage
10
+
11
+ 1. [Clean out](https://developer.intuit.com/hub/blog/2015/12/14/deleting-data-from-your-developer-sandbox-environment) your sandbox.
12
+ 2. `gem install qbo-sandbox`
13
+ 3. Put your production and development/sandbox credentials in an .env file. For example `vim ~/qbo-sandbox.env`
14
+ ```
15
+ # ~/.qbo-sandbox.env
16
+ QBO_SANDBOX_PROD_TOKEN=prod_token_xxxxx
17
+ QBO_SANDBOX_PROD_SECRET=prod_secret_xxxx
18
+ QBO_SANDBOX_PROD_REALM_ID=100000000
19
+ QBO_SANDBOX_PROD_CONSUMER_KEY=prod_consumer_key_ddddddd
20
+ QBO_SANDBOX_PROD_CONSUMER_SECRET=prod_consumer_secret_dddddd
21
+ QBO_SANDBOX_TOKEN=token_gggggg
22
+ QBO_SANDBOX_SECRET=secret_ggggg
23
+ QBO_SANDBOX_CONSUMER_KEY=consumer_key_yyyyyy
24
+ QBO_SANDBOX_CONSUMER_SECRET=consumer_secret_sssssss
25
+ QBO_SANDBOX_REALM_ID=2000000000000
26
+ ```
27
+ 4. `QBO_SANDBOX_ENV_FILE=~/qbo-sandbox.env qbo_sandbox customers`
28
+
29
+ 5. Important: Only tested with QuickBooks Online Name List Resources Customer and Vendor.
30
+
31
+ ## Development
32
+
33
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
34
+
35
+ 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).
36
+
37
+ ## Contributing
38
+
39
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/qbo-sandbox.
40
+
41
+
42
+ ## License
43
+
44
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
45
+
@@ -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
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "qbo/sandbox"
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
@@ -0,0 +1,32 @@
1
+ #!/usr/bin/env ruby
2
+ require 'qbo/sandbox'
3
+ require 'optparse'
4
+
5
+ opt_parser = OptionParser.new do |opt|
6
+ opt.banner = "Usage: qbo-sandbox entity"
7
+ opt.separator ""
8
+ opt.separator "Options"
9
+
10
+ opt.on("-v", "--version", "print the version") do
11
+ $stdout.puts 'qbo-sandbox version ' + Qbo::Sandbox::VERSION
12
+ Kernel.exit
13
+ end
14
+ end
15
+
16
+ opt_parser.parse!
17
+
18
+ unless ARGV.count == 1
19
+ $stdout.puts opt_parser
20
+ exit 1
21
+ end
22
+
23
+ begin
24
+ entity = ARGV.at(0)
25
+ preview = Qbo::Sandbox.new.send(entity)
26
+ $stdout.puts "Done"
27
+ rescue => e
28
+ $stderr.puts e
29
+ exit 1
30
+ end
31
+
32
+ $stdout.flush
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,85 @@
1
+ require "qbo/sandbox/version"
2
+ require "dotenv"
3
+ require "qbo_api"
4
+
5
+ module Qbo
6
+ class Sandbox
7
+ attr_reader :prod, :sandbox
8
+ def initialize(**args)
9
+ load_env!
10
+ keyword_args.merge(args).each do |key, val|
11
+ unless val
12
+ args[key] = get_env(key)
13
+ end
14
+ end
15
+ init_sandbox(args)
16
+ init_prod(args)
17
+ end
18
+
19
+ def get_env(key)
20
+ env_var = 'QBO_SANDBOX_' + key.to_s.upcase
21
+ ENV.fetch(env_var) { |k| raise "Missing value for either ENV['#{k}'] or keyword argument #{key}" }
22
+ end
23
+
24
+ def copy(entity, max: 1000, select: nil, inactive: false)
25
+ payload = { "BatchItemRequest" => [] }
26
+ QboApi.production = true
27
+ #@prod.query(select)
28
+ @prod.all(entity, max: max, select: select, inactive: inactive) do |e|
29
+ payload["BatchItemRequest"] << build_single_batch(e, entity)
30
+ end
31
+ QboApi.production = false
32
+ @sandbox.batch payload
33
+ end
34
+
35
+ private
36
+
37
+ def keyword_args
38
+ {
39
+ token: nil,
40
+ secret: nil,
41
+ realm_id: nil,
42
+ consumer_key: nil,
43
+ consumer_secret: nil,
44
+ prod_token: nil,
45
+ prod_secret: nil,
46
+ prod_realm_id: nil,
47
+ prod_consumer_key: nil,
48
+ prod_consumer_secret: nil
49
+ }
50
+ end
51
+
52
+ def init_sandbox(args)
53
+ @sandbox = QboApi.new(token: args[:token],
54
+ token_secret: args[:secret],
55
+ realm_id: args[:realm_id],
56
+ consumer_key: args[:consumer_key],
57
+ consumer_secret: args[:consumer_secret])
58
+ end
59
+
60
+ def init_prod(args)
61
+ @prod = QboApi.new(token: args[:prod_token],
62
+ token_secret: args[:prod_secret],
63
+ realm_id: args[:prod_realm_id],
64
+ consumer_key: args[:prod_consumer_key],
65
+ consumer_secret: args[:prod_consumer_secret])
66
+
67
+ end
68
+
69
+ def build_single_batch(e, entity)
70
+ {
71
+ "bId" => "bid#{e.delete('Id')}",
72
+ "operation" => "create",
73
+ @prod.singular(entity) => e
74
+ }
75
+ end
76
+
77
+ def load_env!
78
+ if ENV.has_key?('QBO_SANDBOX_ENV_FILE')
79
+ Dotenv.load(ENV['QBO_SANDBOX_ENV_FILE'])
80
+ else
81
+ Dotenv.load
82
+ end
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,5 @@
1
+ module Qbo
2
+ class Sandbox
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'qbo/sandbox/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "qbo-sandbox"
8
+ spec.version = Qbo::Sandbox::VERSION
9
+ spec.authors = ["Christian Pelczarski"]
10
+ spec.email = ["christian@minimul.com"]
11
+
12
+ spec.summary = %q{Copy production QuickBooks Online resources to a sandbox}
13
+ spec.homepage = "https://github.com/minimul/qbo-sandbox"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(%r{^(test|spec|features)/})
18
+ end
19
+ spec.bindir = "bin"
20
+ spec.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.13"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "rspec", "~> 3.0"
26
+ spec.add_development_dependency "webmock", "~> 2.0"
27
+ spec.add_development_dependency "awesome_print"
28
+ spec.add_runtime_dependency "dotenv"
29
+ spec.add_runtime_dependency "qbo_api"
30
+ end
metadata ADDED
@@ -0,0 +1,158 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: qbo-sandbox
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Christian Pelczarski
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-10-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.13'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.13'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: webmock
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '2.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '2.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: awesome_print
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: dotenv
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: qbo_api
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description:
112
+ email:
113
+ - christian@minimul.com
114
+ executables:
115
+ - console
116
+ - qbo-sandbox
117
+ - setup
118
+ extensions: []
119
+ extra_rdoc_files: []
120
+ files:
121
+ - ".gitignore"
122
+ - ".rspec"
123
+ - ".travis.yml"
124
+ - Gemfile
125
+ - LICENSE.txt
126
+ - README.md
127
+ - Rakefile
128
+ - bin/console
129
+ - bin/qbo-sandbox
130
+ - bin/setup
131
+ - lib/qbo/sandbox.rb
132
+ - lib/qbo/sandbox/version.rb
133
+ - qbo-sandbox.gemspec
134
+ homepage: https://github.com/minimul/qbo-sandbox
135
+ licenses:
136
+ - MIT
137
+ metadata: {}
138
+ post_install_message:
139
+ rdoc_options: []
140
+ require_paths:
141
+ - lib
142
+ required_ruby_version: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - ">="
145
+ - !ruby/object:Gem::Version
146
+ version: '0'
147
+ required_rubygems_version: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - ">="
150
+ - !ruby/object:Gem::Version
151
+ version: '0'
152
+ requirements: []
153
+ rubyforge_project:
154
+ rubygems_version: 2.4.8
155
+ signing_key:
156
+ specification_version: 4
157
+ summary: Copy production QuickBooks Online resources to a sandbox
158
+ test_files: []