Class: SportsSouth::Invoice

Inherits:
Base
  • Object
show all
Defined in:
lib/sports_south/invoice.rb

Constant Summary collapse

API_URL =
'http://webservices.theshootingwarehouse.com/smart/invoices.asmx'

Constants inherited from Base

Base::CONTENT_TYPE, Base::TIMEOUT, Base::USER_AGENT

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Invoice

Returns a new instance of Invoice.



14
15
16
17
18
# File 'lib/sports_south/invoice.rb', line 14

def initialize(options = {})
  requires!(options, :username, :password, :source, :customer_number)
  @options = options
  @po_number = options[:po_number]
end

Instance Attribute Details

#po_numberObject (readonly)

Returns the value of attribute po_number.



7
8
9
# File 'lib/sports_south/invoice.rb', line 7

def po_number
  @po_number
end

#response_bodyObject (readonly)

Returns the value of attribute response_body.



6
7
8
# File 'lib/sports_south/invoice.rb', line 6

def response_body
  @response_body
end

Class Method Details

.find_by_po_number(po_number, options = {}) ⇒ Object



9
10
11
12
# File 'lib/sports_south/invoice.rb', line 9

def self.find_by_po_number(po_number, options = {})
  requires!(options, :username, :password)
  new(options.merge({po_number: po_number}))
end

Instance Method Details

#trackingObject

Raises:

  • (StandardError)


20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/sports_south/invoice.rb', line 20

def tracking
  raise StandardError.new("No @po_number present.") if @po_number.nil?

  http, request = get_http_and_request(API_URL, '/GetTrackingByPo')

  request.set_form_data(form_params(@options).merge({
    PONumber: @po_number,
  }))

  response = http.request(request)
  body = sanitize_response(response)
  xml_doc = Nokogiri::XML(body)

  raise SportsSouth::NotAuthenticated if not_authenticated?(xml_doc)

  @response_body = body

  @tracking = {
    invoice_number: content_for(xml_doc, 'INVNO'),
    customer_number: content_for(xml_doc, 'CUSNO'),
    po_number: content_for(xml_doc, 'PONBR'),
    ship_date: content_for(xml_doc, 'SHPDTE'),
    tracking_number: content_for(xml_doc, 'TRACKNO'),
    package_weight: content_for(xml_doc, 'PKGWT'),
    cod_amount: content_for(xml_doc, 'CODAMT'),
    hazmat: content_for(xml_doc, 'HAZMAT'),
    ship_amount: content_for(xml_doc, 'SHPAMT'),
    ship_service: content_for(xml_doc, 'SERVICE'),
  }
end