data-sink-client 0.1.2
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 +7 -0
- data/.gitignore +10 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +53 -0
- data/LICENSE +21 -0
- data/README.md +58 -0
- data/Rakefile +6 -0
- data/data-sink-client.gemspec +31 -0
- data/lib/data-sink-client.rb +4 -0
- data/lib/data-sink-client/version.rb +3 -0
- data/lib/data_sink/client.rb +63 -0
- metadata +140 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b539f32ec6079e8993c531486afe88452e10b5c2
|
4
|
+
data.tar.gz: 9f2259a0f18950ad0ad8846745917a6c3ca0d358
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7444345496e43d4e5ddf6f875e0e5bcc490d693499f9f0850e266b7cf038bad7238c0aaaac6e422c36ccb0bc96dce34540c9e76dc4292f4316d3197b4f6fc1d4
|
7
|
+
data.tar.gz: 5f51a0fee01d9e0c71a90ef73ffdcbbc701027166b6f73c1c8fe7d9aaa06399dd3ca1145ce16ff90959d3aa0bb2c9c82a31ba3a1d6eb879a33cfdfb79bac661e
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
data-sink-client (0.1.2)
|
5
|
+
excon (~> 0.55.0)
|
6
|
+
faraday (> 0.10.0)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
addressable (2.5.0)
|
12
|
+
public_suffix (~> 2.0, >= 2.0.2)
|
13
|
+
crack (0.4.3)
|
14
|
+
safe_yaml (~> 1.0.0)
|
15
|
+
diff-lcs (1.3)
|
16
|
+
excon (0.55.0)
|
17
|
+
faraday (0.11.0)
|
18
|
+
multipart-post (>= 1.2, < 3)
|
19
|
+
hashdiff (0.3.0)
|
20
|
+
multipart-post (2.0.0)
|
21
|
+
public_suffix (2.0.4)
|
22
|
+
rake (10.5.0)
|
23
|
+
rspec (3.5.0)
|
24
|
+
rspec-core (~> 3.5.0)
|
25
|
+
rspec-expectations (~> 3.5.0)
|
26
|
+
rspec-mocks (~> 3.5.0)
|
27
|
+
rspec-core (3.5.4)
|
28
|
+
rspec-support (~> 3.5.0)
|
29
|
+
rspec-expectations (3.5.0)
|
30
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
31
|
+
rspec-support (~> 3.5.0)
|
32
|
+
rspec-mocks (3.5.0)
|
33
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
34
|
+
rspec-support (~> 3.5.0)
|
35
|
+
rspec-support (3.5.0)
|
36
|
+
safe_yaml (1.0.4)
|
37
|
+
webmock (2.1.0)
|
38
|
+
addressable (>= 2.3.6)
|
39
|
+
crack (>= 0.3.2)
|
40
|
+
hashdiff
|
41
|
+
|
42
|
+
PLATFORMS
|
43
|
+
ruby
|
44
|
+
|
45
|
+
DEPENDENCIES
|
46
|
+
bundler (~> 1.13)
|
47
|
+
data-sink-client!
|
48
|
+
rake (~> 10.0)
|
49
|
+
rspec (~> 3.0)
|
50
|
+
webmock (~> 2.1)
|
51
|
+
|
52
|
+
BUNDLED WITH
|
53
|
+
1.13.2
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2017 Roofoods, Ltd https://deliveroo.co.uk
|
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,58 @@
|
|
1
|
+
# DataSink::Client
|
2
|
+
|
3
|
+
[](https://travis-ci.com/deliveroo/data-sink-client)
|
4
|
+
|
5
|
+
A small client library for [data-sink](https://github.com/deliveroo/data-sink).
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'data-sink-client'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install data-sink-client
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
```
|
26
|
+
client = DataSink::Client.new(user: 'user', pass: 'pass', ...)
|
27
|
+
client.post(stream_id, body)
|
28
|
+
|
29
|
+
# or, if body already compressed:
|
30
|
+
|
31
|
+
client.post_gzipped(stream_id, body)
|
32
|
+
```
|
33
|
+
|
34
|
+
Options (with defaults):
|
35
|
+
|
36
|
+
```
|
37
|
+
url: ''
|
38
|
+
endpoint: '/archives'
|
39
|
+
retry_max: 2
|
40
|
+
retry_interval: 0.1
|
41
|
+
retry_backoff_factor: 2
|
42
|
+
adapter: :excon
|
43
|
+
read_timeout: 5
|
44
|
+
open_timeout: 5
|
45
|
+
```
|
46
|
+
|
47
|
+
or pass a Faraday client yourself with `client:`.
|
48
|
+
|
49
|
+
## Development
|
50
|
+
|
51
|
+
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.
|
52
|
+
|
53
|
+
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).
|
54
|
+
|
55
|
+
## Contributing
|
56
|
+
|
57
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/deliveroo/data-sink-client.
|
58
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'data-sink-client/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "data-sink-client"
|
8
|
+
spec.description = "Client for data-sink"
|
9
|
+
spec.version = DataSinkClient::VERSION
|
10
|
+
spec.authors = ["Ivan Pirlik"]
|
11
|
+
spec.email = ["ivan.pirlik@deliveroo.co.uk"]
|
12
|
+
|
13
|
+
spec.summary = %q{Client for the data-sink service}
|
14
|
+
spec.homepage = "https://github.com/deliveroo/data-sink-client"
|
15
|
+
spec.license = 'MIT'
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
18
|
+
f.match(%r{^(bin|test|spec|features)/})
|
19
|
+
end
|
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_dependency 'faraday', '> 0.10.0'
|
25
|
+
spec.add_dependency 'excon', '~> 0.55.0'
|
26
|
+
|
27
|
+
spec.add_development_dependency "bundler", "~> 1.13"
|
28
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
29
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
30
|
+
spec.add_development_dependency "webmock", "~> 2.1"
|
31
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
|
3
|
+
module DataSink
|
4
|
+
class Client
|
5
|
+
DEFAULTS = {
|
6
|
+
url: '',
|
7
|
+
endpoint: '/archives',
|
8
|
+
retry_max: 2,
|
9
|
+
retry_interval: 0.1,
|
10
|
+
retry_backoff_factor: 2,
|
11
|
+
adapter: :excon,
|
12
|
+
read_timeout: 5,
|
13
|
+
open_timeout: 5,
|
14
|
+
}.freeze
|
15
|
+
|
16
|
+
attr_reader :client, :options
|
17
|
+
|
18
|
+
def initialize(options={})
|
19
|
+
@options = DEFAULTS.merge(options)
|
20
|
+
user = @options.fetch(:user)
|
21
|
+
pass = @options.fetch(:pass)
|
22
|
+
@client = options[:client] || create_client(user, pass)
|
23
|
+
end
|
24
|
+
|
25
|
+
def post(stream_id, body)
|
26
|
+
post_gzipped(stream_id, gzip(body))
|
27
|
+
end
|
28
|
+
|
29
|
+
def post_gzipped(stream_id, body)
|
30
|
+
client.post do |req|
|
31
|
+
req.url endpoint(stream_id)
|
32
|
+
req.body = body
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def endpoint(stream_id)
|
39
|
+
[options[:endpoint], stream_id].join('/')
|
40
|
+
end
|
41
|
+
|
42
|
+
def create_client(user, pass)
|
43
|
+
Faraday.new(options[:url], ssl: { verify: true }) do |f|
|
44
|
+
f.headers['Content-Encoding'] = 'application/gzip'
|
45
|
+
f.headers['Content-Type'] = 'application/octet-stream'
|
46
|
+
f.request :retry, methods: [:post], max: options[:retry_max], interval: options[:retry_interval], backoff_factor: options[:retry_backoff_factor]
|
47
|
+
f.options.timeout = options[:read_timeout] if options[:read_timeout]
|
48
|
+
f.options.open_timeout = options[:open_timeout] if options[:open_timeout]
|
49
|
+
f.adapter options[:adapter]
|
50
|
+
end.tap do |client|
|
51
|
+
client.basic_auth(user, pass)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def gzip(body)
|
56
|
+
wio = StringIO.new("w")
|
57
|
+
w_gz = Zlib::GzipWriter.new(wio)
|
58
|
+
w_gz.write(body)
|
59
|
+
w_gz.close
|
60
|
+
wio.string
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
metadata
ADDED
@@ -0,0 +1,140 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: data-sink-client
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ivan Pirlik
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-04-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.10.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.10.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: excon
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.55.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.55.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.13'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.13'
|
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
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: webmock
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '2.1'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '2.1'
|
97
|
+
description: Client for data-sink
|
98
|
+
email:
|
99
|
+
- ivan.pirlik@deliveroo.co.uk
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- ".gitignore"
|
105
|
+
- ".rspec"
|
106
|
+
- ".travis.yml"
|
107
|
+
- Gemfile
|
108
|
+
- Gemfile.lock
|
109
|
+
- LICENSE
|
110
|
+
- README.md
|
111
|
+
- Rakefile
|
112
|
+
- data-sink-client.gemspec
|
113
|
+
- lib/data-sink-client.rb
|
114
|
+
- lib/data-sink-client/version.rb
|
115
|
+
- lib/data_sink/client.rb
|
116
|
+
homepage: https://github.com/deliveroo/data-sink-client
|
117
|
+
licenses:
|
118
|
+
- MIT
|
119
|
+
metadata: {}
|
120
|
+
post_install_message:
|
121
|
+
rdoc_options: []
|
122
|
+
require_paths:
|
123
|
+
- lib
|
124
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
125
|
+
requirements:
|
126
|
+
- - ">="
|
127
|
+
- !ruby/object:Gem::Version
|
128
|
+
version: '0'
|
129
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
130
|
+
requirements:
|
131
|
+
- - ">="
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '0'
|
134
|
+
requirements: []
|
135
|
+
rubyforge_project:
|
136
|
+
rubygems_version: 2.4.5.1
|
137
|
+
signing_key:
|
138
|
+
specification_version: 4
|
139
|
+
summary: Client for the data-sink service
|
140
|
+
test_files: []
|