If you want your Sinatra application to retrieve a URL, you need to run some kind of HTTP client:
get '/mapsproxy/staticmap' do require 'open-uri' open('http://maps.google.com/maps/api/staticmap').read end
I think this will work and is about as minimal as you can get.
You can use HTTPClient if you need more convenient setup.
Also, I think Rack can do this. Sinatra is built on top of the rack, but since then I have played at this level.
I still need to find a way to extract ContentType from the response
From the Open-URI docs:
The opened file has several methods for meta information as follows since it is extended by OpenURI::Meta. open("http://www.ruby-lang.org/en") {|f| f.each_line {|line| p line} p f.base_uri
For your purposes, something like this should work:
content_type = '' body = open("http://www.ruby-lang.org/en") {|f| content_type = f.content_type # "text/html" f.read }
I have not tested this, but I think the return value of the block will be assigned to body . If this does not work, try:
content_type = '' body = '' open("http://www.ruby-lang.org/en") {|f| content_type = f.content_type # "text/html" body = f.read }
but I think the first will work.
the tin man
source share