rsocial 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +1 -0
- data/Gemfile +11 -0
- data/README.md +46 -0
- data/lib/rsocial.rb +9 -0
- data/lib/rsocial/driver.rb +49 -0
- data/lib/rsocial/facebook.rb +8 -0
- data/lib/rsocial/facebook/client.rb +8 -0
- data/lib/rsocial/facebook/client/pages.rb +22 -0
- data/lib/rsocial/instagram.rb +8 -0
- data/lib/rsocial/instagram/client.rb +8 -0
- data/lib/rsocial/instagram/client/users.rb +24 -0
- data/rsocial.gemspec +24 -0
- metadata +123 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9f0466589b828be6e2d447db318ef7acf5d46d63
|
4
|
+
data.tar.gz: ff521364755db6cac833afa9708a68a3ee5598bb
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 05a269d0a0a067de34b26c9cbe891cf3d9f36cc3b53e9ddec5daabee0d845bb3efd3fae4289f7e5607f4edcdfec2a5575d5f6e113a73ddfcb0458fdecc59592b
|
7
|
+
data.tar.gz: f395c23b11c01ee7fb7946799f5863854e06186d400972de86e550176213d01f32e849ed530e70c9973a60c4db8680e0beb1c3e2cc72b481a4519fc58c9c4c68
|
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
Gemfile.lock
|
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
## RSocial
|
2
|
+
|
3
|
+
A gem for crawling social media stats on various web entities
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'rsocial'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundler
|
14
|
+
|
15
|
+
Or install it yourself:
|
16
|
+
|
17
|
+
$ gem install rsocial
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
#### Instagram
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
require 'rsocial'
|
25
|
+
|
26
|
+
client = RSocial::Instagram.client(:requesting_handle => "my_handle")
|
27
|
+
|
28
|
+
client.user("the_skatenerd") #=> {:handle => "the_skatenerd", :posts => "1,140", :followers => "59.8k", :following => "920"}
|
29
|
+
```
|
30
|
+
|
31
|
+
#### Facebook
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
require 'rsocial'
|
35
|
+
|
36
|
+
client = RSocial::Facebook.client(:requesting_handle => "my_handle")
|
37
|
+
|
38
|
+
client.user("TransWorldSkate") #=> {:handle => "TransWorldSkate", :followers => "1,667,861 likes"}
|
39
|
+
```
|
40
|
+
|
41
|
+
## Contributing
|
42
|
+
|
43
|
+
* Fork the project.
|
44
|
+
* Start a feature/bugfix branch.
|
45
|
+
* Commit and push until you are happy with your contribution.
|
46
|
+
* Submit a pull request
|
data/lib/rsocial.rb
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'headless'
|
2
|
+
require 'selenium-webdriver'
|
3
|
+
|
4
|
+
module RSocial
|
5
|
+
class Driver
|
6
|
+
def initialize(options={})
|
7
|
+
@options = options
|
8
|
+
@wd = Selenium::WebDriver.for :firefox
|
9
|
+
end
|
10
|
+
|
11
|
+
def run(url, executables)
|
12
|
+
while_headless do
|
13
|
+
@wd.navigate.to url
|
14
|
+
execute_each do
|
15
|
+
executables
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def while_headless
|
23
|
+
headless = Headless.new
|
24
|
+
headless.start
|
25
|
+
yield
|
26
|
+
ensure
|
27
|
+
puts "destroy"
|
28
|
+
headless.destroy
|
29
|
+
end
|
30
|
+
|
31
|
+
def execute_each(&block)
|
32
|
+
results = {}
|
33
|
+
block.call.each do |key, script|
|
34
|
+
results[key.to_sym] = execute(script)
|
35
|
+
end
|
36
|
+
results
|
37
|
+
end
|
38
|
+
|
39
|
+
def execute(script)
|
40
|
+
begin
|
41
|
+
@wd.execute_script(script)
|
42
|
+
rescue Selenium::WebDriver::Error::JavascriptError
|
43
|
+
"Javascript Error"
|
44
|
+
rescue Selenium::WebDriver::Error::UnknownError
|
45
|
+
"UnknownError"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module RSocial
|
2
|
+
module Facebook
|
3
|
+
class Client
|
4
|
+
module Pages
|
5
|
+
def page(handle)
|
6
|
+
run(
|
7
|
+
"https://www.facebook.com/#{handle}/",
|
8
|
+
user_executables
|
9
|
+
).merge(:handle => handle)
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def user_executables
|
15
|
+
executables = {}
|
16
|
+
executables[:followers] = "return document.getElementById('PagesLikesCountDOMID').childNodes[0].textContent"
|
17
|
+
executables
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module RSocial
|
2
|
+
module Instagram
|
3
|
+
class Client
|
4
|
+
module Users
|
5
|
+
def user(handle)
|
6
|
+
run(
|
7
|
+
"https://www.instagram.com/#{handle}/",
|
8
|
+
user_executables
|
9
|
+
).merge(:handle => handle)
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def user_executables
|
15
|
+
executables = {}
|
16
|
+
executables[:posts] = "return document.getElementsByClassName('_s53mj')[0].getElementsByClassName('_bkw5z')[0].innerHTML"
|
17
|
+
executables[:followers] = "return document.getElementsByClassName('_s53mj')[1].getElementsByClassName('_bkw5z')[0].innerHTML"
|
18
|
+
executables[:following] = "return document.getElementsByClassName('_s53mj')[2].getElementsByClassName('_bkw5z')[0].innerHTML"
|
19
|
+
executables
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/rsocial.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'rsocial'
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.add_development_dependency('rake', '~> 0.9.2.2')
|
8
|
+
s.add_development_dependency('rspec', '~> 2.4')
|
9
|
+
s.add_runtime_dependency('selenium-webdriver', '~> 2.53', '>= 2.53.4')
|
10
|
+
s.add_runtime_dependency('headless', '~> 2.3', '>= 2.3.0')
|
11
|
+
s.description = "A ruby social media stat crawler"
|
12
|
+
s.date = Time.now.utc.strftime("%Y-%m-%d")
|
13
|
+
s.name = 'rsocial'
|
14
|
+
s.version = RSocial::VERSION
|
15
|
+
s.summary = "A ruby social media stat crawler"
|
16
|
+
s.authors = ["Ed Richards"]
|
17
|
+
s.email = 'er@advect.us'
|
18
|
+
s.require_paths = ["lib"]
|
19
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
|
+
s.files = `git ls-files`.split("\n")
|
21
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
22
|
+
s.homepage = 'http://www.github.com/advectus/rsocial'
|
23
|
+
s.license = 'MIT'
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,123 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rsocial
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ed Richards
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-08-24 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.9.2.2
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.9.2.2
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2.4'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '2.4'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: selenium-webdriver
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2.53'
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: 2.53.4
|
51
|
+
type: :runtime
|
52
|
+
prerelease: false
|
53
|
+
version_requirements: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - "~>"
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '2.53'
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: 2.53.4
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: headless
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - "~>"
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '2.3'
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: 2.3.0
|
71
|
+
type: :runtime
|
72
|
+
prerelease: false
|
73
|
+
version_requirements: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - "~>"
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '2.3'
|
78
|
+
- - ">="
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: 2.3.0
|
81
|
+
description: A ruby social media stat crawler
|
82
|
+
email: er@advect.us
|
83
|
+
executables: []
|
84
|
+
extensions: []
|
85
|
+
extra_rdoc_files: []
|
86
|
+
files:
|
87
|
+
- ".gitignore"
|
88
|
+
- Gemfile
|
89
|
+
- README.md
|
90
|
+
- lib/rsocial.rb
|
91
|
+
- lib/rsocial/driver.rb
|
92
|
+
- lib/rsocial/facebook.rb
|
93
|
+
- lib/rsocial/facebook/client.rb
|
94
|
+
- lib/rsocial/facebook/client/pages.rb
|
95
|
+
- lib/rsocial/instagram.rb
|
96
|
+
- lib/rsocial/instagram/client.rb
|
97
|
+
- lib/rsocial/instagram/client/users.rb
|
98
|
+
- rsocial.gemspec
|
99
|
+
homepage: http://www.github.com/advectus/rsocial
|
100
|
+
licenses:
|
101
|
+
- MIT
|
102
|
+
metadata: {}
|
103
|
+
post_install_message:
|
104
|
+
rdoc_options: []
|
105
|
+
require_paths:
|
106
|
+
- lib
|
107
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - ">="
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '0'
|
112
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - ">="
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
117
|
+
requirements: []
|
118
|
+
rubyforge_project:
|
119
|
+
rubygems_version: 2.5.1
|
120
|
+
signing_key:
|
121
|
+
specification_version: 4
|
122
|
+
summary: A ruby social media stat crawler
|
123
|
+
test_files: []
|