Sha256: bd267b46d42268ebb6707432d5166bd691dfedee7e0f7bf8115cd41a8bb3734a

Contents?: true

Size: 1.25 KB

Versions: 15

Compression:

Stored size: 1.25 KB

Contents

module Instagram
  # Defines HTTP request methods
  module Request
    # Perform an HTTP GET request
    def get(path, options={}, raw=false, unformatted=false)
      request(:get, path, options, raw, unformatted)
    end

    # Perform an HTTP POST request
    def post(path, options={}, raw=false, unformatted=false)
      request(:post, path, options, raw, unformatted)
    end

    # Perform an HTTP PUT request
    def put(path, options={}, raw=false, unformatted=false)
      request(:put, path, options, raw, unformatted)
    end

    # Perform an HTTP DELETE request
    def delete(path, options={}, raw=false, unformatted=false)
      request(:delete, path, options, raw, unformatted)
    end

    private

    # Perform an HTTP request
    def request(method, path, options, raw=false, unformatted=false)
      response = connection(raw).send(method) do |request|
        path = formatted_path(path) unless unformatted
        case method
        when :get, :delete
          request.url(path, options)
        when :post, :put
          request.path = path
          request.body = options unless options.empty?
        end
      end
      raw ? response : response.body
    end

    def formatted_path(path)
      [path, format].compact.join('.')
    end
  end
end

Version data entries

15 entries across 15 versions & 4 rubygems

Version Path
instagram_geo-0.8.8 lib/instagram/request.rb
instagram-0.9.0 lib/instagram/request.rb
instagram_geo-0.8.7 lib/instagram/request.rb
instagram-0.8.5 lib/instagram/request.rb
instagram-0.8.4 lib/instagram/request.rb
instagram-0.8.3 lib/instagram/request.rb
instagram-0.8.2 lib/instagram/request.rb
instagram-fixed-0.8.1 lib/instagram-fixed/request.rb
instagram-fixed-0.8 lib/instagram/request.rb
instagram-0.8 lib/instagram/request.rb
instagram-0.7 lib/instagram/request.rb
instagram-0.6.2 lib/instagram/request.rb
localist-instagvram-0.6.2 lib/instagram/request.rb
instagram-0.6.1 lib/instagram/request.rb
instagram-0.6 lib/instagram/request.rb