Class: SocialBee::Twi

Inherits:
Object
  • Object
show all
Includes:
Twitter, YAML
Defined in:
lib/social-bee/twi.rb

Instance Method Summary collapse

Constructor Details

#initialize(p = {}) ⇒ Twi

Returns a new instance of Twi.



9
10
11
12
13
14
15
16
17
18
# File 'lib/social-bee/twi.rb', line 9

def initialize(p={})

  raise 'Undefined config file' unless @config = YAML.load_file(Rails.root + p[:config])[Rails.env]

  Twitter.configure do |config|
    raise 'Undefined consumer key' unless config.consumer_key = @config['app_key']
    raise 'Undefined consumer secret' unless config.consumer_secret = @config['app_secret']
  end

end

Instance Method Details

#client(token, secret) ⇒ Object



20
21
22
# File 'lib/social-bee/twi.rb', line 20

def client( token, secret )
  Twitter::Client.new( :oauth_token => token, :oauth_token_secret => secret )
end

#get_friends(token, secret) ⇒ Object



39
40
41
# File 'lib/social-bee/twi.rb', line 39

def get_friends( token, secret )
  client( token, secret ).follower_ids.ids
end

#say_friends(message, token, secret) ⇒ Object



33
34
35
36
37
# File 'lib/social-bee/twi.rb', line 33

def say_friends( message, token, secret )
  get_friends( token, secret ).each do |itm|
    say_private( itm, message, token, secret )
  end
end

#say_private(to, message, token, secret) ⇒ Object



29
30
31
# File 'lib/social-bee/twi.rb', line 29

def say_private( to, message, token, secret )
  client( token, secret ).direct_message_create( to, message )
end

#say_public(message, token, secret) ⇒ Object



25
26
27
# File 'lib/social-bee/twi.rb', line 25

def say_public( message, token, secret )
  client( token, secret ).update( message )
end