kinesis_cat 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: 7f7d5053daf12cabb8e14acd2bf644fafd386b7b
4
+ data.tar.gz: d97c0d6d5abdae26f02335aba571fcebd391c9d8
5
+ SHA512:
6
+ metadata.gz: 9e4733e2beac0d60a115d2d2f08ccea00505d1626cceb07827ed07e3c01b1635a09af6df74088e7d63144006fe8c70d900b5a4fa938744799f6e448156a98af9
7
+ data.tar.gz: b34564da089230f325291777e9bf3e5e523805a19ce1613eb0a57029dd7e2e5b547281da8cd50952eb6a08d78292d7238bcd60f612fcdedec975f9dc08dda63d
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --colour
2
+ --require spec_helper
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ script:
5
+ - bundle install
6
+ - bundle exec rake
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in kinesis_cat.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Genki Sugawara
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,42 @@
1
+ # KinesisCat
2
+
3
+ [Amazon Kinesis](http://aws.amazon.com/kinesis/) cli for put JSON data.
4
+
5
+ [![Gem Version](https://badge.fury.io/rb/kinesis_cat.svg)](http://badge.fury.io/rb/kinesis_cat)
6
+ [![Build Status](https://travis-ci.org/winebarrel/kinesis_cat.svg?branch=master)](https://travis-ci.org/winebarrel/kinesis_cat)
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem 'kinesis_cat'
14
+ ```
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install kinesis_cat
23
+
24
+ ## Usage
25
+
26
+ ```sh
27
+ cat '{"key": "val"}' | kinesis-cat --stream-name my-stream
28
+ ```
29
+
30
+ ## Help
31
+
32
+ ```
33
+ Usage: kinesis-cat [options]
34
+ -p, --profile PROFILE_NAME
35
+ --credentials-path PATH
36
+ -k, --access-key ACCESS_KEY
37
+ -s, --secret-key SECRET_KEY
38
+ -r, --region REGION
39
+ --stream-name NAME
40
+ --partition-key KEY
41
+ --debug
42
+ ```
@@ -0,0 +1,5 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new('spec')
5
+ task :default => :spec
@@ -0,0 +1,86 @@
1
+ #!/usr/bin/env ruby
2
+ $: << File.expand_path("#{File.dirname __FILE__}/../lib")
3
+ require 'rubygems'
4
+ require 'kinesis_cat'
5
+ require 'logger'
6
+ require 'optparse'
7
+
8
+ Version = KinesisCat::VERSION
9
+
10
+ options = {
11
+ :debug => false,
12
+ }
13
+
14
+ ARGV.options do |opt|
15
+ begin
16
+ access_key = nil
17
+ secret_key = nil
18
+ region = nil
19
+ profile_name = nil
20
+ credentials_path = nil
21
+
22
+ opt.on('-p', '--profile PROFILE_NAME') {|v| profile_name = v }
23
+ opt.on('' , '--credentials-path PATH') {|v| credentials_path = v }
24
+ opt.on('-k', '--access-key ACCESS_KEY') {|v| access_key = v }
25
+ opt.on('-s', '--secret-key SECRET_KEY') {|v| secret_key = v }
26
+ opt.on('-r', '--region REGION') {|v| region = v }
27
+ opt.on('' , '--stream-name NAME') {|v| options[:stream_name] = v }
28
+ opt.on('' , '--partition-key KEY') {|v| options[:partition_key] = v }
29
+ opt.on('' , '--debug') { options[:debug] = true }
30
+ opt.parse!
31
+
32
+ aws_opts = {}
33
+
34
+ if access_key and secret_key
35
+ aws_opts.update(
36
+ :access_key_id => access_key,
37
+ :secret_access_key => secret_key
38
+ )
39
+ elsif profile_name or credentials_path
40
+ credentials_opts = {}
41
+ credentials_opts[:profile_name] = profile_name if profile_name
42
+ credentials_opts[:path] = credentials_path if credentials_path
43
+ credentials = Aws::SharedCredentials.new(credentials_opts)
44
+ aws_opts[:credentials] = credentials
45
+ elsif (access_key and !secret_key) or (!access_key and secret_key)
46
+ puts opt.help
47
+ exit 1
48
+ end
49
+
50
+ aws_opts[:region] = region if region
51
+ Aws.config.update(aws_opts)
52
+
53
+ unless options[:stream_name]
54
+ raise '"--stream-name" is required'
55
+ end
56
+ rescue => e
57
+ $stderr.puts("[ERROR] #{e.message}")
58
+ exit 1
59
+ end
60
+ end
61
+
62
+ if options[:debug]
63
+ Aws.config.update(
64
+ :logger => Logger.new($stderr),
65
+ :http_wire_trace => true,
66
+ )
67
+ end
68
+
69
+ begin
70
+ kinesis = Aws::Kinesis::Client.new
71
+ client = KinesisCat::Client.new(kinesis, options)
72
+ json = JSON.parse($stdin.read)
73
+
74
+ if json.kind_of?(Array)
75
+ json.each {|i| client.put(i) }
76
+ else
77
+ client.put(json)
78
+ end
79
+ rescue => e
80
+ if options[:debug]
81
+ raise e
82
+ else
83
+ $stderr.puts("[ERROR] #{e.message}")
84
+ exit 1
85
+ end
86
+ end
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'kinesis_cat/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'kinesis_cat'
8
+ spec.version = KinesisCat::VERSION
9
+ spec.authors = ['Genki Sugawara']
10
+ spec.email = ['sgwr_dts@yahoo.co.jp']
11
+ spec.summary = %q{Amazon Kinesis cli for put JSON data.}
12
+ spec.description = %q{Amazon Kinesis cli for put JSON data.}
13
+ spec.homepage = 'https://github.com/winebarrel/kinesis_cat'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_dependency 'aws-sdk-core'
22
+ spec.add_development_dependency 'bundler'
23
+ spec.add_development_dependency 'rake'
24
+ spec.add_development_dependency 'rspec', '>= 3.0.0'
25
+ spec.add_development_dependency 'timecop'
26
+ end
@@ -0,0 +1,6 @@
1
+ require 'aws-sdk-core'
2
+ require 'json'
3
+
4
+ module KinesisCat; end
5
+ require 'kinesis_cat/client'
6
+ require 'kinesis_cat/version'
@@ -0,0 +1,22 @@
1
+ class KinesisCat::Client
2
+ def initialize(client, options)
3
+ @client = client
4
+ @options = options
5
+ end
6
+
7
+ def put(data, options = {})
8
+ options = @options.merge(options)
9
+ partition_key = options[:partition_key]
10
+ partition_key ||= Time.now.to_i.to_s
11
+
12
+ if data.kind_of?(Hash)
13
+ data = JSON.dump(data)
14
+ end
15
+
16
+ @client.put_record(
17
+ :stream_name => options.fetch(:stream_name),
18
+ :data => data,
19
+ :partition_key => partition_key,
20
+ )
21
+ end
22
+ end
@@ -0,0 +1,3 @@
1
+ module KinesisCat
2
+ VERSION = '0.1.0'
3
+ end
@@ -0,0 +1,86 @@
1
+ describe KinesisCat::Client do
2
+ subject(:client) do
3
+ described_class.new(kinesis, stream_name: stream_name, partition_key: partition_key)
4
+ end
5
+
6
+ let(:kinesis) { Aws::Kinesis::Client.new(stub_responses: true) }
7
+ let(:stream_name) { 'STREAM_NAME' }
8
+ let(:partition_key) { nil }
9
+ let(:now) { Time.parse('2015/01/12') }
10
+
11
+ context 'when put json' do
12
+ let(:data) { {'key' => 'val'} }
13
+
14
+ context 'without partition_key' do
15
+ before do
16
+ expect(kinesis).to receive(:put_record).with(
17
+ stream_name: stream_name,
18
+ data: JSON.dump(data),
19
+ partition_key: now.to_i.to_s,
20
+ )
21
+ end
22
+
23
+ it do
24
+ Timecop.freeze(now) do
25
+ client.put(data)
26
+ end
27
+ end
28
+ end
29
+
30
+ context 'with partition_key' do
31
+ let(:partition_key) { 'PARTITION_KEY' }
32
+
33
+ before do
34
+ expect(kinesis).to receive(:put_record).with(
35
+ stream_name: stream_name,
36
+ data: JSON.dump(data),
37
+ partition_key: partition_key
38
+ )
39
+ end
40
+
41
+ it do
42
+ Timecop.freeze(now) do
43
+ client.put(data)
44
+ end
45
+ end
46
+ end
47
+ end
48
+
49
+ context 'when put string' do
50
+ let(:data) { 'London Bridge Is Falling Down' }
51
+
52
+ context 'without partition_key' do
53
+ before do
54
+ expect(kinesis).to receive(:put_record).with(
55
+ stream_name: stream_name,
56
+ data: data,
57
+ partition_key: now.to_i.to_s,
58
+ )
59
+ end
60
+
61
+ it do
62
+ Timecop.freeze(now) do
63
+ client.put(data)
64
+ end
65
+ end
66
+ end
67
+
68
+ context 'with partition_key' do
69
+ let(:partition_key) { 'PARTITION_KEY' }
70
+
71
+ before do
72
+ expect(kinesis).to receive(:put_record).with(
73
+ stream_name: stream_name,
74
+ data: data,
75
+ partition_key: partition_key
76
+ )
77
+ end
78
+
79
+ it do
80
+ Timecop.freeze(now) do
81
+ client.put(data)
82
+ end
83
+ end
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,2 @@
1
+ require 'kinesis_cat'
2
+ require 'timecop'
metadata ADDED
@@ -0,0 +1,131 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: kinesis_cat
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Genki Sugawara
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-01-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: aws-sdk-core
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: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
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: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: 3.0.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: 3.0.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: timecop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Amazon Kinesis cli for put JSON data.
84
+ email:
85
+ - sgwr_dts@yahoo.co.jp
86
+ executables:
87
+ - kinesis-cat
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - .gitignore
92
+ - .rspec
93
+ - .travis.yml
94
+ - Gemfile
95
+ - LICENSE.txt
96
+ - README.md
97
+ - Rakefile
98
+ - bin/kinesis-cat
99
+ - kinesis_cat.gemspec
100
+ - lib/kinesis_cat.rb
101
+ - lib/kinesis_cat/client.rb
102
+ - lib/kinesis_cat/version.rb
103
+ - spec/kinesis_cat_spec.rb
104
+ - spec/spec_helper.rb
105
+ homepage: https://github.com/winebarrel/kinesis_cat
106
+ licenses:
107
+ - MIT
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.0.14
126
+ signing_key:
127
+ specification_version: 4
128
+ summary: Amazon Kinesis cli for put JSON data.
129
+ test_files:
130
+ - spec/kinesis_cat_spec.rb
131
+ - spec/spec_helper.rb