Class: Workarea::GlobalE::UpdateOrderDispatch

Inherits:
Object
  • Object
show all
Includes:
Sidekiq::Worker
Defined in:
app/workers/workarea/global_e/update_order_dispatch.rb

Instance Method Summary collapse

Instance Method Details

#perform(id, tracking_number) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/workers/workarea/global_e/update_order_dispatch.rb', line 6

def perform(id, tracking_number)
  domain = GlobalE.domains[GlobalE.environment]
  path = "/Order/UpdateOrderDispatchV2?merchantGUID=#{GlobalE.merchant_guid}"

  dispatch = UpdateOrderDispatchRequest.new(id, tracking_number: tracking_number)
  uri = URI("#{domain}#{path}")

  http = Net::HTTP.new(uri.host, uri.port).tap do |net_http|
    net_http.use_ssl = true
  end

  post = Net::HTTP::Post.new(path).tap do |request|
    request['Content-Type'] = 'application/json'
    request.body = dispatch.to_json
  end

  response = http.request(post)

  raise response.body unless response.is_a? Net::HTTPSuccess
end