Class: BatchGateway

Inherits:
Object
  • Object
show all
Defined in:
lib/BatchGateway.rb

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ BatchGateway

Returns a new instance of BatchGateway.



4
5
6
# File 'lib/BatchGateway.rb', line 4

def initialize(client)
  @client = client
end

Instance Method Details

#allObject



13
14
15
16
# File 'lib/BatchGateway.rb', line 13

def all
  response = @client.get('/v1/batches/')
  batch_list_builder(response)
end

#batch_builder(response) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
# 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) ⇒ Object



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# 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) ⇒ Object



18
19
20
21
# File 'lib/BatchGateway.rb', line 18

def create(body)
  response = @client.post('/v1/batches/', body)
  batch_builder(response)
end

#delete(batch_id) ⇒ Object



28
29
30
31
# File 'lib/BatchGateway.rb', line 28

def delete(batch_id)
  @client.delete('/v1/batches/' + batch_id)
  true
end

#find(batch_id) ⇒ Object



8
9
10
11
# 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) ⇒ Object



33
34
35
36
# File 'lib/BatchGateway.rb', line 33

def generate_quote(batch_id)
  response = @client.post('/v1/batches/' + batch_id + '/generate-quote', {})
  batch_builder(response)
end

#search(page = 1, page_number = 10, term = '') ⇒ Object



43
44
45
46
# File 'lib/BatchGateway.rb', line 43

def search(page = 1, page_number = 10, term = '')
  response = @client.get('/v1/batches/?search=' + term + 'page=' + page + '&pageSize=' + page_number)
  batch_list_builder(response)
end

#start_processing(batch_id) ⇒ Object



38
39
40
41
# 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) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
# 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) ⇒ Object



23
24
25
26
# File 'lib/BatchGateway.rb', line 23

def update(batch_id, body)
  @client.patch('/v1/batches/' + batch_id, body)
  true
end