Sha256: ee44e1bb22164d142f3fdb8e4dadf5a3b87f47c819b41151c2e11ceb94ed61ea
Contents?: true
Size: 1.31 KB
Versions: 1
Compression:
Stored size: 1.31 KB
Contents
# -*- encoding : utf-8 -*- module Douban # Defines HTTP request methods module Request # Perform an HTTP GET request def get(path, options={}, raw=false) request(:get, path, options, raw) end # Perform an HTTP POST request def post(path, options={}, raw=false) request(:post, path, options, raw) end # Perform an HTTP PUT request def put(path, options={}, raw=false) request(:put, path, options, raw) end # Perform an HTTP DELETE request def delete(path, options={}, raw=false) request(:delete, path, options, raw) end private # Perform an HTTP request def request(method, path, options={}, raw=false) response = connection(raw).send(method) do |request| case method when :get, :delete request.url(path, options) when :post, :put request.path = path request.body = options unless options.empty? end end @rate_limit_info = extract_rate_limit_info(response.headers) raw ? response : response.body end def extract_rate_limit_info(headers) headers.reject do |k, v| !['x-ratelimit-limit', 'x-ratelimit-limit2', 'x-ratelimit-remaining', 'x-ratelimit-remaining2' ].include?(k) end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
douban_api-0.1.6 | lib/douban_api/request.rb |