url_meta_data 0.1.0

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: be2d33e54be5a681841a7b59cecb90595a4ecc61
4
+ data.tar.gz: 61ab6cf5a689752459ddf4289f829c22d28eae08
5
+ SHA512:
6
+ metadata.gz: e1dca1070dde11be6d58a0537656b139725118a70a8674b2ffbb620f1ab22b99c0d6153395061702d1828b1700c8df10230134d9f19e072e7d53cd0c2fc9c122
7
+ data.tar.gz: 2fa984e0d26b2c54ad1b8317c4f21294d2b0fca6a065cb553696d63d9da6a1b78ede3f0e4d46128eca70f7ad7abe58cc96c470725d34780b3b5b62aafd741814
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rbenv-gemsets ADDED
@@ -0,0 +1 @@
1
+ -global
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.3.0
4
+ before_install: gem install bundler -v 1.11.2
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at mkyryk@payrollhero.com. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in url_meta_data.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Myk
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,44 @@
1
+ # Travic CI
2
+ [![Build Status](https://travis-ci.org/mykola-kyryk/url_meta_data_fetcher.svg?branch=master)](https://travis-ci.org/mykola-kyryk/url_meta_data_fetcher)
3
+
4
+ # UrlMetaData
5
+
6
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/url_meta_data_fetcher`. To experiment with that code, run `bin/console` for an interactive prompt.
7
+
8
+ TODO: Delete this and the text above, and describe your gem
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ ```ruby
15
+ gem 'url_meta_data'
16
+ ```
17
+
18
+ And then execute:
19
+
20
+ $ bundle
21
+
22
+ Or install it yourself as:
23
+
24
+ $ gem install url_meta_data
25
+
26
+ ## Usage
27
+
28
+ TODO: Write usage instructions here
29
+
30
+ ## Development
31
+
32
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
33
+
34
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
35
+
36
+ ## Contributing
37
+
38
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/url_meta_data_fetcher. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
39
+
40
+
41
+ ## License
42
+
43
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
44
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'url_meta_data'
5
+
6
+ require 'pry'
7
+ Pry.start
@@ -0,0 +1,30 @@
1
+ module UrlMetaData
2
+ class Fetcher
3
+ private_class_method :new
4
+
5
+ def self.fetch(url)
6
+ new(url).send(:fetch)
7
+ end
8
+
9
+ private
10
+
11
+ attr_reader :url
12
+
13
+ def initialize(url)
14
+ @url = url
15
+ end
16
+
17
+ def fetch
18
+ Parser.parse(document)
19
+ end
20
+
21
+ def document
22
+ begin
23
+ HTTPClient.get(url).body
24
+ rescue HTTPClient::TooManyRedirects, Timeout::Error, IOError, Errno::ECONNREFUSED, SocketError
25
+ # too many redirects, resource not found, slow resource, invalid resource, etc
26
+ ''
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,42 @@
1
+ require 'net/http'
2
+
3
+ module UrlMetaData
4
+ class HTTPClient
5
+ MAX_REDIRECTS = 5
6
+ class TooManyRedirects < StandardError
7
+ end
8
+
9
+ private_class_method :new
10
+
11
+ def self.get(url)
12
+ new.get(url)
13
+ end
14
+
15
+ def get(url)
16
+ perform_get(url, MAX_REDIRECTS)
17
+ end
18
+
19
+ private
20
+
21
+ def perform_get(url, redirect_count)
22
+ raise TooManyRedirects, "More than #{MAX_REDIRECTS} redirects encountered" if redirect_count == 0
23
+
24
+ @request_url = url
25
+ response = Net::HTTP.get_response(uri)
26
+
27
+ if redirect_encountered?(response)
28
+ perform_get(response.header['location'], redirect_count - 1)
29
+ else
30
+ response
31
+ end
32
+ end
33
+
34
+ def redirect_encountered?(response)
35
+ response.is_a?(Net::HTTPRedirection) && response.header.key?('location')
36
+ end
37
+
38
+ def uri
39
+ URI(@request_url)
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,45 @@
1
+ require 'nokogiri'
2
+
3
+ module UrlMetaData
4
+ class Parser
5
+ private_class_method :new
6
+
7
+ def self.parse(document)
8
+ new(document).send(:parse)
9
+ end
10
+
11
+ private
12
+
13
+ attr_reader :document
14
+
15
+ def initialize(document)
16
+ @document = Nokogiri::HTML.parse(document) do |config|
17
+ config.options = Nokogiri::XML::ParseOptions::DEFAULT_HTML | Nokogiri::XML::ParseOptions::NONET
18
+ end
19
+ end
20
+
21
+ def parse
22
+ {
23
+ title: get_page_title,
24
+ keywords: get_meta_keywords,
25
+ description: get_meta_description
26
+ }
27
+ end
28
+
29
+ def get_page_title
30
+ document.css('title').first&.content
31
+ end
32
+
33
+ def get_meta_keywords
34
+ get_meta_content(name: 'keywords')
35
+ end
36
+
37
+ def get_meta_description
38
+ get_meta_content(name: 'description')
39
+ end
40
+
41
+ def get_meta_content(name:)
42
+ document.css("meta[name='#{name}']").first&.attribute('content')&.value
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,3 @@
1
+ module UrlMetaData
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,7 @@
1
+ require 'url_meta_data/version'
2
+ require 'url_meta_data/http_client'
3
+ require 'url_meta_data/fetcher'
4
+ require 'url_meta_data/parser'
5
+
6
+ module UrlMetaData
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 'url_meta_data/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "url_meta_data"
8
+ spec.version = UrlMetaData::VERSION
9
+ spec.authors = ["Myk Kyryk", "Lana Dzyuban"]
10
+ spec.email = ["mykola.kyryk@gmail.com", "svitlana.dzyuban@gmail.com"]
11
+
12
+ spec.summary = %q{Visit URL and fetch page title, short description and keywords}
13
+ spec.description = %q{Visit URL and fetch page title, short description and keywords}
14
+ spec.homepage = "https://github.com/mykola-kyryk/url_meta_data_fetcher"
15
+ spec.license = "MIT"
16
+
17
+ spec.required_ruby_version = '~> 2.3'
18
+
19
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
20
+ spec.bindir = "exe"
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_runtime_dependency "nokogiri", "~> 1.6.7"
25
+
26
+ spec.add_development_dependency "bundler", "~> 1.11"
27
+ spec.add_development_dependency "rake", "~> 10.0"
28
+ spec.add_development_dependency "rubygems-tasks", "~> 0.2.4"
29
+ spec.add_development_dependency "rspec", "~> 3.0"
30
+ spec.add_development_dependency "webmock", "~> 1.24"
31
+ spec.add_development_dependency "pry"
32
+ end
metadata ADDED
@@ -0,0 +1,160 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: url_meta_data
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Myk Kyryk
8
+ - Lana Dzyuban
9
+ autorequire:
10
+ bindir: exe
11
+ cert_chain: []
12
+ date: 2016-04-07 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: nokogiri
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: 1.6.7
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: 1.6.7
28
+ - !ruby/object:Gem::Dependency
29
+ name: bundler
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '1.11'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '1.11'
42
+ - !ruby/object:Gem::Dependency
43
+ name: rake
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: '10.0'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: '10.0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: rubygems-tasks
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: 0.2.4
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: 0.2.4
70
+ - !ruby/object:Gem::Dependency
71
+ name: rspec
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - "~>"
75
+ - !ruby/object:Gem::Version
76
+ version: '3.0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - "~>"
82
+ - !ruby/object:Gem::Version
83
+ version: '3.0'
84
+ - !ruby/object:Gem::Dependency
85
+ name: webmock
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - "~>"
89
+ - !ruby/object:Gem::Version
90
+ version: '1.24'
91
+ type: :development
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - "~>"
96
+ - !ruby/object:Gem::Version
97
+ version: '1.24'
98
+ - !ruby/object:Gem::Dependency
99
+ name: pry
100
+ requirement: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ type: :development
106
+ prerelease: false
107
+ version_requirements: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ description: Visit URL and fetch page title, short description and keywords
113
+ email:
114
+ - mykola.kyryk@gmail.com
115
+ - svitlana.dzyuban@gmail.com
116
+ executables: []
117
+ extensions: []
118
+ extra_rdoc_files: []
119
+ files:
120
+ - ".gitignore"
121
+ - ".rbenv-gemsets"
122
+ - ".rspec"
123
+ - ".travis.yml"
124
+ - CODE_OF_CONDUCT.md
125
+ - Gemfile
126
+ - LICENSE.txt
127
+ - README.md
128
+ - Rakefile
129
+ - bin/console
130
+ - lib/url_meta_data.rb
131
+ - lib/url_meta_data/fetcher.rb
132
+ - lib/url_meta_data/http_client.rb
133
+ - lib/url_meta_data/parser.rb
134
+ - lib/url_meta_data/version.rb
135
+ - url_meta_data.gemspec
136
+ homepage: https://github.com/mykola-kyryk/url_meta_data_fetcher
137
+ licenses:
138
+ - MIT
139
+ metadata: {}
140
+ post_install_message:
141
+ rdoc_options: []
142
+ require_paths:
143
+ - lib
144
+ required_ruby_version: !ruby/object:Gem::Requirement
145
+ requirements:
146
+ - - "~>"
147
+ - !ruby/object:Gem::Version
148
+ version: '2.3'
149
+ required_rubygems_version: !ruby/object:Gem::Requirement
150
+ requirements:
151
+ - - ">="
152
+ - !ruby/object:Gem::Version
153
+ version: '0'
154
+ requirements: []
155
+ rubyforge_project:
156
+ rubygems_version: 2.5.1
157
+ signing_key:
158
+ specification_version: 4
159
+ summary: Visit URL and fetch page title, short description and keywords
160
+ test_files: []