thrift-faraday_transport 1.0.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
+ SHA256:
3
+ metadata.gz: febd0f264a54d872d030590a957575af995477ae58af7fffc732b76c3007a243
4
+ data.tar.gz: 9ca0efe60d66b418c9f0cbe13a62fc8fd5ce9abf78e50b3e94ce4eae0d17f860
5
+ SHA512:
6
+ metadata.gz: a9e9e21d1ecfbb985359f6722ed100d952825f3a0618ea9d7e4a7f59623dd632ddd992a94a8fb1dce6445b1ad5d4d2308027a878c2bb34a5b923745d52e9c320
7
+ data.tar.gz: 143c5223ed65ec8af4702e6c42dd5256dbab10c35e853b0774e182410fedeaebc2c901020b41a824a7260e2a7a57a3591f1361ec7186f054c8172870ceba4fc9
@@ -0,0 +1,4 @@
1
+ .rspec_status
2
+ doc/
3
+ .yardoc/
4
+ .rake_tasks~
@@ -0,0 +1,8 @@
1
+ require: rubocop-rspec
2
+
3
+ AllCops:
4
+ TargetRubyVersion: 2.2
5
+
6
+ Metrics/BlockLength:
7
+ Exclude:
8
+ - "spec/**/*_spec.rb"
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2
4
+ - 2.3
5
+ - 2.4
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in thrift-faraday-transport.gemspec
6
+ gemspec
@@ -0,0 +1,62 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ thrift-faraday_transport (1.0.0)
5
+ faraday (~> 0.9.0)
6
+ thrift (~> 0.9.0)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ ast (2.3.0)
12
+ diff-lcs (1.3)
13
+ faraday (0.9.2)
14
+ multipart-post (>= 1.2, < 3)
15
+ multipart-post (2.0.0)
16
+ parallel (1.12.1)
17
+ parser (2.4.0.2)
18
+ ast (~> 2.3)
19
+ powerpack (0.1.1)
20
+ rainbow (3.0.0)
21
+ rake (10.5.0)
22
+ rspec (3.7.0)
23
+ rspec-core (~> 3.7.0)
24
+ rspec-expectations (~> 3.7.0)
25
+ rspec-mocks (~> 3.7.0)
26
+ rspec-core (3.7.0)
27
+ rspec-support (~> 3.7.0)
28
+ rspec-expectations (3.7.0)
29
+ diff-lcs (>= 1.2.0, < 2.0)
30
+ rspec-support (~> 3.7.0)
31
+ rspec-mocks (3.7.0)
32
+ diff-lcs (>= 1.2.0, < 2.0)
33
+ rspec-support (~> 3.7.0)
34
+ rspec-support (3.7.0)
35
+ rubocop (0.52.0)
36
+ parallel (~> 1.10)
37
+ parser (>= 2.4.0.2, < 3.0)
38
+ powerpack (~> 0.1)
39
+ rainbow (>= 2.2.2, < 4.0)
40
+ ruby-progressbar (~> 1.7)
41
+ unicode-display_width (~> 1.0, >= 1.0.1)
42
+ rubocop-rspec (1.21.0)
43
+ rubocop (>= 0.52.0)
44
+ ruby-progressbar (1.9.0)
45
+ thrift (0.9.3.0)
46
+ unicode-display_width (1.3.0)
47
+ yard (0.9.12)
48
+
49
+ PLATFORMS
50
+ ruby
51
+
52
+ DEPENDENCIES
53
+ bundler (~> 1.16)
54
+ rake (~> 10.0)
55
+ rspec (~> 3.0)
56
+ rubocop (~> 0.52.0)
57
+ rubocop-rspec (~> 1.21.0)
58
+ thrift-faraday_transport!
59
+ yard (~> 0.9.11)
60
+
61
+ BUNDLED WITH
62
+ 1.16.0
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Dmitrij Fedorenko
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,65 @@
1
+ # Thrift::FaradayTransport
2
+
3
+ [![Build Status](https://travis-ci.org/c0va23/ruby-thrift-faraday_transport.svg?branch=feature%2Fconfigure-travis)](https://travis-ci.org/c0va23/ruby-thrift-faraday_transport)
4
+ [![Inline docs](http://inch-ci.org/github/c0va23/ruby-thrift-faraday_transport.svg?branch=master)](http://inch-ci.org/github/c0va23/ruby-thrift-faraday_transport)
5
+
6
+ Ruby GEM implemented [Thrift](https://github.com/apache/thrift/tree/master/lib/rb)
7
+ HTTP transport basen on [Faraday](https://github.com/lostisland/faraday).
8
+
9
+ It GEM allow use any HTTP-adapter supported by Faraday as HTTP-transport for
10
+ Thrift. See [Usage](#Usage) for examples.
11
+
12
+ ## Documentation
13
+
14
+ http://www.rubydoc.info/github/c0va23/ruby-thrift-faraday_transport/
15
+
16
+ ## Installation
17
+
18
+ Add this line to your application's Gemfile:
19
+
20
+ gem 'thrift-faraday_transport'
21
+
22
+ And then execute:
23
+
24
+ $ bundle
25
+
26
+ Or install it yourself as:
27
+
28
+ $ gem install thrift-faraday_transport
29
+
30
+ ## Usage
31
+
32
+ require 'uri'
33
+ require 'net/http/persistent'
34
+
35
+ url = URI('http://mytriftserver:12345/endpoint')
36
+
37
+ faraday_connection = Faraday.new(url: url) do |f|
38
+ f.adapter :net_http_persistent
39
+ f.options.timeout = 30
40
+ end
41
+ transport = ::Thrift::FaradayTransport.new(faraday_connection)
42
+ protocol = ::Thrift::BinaryProtocol.new(transport)
43
+ thrift_client = RpcService::Client.new(protocol)
44
+
45
+ ## Development
46
+
47
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run
48
+ `rake` to run the tests and rubcop linter. You can also run `bin/console`
49
+ for an interactive prompt that will allow you to experiment.
50
+
51
+ To install this gem onto your local machine, run `bundle exec rake install`.
52
+ To release a new version, update the version number in `VERSION`, and then run
53
+ `bundle exec rake release`, which will create a git tag for the version, push
54
+ git commits and tags, and push the `.gem` file to
55
+ [rubygems.org](https://rubygems.org).
56
+
57
+ ## Contributing
58
+
59
+ Bug reports and pull requests are welcome on GitHub at
60
+ https://github.com/c0va23/thrift-faraday_transport.
61
+
62
+ ## License
63
+
64
+ The gem is available as open source under the terms of the
65
+ [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,18 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ require 'rubocop/rake_task'
7
+
8
+ RuboCop::RakeTask.new
9
+
10
+ require 'yard/rake/yardoc_task'
11
+
12
+ YARD::Rake::YardocTask.new
13
+
14
+ # rubocop:disable Style/HashSyntax
15
+
16
+ task :default => %i[rubocop spec]
17
+
18
+ # rubocop:enable Style/HashSyntax
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.0.0
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'thrift/faraday_transport'
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__)
@@ -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,93 @@
1
+ require 'thrift'
2
+ require 'faraday'
3
+ require 'stringio'
4
+
5
+ module Thrift
6
+ # Faraday HTTP-transport for Thrift
7
+ class FaradayTransport < Thrift::BaseTransport
8
+ # Gem trhfit-faraday_transport version
9
+ VERSION = Gem.loaded_specs['thrift-faraday_transport'].version.to_s
10
+ # Base headers for response
11
+ BASE_HEADERS = { 'Content-Type' => 'application/x-thrift' }.freeze
12
+
13
+ # Unexpected HTTP code raise #flush when HTTP respond with not 200 status
14
+ class UnexpectedHTTPCode < TransportException
15
+ # Initialize new UnexpectedHTTPCode
16
+ #
17
+ # @param http_code [Integer] - response http code
18
+ def initialize(http_code)
19
+ super(TransportException::UNKNOWN, "Invalid HTTP code #{http_code}")
20
+ @http_code = http_code
21
+ end
22
+ end
23
+
24
+ # Faraday exception raise #flush
25
+ class FaradayException < TransportException
26
+ # Initialize new FaradayException
27
+ #
28
+ # @param faraday_exception [Faraday::ClientError]
29
+ def initialize(faraday_exception)
30
+ super(TransportException::UNKNOWN, faraday_exception.inspect)
31
+ end
32
+ end
33
+
34
+ # @return [Faraday::Connection] attribute faraday_connection
35
+ attr_reader :faraday_connection
36
+
37
+ # Initialize new Faraday transport
38
+ #
39
+ # @param faraday_connection [Faraday::Connection]
40
+ #
41
+ # @return [Thrift::FaradayTransport]
42
+ def initialize(faraday_connection)
43
+ @faraday_connection = faraday_connection
44
+ flush_out_buffer
45
+ end
46
+
47
+ def open?
48
+ true
49
+ end
50
+
51
+ # Implement Thrift::BaseTransport#write
52
+ #
53
+ # @param data [String]
54
+ def write(data)
55
+ @out_buffer << data
56
+ end
57
+
58
+ # Implement Thrift::BaseTransport#read
59
+ #
60
+ # @param size [Integer]
61
+ def read(size)
62
+ @in_buffer.read(size)
63
+ end
64
+
65
+ # Perform HTTP request. Implement Thrift::BaseTransport#flush
66
+ #
67
+ # @raise [UnexpectedHTTPCode] when HTTP server respond with not 200 status
68
+ # @raise [FaradayException] on Faraday client exception
69
+ def flush
70
+ response = perform_request
71
+ raise UnexpectedHTTPCode, response.status if response.status != 200
72
+ body = Bytes.force_binary_encoding(response.body)
73
+ @in_buffer = StringIO.new(body)
74
+ ensure
75
+ flush_out_buffer
76
+ end
77
+
78
+ private
79
+
80
+ def flush_out_buffer
81
+ @out_buffer = Bytes.empty_byte_buffer
82
+ end
83
+
84
+ def perform_request
85
+ @faraday_connection.post do |request|
86
+ request.body = @out_buffer
87
+ request.headers.merge!(BASE_HEADERS)
88
+ end
89
+ rescue Faraday::ClientError => e
90
+ raise FaradayException, e
91
+ end
92
+ end
93
+ end
@@ -0,0 +1,34 @@
1
+
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'thrift-faraday_transport'
7
+ spec.version = File.read(__dir__ + '/VERSION')
8
+ spec.authors = ['Dmitrij Fedorenko']
9
+ spec.email = ['<c0va23@gmail.com>']
10
+
11
+ spec.summary = 'Thrift HTTP transport'
12
+ spec.description = 'Thrift HTTP transport over Faraday'
13
+ spec.homepage = 'https://github.com/c0va23/ruby-thrift-faraday-transport'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(%r{^(test|spec|features)/})
18
+ end
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.required_ruby_version = '>= 2.2'
22
+
23
+ spec.add_development_dependency 'bundler', '~> 1.16'
24
+ spec.add_development_dependency 'rake', '~> 10.0'
25
+ spec.add_development_dependency 'rspec', '~> 3.0'
26
+ spec.add_development_dependency 'rubocop', '~> 0.52.0'
27
+ spec.add_development_dependency 'rubocop-rspec', '~> 1.21.0'
28
+ spec.add_development_dependency 'yard', '~> 0.9.11'
29
+
30
+ spec.add_dependency 'faraday', '~> 0.9.0'
31
+ spec.add_dependency 'thrift', '~> 0.9.0'
32
+
33
+ spec.metadata['yard.run'] = 'yard'
34
+ end
metadata ADDED
@@ -0,0 +1,170 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: thrift-faraday_transport
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Dmitrij Fedorenko
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-02-27 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: '1.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
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: rubocop
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.52.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.52.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop-rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 1.21.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 1.21.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: yard
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 0.9.11
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 0.9.11
97
+ - !ruby/object:Gem::Dependency
98
+ name: faraday
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 0.9.0
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 0.9.0
111
+ - !ruby/object:Gem::Dependency
112
+ name: thrift
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: 0.9.0
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: 0.9.0
125
+ description: Thrift HTTP transport over Faraday
126
+ email:
127
+ - "<c0va23@gmail.com>"
128
+ executables: []
129
+ extensions: []
130
+ extra_rdoc_files: []
131
+ files:
132
+ - ".gitignore"
133
+ - ".rubocop.yml"
134
+ - ".travis.yml"
135
+ - Gemfile
136
+ - Gemfile.lock
137
+ - LICENSE.txt
138
+ - README.md
139
+ - Rakefile
140
+ - VERSION
141
+ - bin/console
142
+ - bin/setup
143
+ - lib/thrift/faraday_transport.rb
144
+ - thrift-faraday_transport.gemspec
145
+ homepage: https://github.com/c0va23/ruby-thrift-faraday-transport
146
+ licenses:
147
+ - MIT
148
+ metadata:
149
+ yard.run: yard
150
+ post_install_message:
151
+ rdoc_options: []
152
+ require_paths:
153
+ - lib
154
+ required_ruby_version: !ruby/object:Gem::Requirement
155
+ requirements:
156
+ - - ">="
157
+ - !ruby/object:Gem::Version
158
+ version: '2.2'
159
+ required_rubygems_version: !ruby/object:Gem::Requirement
160
+ requirements:
161
+ - - ">="
162
+ - !ruby/object:Gem::Version
163
+ version: '0'
164
+ requirements: []
165
+ rubyforge_project:
166
+ rubygems_version: 2.7.3
167
+ signing_key:
168
+ specification_version: 4
169
+ summary: Thrift HTTP transport
170
+ test_files: []