Class: Twitter4j4r::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/twitter4j4r/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Client

Returns a new instance of Client.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/twitter4j4r/client.rb', line 10

def initialize(config)
  unless config.is_a? Config
    auth_map                    = config
    config                      = Twitter4j4r::Config.new
    config.consumer_key         = auth_map[:consumer_key]
    config.consumer_secret      = auth_map[:consumer_secret]
    config.access_token         = auth_map[:access_token]
    config.access_token_secret  = auth_map[:access_secret]
  end

  build = config.build
  @stream = Java::Twitter4j::TwitterStreamFactory.new(build).instance
  @twitter = Java::Twitter4j::TwitterFactory.new(build).instance
end

Instance Method Details

#add_listener(&block) ⇒ Object



66
67
68
69
# File 'lib/twitter4j4r/client.rb', line 66

def add_listener(&block)
  on_status(&block)
  @stream.addListener(Listener.new(self, @status_block, @exception_block, @limitation_block))
end

#filter(twitter_ids, *search_terms, &block) ⇒ Object



50
51
52
53
54
55
# File 'lib/twitter4j4r/client.rb', line 50

def filter(twitter_ids, *search_terms, &block)
  add_listener(&block)
  @stream.filter(Java::Twitter4j::FilterQuery.new(0,
                 twitter_ids.to_java(:long),
                 search_terms.to_java(:string)))
end

#follow(twitter_ids, &block) ⇒ Object



40
41
42
43
# File 'lib/twitter4j4r/client.rb', line 40

def follow(twitter_ids, &block)
  add_listener(&block)
  @stream.filter(Java::Twitter4j::FilterQuery.new(0, twitter_ids.to_java(:long), nil))
end

#lookup_users(user_names) ⇒ Object



57
58
59
# File 'lib/twitter4j4r/client.rb', line 57

def lookup_users(user_names)
  @twitter.lookup_users(user_names.to_java(:string))
end

#on_exception(&block) ⇒ Object



25
26
27
28
# File 'lib/twitter4j4r/client.rb', line 25

def on_exception(&block)
  @exception_block = block
  self
end

#on_limitation(&block) ⇒ Object



30
31
32
33
# File 'lib/twitter4j4r/client.rb', line 30

def on_limitation(&block)
  @limitation_block = block
  self
end

#on_status(&block) ⇒ Object



35
36
37
38
# File 'lib/twitter4j4r/client.rb', line 35

def on_status(&block)
  @status_block = block
  self
end

#sample(&block) ⇒ Object



61
62
63
64
# File 'lib/twitter4j4r/client.rb', line 61

def sample(&block)
  add_listener(&block)
  @stream.sample
end

#stopObject



71
72
73
74
# File 'lib/twitter4j4r/client.rb', line 71

def stop
  @stream.cleanUp
  @stream.shutdown
end

#track(*search_terms, &block) ⇒ Object



45
46
47
48
# File 'lib/twitter4j4r/client.rb', line 45

def track(*search_terms, &block)
  add_listener(&block)
  @stream.filter(Java::Twitter4j::FilterQuery.new(0, nil, search_terms.to_java(:string)))
end