picture_from 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ Gemfile.lock
6
+ InstalledFiles
7
+ coverage
8
+ coverage.data
9
+ doc/
10
+ lib/bundler/man
11
+ pkg
12
+ rdoc
13
+ spec/reports
14
+ test/tmp
15
+ test/version_tmp
16
+ tmp
17
+ *.swp
data/.rspec ADDED
@@ -0,0 +1,5 @@
1
+ --color
2
+ --format documentation
3
+ --fail-fast
4
+ --backtrace
5
+
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
@@ -0,0 +1,13 @@
1
+ language: ruby
2
+
3
+ rvm:
4
+ - 2.0.0
5
+
6
+ notifications:
7
+ email:
8
+ on_success: change
9
+ on_failure: change
10
+
11
+ script:
12
+ - bundle exec rspec
13
+ - bundle exec rubocop
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
@@ -0,0 +1,3 @@
1
+ module PictureFrom
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,7 @@
1
+ require 'picture_from/crawlers/facebook_crawler'
2
+ require 'picture_from/facebook_picture'
3
+ require 'picture_from/gravatar_picture'
4
+
5
+ module PictureFrom
6
+ # TODO
7
+ end
@@ -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