link_rel_parser 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: 841f4f2d64a7f8fc87fc1ea182136c4ee10dc224
4
+ data.tar.gz: 7f0de68dc12760ae1d90ffdf2d46a7de0d03937e
5
+ SHA512:
6
+ metadata.gz: 28b51d90582296abd308de0c93d6b450607b477832ff709f625c1ee4c44cb3a7d146fe7df7aef3c037a78773aafba94e05206bc30ce3c51cac3300f6cc9df507
7
+ data.tar.gz: 12950785da3db3b822d5f68fa6fcf75072637f2817c3c34aaabc38333640853030e88ca582640671a53b61a4176311b6d4dd708317ecae39251188db679fe668
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/.rspec ADDED
@@ -0,0 +1 @@
1
+ --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 veganstraightedge@gmail.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 link_rel_parser.gemspec
4
+ gemspec
data/LICENSE.md ADDED
@@ -0,0 +1,36 @@
1
+ # Creative Commons Legal Code
2
+
3
+ ## CC0 1.0 Universal
4
+
5
+ http://creativecommons.org/publicdomain/zero/1.0
6
+
7
+ Official translations of this legal tool are available> CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED HEREUNDER.
8
+
9
+ ### _Statement of Purpose_
10
+
11
+ The laws of most jurisdictions throughout the world automatically confer exclusive Copyright and Related Rights (defined below) upon the creator and subsequent owner(s) (each and all, an "owner") of an original work of authorship and/or a database (each, a "Work").
12
+
13
+ Certain owners wish to permanently relinquish those rights to a Work for the purpose of contributing to a commons of creative, cultural and scientific works ("Commons") that the public can reliably and without fear of later claims of infringement build upon, modify, incorporate in other works, reuse and redistribute as freely as possible in any form whatsoever and for any purposes, including without limitation commercial purposes. These owners may contribute to the Commons to promote the ideal of a free culture and the further production of creative, cultural and scientific works, or to gain reputation or greater distribution for their Work in part through the use and efforts of others.
14
+
15
+ For these and/or other purposes and motivations, and without any expectation of additional consideration or compensation, the person associating CC0 with a Work (the "Affirmer"), to the extent that he or she is an owner of Copyright and Related Rights in the Work, voluntarily elects to apply CC0 to the Work and publicly distribute the Work under its terms, with knowledge of his or her Copyright and Related Rights in the Work and the meaning and intended legal effect of CC0 on those rights.
16
+
17
+ **1. Copyright and Related Rights.** A Work made available under CC0 may be protected by copyright and related or neighboring rights ("Copyright and Related Rights"). Copyright and Related Rights include, but are not limited to, the following:
18
+
19
+ 1. the right to reproduce, adapt, distribute, perform, display, communicate, and translate a Work;
20
+ 2. moral rights retained by the original author(s) and/or performer(s);
21
+ 3. publicity and privacy rights pertaining to a person's image or likeness depicted in a Work;
22
+ 4. rights protecting against unfair competition in regards to a Work, subject to the limitations in paragraph 4(a), below;
23
+ 5. rights protecting the extraction, dissemination, use and reuse of data in a Work;
24
+ 6. database rights (such as those arising under Directive 96/9/EC of the European Parliament and of the Council of 11 March 1996 on the legal protection of databases, and under any national implementation thereof, including any amended or successor version of such directive); and
25
+ 7. other similar, equivalent or corresponding rights throughout the world based on applicable law or treaty, and any national implementations thereof.
26
+
27
+ **2. Waiver.** To the greatest extent permitted by, but not in contravention of, applicable law, Affirmer hereby overtly, fully, permanently, irrevocably and unconditionally waives, abandons, and surrenders all of Affirmer's Copyright and Related Rights and associated claims and causes of action, whether now known or unknown (including existing as well as future claims and causes of action), in the Work (i) in all territories worldwide, (ii) for the maximum duration provided by applicable law or treaty (including future time extensions), (iii) in any current or future medium and for any number of copies, and (iv) for any purpose whatsoever, including without limitation commercial, advertising or promotional purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each member of the public at large and to the detriment of Affirmer's heirs and successors, fully intending that such Waiver shall not be subject to revocation, rescission, cancellation, termination, or any other legal or equitable action to disrupt the quiet enjoyment of the Work by the public as contemplated by Affirmer's express Statement of Purpose.
28
+
29
+ **3. Public License Fallback.** Should any part of the Waiver for any reason be judged legally invalid or ineffective under applicable law, then the Waiver shall be preserved to the maximum extent permitted taking into account Affirmer's express Statement of Purpose. In addition, to the extent the Waiver is so judged Affirmer hereby grants to each affected person a royalty-free, non transferable, non sublicensable, non exclusive, irrevocable and unconditional license to exercise Affirmer's Copyright and Related Rights in the Work (i) in all territories worldwide, (ii) for the maximum duration provided by applicable law or treaty (including future time extensions), (iii) in any current or future medium and for any number of copies, and (iv) for any purpose whatsoever, including without limitation commercial, advertising or promotional purposes (the "License"). The License shall be deemed effective as of the date CC0 was applied by Affirmer to the Work. Should any part of the License for any reason be judged legally invalid or ineffective under applicable law, such partial invalidity or ineffectiveness shall not invalidate the remainder of the License, and in such case Affirmer hereby affirms that he or she will not (i) exercise any of his or her remaining Copyright and Related Rights in the Work or (ii) assert any associated claims and causes of action with respect to the Work, in either case contrary to Affirmer's express Statement of Purpose.
30
+
31
+ **4. Limitations and Disclaimers.**
32
+
33
+ 1. No trademark or patent rights held by Affirmer are waived, abandoned, surrendered, licensed or otherwise affected by this document.
34
+ 2. Affirmer offers the Work as-is and makes no representations or warranties of any kind concerning the Work, express, implied, statutory or otherwise, including without limitation warranties of title, merchantability, fitness for a particular purpose, non infringement, or the absence of latent or other defects, accuracy, or the present or absence of errors, whether or not discoverable, all to the greatest extent permissible under applicable law.
35
+ 3. Affirmer disclaims responsibility for clearing rights of other persons that may apply to the Work or any use thereof, including without limitation any person's Copyright and Related Rights in the Work. Further, Affirmer disclaims responsibility for obtaining any necessary consents, permissions or other rights required for any use of the Work.
36
+ 4. Affirmer understands and acknowledges that Creative Commons is not a party to this document and has no duty or obligation with respect to this CC0 or use of the Work.
data/README.md ADDED
@@ -0,0 +1,105 @@
1
+ # LinkRelParser (Ruby)
2
+
3
+ Parse HTTP `Link` headers into a structured format
4
+
5
+
6
+ ## Version
7
+
8
+ 0.1.0
9
+
10
+ ![Version 0.1.0](https://img.shields.io/badge/VERSION-0.1.0-green.svg)
11
+
12
+
13
+ ## Code Status
14
+
15
+ [![Build Status](https://travis-ci.org/indieweb/link_rel_parser-ruby.svg?branch=master)](https://travis-ci.org/indieweb/link_rel_parser-ruby)
16
+ [![Code Climate](https://codeclimate.com/github/indieweb/link_rel_parser-ruby/badges/gpa.svg)](https://codeclimate.com/github/indieweb/link_rel_parser-ruby)
17
+
18
+
19
+ ## Installation
20
+
21
+ Add this line to your application's Gemfile:
22
+
23
+ ```ruby
24
+ gem "link_rel_parser"
25
+ ```
26
+
27
+ And then execute:
28
+
29
+ ```
30
+ bundle
31
+ ```
32
+
33
+ Or install it yourself as:
34
+
35
+ ```
36
+ gem install link_rel_parser
37
+ ```
38
+
39
+
40
+ ## Usage
41
+
42
+ ```ruby
43
+ require "LinkRelParser"
44
+ LinkRelParser("https://aaronparecki.com")
45
+
46
+ {
47
+ "authorization_endpoint" => "https://aaronparecki.com/auth",
48
+ "hub" => "https://switchboard.p3k.io/",
49
+ "micropub" => "https://aaronparecki.com/micropub",
50
+ "self" => "https://aaronparecki.com/",
51
+ "token_endpoint" => "https://aaronparecki.com/auth/token",
52
+ }
53
+ ```
54
+
55
+
56
+ ## Development
57
+
58
+ ```bash
59
+ git clone git@github.com:indieweb/link_rel_parser-ruby.git
60
+ cd link_rel_parser-ruby
61
+ bin/setup
62
+ ```
63
+
64
+ 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. Run `bundle exec link_rel_parser` to use the gem in this directory, ignoring other installed copies of this gem.
65
+
66
+ 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).
67
+
68
+ ## Authors
69
+
70
+ * Shane Becker / [@veganstraightedge](https://github.com/veganstraightedge)
71
+
72
+
73
+ ## Contributing
74
+
75
+ Bug reports and pull requests are welcome on GitHub at https://github.com/indieweb/link_rel_parser-ruby/issues. 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.
76
+
77
+ 1. Fork it
78
+ 2. Get it running (see Installation above)
79
+ 3. Create your feature branch (`git checkout -b my-new-feature`)
80
+ 4. Write your code and **specs**
81
+ 5. Commit your changes (`git commit -am 'Add some feature'`)
82
+ 6. Push to the branch (`git push origin my-new-feature`)
83
+ 7. Create new Pull Request
84
+
85
+ If you find bugs, have feature requests or questions, please
86
+ [file an issue](https://github.com/indieweb/link_rel_parser-ruby/issues).
87
+
88
+
89
+ ## Code of Conduct
90
+
91
+ Everyone interacting in the LinkRelParser (Ruby) codebase, issue tracker, chat room, and mailing lists is expected to follow the
92
+ [LinkRelParser (Ruby) code of conduct](https://github.com/indieweb/link_rel_parser-ruby/blob/master/CODE_OF_CONDUCT.md).
93
+
94
+
95
+ ## License
96
+
97
+ **PUBLIC DOMAIN**
98
+
99
+ Your heart is as free as the air you breathe. <br>
100
+ The ground you stand on is liberated territory.
101
+
102
+ In legal text, LinkRelParser (Ruby) is dedicated to the public domain
103
+ using Creative Commons -- CC0 1.0 Universal.
104
+
105
+ [http://creativecommons.org/publicdomain/zero/1.0](http://creativecommons.org/publicdomain/zero/1.0 "Creative Commons &mdash; CC0 1.0 Universal")
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 "link_rel_parser"
5
+
6
+ require "irb"
7
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "link_rel_parser"
@@ -0,0 +1,3 @@
1
+ module LinkRelParser
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,84 @@
1
+ require "active_support"
2
+ require "active_support/core_ext/object/blank"
3
+ require "link_rel_parser/version"
4
+ require "metainspector"
5
+ require "uri"
6
+
7
+ module LinkRelParser
8
+ class << self
9
+
10
+ # Public: Parse out LINK headers with a REL value.
11
+ #
12
+ # url - URL to get HTTP HEAD Link (and effective/x-extended) rels.
13
+ #
14
+ # Examples
15
+ #
16
+ # LinkRelParser.parse("http://example.com")
17
+ # # =>
18
+ # {
19
+ # status: "200",
20
+ # type: "text/HTML",
21
+ # rels: { "pingback" => "http://www.example.com/xmlrpc.php", "indieauth" => "https://indieauth.com" }
22
+ # }
23
+ #
24
+ # Returns a hash of HTTP status code, content type, and LINKs with a REL value or an empty {}
25
+ def parse(url)
26
+ page = MetaInspector.new(url)
27
+ header_links = page.response.headers[:link]
28
+
29
+ # Convert X-Pingback to a Link header and have common code handle it
30
+ unless page.response.headers["x-pingback"].nil?
31
+ header_links << %Q{, <#{header_links['x-pingback']}>; rel="pingback"}
32
+ end
33
+
34
+ output = {
35
+ status: page.response.status,
36
+ type: page.response["content-type"],
37
+ rels: link_rels(header_links)
38
+ }
39
+
40
+ output[:rels].blank? ? {} : output
41
+ end
42
+
43
+ # Internal: Parse out the HTTP LINK headers with a REL value.
44
+ #
45
+ # headers - string to HTTP headers.
46
+ # base_url - optional base URL to resolve relative URLs (default: nil).
47
+ #
48
+ # Examples
49
+ #
50
+ # link_rels(headers)
51
+ # # => { "pingback" => "http://www.example.com/xmlrpc.php", "indieauth" => "https://indieauth.com" }
52
+ #
53
+ # Returns a hash of LINK name and REL value or an empty {}
54
+ def link_rels(headers, base_url: nil)
55
+ links = {}
56
+
57
+ unless headers.nil?
58
+ headers.split(", ").each do |link, index|
59
+ section = link.split(';')
60
+ url = section[0][/<(.*)>/,1]
61
+
62
+ # ignore link headers without rel
63
+ if section[1] =~ /rel=/
64
+ rel = section[1][/rel="*(.*)"*/,1].gsub(/"$/, "")
65
+ rel.split.each do |name|
66
+
67
+ unless base_url.blank?
68
+ uri = URI.parse(base_url)
69
+ path = url.gsub(%r{^/*}, "")
70
+ uri.path = "/" + path
71
+ url = uri.normalize
72
+ end
73
+
74
+ links[name] = url
75
+ end
76
+ end
77
+ end
78
+ end
79
+
80
+ links
81
+ end
82
+
83
+ end
84
+ end
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "link_rel_parser/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "link_rel_parser"
8
+ spec.version = LinkRelParser::VERSION
9
+ spec.authors = ["Shane Becker"]
10
+ spec.email = ["veganstraightedge@gmail.com"]
11
+
12
+ spec.summary = %q{Parse HTTP `Link` headers into a structured format}
13
+ spec.description = %q{Ruby port of https://github.com/indieweb/link-rel-parser-php}
14
+ spec.homepage = "https://github.com/indieweb/link-rel-parser-ruby"
15
+ spec.license = "CC0"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_runtime_dependency "activesupport"
23
+ spec.add_runtime_dependency "metainspector"
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.11"
26
+ spec.add_development_dependency "rake", "~> 10.0"
27
+ spec.add_development_dependency "rspec", "~> 3.0"
28
+ end
metadata ADDED
@@ -0,0 +1,129 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: link_rel_parser
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Shane Becker
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-04-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: metainspector
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.11'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.11'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ description: Ruby port of https://github.com/indieweb/link-rel-parser-php
84
+ email:
85
+ - veganstraightedge@gmail.com
86
+ executables:
87
+ - link_rel_parser
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".gitignore"
92
+ - ".rspec"
93
+ - ".travis.yml"
94
+ - CODE_OF_CONDUCT.md
95
+ - Gemfile
96
+ - LICENSE.md
97
+ - README.md
98
+ - Rakefile
99
+ - bin/console
100
+ - bin/setup
101
+ - exe/link_rel_parser
102
+ - lib/link_rel_parser.rb
103
+ - lib/link_rel_parser/version.rb
104
+ - link_rel_parser.gemspec
105
+ homepage: https://github.com/indieweb/link-rel-parser-ruby
106
+ licenses:
107
+ - CC0
108
+ metadata: {}
109
+ post_install_message:
110
+ rdoc_options: []
111
+ require_paths:
112
+ - lib
113
+ required_ruby_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ required_rubygems_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ requirements: []
124
+ rubyforge_project:
125
+ rubygems_version: 2.5.1
126
+ signing_key:
127
+ specification_version: 4
128
+ summary: Parse HTTP `Link` headers into a structured format
129
+ test_files: []