ids_please 2.0.0.beta1 → 2.0.0.beta2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a1bbac04168fe627471c08ba5bf7194969f74f66
4
- data.tar.gz: d7de09b8cea91f8f10a554ed4d350ef1fe3f5280
3
+ metadata.gz: c90688ce29bb8d767bed1b76578372de08fd159e
4
+ data.tar.gz: 05f2a555c749d65e856fd7f7564df5eefea1fdbd
5
5
  SHA512:
6
- metadata.gz: 29242a29434737cfa8972e0cc24b54f003906e344d2fd129416b98dc324cf77f7e5f0c38cc4c592488968e7c2e3a9dd3a8a30010d6cd897ef808b9599884ed3f
7
- data.tar.gz: 1e12f7f16e51eabf4c8fc14a7b2d681a2f69bfe3757af0de933edd399b9aaebae45b582d26e31b6b4547a26d4d82a708a937c6b3e8d2e56d646483151872a19b
6
+ metadata.gz: a9fb21b711bc75b247e91b5748473787d8ffefc27f22531c9137c0cee37960fc696f778fd3a44ed5c6cb2a8a815c4443c2ebabcfc503c25894e393b2218aa55c
7
+ data.tar.gz: 7c88c109074baf10941152bfb97b82a6695d0298a57fcbadbaf4dd77535f4789ad61822f7b7204daa339da78634e488ebf481628d36e72ab18bcff5e97afac47
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  [![Build Status](https://travis-ci.org/gazay/ids_please.svg)](https://codeclimate.com/github/gazay/ids_please) [![ids_please API Documentation](https://www.omniref.com/ruby/gems/ids_please.png)](https://www.omniref.com/ruby/gems/ids_please)
4
4
 
5
- Get social network IDs or screen names from links to social network accounts.
5
+ Grab some hidden in html data from social account page. Get social network IDs or screen names from links to social network accounts.
6
6
 
7
7
  Sometimes you need to get a social network account name from a link —
8
8
  to store a screen name in your database instead of parsing the link every time,
@@ -28,7 +28,55 @@ gem 'ids_please'
28
28
 
29
29
  ## Usage
30
30
 
31
- This is how you get social IDs from from links:
31
+ This gem works in two modes – you can get real data from social network by http request and page parsing
32
+ and you can just parse link to social account to find username/id. Sometimes username from link can't be
33
+ used with social network's API, in this case try to get real ID with grab mode.
34
+
35
+ ### Grabbing data from social account's page
36
+
37
+ This functionality works through real http requests, so if you feed it with many links – it can take a while.
38
+
39
+ As Facebook shows data only from public pages and public groups – in most cases you can't gather data from
40
+ any profile page. Same thing about private `instagram` accounts, profiles and private groups in `vk`.
41
+
42
+ Also you should provide real urls with right protocols. For example you will not receive any data from `http://facebook.com/Microsoft`,
43
+ but from `https://facebook.com/Microsoft` you'll receive all data as in example below:
44
+
45
+ ```ruby
46
+ ids = IdsPlease.new('https://instagram.com/microsoft/', 'https://facebook.com/Microsoft')
47
+ ids.grab
48
+ => {:instagram=>
49
+ [IdsPlease::Grabbers::Instagram#70339427221180
50
+ @link=https://instagram.com/microsoft/,
51
+ @network_id=524549267,
52
+ @avatar=https://igcdn-photos-h-a.akamaihd.net/hphotos-ak-xpf1/t51.2885-19/10729318_654650964633655_619168277_a.jpg,
53
+ @display_name=Microsoft,
54
+ @username=microsoft,
55
+ @data={:bio=>"The official Instagram account of Microsoft. Celebrating people who break boundaries, achieve their goals, and #DoMore every day.", :website=>"http://msft.it/MSFTDoMore"}],
56
+ :facebook=>
57
+ [IdsPlease::Grabbers::Facebook#70339427168960
58
+ @link=https://facebook.com/Microsoft,
59
+ @network_id=20528438720,
60
+ @avatar=https://fbcdn-profile-a.akamaihd.net/hprofile-ak-xfa1/v/t1.0-1/394366_10151053222893721_1961351328_n.jpg?oh=f3efc47a669cf291221ca421eaf016fb&oe=55C61365&__gda__=1440162054_3bf920ed0b4c0c7873c4ec44affcec15,
61
+ @display_name=Microsoft,
62
+ @username=Microsoft,
63
+ @data={:type=>"company", :description=>"Welcome to the official Microsoft Facebook page, your source for news and conversation about..."}
64
+ ]
65
+ }
66
+
67
+ insta = ids.grabbed[:instagram].first
68
+ insta.avatar
69
+ => "https://igcdn-photos-h-a.akamaihd.net/hphotos-ak-xpf1/t51.2885-19/10729318_654650964633655_619168277_a.jpg"
70
+ ```
71
+
72
+ Social networks supported for grabbing at the moment:
73
+
74
+ * [Facebook](https://www.facebook.com)
75
+ * [Twitter](https://www.twitter.com)
76
+ * [Instagram](http://instagram.com)
77
+ * [Vkontakte](https://vk.com)
78
+
79
+ ### Link parsing
32
80
 
33
81
  ```ruby
34
82
  ids = IdsPlease.new('https://twitter.com/gazay', 'http://facebook.com/alexey.gaziev')
@@ -24,7 +24,7 @@ class IdsPlease
24
24
  next if iv == :@page_source
25
25
  val = self.instance_variable_get(iv)
26
26
  next if val.nil? || val == ''
27
- line += ", #{iv}=#{val}"
27
+ line += ", \n#{iv}=#{val}"
28
28
  end
29
29
  "#{self.class}##{self.object_id} #{line[1..-1]}"
30
30
  end
@@ -7,7 +7,7 @@ class IdsPlease
7
7
  @network_id = @page_source.scan(/entity_id":"(\d+)"/).flatten.first
8
8
  @avatar = @page_source.scan(/og:image" content="([^"]+)"/).flatten.first
9
9
  @display_name = @page_source.scan(/og:title" content="([^"]+)"/).flatten.first
10
- @username = @page_source.scan(/og:url" content=".+\/([^\/"]+)"/).flatten.first
10
+ @username = @page_source.scan(/og:url" content="[^"]+\/([^\/"]+)"/).flatten.first
11
11
  @avatar = CGI.unescapeHTML(@avatar.encode('utf-8')) if @avatar
12
12
  @display_name = CGI.unescapeHTML(@display_name.encode('utf-8')) if @display_name
13
13
  @data = {}
@@ -0,0 +1,28 @@
1
+ class IdsPlease
2
+ module Grabbers
3
+ class Twitter < IdsPlease::Grabbers::Base
4
+
5
+ def grab_link
6
+ @page_source ||= open(link).read
7
+ @network_id = @page_source.scan(/data-user-id="(\d+)"/).flatten.first
8
+ @avatar = @page_source.scan(/ProfileAvatar-image " src="([^"]+)"/).flatten.first
9
+ @display_name = @page_source.scan(/ProfileHeaderCard-nameLink[^>]+>([^<]+)</).flatten.first
10
+ @username = @page_source.scan(/<title>[^\(]+\(@([^\)]+)\)/).flatten.first
11
+ @data = {}
12
+ {
13
+ description: @page_source.scan(/ProfileHeaderCard-bio[^>]+>([^<]+)</).flatten.first.encode('utf-8'),
14
+ location: @page_source.scan(/ProfileHeaderCard-locationText[^>]+>([^<]+)</).flatten.first.encode('utf-8'),
15
+ join_date: @page_source.scan(/ProfileHeaderCard-joinDateText[^>]+>([^<]+)</).flatten.first.encode('utf-8'),
16
+ }.each do |k, v|
17
+ next if v.nil? || v == ''
18
+ @data[k] = CGI.unescapeHTML(v)
19
+ end
20
+ self
21
+ rescue => e
22
+ p e
23
+ return self
24
+ end
25
+
26
+ end
27
+ end
28
+ end
@@ -2,23 +2,24 @@ require_relative 'grabbers/base'
2
2
  require_relative 'grabbers/facebook'
3
3
  require_relative 'grabbers/vkontakte'
4
4
  require_relative 'grabbers/instagram'
5
+ require_relative 'grabbers/twitter'
5
6
 
6
7
  class IdsPlease
7
8
  module Grabbers
8
9
 
9
- NETWORKS = [
10
- IdsPlease::Grabbers::Facebook,
11
- IdsPlease::Grabbers::Vkontakte,
12
- IdsPlease::Grabbers::Instagram
13
- ]
10
+ NETWORKS = {
11
+ facebook: IdsPlease::Grabbers::Facebook,
12
+ vkontakte: IdsPlease::Grabbers::Vkontakte,
13
+ twitter: IdsPlease::Grabbers::Twitter,
14
+ instagram: IdsPlease::Grabbers::Instagram
15
+ }
14
16
 
15
17
  def self.each
16
- NETWORKS.each { |n| yield n }
18
+ NETWORKS.values.each { |n| yield n }
17
19
  end
18
20
 
19
21
  def self.by_symbol(sym)
20
- klass_name = "#{sym.to_s[0].upcase}#{sym.to_s[1..-1]}"
21
- self.const_get(klass_name)
22
+ NETWORKS[sym]
22
23
  end
23
24
 
24
25
  end
@@ -21,38 +21,33 @@ require_relative 'parsers/moikrug'
21
21
  class IdsPlease
22
22
  module Parsers
23
23
 
24
- NETWORKS = [
25
- IdsPlease::Parsers::GooglePlus,
26
- IdsPlease::Parsers::Vkontakte,
27
- IdsPlease::Parsers::Twitter,
28
- IdsPlease::Parsers::Facebook,
29
- IdsPlease::Parsers::Instagram,
30
- IdsPlease::Parsers::Blogger,
31
- IdsPlease::Parsers::Ameba,
32
- IdsPlease::Parsers::Hi5,
33
- IdsPlease::Parsers::Linkedin,
34
- IdsPlease::Parsers::Livejournal,
35
- IdsPlease::Parsers::Reddit,
36
- IdsPlease::Parsers::Pinterest,
37
- IdsPlease::Parsers::Soundcloud,
38
- IdsPlease::Parsers::Vimeo,
39
- IdsPlease::Parsers::Youtube,
40
- IdsPlease::Parsers::Odnoklassniki,
41
- IdsPlease::Parsers::Tumblr,
42
- IdsPlease::Parsers::Moikrug
43
- ]
24
+ NETWORKS = {
25
+ google_plus: IdsPlease::Parsers::GooglePlus,
26
+ vkontakte: IdsPlease::Parsers::Vkontakte,
27
+ twitter: IdsPlease::Parsers::Twitter,
28
+ facebook: IdsPlease::Parsers::Facebook,
29
+ instagram: IdsPlease::Parsers::Instagram,
30
+ blogger: IdsPlease::Parsers::Blogger,
31
+ ameba: IdsPlease::Parsers::Ameba,
32
+ hi5: IdsPlease::Parsers::Hi5,
33
+ linkedin: IdsPlease::Parsers::Linkedin,
34
+ livejournal: IdsPlease::Parsers::Livejournal,
35
+ reddit: IdsPlease::Parsers::Reddit,
36
+ pinterest: IdsPlease::Parsers::Pinterest,
37
+ soundcloud: IdsPlease::Parsers::Soundcloud,
38
+ vimeo: IdsPlease::Parsers::Vimeo,
39
+ youtube: IdsPlease::Parsers::Youtube,
40
+ odnoklassniki: IdsPlease::Parsers::Odnoklassniki,
41
+ tumblr: IdsPlease::Parsers::Tumblr,
42
+ moikrug: IdsPlease::Parsers::Moikrug
43
+ }
44
44
 
45
45
  def self.each
46
- NETWORKS.each { |n| yield n }
46
+ NETWORKS.values.each { |n| yield n }
47
47
  end
48
48
 
49
49
  def self.by_symbol(sym)
50
- if sym == :google_plus
51
- IdsPlease::Parsers::GooglePlus
52
- else
53
- klass_name = "#{sym.to_s[0].upcase}#{sym.to_s[1..-1]}"
54
- self.const_get(klass_name)
55
- end
50
+ NETWORKS[sym]
56
51
  end
57
52
 
58
53
  end
@@ -1,3 +1,3 @@
1
1
  class IdsPlease
2
- VERSION = '2.0.0.beta1'
2
+ VERSION = '2.0.0.beta2'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ids_please
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0.beta1
4
+ version: 2.0.0.beta2
5
5
  platform: ruby
6
6
  authors:
7
7
  - gazay
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-13 00:00:00.000000000 Z
11
+ date: 2015-05-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -57,6 +57,7 @@ files:
57
57
  - lib/ids_please/grabbers/base.rb
58
58
  - lib/ids_please/grabbers/facebook.rb
59
59
  - lib/ids_please/grabbers/instagram.rb
60
+ - lib/ids_please/grabbers/twitter.rb
60
61
  - lib/ids_please/grabbers/vkontakte.rb
61
62
  - lib/ids_please/parsers.rb
62
63
  - lib/ids_please/parsers/ameba.rb