Class: Twitter::Client

Inherits:
Object
  • Object
show all
Includes:
API::Timelines
Defined in:
lib/twitter/client.rb

Overview

Note:

Inspired from twitter-4.5.0/spec/twitter/tweet_spec.rb

Constant Summary collapse

ConnectionError =
Class.new(StandardError)

Instance Method Summary collapse

Methods included from API::Timelines

#last_tweet, #user_timeline

Instance Method Details

#get(path, qry = []) ⇒ Array<Hash>

Perform an HTTP get request against Twitter API then parse the result

Examples:

path = "statuses/user_timeline.json"
qry = [['screen_name', 'elgalu'], ['count', '1']]
Twitter::Client.new.get(path, qry)
#=> [{"created_at"=>"Fri Mar 01 21:42:19 +0000 2013", "id"=>30760....

Parameters:

  • path (String)

    the relative path to twitter API

  • qry (Array<Array<(String, String)>>) (defaults to: [])

    a nested array used to build the http query string

Returns:

  • (Array<Hash>)

    a collection of twitter response object, for example tweets



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/twitter/client.rb', line 27

def get(path, qry=[])
  uri = build_uri(path, qry)
  begin
    result = Net::HTTP.get(uri)
  rescue => ex
    pute uri, "Some network connection error: #{ex.inspect}"
  end

  pute uri, "The result contains errors: #{result}" if result =~ /error/
  JSON.parse(result)
end