Sha256: 9c6ba40f6dd3e1ddcb90984de09a0d5f09d8805452abf74c1e85363275f6469e

Contents?: true

Size: 907 Bytes

Versions: 3

Compression:

Stored size: 907 Bytes

Contents

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 ||= '/'

        # 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

3 entries across 3 versions & 1 rubygems

Version Path
locomotive_cms-1.0.0.beta.2 lib/locomotive/httparty/webservice.rb
locomotive_cms-1.0.0.beta lib/locomotive/httparty/webservice.rb
locomotive_cms-0.0.4.beta12 lib/locomotive/httparty/webservice.rb