Class: WhiplashApi::ShipnoticeItem

Inherits:
Base
  • Object
show all
Defined in:
lib/whiplash_api/shipnotice_item.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

connection, headers, reset_headers!, testing!

Class Method Details

.delete(*args) ⇒ Object



27
28
29
30
31
# File 'lib/whiplash_api/shipnotice_item.rb', line 27

def delete(*args)
  super
rescue WhiplashApi::RecordNotFound
  raise RecordNotFound, "No shipnotice item found with given ID."
end

.find(*args) ⇒ Object

Finders for ShipnoticeItem require ‘shipnotice_id` key to be present. The following routine enforces this condition.



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/whiplash_api/shipnotice_item.rb', line 8

def find(*args)
  scope   = args.slice!(0)
  options = args.slice!(0) || {}

  if [:all, :first, :last, :one].include?(scope)
    invalid = options[:params].to_s.empty? || options[:params][:shipnotice_id].to_s.empty?
    raise Error, "You must supply a Shipment Notice ID (as parameter) to retrieve shipnotice items for." if invalid
  end

  super(scope, options)
end

.update(id, args = {}) ⇒ Object



20
21
22
23
24
25
# File 'lib/whiplash_api/shipnotice_item.rb', line 20

def update(id, args={})
  response = self.put(id, {}, args.to_json)
  response.code.to_i >= 200 && response.code.to_i < 300
rescue WhiplashApi::RecordNotFound
  raise RecordNotFound, "No shipnotice item found with given ID."
end

Instance Method Details

#destroyObject

instance methods



35
36
37
# File 'lib/whiplash_api/shipnotice_item.rb', line 35

def destroy
  self.class.delete(self.id)
end