Class: Ghtk::Order

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

Class Method Summary collapse

Class Method Details

.cancel(tracking_code) ⇒ Object



21
22
23
24
# File 'lib/ghtk/order.rb', line 21

def self.cancel(tracking_code)
  raise Ghtk::BadParamsError.new('Tracking code is blank!') if Ghtk.is_blank?(tracking_code)
  Ghtk::Request.post("/services/shipment/cancel/#{tracking_code}")
end

.create(serializer) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
# File 'lib/ghtk/order.rb', line 4

def self.create(serializer)
  create_data = Ghtk::FlexibleParams.new(serializer).hash
  Ghtk::Validations::OrderValidation.new(create_data).validate!
  Ghtk::Request.post('/services/shipment/order', create_data)
rescue Ghtk::RequestError => e
  error_code = e.response.dig('error', 'code') || 'REQUEST'
  error_class = "Ghtk::#{error_code.downcase.classify}Error".safe_constantize || Ghtk::RequestError
  raise error_class, e.response
rescue Ghtk::ForbiddenError
  raise Ghtk::CreateOrderError.new(create_data)
end

.get_detail(tracking_code) ⇒ Object



16
17
18
19
# File 'lib/ghtk/order.rb', line 16

def self.get_detail(tracking_code)
  raise Ghtk::BadParamsError.new('Tracking code is blank!') if Ghtk.is_blank?(tracking_code)
  Ghtk::Request.get("/services/shipment/v2/#{tracking_code}")
end