class Qbo::Sandbox
Constants
- VERSION
Attributes
prod[R]
sandbox[R]
Public Class Methods
new(**args)
click to toggle source
# File lib/qbo/sandbox.rb, line 8 def initialize(**args) load_env! keyword_args.merge(args).each do |key, val| unless val args[key] = get_env(key) end end init_sandbox(args) init_prod(args) end
Public Instance Methods
copy(entity, max: 1000, select: nil, inactive: false, batch_size: 30)
click to toggle source
# File lib/qbo/sandbox.rb, line 24 def copy(entity, max: 1000, select: nil, inactive: false, batch_size: 30) batch = [] QboApi.production = true @prod.all(entity, max: max, select: select, inactive: inactive) do |e| batch << build_single_batch(e, entity) end submit_batch(batch, batch_size) end
get_env(key)
click to toggle source
# File lib/qbo/sandbox.rb, line 19 def get_env(key) env_var = 'QBO_SANDBOX_' + key.to_s.upcase ENV.fetch(env_var) { |k| raise "Missing value for either ENV['#{k}'] or keyword argument #{key}" } end
Private Instance Methods
build_single_batch(e, entity)
click to toggle source
# File lib/qbo/sandbox.rb, line 77 def build_single_batch(e, entity) { "bId" => "bid#{e.delete('Id')}", "operation" => "create", @prod.singular(entity) => e } end
init_prod(args)
click to toggle source
# File lib/qbo/sandbox.rb, line 68 def init_prod(args) @prod = QboApi.new(token: args[:prod_token], token_secret: args[:prod_secret], realm_id: args[:prod_realm_id], consumer_key: args[:prod_consumer_key], consumer_secret: args[:prod_consumer_secret]) end
init_sandbox(args)
click to toggle source
# File lib/qbo/sandbox.rb, line 60 def init_sandbox(args) @sandbox = QboApi.new(token: args[:token], token_secret: args[:secret], realm_id: args[:realm_id], consumer_key: args[:consumer_key], consumer_secret: args[:consumer_secret]) end
keyword_args()
click to toggle source
# File lib/qbo/sandbox.rb, line 45 def keyword_args { token: nil, secret: nil, realm_id: nil, consumer_key: nil, consumer_secret: nil, prod_token: nil, prod_secret: nil, prod_realm_id: nil, prod_consumer_key: nil, prod_consumer_secret: nil } end
load_env!()
click to toggle source
# File lib/qbo/sandbox.rb, line 85 def load_env! if ENV.has_key?('QBO_SANDBOX_ENV_FILE') Dotenv.load(ENV['QBO_SANDBOX_ENV_FILE']) else Dotenv.load end end
submit_batch(batch, batch_size)
click to toggle source
# File lib/qbo/sandbox.rb, line 35 def submit_batch(batch, batch_size) QboApi.production = false collect_responses = [] batch.each_slice(batch_size) do |b| payload = { "BatchItemRequest" => b } collect_responses << @sandbox.batch(payload) end collect_responses end