Class: Twitterscraper::Client

Inherits:
Object
  • Object
show all
Includes:
Query
Defined in:
lib/twitterscraper/client.rb

Constant Summary collapse

USER_AGENT_LIST =
[
    'Mozilla/5.0 (Windows; U; Windows NT 6.1; x64; fr; rv:1.9.2.13) Gecko/20101203 Firebird/3.6.13',
    'Mozilla/5.0 (compatible, MSIE 11, Windows NT 6.3; Trident/7.0; rv:11.0) like Gecko',
    'Mozilla/5.0 (Windows; U; Windows NT 6.1; rv:2.2) Gecko/20110201',
    'Opera/9.80 (X11; Linux i686; Ubuntu/14.10) Presto/2.12.388 Version/12.16',
    'Mozilla/5.0 (Windows NT 5.2; RW; rv:7.0a1) Gecko/20091211 SeaMonkey/9.23a1pre',
]

Constants included from Query

Query::INIT_URL, Query::INIT_URL_USER, Query::OLDEST_DATE, Query::RELOAD_URL, Query::RELOAD_URL_USER

Instance Method Summary collapse

Methods included from Query

#build_queries, #build_query_url, #get_single_page, #main_loop, #parse_single_page, #query_single_page, #query_tweets, #search, #stop_requested?, #user_timeline, #validate_options!

Methods included from Logger

#logger

Constructor Details

#initialize(cache: true, proxy: true) ⇒ Client

Returns a new instance of Client.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/twitterscraper/client.rb', line 13

def initialize(cache: true, proxy: true)
  @request_headers = {'User-Agent': USER_AGENT_LIST.sample, 'X-Requested-With': 'XMLHttpRequest'}
  Twitterscraper.logger.info "Headers #{@request_headers}"

  @cache = cache

  if (@proxy = proxy)
    @proxies = Proxy::Pool.new
    Twitterscraper.logger.debug "Fetch #{@proxies.size} proxies"
  else
    @proxies = []
    Twitterscraper.logger.debug 'Proxy disabled'
  end
end

Instance Method Details

#cache_enabled?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/twitterscraper/client.rb', line 32

def cache_enabled?
  @cache
end

#proxiesObject



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

def proxies
  @proxies
end

#proxy_enabled?Boolean

Returns:

  • (Boolean)


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

def proxy_enabled?
  @proxy
end

#request_headersObject



28
29
30
# File 'lib/twitterscraper/client.rb', line 28

def request_headers
  @request_headers
end