Class: Atig::Twitter

Inherits:
BasicTwitter show all
Defined in:
lib/atig/twitter.rb

Overview

from tig.rb

Instance Attribute Summary

Attributes inherited from BasicTwitter

#limit, #remain, #reset

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BasicTwitter

#api

Constructor Details

#initialize(context, oauth) ⇒ Twitter

Returns a new instance of Twitter.



9
10
11
12
13
# File 'lib/atig/twitter.rb', line 9

def initialize(context, oauth)
  super context, :api_base
  @oauth = oauth
  @http  = Atig::Http.new @log
end

Class Method Details

.http_methods(*methods) ⇒ Object



31
32
33
34
35
36
37
38
39
40
# File 'lib/atig/twitter.rb', line 31

def self.http_methods(*methods)
  methods.each do |m|
    self.module_eval <<END
      def #{m}(path, query = {}, opts = {})
        opts.update( :method => :#{m})
        api path, query, opts
      end
END
  end
end

Instance Method Details

#page(path, name, authenticate = true, &block) ⇒ Object

authenticate = trueでないとSSL verified errorがでることがある



16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/atig/twitter.rb', line 16

def page(path, name, authenticate = true, &block)
  limit = 0.98 * @remain # 98% of IP based rate limit
  r     = []
  cursor = -1
  1.upto(limit) do |num|
    # next_cursor にアクセスするとNot found が返ってくることがあるので,その時はbreak
    ret = api(path, { :cursor => cursor }, { :authenticate => authenticate }) rescue break
    arr = ret[name.to_s]
    r.concat arr
    cursor = ret[:next_cursor]
    break if cursor.zero?
  end
  r
end