user_profile_formatter 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm use 1.9.3@user_profile_formatter
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.2
4
+ - 1.9.3
data/CHANGELOG.md ADDED
@@ -0,0 +1,3 @@
1
+ ## v0.0.1
2
+
3
+ * initial release
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in user_profile_formatter.gemspec
4
+ gemspec
data/Guardfile ADDED
@@ -0,0 +1,25 @@
1
+ guard 'bundler' do
2
+ watch('Gemfile')
3
+ watch(/^.+\.gemspec/)
4
+ end
5
+
6
+ guard 'rspec', :version => 2 do
7
+ watch(%r{^spec/.+_spec\.rb$})
8
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
9
+ watch('spec/spec_helper.rb') { "spec" }
10
+
11
+ # Rails example
12
+ watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
13
+ watch(%r{^app/(.*)(\.erb|\.haml)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
14
+ watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
15
+ watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
16
+ watch('config/routes.rb') { "spec/routing" }
17
+ watch('app/controllers/application_controller.rb') { "spec/controllers" }
18
+
19
+ # Capybara request specs
20
+ watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/requests/#{m[1]}_spec.rb" }
21
+
22
+ # Turnip features and steps
23
+ watch(%r{^spec/acceptance/(.+)\.feature$})
24
+ watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
25
+ end
data/LICENSE ADDED
@@ -0,0 +1,11 @@
1
+ Copyright (c) 2012 Fractal Soft
2
+
3
+ All rights reserved.
4
+
5
+ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
6
+
7
+ Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
8
+ Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
9
+ Neither the name of the Fractal Soft nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
10
+
11
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/README.md ADDED
@@ -0,0 +1,65 @@
1
+ # UserProfileFormatter
2
+
3
+ UserProfileFormatter is a gem to validate a username of social media.
4
+ If username does not exists then the name is not valid.
5
+ Integrated with:
6
+ - Twitter
7
+ - Facebook
8
+ - YouTube
9
+ - Tumblr
10
+ - GoldenLine
11
+ - Blip
12
+
13
+ ## Installation
14
+
15
+ Add this line to your application's Gemfile:
16
+
17
+ ```ruby
18
+ gem 'user_profile_formatter'
19
+ ```
20
+
21
+ And then execute:
22
+
23
+ $ bundle
24
+
25
+ Or install it yourself as:
26
+
27
+ $ gem install user_profile_formatter
28
+
29
+ **Requires Ruby 1.9.2 or latter.**
30
+
31
+ ## Usage
32
+
33
+ To start using **UserProfileFormatter** you just have to call format_user_profile in an ActiveRecord class and pass the name of the attribute. The second parameter is social media. If username is the same like social media then you need not specify second parameter.
34
+
35
+ ```ruby
36
+ class Profile < ActiveRecord::Base
37
+ format_user_profile :twitter
38
+ format_user_profile :facebook
39
+ format_user_profile :youtube
40
+ format_user_profile :tumblr
41
+ format_user_profile :goldenline
42
+ format_user_profile :blip
43
+ end
44
+ ```
45
+
46
+ Or use specific names:
47
+
48
+ ```ruby
49
+ class Profile < ActiveRecord::Base
50
+ format_user_profile :twitter_name, :twitter
51
+ format_user_profile :facebook_name, :facebook
52
+ format_user_profile :youtube_name, :youtube
53
+ format_user_profile :tumblr_name, :tumblr
54
+ format_user_profile :goldenline_name, :goldenline
55
+ format_user_profile :blip_name, :blip
56
+ end
57
+ ```
58
+
59
+ ## Contributing
60
+
61
+ 1. Fork it
62
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
63
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
64
+ 4. Push to the branch (`git push origin my-new-feature`)
65
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+ require "rspec/core/rake_task"
4
+
5
+ RSpec::Core::RakeTask.new(:spec)
6
+
7
+ desc "Bundle the gem"
8
+ task :bundle do
9
+ sh('bundle install')
10
+ sh 'gem build *.gemspec'
11
+ sh 'gem install *.gem'
12
+ sh 'rm *.gem'
13
+ end
14
+
15
+ task(:default).clear
16
+ task default: :spec
17
+ # task default: :bundle
@@ -0,0 +1,17 @@
1
+ # encoding: utf-8
2
+ require "user_profile_formatter/version"
3
+
4
+ require "user_profile_formatter/social_media"
5
+ require "user_profile_formatter/login_checker"
6
+ require "user_profile_formatter/model_additions"
7
+ require "user_profile_formatter/railtie" if defined? Rails
8
+
9
+ module UserProfileFormatter
10
+ def self.format_user_profile(name, key)
11
+ pattern = format(key)
12
+ match_data = pattern.match(name)
13
+ return nil if match_data.nil? or match_data[0] != name
14
+ return nil unless exists? name, url(key)
15
+ name
16
+ end
17
+ end
@@ -0,0 +1,19 @@
1
+ # encoding: utf-8
2
+ require "net/http"
3
+ require "net/https"
4
+
5
+ module UserProfileFormatter
6
+ def self.exists?(name, url)
7
+ uri = URI.parse(url.gsub(/{{NAME}}/, name))
8
+ http = Net::HTTP.new(uri.host, uri.port)
9
+ if url.start_with? "https"
10
+ http.use_ssl = true
11
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
12
+ end
13
+ answer = nil
14
+ http.start do
15
+ answer = http.get(uri.path).code
16
+ end
17
+ answer == "200"
18
+ end
19
+ end
@@ -0,0 +1,25 @@
1
+ # encoding: utf-8
2
+
3
+ module UserProfileFormatter
4
+ module ModelAdditions
5
+ # Call <tt>format_user_profile</tt> in an Active Record model class
6
+ # to validate username of social media.
7
+ #
8
+ # class Profile < ActiveRecord::Base
9
+ # format_user_profile :twitter
10
+ # format_user_profile :facebook
11
+ # format_user_profile :youtube
12
+ # format_user_profile :tumblr
13
+ # format_user_profile :goldenline
14
+ # format_user_profile :blip
15
+ # end
16
+ #
17
+ def format_user_profile(attribute, param = nil)
18
+ param = attribute if param.nil? and UserProfileFormatter.keys.include? attribute
19
+ before_validation do
20
+ send("#{attribute}=", UserProfileFormatter.format_user_profile(send(attribute), param))
21
+ end
22
+ validates_format_of attribute, with: UserProfileFormatter.format(param), message: "is not a valid"
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,11 @@
1
+ # encoding: utf-8
2
+
3
+ module UserProfileFormatter
4
+ class Railtie < Rails::Railtie
5
+ initializer 'user_profile_formatter.model_additions' do
6
+ ActiveSupport.on_load :active_record do
7
+ extend ModelAdditions
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,26 @@
1
+ # encoding: utf-8
2
+
3
+ module UserProfileFormatter
4
+ SOCIAL = {
5
+ twitter: {format: %r(\w{1,15}), url: "http://twitter.com/{{NAME}}"},
6
+ facebook: {format: %r([a-zA-Z0-9.]{5,}), url: "https://www.facebook.com/{{NAME}}"},
7
+ youtube: {format: %r([A-Za-z0-9]{3,20}), url: "http://www.youtube.com/user/{{NAME}}"},
8
+ tumblr: {format: %r([a-z0-9][a-z0-9]{0,31}), url: "http://{{NAME}}.tumblr.com/"},
9
+ goldenline: {format: %r([0-9a-zA-Z]*[-_][0-9a-zA-Z]*[-_][0-9a-zA-Z]*|[0-9a-zA-Z]*[-_][0-9a-zA-Z]*), url: "http://www.goldenline.pl/{{NAME}}"},
10
+ blip: {format: %r([a-z][a-z0-9]{2,24}), url: "http://{{NAME}}.blip.pl/"}
11
+ }
12
+ # Following sites don't return code 404:
13
+ # eBay, Allegro
14
+
15
+ def self.keys
16
+ SOCIAL.keys
17
+ end
18
+
19
+ def self.format(key)
20
+ SOCIAL[key][:format]
21
+ end
22
+
23
+ def self.url(key)
24
+ SOCIAL[key][:url]
25
+ end
26
+ end
@@ -0,0 +1,3 @@
1
+ module UserProfileFormatter
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,3 @@
1
+ # encoding: utf-8
2
+ require "user_profile_formatter"
3
+ require "supermodel"
@@ -0,0 +1 @@
1
+ # encoding: utf-8
@@ -0,0 +1,32 @@
1
+ # encoding: utf-8
2
+ require "spec_helper"
3
+
4
+ class UserProfile < SuperModel::Base
5
+ include ActiveModel::Validations::Callbacks
6
+ extend UserProfileFormatter::ModelAdditions
7
+ format_user_profile :twitter
8
+ format_user_profile :youtube
9
+ format_user_profile :tumblr
10
+ format_user_profile :blip
11
+ end
12
+
13
+ describe UserProfileFormatter::ModelAdditions do
14
+ it "validates correct social media formats" do
15
+ attributes = {
16
+ twitter: "fractal_soft",
17
+ youtube: "fractalsoft",
18
+ tumblr: "fractalsoft",
19
+ blip: "fractalsoft",
20
+ }
21
+ user_profile = UserProfile.new(attributes)
22
+ user_profile.should be_valid
23
+ end
24
+
25
+ it "validates wrong social media formats" do
26
+ attributes = {
27
+ twitter: "google+"
28
+ }
29
+ user_profile = UserProfile.new(attributes)
30
+ user_profile.should_not be_valid
31
+ end
32
+ end
@@ -0,0 +1 @@
1
+ # encoding: utf-8
@@ -0,0 +1,43 @@
1
+ # encoding: utf-8
2
+ require "spec_helper"
3
+
4
+ EXAMPLES = {
5
+ twitter: {
6
+ "fractal_soft" => true,
7
+ "twitter" => true,
8
+ "facebook" => true,
9
+ "google" => true,
10
+ "google+" => false,
11
+ "superuser" => false,
12
+ },
13
+ facebook: {},
14
+ youtube: {
15
+ "fractalsoft" => true,
16
+ },
17
+ tumblr: {
18
+ "fractalsoft" => true,
19
+ "google" => true,
20
+ "google+" => false,
21
+ },
22
+ goldenline: {},
23
+ blip: {
24
+ "fractalsoft" => true,
25
+ }
26
+ }
27
+
28
+ describe :UserProfileFormatter do
29
+ context "validate user profile name" do
30
+ EXAMPLES.each_pair do |key, examples|
31
+ examples.each_pair do |name, correct|
32
+ it "#{name} in #{key}" do
33
+ result = UserProfileFormatter.format_user_profile(name, key)
34
+ if correct
35
+ result.should == name
36
+ else
37
+ result.should_not == name
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/user_profile_formatter/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Aleksander Malaszkiewicz"]
6
+ gem.email = ["info@fractalsoft.org"]
7
+ gem.description = %q{Simple user profile formatter. It checks that user profile exists.}
8
+ gem.summary = %q{Format and validate a social media user profile}
9
+ gem.homepage = "https://github.com/fractalsoft/user_profile_formatter"
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "user_profile_formatter"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = UserProfileFormatter::VERSION
17
+
18
+ gem.add_development_dependency "rake"
19
+ gem.add_development_dependency "rspec"
20
+ gem.add_development_dependency "guard"
21
+ gem.add_development_dependency "guard-bundler"
22
+ gem.add_development_dependency "guard-rspec"
23
+ gem.add_development_dependency "supermodel"
24
+ end
metadata ADDED
@@ -0,0 +1,168 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: user_profile_formatter
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Aleksander Malaszkiewicz
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-07-17 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rspec
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: guard
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: guard-bundler
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: guard-rspec
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: supermodel
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ description: Simple user profile formatter. It checks that user profile exists.
111
+ email:
112
+ - info@fractalsoft.org
113
+ executables: []
114
+ extensions: []
115
+ extra_rdoc_files: []
116
+ files:
117
+ - .gitignore
118
+ - .rspec
119
+ - .rvmrc
120
+ - .travis.yml
121
+ - CHANGELOG.md
122
+ - Gemfile
123
+ - Guardfile
124
+ - LICENSE
125
+ - README.md
126
+ - Rakefile
127
+ - lib/user_profile_formatter.rb
128
+ - lib/user_profile_formatter/login_checker.rb
129
+ - lib/user_profile_formatter/model_additions.rb
130
+ - lib/user_profile_formatter/railtie.rb
131
+ - lib/user_profile_formatter/social_media.rb
132
+ - lib/user_profile_formatter/version.rb
133
+ - spec/spec_helper.rb
134
+ - spec/user_profile_formatter/login_checker_spec.rb
135
+ - spec/user_profile_formatter/model_additions_spec.rb
136
+ - spec/user_profile_formatter/social_media_spec.rb
137
+ - spec/user_profile_formatter_spec.rb
138
+ - user_profile_formatter.gemspec
139
+ homepage: https://github.com/fractalsoft/user_profile_formatter
140
+ licenses: []
141
+ post_install_message:
142
+ rdoc_options: []
143
+ require_paths:
144
+ - lib
145
+ required_ruby_version: !ruby/object:Gem::Requirement
146
+ none: false
147
+ requirements:
148
+ - - ! '>='
149
+ - !ruby/object:Gem::Version
150
+ version: '0'
151
+ required_rubygems_version: !ruby/object:Gem::Requirement
152
+ none: false
153
+ requirements:
154
+ - - ! '>='
155
+ - !ruby/object:Gem::Version
156
+ version: '0'
157
+ requirements: []
158
+ rubyforge_project:
159
+ rubygems_version: 1.8.24
160
+ signing_key:
161
+ specification_version: 3
162
+ summary: Format and validate a social media user profile
163
+ test_files:
164
+ - spec/spec_helper.rb
165
+ - spec/user_profile_formatter/login_checker_spec.rb
166
+ - spec/user_profile_formatter/model_additions_spec.rb
167
+ - spec/user_profile_formatter/social_media_spec.rb
168
+ - spec/user_profile_formatter_spec.rb