httpi-adapter-typhoeus 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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 11a5ff9677d73d70dffce3aff18988adcaa6403967004dd015e1ecdf108a9a84
4
+ data.tar.gz: 0c9e88ede7d2c7905a75b9b0864666cba0df4d918ceeab257165840d6862779c
5
+ SHA512:
6
+ metadata.gz: 535583caf77a69bd9b68c3f8ed8e9ca10504df1e3591dc182e08c697847ecc9b81f8bd8c60388e0d51ceaedcf49dbface833007d8438ee0d90a36e4b94466792
7
+ data.tar.gz: 1c679150ab83e112b7de30850f7bebddab664a9b7b4b6ac0944cf63220bb16e265abc233ad22efde78fbe2ebfb004a80c22d03443c7b0d904c69d29ddef64223
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ Gemfile.lock
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ dist: xenial
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.7
6
+ script:
7
+ - bundle exec rake
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in httpi-adapter-typhoeus.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Micke Lisinge
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,39 @@
1
+ # HTTPI::Adapter::Typhoeus
2
+
3
+ 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/httpi/adapter/typhoeus`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'httpi-adapter-typhoeus'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install httpi-adapter-typhoeus
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ 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.
30
+
31
+ 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).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/micke/httpi-adapter-typhoeus.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
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,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "httpi/adapter/typhoeus"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
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,37 @@
1
+ lib = File.expand_path("lib", __dir__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+
4
+ Gem::Specification.new do |spec|
5
+ spec.name = "httpi-adapter-typhoeus"
6
+ spec.version = "0.1.0"
7
+ spec.authors = ["Micke Lisinge"]
8
+ spec.email = ["micke@apoex.se"]
9
+
10
+ spec.summary = %q{An adapter for HTTPI that uses Typhoeus}
11
+ spec.description = %q{An adapter for HTTPI that uses Typhoeus}
12
+ spec.homepage = "https://github.com/apoex/httpi-adapter-typhoeus"
13
+ spec.license = "MIT"
14
+
15
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
16
+
17
+ spec.metadata["homepage_uri"] = spec.homepage
18
+ spec.metadata["source_code_uri"] = spec.homepage
19
+ spec.metadata["changelog_uri"] = spec.homepage
20
+
21
+ # Specify which files should be added to the gem when it is released.
22
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
23
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
24
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25
+ end
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+
30
+ spec.add_development_dependency "bundler", "~> 2.0"
31
+ spec.add_development_dependency "rake", "~> 12.3"
32
+ spec.add_development_dependency "rspec", "~> 3.0"
33
+ spec.add_development_dependency "webmock"
34
+
35
+ spec.add_dependency "httpi"
36
+ spec.add_dependency "typhoeus"
37
+ end
@@ -0,0 +1,88 @@
1
+ require "httpi"
2
+
3
+ module HTTPI
4
+ module Adapter
5
+ class Typhoeus < Base
6
+ class TyphoesConnectionError < StandardError
7
+ extend ConnectionError
8
+ end
9
+
10
+ register :typhoeus, deps: %w(typhoeus)
11
+
12
+ def initialize(request)
13
+ @request = request
14
+ end
15
+
16
+ def request(http_method)
17
+ @client = ::Typhoeus::Request.new(
18
+ @request.url,
19
+ method: http_method,
20
+ body: @request.body,
21
+ headers: @request.headers
22
+ )
23
+
24
+ configure_auth
25
+ configure_proxy
26
+ configure_ssl
27
+ configure_timeouts
28
+
29
+ response = @client.run
30
+
31
+ if response.success?
32
+ Response.new(response.code, response.headers, response.body)
33
+ elsif response.timed_out?
34
+ raise TimeoutError
35
+ elsif response.response_code == 0
36
+ raise TyphoesConnectionError, response.return_message
37
+ end
38
+ end
39
+
40
+ private
41
+
42
+ def configure_auth
43
+ return unless @request.auth.http? || @request.auth.ntlm?
44
+
45
+ @client.options[:httpauth] = @request.auth.type
46
+ @client.options[:username], @client.options[:password] = *@request.auth.credentials
47
+ end
48
+
49
+ def configure_proxy
50
+ @client.options[:proxy] = @request.proxy.to_s if @request.proxy
51
+ end
52
+
53
+ def configure_ssl
54
+ ssl = @request.auth.ssl
55
+
56
+ @client.options[:sslversion] = case ssl.ssl_version
57
+ when :TLSv1_2 then :tlsv1_2
58
+ when :TLSv1_1 then :tlsv1_1
59
+ when :TLSv1 then :tlsv1
60
+ when :SSLv2 then :sslv2
61
+ when :SSLv23 then :sslv2
62
+ when :SSLv3 then :sslv3
63
+ end
64
+
65
+ return unless @request.auth.ssl?
66
+
67
+ if ssl.verify_mode == :none
68
+ @client.options[:ssl_verifyhost] = 0
69
+ else
70
+ @client.options[:ssl_verifyhost] = 2
71
+ @client.options[:ssl_verifypeer] = ssl.verify_mode == :peer
72
+ end
73
+
74
+ @client.options[:sslcerttype] = ssl.cert_type.to_s.upcase
75
+ @client.options[:sslcert] = ssl.cert_file if ssl.cert_file
76
+ @client.options[:sslkey] = ssl.cert_key_file if ssl.cert_key_file
77
+ @client.options[:sslkeypasswd] = ssl.cert_key_password if ssl.cert_key_password
78
+ @client.options[:cainfo] = ssl.ca_cert_file if ssl.ca_cert_file
79
+ end
80
+
81
+ def configure_timeouts
82
+ @client.options[:connecttimeout_ms] = (@request.open_timeout * 1000).to_i if @request.open_timeout
83
+ read_or_write_timeout = @request.read_timeout || @request.write_timeout
84
+ @client.options[:timeout_ms] = (read_or_write_timeout * 1000).to_i if read_or_write_timeout
85
+ end
86
+ end
87
+ end
88
+ end
metadata ADDED
@@ -0,0 +1,142 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: httpi-adapter-typhoeus
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Micke Lisinge
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-03-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '12.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '12.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: webmock
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: httpi
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: typhoeus
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: An adapter for HTTPI that uses Typhoeus
98
+ email:
99
+ - micke@apoex.se
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".rspec"
106
+ - ".travis.yml"
107
+ - Gemfile
108
+ - LICENSE.txt
109
+ - README.md
110
+ - Rakefile
111
+ - bin/console
112
+ - bin/setup
113
+ - httpi-adapter-typhoeus.gemspec
114
+ - lib/httpi/adapter/typhoeus.rb
115
+ homepage: https://github.com/apoex/httpi-adapter-typhoeus
116
+ licenses:
117
+ - MIT
118
+ metadata:
119
+ allowed_push_host: https://rubygems.org
120
+ homepage_uri: https://github.com/apoex/httpi-adapter-typhoeus
121
+ source_code_uri: https://github.com/apoex/httpi-adapter-typhoeus
122
+ changelog_uri: https://github.com/apoex/httpi-adapter-typhoeus
123
+ post_install_message:
124
+ rdoc_options: []
125
+ require_paths:
126
+ - lib
127
+ required_ruby_version: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ required_rubygems_version: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - ">="
135
+ - !ruby/object:Gem::Version
136
+ version: '0'
137
+ requirements: []
138
+ rubygems_version: 3.0.3
139
+ signing_key:
140
+ specification_version: 4
141
+ summary: An adapter for HTTPI that uses Typhoeus
142
+ test_files: []