Class: IdsPlease::Grabbers::Twitter

Inherits:
Base
  • Object
show all
Defined in:
lib/ids_please/grabbers/twitter.rb

Instance Attribute Summary

Attributes inherited from Base

#avatar, #counts, #data, #display_name, #link, #network_id, #page_source, #username

Instance Method Summary collapse

Methods inherited from Base

#errors, #find_by_regex, #initialize, #inspect, interact, #record_error, #to_h, #to_s

Constructor Details

This class inherits a constructor from IdsPlease::Grabbers::Base

Instance Method Details

#find_avatarObject



38
39
40
41
42
43
# File 'lib/ids_please/grabbers/twitter.rb', line 38

def find_avatar
  find_by_regex(/ProfileAvatar-image " src="([^"]+)"/)
rescue => e
  record_error __method__, e.message
  return nil
end

#find_descriptionObject



59
60
61
62
63
64
65
# File 'lib/ids_please/grabbers/twitter.rb', line 59

def find_description
  _desc = find_by_regex(/ProfileHeaderCard-bio[^>]+>([^<]+)</)
  CGI.unescapeHTML(_desc.encode('utf-8')).strip
rescue => e
  record_error __method__, e.message
  return nil
end

#find_display_nameObject



45
46
47
48
49
50
# File 'lib/ids_please/grabbers/twitter.rb', line 45

def find_display_name
  find_by_regex(/ProfileHeaderCard-nameLink[^>]+>([^<]+)</)
rescue => e
  record_error __method__, e.message
  return nil
end

#find_favoritesObject



104
105
106
107
108
109
# File 'lib/ids_please/grabbers/twitter.rb', line 104

def find_favorites
  find_by_regex(/favourites_count&quot;:(\d+),&quot;/).to_i
rescue => e
  record_error __method__, e.message
  return nil
end

#find_followersObject



90
91
92
93
94
95
# File 'lib/ids_please/grabbers/twitter.rb', line 90

def find_followers
  find_by_regex(/followers_count&quot;:(\d+),&quot;/).to_i
rescue => e
  record_error __method__, e.message
  return nil
end

#find_followingObject



97
98
99
100
101
102
# File 'lib/ids_please/grabbers/twitter.rb', line 97

def find_following
  find_by_regex(/friends_count&quot;:(\d+),&quot;/).to_i
rescue => e
  record_error __method__, e.message
  return nil
end

#find_join_dateObject



75
76
77
78
79
80
81
# File 'lib/ids_please/grabbers/twitter.rb', line 75

def find_join_date
  _date = find_by_regex(/ProfileHeaderCard-joinDateText[^>]+>([^<]+)</)
  CGI.unescapeHTML(_date.encode('utf-8')).strip
rescue => e
  record_error __method__, e.message
  return nil
end

#find_listedObject



111
112
113
114
115
116
# File 'lib/ids_please/grabbers/twitter.rb', line 111

def find_listed
  find_by_regex(/listed_count&quot;:(\d+),&quot;/).to_i
rescue => e
  record_error __method__, e.message
  return nil
end

#find_locationObject



67
68
69
70
71
72
73
# File 'lib/ids_please/grabbers/twitter.rb', line 67

def find_location
  _loc = find_by_regex(/ProfileHeaderCard-locationText[^>]+>([^<]+)</)
  CGI.unescapeHTML(_loc.encode('utf-8')).strip
rescue => e
  record_error __method__, e.message
  return nil
end

#find_network_idObject



31
32
33
34
35
36
# File 'lib/ids_please/grabbers/twitter.rb', line 31

def find_network_id
  find_by_regex(/data-user-id="(\d+)"/)
rescue => e
  record_error __method__, e.message
  return nil
end

#find_tweetsObject



83
84
85
86
87
88
# File 'lib/ids_please/grabbers/twitter.rb', line 83

def find_tweets
  find_by_regex(/statuses_count&quot;:(\d+),&quot;/).to_i
rescue => e
  record_error __method__, e.message
  return nil
end

#find_usernameObject



52
53
54
55
56
57
# File 'lib/ids_please/grabbers/twitter.rb', line 52

def find_username
  find_by_regex(/<title>[^\(]+\(@([^\)]+)\)/)
rescue => e
  record_error __method__, e.message
  return nil
end


5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/ids_please/grabbers/twitter.rb', line 5

def grab_link
  @network_id   = find_network_id
  @avatar       = find_avatar
  @display_name = find_display_name
  @username     = find_username

  @counts = {
    tweets: find_tweets,
    following: find_following,
    followers: find_followers,
    favorites: find_favorites,
    lists: find_listed
  }.delete_if { |_k, v| v.nil? }

  @data = {
    description: find_description,
    location: find_location,
    join_date: find_join_date
  }.delete_if { |_k, v| v.nil? }

  self
rescue => e
  record_error __method__, e.message
  return self
end