Class: Trolley::BatchGateway

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

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ BatchGateway

Returns a new instance of BatchGateway.



5
6
7
# File 'lib/trolley/gateways/BatchGateway.rb', line 5

def initialize(client)
  @client = client
end

Instance Method Details

#allObject



14
15
16
17
# File 'lib/trolley/gateways/BatchGateway.rb', line 14

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

#batch_builder(response) ⇒ Object



61
62
63
# File 'lib/trolley/gateways/BatchGateway.rb', line 61

def batch_builder(response)
  Utils::ResponseMapper.build(response, Batch)
end

#batch_list_builder(response) ⇒ Object



70
71
72
# File 'lib/trolley/gateways/BatchGateway.rb', line 70

def batch_list_builder(response)
  Utils::PaginatedArray.from_response(response, Batch)
end

#create(body) ⇒ Object



19
20
21
22
# File 'lib/trolley/gateways/BatchGateway.rb', line 19

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

#delete(batch_id) ⇒ Object

Parameters:

  • batch_id (String)

    or [Array] The id (or array of ids) of the batch to delete



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/trolley/gateways/BatchGateway.rb', line 30

def delete(batch_id)
  path = '/v1/batches/'
  body = ''

  if batch_id.is_a?(String)
    path += batch_id
  elsif batch_id.is_a?(Array)
    body = { ids: batch_id }
  else
    raise 'Invalid batch_id type, please pass a string or array of strings'
  end

  @client.delete(path, body)
  true
end

#find(batch_id) ⇒ Object



9
10
11
12
# File 'lib/trolley/gateways/BatchGateway.rb', line 9

def find(batch_id)
  response = @client.get("/v1/batches/#{batch_id}")
  batch_builder(response)
end

#generate_quote(batch_id) ⇒ Object



46
47
48
49
# File 'lib/trolley/gateways/BatchGateway.rb', line 46

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

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



56
57
58
59
# File 'lib/trolley/gateways/BatchGateway.rb', line 56

def search(page = 1, page_size = 10, term = '')
  response = @client.get("/v1/batches?page=#{page}&pageSize=#{page_size}&search=#{term}")
  batch_list_builder(response)
end

#start_processing(batch_id) ⇒ Object



51
52
53
54
# File 'lib/trolley/gateways/BatchGateway.rb', line 51

def start_processing(batch_id)
  response = @client.post("/v1/batches/#{batch_id}/start-processing", {})
  batch_builder(response)
end

#summary(batch_id) ⇒ Object



65
66
67
68
# File 'lib/trolley/gateways/BatchGateway.rb', line 65

def summary(batch_id)
  response = @client.get("/v1/batches/#{batch_id}/summary")
  Utils::ResponseMapper.build(response, BatchSummary)
end

#update(batch_id, body) ⇒ Object



24
25
26
27
# File 'lib/trolley/gateways/BatchGateway.rb', line 24

def update(batch_id, body)
  @client.patch("/v1/batches/#{batch_id}", body)
  true
end