Class: AfterShip::V4::Tracking

Inherits:
Base
  • Object
show all
Defined in:
lib/aftership/v4/tracking.rb

Constant Summary

Constants inherited from Base

Base::CALL_SLEEP, Base::MAX_TRIAL

Instance Attribute Summary

Attributes inherited from Base

#body, #end_point, #http_verb_method, #query

Class Method Summary collapse

Methods inherited from Base

#call, #initialize

Constructor Details

This class inherits a constructor from AfterShip::V4::Base

Class Method Details

.create(tracking_number, params = {}) ⇒ Object

POST /trackings



8
9
10
11
12
13
14
15
16
17
# File 'lib/aftership/v4/tracking.rb', line 8

def self.create(tracking_number, params = {})
  if tracking_number.empty? || tracking_number.nil?
    raise ArgumentError.new('tracking_number is required.')
  else
    query_hash = {:tracking_number => tracking_number}
    query_hash.merge!(params)
    body = {:tracking => query_hash}
    new(:post, 'trackings', {}, body).call
  end
end

.delete(slug, tracking_number) ⇒ Object

DELETE /trackings/:slug/:tracking_number



28
29
30
31
32
33
# File 'lib/aftership/v4/tracking.rb', line 28

def self.delete(slug, tracking_number)
  if slug.empty? || slug.nil? || tracking_number.empty? || tracking_number.nil?
    raise ArgumentError.new('slug and tracking_number are required.')
  end
  new(:delete, "trackings/#{slug}/#{tracking_number}").call
end

.delete_by_id(id) ⇒ Object

DELETE /trackings/:id



36
37
38
39
40
41
# File 'lib/aftership/v4/tracking.rb', line 36

def self.delete_by_id(id)
  if id.empty? || id.nil?
    raise ArgumentError.new('id is required.')
  end
  new(:delete, "trackings/#{id}").call
end

.export(params = {}) ⇒ Object

GET /trackings/exports



65
66
67
# File 'lib/aftership/v4/tracking.rb', line 65

def self.export(params = {})
  new(:get, 'trackings/exports', params).call
end

.get(slug, tracking_number, params = {}) ⇒ Object

GET /trackings/:slug/:tracking_number



44
45
46
47
48
49
# File 'lib/aftership/v4/tracking.rb', line 44

def self.get(slug, tracking_number, params = {})
  if slug.empty? || slug.nil? || tracking_number.empty? || tracking_number.nil?
    raise ArgumentError.new('slug and tracking_number are required.')
  end
  new(:get, "trackings/#{slug}/#{tracking_number}", params).call
end

.get_all(params = {}) ⇒ Object

GET /trackings



60
61
62
# File 'lib/aftership/v4/tracking.rb', line 60

def self.get_all(params = {})
  new(:get, 'trackings', params).call
end

.get_by_id(id, params = {}) ⇒ Object

GET /trackings/:id



52
53
54
55
56
57
# File 'lib/aftership/v4/tracking.rb', line 52

def self.get_by_id(id, params = {})
  if id.empty? || id.nil?
    raise ArgumentError.new('id is required.')
  end
  new(:get, "trackings/#{id}", params).call
end

.reactivate(slug, tracking_number) ⇒ Object

Deprecated POST /trackings/:slug/:tracking_number/reactivate

Raises:

  • (StandardError)


80
81
82
# File 'lib/aftership/v4/tracking.rb', line 80

def self.reactivate(slug, tracking_number)
  raise StandardError.new('This method is deprecated, please use "retrack" instead')
end

.retrack(slug, tracking_number) ⇒ Object

POST /trackings/:slug/:tracking_number/retrack



20
21
22
23
24
25
# File 'lib/aftership/v4/tracking.rb', line 20

def self.retrack(slug, tracking_number)
  if slug.empty? || slug.nil? || tracking_number.empty? || tracking_number.nil?
    raise ArgumentError.new('slug and tracking_number are required.')
  end
  new(:post, "trackings/#{slug}/#{tracking_number}/retrack").call
end

.update(slug, tracking_number, params = {}) ⇒ Object

PUT /trackings/:slug/:tracking_number



70
71
72
73
74
75
76
# File 'lib/aftership/v4/tracking.rb', line 70

def self.update(slug, tracking_number, params = {})
  if slug.empty? || slug.nil? || tracking_number.empty? || tracking_number.nil?
    raise ArgumentError.new('slug and tracking_number are required.')
  end
  body = {:tracking => params}
  new(:put, "trackings/#{slug}/#{tracking_number}", {}, body).call
end