diff --git a/doc/TODO b/doc/TODO index 3698ca84..34402261 100644 --- a/doc/TODO +++ b/doc/TODO @@ -22,8 +22,12 @@ x BUG: has_one / has_many. Delete an author x bushido changes in the master ? edit sidebar (inline editor). Unable to reset it x SEO: support and support/ should be 2 different pages. Remove trailing slash -- Httparty (issue #...) +x issue #91: httparty +- issue #90: seo metadata - Has_one => group by in the select +- better hints: + - notify the user that after changing the page title, they still have to click "update" for the change to be saved + - BACKLOG: diff --git a/lib/locomotive/httparty/webservice.rb b/lib/locomotive/httparty/webservice.rb index 02881b71..f2753103 100644 --- a/lib/locomotive/httparty/webservice.rb +++ b/lib/locomotive/httparty/webservice.rb @@ -1,3 +1,5 @@ +require 'uri' + module Locomotive module Httparty class Webservice @@ -7,7 +9,11 @@ module Locomotive def self.consume(url, options = {}) url = HTTParty.normalize_base_uri(url) - options[:base_uri], path = url.scan(/^(http[s]?:\/\/.+\.[a-z]{2,})(\/.+)*/).first + uri = URI.parse(url) + options[:base_uri] = "#{uri.scheme}://#{uri.host}" + options[:base_uri] += ":#{uri.port}" if uri.port != 80 + path = uri.request_uri + options.delete(:format) if options[:format] == 'default' username, password = options.delete(:username), options.delete(:password) diff --git a/spec/lib/locomotive/httparty/webservice_spec.rb b/spec/lib/locomotive/httparty/webservice_spec.rb index 3f5f23ea..ca59e585 100644 --- a/spec/lib/locomotive/httparty/webservice_spec.rb +++ b/spec/lib/locomotive/httparty/webservice_spec.rb @@ -13,6 +13,11 @@ describe Locomotive::Httparty::Webservice do Locomotive::Httparty::Webservice.consume('http://blog.locomotiveapp.org') end + it 'sets the base uri from a much more complex url' do + Locomotive::Httparty::Webservice.expects(:get).with('/feed/weather.ashx?key=secretapikey&format=json', { :base_uri => 'http://free.worldweatheronline.com' }).returns(@response) + Locomotive::Httparty::Webservice.consume('http://free.worldweatheronline.com/feed/weather.ashx?key=secretapikey&format=json') + end + it 'sets both the base uri and the path from an url with parameters' do Locomotive::Httparty::Webservice.expects(:get).with('/api/read/json?num=3', { :base_uri => 'http://blog.locomotiveapp.org' }).returns(@response) Locomotive::Httparty::Webservice.consume('http://blog.locomotiveapp.org/api/read/json?num=3')