faraday-scheme_mapper 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 703db7d028ca5702e062ecdb5cdaf9de4bbfefd9
4
+ data.tar.gz: 5ddb27a64f351f1094a22393a5f6ef8a8a284341
5
+ SHA512:
6
+ metadata.gz: 676822070df92cbee2b7a27fda4cd77120ddfce9d17001a61fca611a8faecf1fe83c45ec5095871f018b7f44575778cea9a01357febbc7d86036c6cca42f67c5
7
+ data.tar.gz: 25761ff90b1291cdb1f5cd8db21ae0343e2b7c399e14040fad1a96e8d87719e2415ea0f22e368ff687d5036433abe4ab00c3db49ee0ffa56e089fba5547746c4
@@ -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,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ before_install: gem install bundler -v 1.12.5
@@ -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 tetsuya.shiota.1231@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,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Tetsuya Shiota
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.
@@ -0,0 +1,52 @@
1
+ # Faraday::SchemeMapper
2
+
3
+ Faraday middleware to manage mapping schemes(https,http) to each endpoint.
4
+
5
+ This gem is a Faraday middleware that manages mapping schemes(https,http) to each endpoints. You can switch http/https more easily.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'faraday-scheme_mapper'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install faraday-scheme_mapper
22
+
23
+ ## Usage
24
+
25
+ ``` rb
26
+ require 'faraday/scheme_mapper'
27
+
28
+ mapping = { http: ['/'], https: ['/login', %r{\A/secure/.*}] }
29
+
30
+ connection = Faraday.new 'http://example.com/api' do |conn|
31
+ conn.request :scheme_mapper, mapping
32
+ conn.adapter Faraday.default_adapter
33
+ end
34
+
35
+ # request by http
36
+ connection.get('/')
37
+ connection.get('/login/hoge')
38
+
39
+ # request by https
40
+ connection.get('/login')
41
+ connection.get('/secure/hoge')
42
+ ```
43
+
44
+ ## Contributing
45
+
46
+ Bug reports and pull requests are welcome on GitHub at https://github.com/shioshiota/faraday-scheme_mapper. 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.
47
+
48
+
49
+ ## License
50
+
51
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
52
+
@@ -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
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'faraday/scheme_mapper/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "faraday-scheme_mapper"
8
+ spec.version = Faraday::SchemeMapper::VERSION
9
+ spec.authors = ["Tetsuya Shiota"]
10
+ spec.email = ["tetsuya.shiota.1231@gmail.com"]
11
+
12
+ spec.summary = %q{Faraday middleware to manage mapping schemes(https,http) to each endpoint.}
13
+ spec.description = %q{This gem is a Faraday middleware that manages mapping schemes(https,http) to each endpoints. You can switch http/https more easily.}
14
+ spec.homepage = "https://github.com/shioshiota/faraday-scheme_mapper"
15
+ spec.license = "MIT"
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_dependency "faraday", "0.9.2"
23
+ end
@@ -0,0 +1 @@
1
+ require 'faraday/scheme_mapper'
@@ -0,0 +1,51 @@
1
+ require "faraday"
2
+
3
+ module Faraday
4
+ class SchemeMapper < Faraday::Middleware
5
+ SUPPORTED_SCHEMES = [:http, :https].freeze
6
+ def initialize(app, mapping)
7
+ super(app)
8
+ raise 'mapping should be HASH!' unless mapping.is_a? Hash
9
+ unless mapping.keys.all? { |v| SUPPORTED_SCHEMES.member? v }
10
+ raise 'supported schemes are only http and https!'
11
+ end
12
+ @mapping = mapping
13
+ end
14
+
15
+ def call(env)
16
+ original_url = env.url
17
+ new_scheme = matched_scheme(original_url.path) || original_url.scheme
18
+ env.url = rebuild_url(original_url, new_scheme)
19
+ @app.call env
20
+ end
21
+
22
+ private
23
+
24
+ def matched_scheme(path)
25
+ matched_mapping = @mapping.select do |_, patterns|
26
+ patterns.any? { |p| p === path }
27
+ end
28
+ schemes = matched_mapping.keys
29
+ return nil if schemes.count.zero?
30
+ return schemes.first.to_s if schemes.count == 1
31
+ STDERR.puts "[Faraday::SchemeMapper] not unique matched. path: #{path}"
32
+ :https.to_s
33
+ end
34
+
35
+ def rebuild_url(url, scheme)
36
+ params = {
37
+ scheme: scheme,
38
+ userinfo: url.userinfo,
39
+ host: url.host,
40
+ path: url.path,
41
+ opaque: url.opaque,
42
+ query: url.query,
43
+ fragment: url.fragment
44
+ }
45
+ return URI::HTTP.build(params) if scheme == 'http'
46
+ return URI::HTTPS.build(params) if scheme == 'https'
47
+ raise 'unknown scheme'
48
+ end
49
+ end
50
+ end
51
+ Faraday::Request.register_middleware scheme_mapper: -> { Faraday::SchemeMapper }
@@ -0,0 +1,5 @@
1
+ module Faraday
2
+ module SchemeMapper
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,71 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: faraday-scheme_mapper
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Tetsuya Shiota
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-08-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '='
18
+ - !ruby/object:Gem::Version
19
+ version: 0.9.2
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: 0.9.2
27
+ description: This gem is a Faraday middleware that manages mapping schemes(https,http)
28
+ to each endpoints. You can switch http/https more easily.
29
+ email:
30
+ - tetsuya.shiota.1231@gmail.com
31
+ executables: []
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - ".gitignore"
36
+ - ".rspec"
37
+ - ".travis.yml"
38
+ - CODE_OF_CONDUCT.md
39
+ - Gemfile
40
+ - LICENSE.txt
41
+ - README.md
42
+ - Rakefile
43
+ - faraday-scheme_mapper.gemspec
44
+ - lib/faraday-scheme_mapper.rb
45
+ - lib/faraday/scheme_mapper.rb
46
+ - lib/faraday/scheme_mapper/version.rb
47
+ homepage: https://github.com/shioshiota/faraday-scheme_mapper
48
+ licenses:
49
+ - MIT
50
+ metadata: {}
51
+ post_install_message:
52
+ rdoc_options: []
53
+ require_paths:
54
+ - lib
55
+ required_ruby_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ required_rubygems_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: '0'
65
+ requirements: []
66
+ rubyforge_project:
67
+ rubygems_version: 2.5.1
68
+ signing_key:
69
+ specification_version: 4
70
+ summary: Faraday middleware to manage mapping schemes(https,http) to each endpoint.
71
+ test_files: []