Class: Pixelletter::Request

Inherits:
Base
  • Object
show all
Defined in:
lib/pixelletter/request/request.rb

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Request

Returns a new instance of Request.



7
8
9
# File 'lib/pixelletter/request/request.rb', line 7

def initialize(attributes = {})
  super
end

Instance Method Details

#request(order, file = nil) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/pixelletter/request/request.rb', line 11

def request(order, file=nil)
  xml = build_xml(order)
  xml_file = File.join(File.dirname('../'), "pixml.xml")
  File.open(xml_file, 'w') { |file| file.write(xml) }
  upload = File.new(File.join(File.dirname('../'), "pixml.xml"), 'rb')

  if file
    response = handle_response do
      RestClient.post(endpoint, xml: upload, "uploadfile0" => file)
    end
  else
    response = handle_response do
      RestClient.post(endpoint, xml: upload)
    end
  end

  File.delete(File.join(File.dirname('../'), "pixml.xml"))
  return response
end