Class: Dribble::Request

Inherits:
Object show all
Defined in:
lib/dribble/request.rb

Constant Summary collapse

DRIBBLE_API =
'api.dribbble.com'

Class Method Summary collapse

Class Method Details

.get(query, options = {}) ⇒ Array/Hash

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Get

Parameters:

Returns:



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/dribble/request.rb', line 14

def get(query, options={})
  meth = options.delete(:api_endpoint)
  ::EventMachine.run do
    http = ::EventMachine::HttpRequest.new("#{to_url(query)}").get(:query => options, :timeout => 10)
    http.callback do
      @response = {
        :status => http.response_header.status.to_i,
        :header => http.response_header,
        :body   => http.response,
        :data   => ::Yajl::Parser.new(:symbolize_keys => true).parse(http.response)
      }
      ::EventMachine.stop
    end
  end

  @response[:data][:api_endpoint] = meth if meth
  @response[:status] == 200 ? @response[:data] : @response[:data][:message]
end