Class: TwitterClient

Inherits:
Object
  • Object
show all
Includes:
Contracts::Core
Defined in:
lib/twitter_client.rb

Overview

Establishes the Twitter client

Constant Summary collapse

C =

Shortcut for contracts

Contracts

Instance Method Summary collapse

Constructor Details

#initialize(credentials) ⇒ TwitterClient

Returns a new instance of TwitterClient.



12
13
14
15
16
17
18
19
20
21
# File 'lib/twitter_client.rb', line 12

def initialize(credentials)
  # @config = {
  # consumer_key: '7Jw0Oc7ZVO9NHY5Z5ieYB91Rs',
  # consumer_secret: 'hjKJVdd2ikwHdD8SMJjDQQOxxw8FmhI22s3oGXtR7u3OllcDqf',
  # access_token: '794719566966333440-dR7EPJfd6wR5Wc0nhSR1yGZfKmrqPpI',
  # access_token_secret: 'YWwWVFhRRx84NH2VxjyxnUIiyeT2tEZZiBb8wjQ72ARRX'
  # }
  @client = Twitter::REST::Client.new(credentials)
  fail 'Unable to load your credentials' unless @client.credentials?
end

Instance Method Details

#update(post) ⇒ Object

Wrapper for Twitter::Rest::Client.update with retries if too many requests



25
26
27
28
29
30
31
32
# File 'lib/twitter_client.rb', line 25

def update(post)
  @client.update(post)
rescue Twitter::Error::TooManyRequests => error
  # NOTE: Your process could go to sleep for up to 15 minutes but if you
  # retry any sooner, it will almost certainly fail with the same exception.
  sleep error.rate_limit.reset_in + 1
  retry
end