2010-07-06 00:05:47 +00:00
|
|
|
module Locomotive
|
|
|
|
module Httparty
|
|
|
|
class Webservice
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-07-06 21:44:24 +00:00
|
|
|
include ::HTTParty
|
2010-07-06 00:05:47 +00:00
|
|
|
|
|
|
|
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}"
|
2010-07-06 00:05:47 +00:00
|
|
|
|
2010-07-09 10:38:50 +00:00
|
|
|
self.get(path, options).try(:underscore_keys)
|
2010-07-06 00:05:47 +00:00
|
|
|
end
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-07-06 00:05:47 +00:00
|
|
|
end
|
|
|
|
end
|
2010-07-23 20:09:54 +00:00
|
|
|
end
|