Class: TweetSearch::TwitterClient

Inherits:
Object
  • Object
show all
Defined in:
lib/tweetsearch/twitter_client.rb

Constant Summary collapse

API_BASE =
'https://api.twitter.com/'
API_VERSION =
'1.1/'
SEARCH_TWEET_ENDPOINT =
URI.join(API_BASE, API_VERSION, 'search/tweets.json')

Class Method Summary collapse

Class Method Details

.authorization_headerObject



25
26
27
# File 'lib/tweetsearch/twitter_client.rb', line 25

def self.authorization_header
  @authorization_header ||= { Authorization: "Bearer #{config[:access_token]}" }
end

.configObject



15
16
17
# File 'lib/tweetsearch/twitter_client.rb', line 15

def self.config
  @config ||= { access_token: ENV['ACCESS_TOKEN'] }
end

.config=(conf) ⇒ Object



11
12
13
# File 'lib/tweetsearch/twitter_client.rb', line 11

def self.config=(conf)
  @config ? @config.update(conf) : (@config = conf)
end

.search_tweets(*tags) ⇒ Object



19
20
21
22
23
# File 'lib/tweetsearch/twitter_client.rb', line 19

def self.search_tweets(*tags)
  HTTParty.get(SEARCH_TWEET_ENDPOINT,
               headers: authorization_header,
               query: { q: tags.join(' ') }).parsed_response['statuses']
end