This commit is contained in:
did 2011-06-22 15:57:24 -07:00
parent 40530de8bb
commit d31f1f959a
3 changed files with 17 additions and 2 deletions

View File

@ -22,8 +22,12 @@ x BUG: has_one / has_many. Delete an author
x bushido changes in the master x bushido changes in the master
? edit sidebar (inline editor). Unable to reset it ? edit sidebar (inline editor). Unable to reset it
x SEO: support and support/ should be 2 different pages. Remove trailing slash 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 - 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: BACKLOG:

View File

@ -1,3 +1,5 @@
require 'uri'
module Locomotive module Locomotive
module Httparty module Httparty
class Webservice class Webservice
@ -7,7 +9,11 @@ module Locomotive
def self.consume(url, options = {}) def self.consume(url, options = {})
url = HTTParty.normalize_base_uri(url) 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' options.delete(:format) if options[:format] == 'default'
username, password = options.delete(:username), options.delete(:password) username, password = options.delete(:username), options.delete(:password)

View File

@ -13,6 +13,11 @@ describe Locomotive::Httparty::Webservice do
Locomotive::Httparty::Webservice.consume('http://blog.locomotiveapp.org') Locomotive::Httparty::Webservice.consume('http://blog.locomotiveapp.org')
end 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 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.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') Locomotive::Httparty::Webservice.consume('http://blog.locomotiveapp.org/api/read/json?num=3')