Class: IdsPlease::Grabbers::GooglePlus

Inherits:
Base
  • Object
show all
Defined in:
lib/ids_please/grabbers/google_plus.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



33
34
35
36
37
38
39
40
# File 'lib/ids_please/grabbers/google_plus.rb', line 33

def find_avatar
  _avatar = find_by_regex(/meta itemprop="image" content="([^"]+)/).encode('utf-8')
  _avatar = "http:#{_avatar}" unless _avatar =~ /\Ahttps?:\/\//
  _avatar
rescue => e
  record_error __method__, e.message
  return nil
end

#find_descriptionObject



56
57
58
59
60
61
# File 'lib/ids_please/grabbers/google_plus.rb', line 56

def find_description
  find_by_regex(/name="Description" content="([^"]+)">/).encode('utf-8')
rescue => e
  record_error __method__, e.message
  return nil
end

#find_display_nameObject



42
43
44
45
46
47
# File 'lib/ids_please/grabbers/google_plus.rb', line 42

def find_display_name
  find_by_regex(/og:title" content="([^"]+)"/).gsub(' - Google+', '')
rescue => e
  record_error __method__, e.message
  return nil
end

#find_followersObject



63
64
65
66
67
68
69
70
# File 'lib/ids_please/grabbers/google_plus.rb', line 63

def find_followers
  if followers = find_by_regex(/">([^"]+)<\/span> followers</)
    followers.tr(',', '').to_i
  end
rescue => e
  record_error __method__, e.message
  return nil
end

#find_network_idObject



26
27
28
29
30
31
# File 'lib/ids_please/grabbers/google_plus.rb', line 26

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

#find_usernameObject



49
50
51
52
53
54
# File 'lib/ids_please/grabbers/google_plus.rb', line 49

def find_username
  "+#{find_by_regex(/&quot;https:\/\/plus.google.com\/\+(.+?)&quot;/)}"
rescue => e
  record_error __method__, e.message
  return nil
end

#find_viewsObject



72
73
74
75
76
77
78
79
# File 'lib/ids_please/grabbers/google_plus.rb', line 72

def find_views
  if views = find_by_regex(/">([^"]+)<\/span> views</)
    views.tr(',', '').to_i
  end
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
# File 'lib/ids_please/grabbers/google_plus.rb', line 5

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

  @counts = {
    followers: find_followers,
    views: find_views
  }.delete_if { |_k, v| v.nil? }

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

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