engine/lib/locomotive/httparty/webservice.rb

26 lines
679 B
Ruby
Raw Normal View History

module Locomotive
module Httparty
class Webservice
include ::HTTParty
def self.consume(url, options = {})
url = HTTParty.normalize_base_uri(url)
options[:base_uri], path = url.scan(/^(http[s]?:\/\/.+\.[a-z]{2,})(\/.+)*/).first
options.delete(:format) if options[:format] == 'default'
username, password = options.delete(:username), options.delete(:password)
options[:basic_auth] = { :username => username, :password => password } if username
path ||= '/'
2010-07-20 10:21:18 +00:00
# puts "[WebService] consuming #{path}, #{options.inspect}"
self.get(path, options).try(:underscore_keys)
end
end
end
end