class BatchGateway

Public Class Methods

new(client) click to toggle source
# File lib/BatchGateway.rb, line 4
def initialize(client)
  @client = client
end

Public Instance Methods

all() click to toggle source
# File lib/BatchGateway.rb, line 13
def all
  response = @client.get('/v1/batches/')
  batch_list_builder(response)
end
batch_builder(response) click to toggle source
# File lib/BatchGateway.rb, line 48
def batch_builder(response)
  batch = Batch.new
  data = JSON.parse(response)
  data.each do |key, value|
    next unless key === 'batch'
    value.each do |newKey, newValue|
      batch.send("#{newKey}=", newValue)
    end
  end
  batch
end
batch_list_builder(response) click to toggle source
# File lib/BatchGateway.rb, line 73
def batch_list_builder(response)
  batches = []
  data = JSON.parse(response)

  data.each do |key, value|
    next unless key === 'batches'
    value.each do |newKey, _newValue|
      batch = Batch.new
      newKey.each do |key1, value1|
        batch.send("#{key1}=", value1)
      end
      batches.push(batch)
    end
  end
  batches
end
create(body) click to toggle source
# File lib/BatchGateway.rb, line 18
def create(body)
  response = @client.post('/v1/batches/', body)
  batch_builder(response)
end
delete(batch_id) click to toggle source
# File lib/BatchGateway.rb, line 28
def delete(batch_id)
  @client.delete('/v1/batches/' + batch_id)
  true
end
find(batch_id) click to toggle source
# File lib/BatchGateway.rb, line 8
def find(batch_id)
  response = @client.get('/v1/batches/' + batch_id)
  batch_builder(response)
end
generate_quote(batch_id) click to toggle source
# File lib/BatchGateway.rb, line 33
def generate_quote(batch_id)
  response = @client.post('/v1/batches/' + batch_id + '/generate-quote', {})
  batch_builder(response)
end
start_processing(batch_id) click to toggle source
# File lib/BatchGateway.rb, line 38
def start_processing(batch_id)
  response = @client.post('/v1/batches/' + batch_id + '/start-processing', {})
  batch_builder(response)
end
summary(batch_id) click to toggle source
# File lib/BatchGateway.rb, line 60
def summary(batch_id)
  response = @client.get('/v1/batches/' + batch_id + '/summary')
  summary = BatchSummary.new
  data = JSON.parse(response)
  data.each do |key, value|
    next unless key === 'batchSummary'
    value.each do |newKey, newValue|
      summary.send("#{newKey}=", newValue)
    end
  end
  summary
end
update(batch_id, body) click to toggle source
# File lib/BatchGateway.rb, line 23
def update(batch_id, body)
  @client.patch('/v1/batches/' + batch_id, body)
  true
end