Class: EFax::InboundPostRequest

Inherits:
Object
  • Object
show all
Defined in:
lib/efax/inbound.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(xml) ⇒ InboundPostRequest

Returns a new instance of InboundPostRequest.



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/efax/inbound.rb', line 29

def initialize(xml)
  doc            = Hpricot(xml)
  @encoded_file_contents = doc.at(:filecontents).inner_text
  @file_type     = doc.at(:filetype).inner_text.to_sym
  @ani           = doc.at(:ani).inner_text
  @account_id    = doc.at(:accountid).inner_text
  @fax_name      = doc.at(:faxname).inner_text
  @csid          = doc.at(:csid).inner_text
  @status        = doc.at(:status).inner_text.to_i
  @mcfid         = doc.at(:mcfid).inner_text.to_i
  @page_count    = doc.at(:pagecount).inner_text.to_i
  @request_type  = doc.at(:requesttype).inner_text
  @date_received = datetime_to_time(DateTime.strptime("#{doc.at(:datereceived).inner_text} -08:00", "%m/%d/%Y %H:%M:%S %z"))
  @request_date  = datetime_to_time(DateTime.strptime("#{doc.at(:requestdate).inner_text} -08:00", "%m/%d/%Y %H:%M:%S %z"))
  @barcodes      = doc.search("//barcode/key").map { |key| key.inner_html }
  @barcode_pages = doc.search("//barcode/AdditionalInfo/CodeLocation/PageNumber").map { |key| key.inner_html }
end

Instance Attribute Details

#account_idObject (readonly)

Returns the value of attribute account_id.



12
13
14
# File 'lib/efax/inbound.rb', line 12

def 
  @account_id
end

#aniObject (readonly) Also known as: sender_fax_number

Returns the value of attribute ani.



12
13
14
# File 'lib/efax/inbound.rb', line 12

def ani
  @ani
end

#barcode_pagesObject (readonly)

Returns the value of attribute barcode_pages.



12
13
14
# File 'lib/efax/inbound.rb', line 12

def barcode_pages
  @barcode_pages
end

#barcodesObject (readonly)

Returns the value of attribute barcodes.



12
13
14
# File 'lib/efax/inbound.rb', line 12

def barcodes
  @barcodes
end

#csidObject (readonly)

Returns the value of attribute csid.



12
13
14
# File 'lib/efax/inbound.rb', line 12

def csid
  @csid
end

#date_receivedObject (readonly)

Returns the value of attribute date_received.



12
13
14
# File 'lib/efax/inbound.rb', line 12

def date_received
  @date_received
end

#encoded_file_contentsObject (readonly)

Returns the value of attribute encoded_file_contents.



12
13
14
# File 'lib/efax/inbound.rb', line 12

def encoded_file_contents
  @encoded_file_contents
end

#fax_nameObject (readonly)

Returns the value of attribute fax_name.



12
13
14
# File 'lib/efax/inbound.rb', line 12

def fax_name
  @fax_name
end

#file_typeObject (readonly)

Returns the value of attribute file_type.



12
13
14
# File 'lib/efax/inbound.rb', line 12

def file_type
  @file_type
end

#mcfidObject (readonly)

Returns the value of attribute mcfid.



12
13
14
# File 'lib/efax/inbound.rb', line 12

def mcfid
  @mcfid
end

#page_countObject (readonly)

Returns the value of attribute page_count.



12
13
14
# File 'lib/efax/inbound.rb', line 12

def page_count
  @page_count
end

#request_dateObject (readonly)

Returns the value of attribute request_date.



12
13
14
# File 'lib/efax/inbound.rb', line 12

def request_date
  @request_date
end

#request_typeObject (readonly)

Returns the value of attribute request_type.



12
13
14
# File 'lib/efax/inbound.rb', line 12

def request_type
  @request_type
end

#statusObject (readonly)

Returns the value of attribute status.



12
13
14
# File 'lib/efax/inbound.rb', line 12

def status
  @status
end

Class Method Details

.receive_by_params(params) ⇒ Object



68
69
70
# File 'lib/efax/inbound.rb', line 68

def self.receive_by_params(params)
  receive_by_xml(params[:xml] || params["xml"])
end

.receive_by_xml(xml) ⇒ Object



72
73
74
# File 'lib/efax/inbound.rb', line 72

def self.receive_by_xml(xml)
  new(xml)
end

Instance Method Details

#fileObject



51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/efax/inbound.rb', line 51

def file
  @file ||= begin
    if defined?(Encoding)
      file = Tempfile.new(fax_name, {:encoding => 'ascii-8bit'})
    else
      file = Tempfile.new(fax_name)
    end
    file << file_contents
    file.rewind
    file
  end
end

#file_contentsObject



47
48
49
# File 'lib/efax/inbound.rb', line 47

def file_contents
  @file_contents ||= Base64.decode64(encoded_file_contents)
end

#post_successful_messageObject



64
65
66
# File 'lib/efax/inbound.rb', line 64

def post_successful_message
  "Post Successful"
end