Class: TwitterKnife::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/twitter-knife/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Client

Returns a new instance of Client.



9
10
11
12
13
14
# File 'lib/twitter-knife/client.rb', line 9

def initialize(options)
  @options = options

  # Exchange our oauth_token and oauth_token secret for the AccessToken instance.
  @access_token = prepare_access_token()
end

Instance Method Details

#get(api, options = {}) ⇒ Object



16
17
18
19
20
# File 'lib/twitter-knife/client.rb', line 16

def get(api, options={})
  args = options.map{|k,v| "#{k}=#{v}" }.join('&')
  response = @access_token.request(:get, "/#{API_VERSION}/#{api}?#{args}")
  response.body
end

#post(api, body = '') ⇒ Object



22
23
24
25
# File 'lib/twitter-knife/client.rb', line 22

def post(api, body='')
  response = @access_token.request(:post, "/#{API_VERSION}/#{api}", body)
  response.body
end

#prepare_access_tokenObject

Exchange your oauth_token and oauth_token_secret for an AccessToken instance.



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

def prepare_access_token
  consumer = OAuth::Consumer.new(@options[:consumer_key], @options[:consumer_secret],
    { :site => "https://#{TWITTER_API_HOST}",
      :scheme => :header
    })
  # now create the access token object from passed values
  token_hash = { :oauth_token => @options[:oauth_token],
                 :oauth_token_secret => @options[:oauth_token_secret]
               }
  access_token = OAuth::AccessToken.from_hash(consumer, token_hash)
end