Class: Qbo::Sandbox

Inherits:
Object
  • Object
show all
Defined in:
lib/qbo/sandbox.rb,
lib/qbo/sandbox/version.rb

Constant Summary collapse

VERSION =
"0.1.0"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**args) ⇒ Sandbox

Returns a new instance of Sandbox.



8
9
10
11
12
13
14
15
16
17
# 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

Instance Attribute Details

#prodObject (readonly)

Returns the value of attribute prod.



7
8
9
# File 'lib/qbo/sandbox.rb', line 7

def prod
  @prod
end

#sandboxObject (readonly)

Returns the value of attribute sandbox.



7
8
9
# File 'lib/qbo/sandbox.rb', line 7

def sandbox
  @sandbox
end

Instance Method Details

#copy(entity, max: 1000, select: nil, inactive: false) ⇒ Object



24
25
26
27
28
29
30
31
32
33
# File 'lib/qbo/sandbox.rb', line 24

def copy(entity, max: 1000, select: nil, inactive: false)
  payload = { "BatchItemRequest" => [] }
  QboApi.production = true
  #@prod.query(select)
  @prod.all(entity, max: max, select: select, inactive: inactive) do |e|
    payload["BatchItemRequest"] << build_single_batch(e, entity)
  end
  QboApi.production = false
  @sandbox.batch payload
end

#get_env(key) ⇒ Object



19
20
21
22
# 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