Sha256: ffc248901a62da22c14c7d65adeb9baa7d0be483798f78e610ee52cdc0cfa227

Contents?: true

Size: 1015 Bytes

Versions: 17

Compression:

Stored size: 1015 Bytes

Contents

require 'uri'

module Locomotive
  module Httparty
    class Webservice

      include ::HTTParty

      def self.consume(url, options = {})
        url = HTTParty.normalize_base_uri(url)

        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)
        options[:basic_auth] = { :username => username, :password => password } if username

        path ||= '/'

        # puts "[WebService] consuming #{path}, #{options.inspect}"

        response = self.get(path, options)

        if response.code == 200
          if response.respond_to?(:underscore_keys)
            response.underscore_keys
          else
            response.collect(&:underscore_keys)
          end
        else
          nil
        end

      end

    end
  end
end

Version data entries

17 entries across 17 versions & 2 rubygems

Version Path
locomotive_cms-2.0.3 lib/locomotive/httparty/webservice.rb
locomotive_cms-2.0.2 lib/locomotive/httparty/webservice.rb
locomotive_cms-2.0.1 lib/locomotive/httparty/webservice.rb
locomotive_cms-2.0.0 lib/locomotive/httparty/webservice.rb
tribeca_cms-0.1.1 lib/locomotive/httparty/webservice.rb
tribeca_cms-2.0.0.rc12 lib/locomotive/httparty/webservice.rb
locomotive_cms-2.0.0.rc12 lib/locomotive/httparty/webservice.rb
locomotive_cms-2.0.0.rc11 lib/locomotive/httparty/webservice.rb
locomotive_cms-2.0.0.rc10 lib/locomotive/httparty/webservice.rb
locomotive_cms-2.0.0.rc9 lib/locomotive/httparty/webservice.rb
locomotive_cms-2.0.0.rc8 lib/locomotive/httparty/webservice.rb
locomotive_cms-2.0.0.rc7 lib/locomotive/httparty/webservice.rb
locomotive_cms-2.0.0.rc6 lib/locomotive/httparty/webservice.rb
locomotive_cms-2.0.0.rc5 lib/locomotive/httparty/webservice.rb
locomotive_cms-2.0.0.rc4 lib/locomotive/httparty/webservice.rb
locomotive_cms-2.0.0.rc2 lib/locomotive/httparty/webservice.rb
locomotive_cms-2.0.0.rc1 lib/locomotive/httparty/webservice.rb