picture_from 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.rspec +5 -0
- data/.rubocop.yml +19 -0
- data/.ruby-gemset +1 -0
- data/.travis.yml +13 -0
- data/Gemfile +14 -0
- data/LICENSE.txt +22 -0
- data/README.md +56 -0
- data/Rakefile +22 -0
- data/lib/picture_from/crawlers/facebook_crawler.rb +29 -0
- data/lib/picture_from/facebook_picture.rb +18 -0
- data/lib/picture_from/gravatar_picture.rb +17 -0
- data/lib/picture_from/version.rb +3 -0
- data/lib/picture_from.rb +7 -0
- data/picture_from.gemspec +32 -0
- data/spec/fixtures/facebook_crawler.response +895 -0
- data/spec/fixtures/facebook_crawler_empty.response +866 -0
- data/spec/lib/picture_from/crawlers/facebook_crawler_spec.rb +71 -0
- data/spec/lib/picture_from/facebook_picture_spec.rb +27 -0
- data/spec/lib/picture_from/gravatar_picture_spec.rb +14 -0
- data/spec/spec_helper.rb +10 -0
- data/spec/support/coverage.rb +14 -0
- data/spec/support/fake_web_helper.rb +14 -0
- metadata +188 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 11924f08d55e6f4104bc764e3ee2f49de4a130ac
|
4
|
+
data.tar.gz: 7396b3c9329034a6caf1853ff70b49bada0513cd
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e5fc95bfdf460835a048601f91f5aff3db9b20ce6a284ce56317de19ce8772e586cecde541e30f38295caddc1ea949373aeba2401bbc78ccb189cb496a3e2676
|
7
|
+
data.tar.gz: ece08909c8b2b98d9eea91c57af861d7f2e7b683f45000c8a28c100e0164f5b90192196d05b9f150b41fb41deb3eafbe2ea67cbfe613422fb4291aea4e2d4c9e
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# Document classes and non-namespace modules.
|
2
|
+
Documentation:
|
3
|
+
Enabled: false
|
4
|
+
|
5
|
+
# Keep blank lines around access modifiers.
|
6
|
+
Style/EmptyLinesAroundAccessModifier:
|
7
|
+
Enabled: false
|
8
|
+
|
9
|
+
# Keeps track of empty lines around block bodies.
|
10
|
+
Style/EmptyLinesAroundBlockBody:
|
11
|
+
Enabled: false
|
12
|
+
|
13
|
+
# Keeps track of empty lines around class bodies.
|
14
|
+
Style/EmptyLinesAroundClassBody:
|
15
|
+
Enabled: false
|
16
|
+
|
17
|
+
# Keeps track of empty lines around module bodies.
|
18
|
+
Style/EmptyLinesAroundModuleBody:
|
19
|
+
Enabled: false
|
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
picture_from
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
# Specify your gem's dependencies in picture_from.gemspec
|
4
|
+
gemspec
|
5
|
+
|
6
|
+
group :test do
|
7
|
+
gem 'codeclimate-test-reporter', require: false
|
8
|
+
end
|
9
|
+
|
10
|
+
local_gemfile = 'Gemfile.local'
|
11
|
+
|
12
|
+
if File.exist?(local_gemfile)
|
13
|
+
eval(File.read(local_gemfile)) # rubocop:disable Lint/Eval
|
14
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 jzeta
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
PictureFrom
|
2
|
+
============
|
3
|
+
|
4
|
+
[![Build Status](https://travis-ci.org/karreiro/picture_from.svg?branch=master)](https://travis-ci.org/karreiro/picture_from)
|
5
|
+
[![Code Climate](https://codeclimate.com/github/karreiro/picture_from/badges/gpa.svg)](https://codeclimate.com/github/karreiro/picture_from)
|
6
|
+
[![Test Coverage](https://codeclimate.com/github/karreiro/picture_from/badges/coverage.svg)](https://codeclimate.com/github/karreiro/picture_from)
|
7
|
+
|
8
|
+
PictureFrom is the most efficient library for getting profile pictures.
|
9
|
+
|
10
|
+
Installation
|
11
|
+
------------
|
12
|
+
```
|
13
|
+
gem install picture_from
|
14
|
+
```
|
15
|
+
|
16
|
+
Usage
|
17
|
+
------------
|
18
|
+
|
19
|
+
Using PictureFrom is pretty simple! First, make sure the library is required:
|
20
|
+
``` ruby
|
21
|
+
require 'picture_from'
|
22
|
+
```
|
23
|
+
|
24
|
+
Pass an user information to the library's interface:
|
25
|
+
``` ruby
|
26
|
+
PictureFrom.url('karreiro')
|
27
|
+
# => http://graph.facebook.com/karreiro/picture
|
28
|
+
```
|
29
|
+
|
30
|
+
Engines
|
31
|
+
------------
|
32
|
+
PicutreFrom has many engines for finding the appropriete image for any user in your application:
|
33
|
+
|
34
|
+
- Gravatar
|
35
|
+
- by e-mail ✔
|
36
|
+
- by GitHub username
|
37
|
+
- Facebook
|
38
|
+
- by username ✔
|
39
|
+
- by e-mail ✔
|
40
|
+
- by user information ✔
|
41
|
+
- Twitter
|
42
|
+
- by username
|
43
|
+
- by user information
|
44
|
+
- Linkedin
|
45
|
+
- by username
|
46
|
+
- Ello
|
47
|
+
- by username
|
48
|
+
|
49
|
+
Contributing
|
50
|
+
------------
|
51
|
+
|
52
|
+
1. Fork it
|
53
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
54
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
55
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
56
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
require 'rspec/core/rake_task'
|
3
|
+
|
4
|
+
begin
|
5
|
+
Bundler.setup :default, :development
|
6
|
+
Bundler::GemHelper.install_tasks
|
7
|
+
rescue Bundler::BundlerError => error
|
8
|
+
$stderr.puts error.message
|
9
|
+
$stderr.puts 'Run `bundle install` to install missing gems'
|
10
|
+
exit error.status_code
|
11
|
+
end
|
12
|
+
|
13
|
+
desc 'Run RSpec with code coverage'
|
14
|
+
task :coverage do
|
15
|
+
ENV['COVERAGE'] = 'true'
|
16
|
+
Rake::Task['spec'].execute
|
17
|
+
end
|
18
|
+
|
19
|
+
RSpec::Core::RakeTask.new(:spec)
|
20
|
+
|
21
|
+
desc 'Default: run tests'
|
22
|
+
task default: [:spec]
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'open-uri'
|
2
|
+
require 'nokogiri'
|
3
|
+
|
4
|
+
module PictureFrom
|
5
|
+
module Crawlers
|
6
|
+
class FacebookCrawler
|
7
|
+
|
8
|
+
def query(keyword)
|
9
|
+
page = search_page(keyword)
|
10
|
+
results = page.css('#pagelet_search_results .instant_search_title a')
|
11
|
+
username_from_url(results.first['href']) if results.size > 0
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def search_page(query)
|
17
|
+
search_page_url = "https://www.facebook.com/search.php?q=#{query}"
|
18
|
+
Nokogiri::HTML open(search_page_url)
|
19
|
+
end
|
20
|
+
|
21
|
+
def username_from_url(url)
|
22
|
+
url_regex = %r{^https?://(www\.)?facebook.com/(?<username>[^/\.]*)}
|
23
|
+
match = url_regex.match(url)
|
24
|
+
match[:username] if match
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module PictureFrom
|
2
|
+
class FacebookPicture
|
3
|
+
|
4
|
+
def initialize
|
5
|
+
@facebook_crawler = Crawlers::FacebookCrawler.new
|
6
|
+
end
|
7
|
+
|
8
|
+
def picture_from_username(username)
|
9
|
+
"http://graph.facebook.com/#{username}/picture"
|
10
|
+
end
|
11
|
+
|
12
|
+
def picture_from_user_info(user_info)
|
13
|
+
username = @facebook_crawler.query(user_info)
|
14
|
+
picture_from_username(username)
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'digest/md5'
|
2
|
+
|
3
|
+
module PictureFrom
|
4
|
+
class GravatarPicture
|
5
|
+
|
6
|
+
def picture_from_email(email)
|
7
|
+
"http://www.gravatar.com/avatar/#{digest(email)}"
|
8
|
+
end
|
9
|
+
|
10
|
+
private
|
11
|
+
|
12
|
+
def digest(email)
|
13
|
+
Digest::MD5.hexdigest(email)
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
data/lib/picture_from.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'picture_from/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'picture_from'
|
8
|
+
spec.version = PictureFrom::VERSION
|
9
|
+
spec.authors = ['Guilherme Carreiro']
|
10
|
+
spec.email = ['karreiro@gmail.com']
|
11
|
+
spec.homepage = 'https://github.com/karreiro/picture_from'
|
12
|
+
spec.license = 'MIT'
|
13
|
+
spec.description = 'A gem for getting profile pictures.'
|
14
|
+
spec.summary = 'PictureFrom is the most efficient library for getting '\
|
15
|
+
'profile pictures.'
|
16
|
+
|
17
|
+
spec.files = `git ls-files`.split($RS)
|
18
|
+
spec.executables = spec.files.grep(/^bin\//) { |f| File.basename(f) }
|
19
|
+
spec.test_files = spec.files.grep(/^spec\//)
|
20
|
+
spec.require_paths = ['lib']
|
21
|
+
|
22
|
+
spec.add_runtime_dependency 'nokogiri', '~> 1.6'
|
23
|
+
|
24
|
+
spec.add_development_dependency 'bundler', '~> 1.7'
|
25
|
+
spec.add_development_dependency 'fakeweb', '~> 1.3'
|
26
|
+
spec.add_development_dependency 'rubocop', '~> 0.28'
|
27
|
+
spec.add_development_dependency 'rake', '~> 10.4'
|
28
|
+
spec.add_development_dependency 'rspec', '~> 3.1'
|
29
|
+
spec.add_development_dependency 'mocha', '~> 0.14'
|
30
|
+
spec.add_development_dependency 'simplecov', '~> 0.9'
|
31
|
+
|
32
|
+
end
|