Module: EpnApi::Api

Included in:
ApiDoc
Defined in:
lib/epn_api/api.rb

Instance Method Summary collapse

Instance Method Details

#accept_status(response_doc) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/epn_api/api.rb', line 20

def accept_status( response_doc )
  if    (response_doc.inspect =~ /400/) then raise "HTTP Code 400 | Bad Request | The request cannot be fulfilled due to bad syntax."
  elsif (response_doc.inspect =~ /500/) then raise "HTTP Code 500 | Internal Server Error"
  elsif (response_doc.inspect =~ /200/) then return true
  else                                       raise "Unknown HTTP Code Error"
  end
end

#get_epn_response_doc(request_xml) ⇒ Object



15
16
17
18
# File 'lib/epn_api/api.rb', line 15

def get_epn_response_doc( request_xml )
  encoded_url = self.uri_builder( request_xml )
  Net::HTTP.get_response( encoded_url )
end

#uri_builder(request_xml) ⇒ Object



5
6
7
8
9
10
11
12
13
# File 'lib/epn_api/api.rb', line 5

def uri_builder( request_xml )
  uri = URI.parse("http://calculator.environmentalpaper.org/v0/xml")
  
  url_value = URI.escape( request_xml )
  url_query = "papers=#{url_value}"
  
  encoded_url = URI::HTTP.build({:host => "calculator.environmentalpaper.org", :path => "/v0/xml", :query => url_query})
  return encoded_url
end