reckoner_cdp 0.1.1

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: 676a986296672d387afef2efff263bd3c510f673680a3e587ef9ea269959e007
4
+ data.tar.gz: 1bc6122596c19978a39aa9584e30f4be00ac0ae9541fcaec835fbc4302211a54
5
+ SHA512:
6
+ metadata.gz: 8fe63a5a7c0d15a253fb89a0782b48347e627731a0dfa74647a7e8e8f1810e7dc10788c28b051b15c0c8f5062f8e6d95bce027f6e247234cf3bcec9745e3e61c
7
+ data.tar.gz: 18b8e6341a8ff2d72503c03bfd7ffe27127adb7fe49c4e6d866d7645dd2b1636a5cfe7d4efc63bb1abc040ea5afc4647d59c8c63ba41084e1d0e4c503f12a03c
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ /vendor/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
13
+
14
+ *.gem
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
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.5.0
7
+ before_install: gem install bundler -v 1.16.6
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,81 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ reckoner_cdp (0.1.1)
5
+ faraday_middleware (~> 0.12)
6
+ google-api-client (~> 0.34)
7
+ msgpack (~> 1.2)
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ addressable (2.7.0)
13
+ public_suffix (>= 2.0.2, < 5.0)
14
+ declarative (0.0.10)
15
+ declarative-option (0.1.0)
16
+ diff-lcs (1.3)
17
+ faraday (0.17.3)
18
+ multipart-post (>= 1.2, < 3)
19
+ faraday_middleware (0.14.0)
20
+ faraday (>= 0.7.4, < 1.0)
21
+ google-api-client (0.39.0)
22
+ addressable (~> 2.5, >= 2.5.1)
23
+ googleauth (~> 0.9)
24
+ httpclient (>= 2.8.1, < 3.0)
25
+ mini_mime (~> 1.0)
26
+ representable (~> 3.0)
27
+ retriable (>= 2.0, < 4.0)
28
+ signet (~> 0.12)
29
+ googleauth (0.12.0)
30
+ faraday (>= 0.17.3, < 2.0)
31
+ jwt (>= 1.4, < 3.0)
32
+ memoist (~> 0.16)
33
+ multi_json (~> 1.11)
34
+ os (>= 0.9, < 2.0)
35
+ signet (~> 0.14)
36
+ httpclient (2.8.3)
37
+ jwt (2.2.1)
38
+ memoist (0.16.2)
39
+ mini_mime (1.0.2)
40
+ msgpack (1.3.3)
41
+ multi_json (1.14.1)
42
+ multipart-post (2.1.1)
43
+ os (1.1.0)
44
+ public_suffix (4.0.4)
45
+ rake (10.5.0)
46
+ representable (3.0.4)
47
+ declarative (< 0.1.0)
48
+ declarative-option (< 0.2.0)
49
+ uber (< 0.2.0)
50
+ retriable (3.1.2)
51
+ rspec (3.8.0)
52
+ rspec-core (~> 3.8.0)
53
+ rspec-expectations (~> 3.8.0)
54
+ rspec-mocks (~> 3.8.0)
55
+ rspec-core (3.8.0)
56
+ rspec-support (~> 3.8.0)
57
+ rspec-expectations (3.8.2)
58
+ diff-lcs (>= 1.2.0, < 2.0)
59
+ rspec-support (~> 3.8.0)
60
+ rspec-mocks (3.8.0)
61
+ diff-lcs (>= 1.2.0, < 2.0)
62
+ rspec-support (~> 3.8.0)
63
+ rspec-support (3.8.0)
64
+ signet (0.14.0)
65
+ addressable (~> 2.3)
66
+ faraday (>= 0.17.3, < 2.0)
67
+ jwt (>= 1.5, < 3.0)
68
+ multi_json (~> 1.10)
69
+ uber (0.1.0)
70
+
71
+ PLATFORMS
72
+ ruby
73
+
74
+ DEPENDENCIES
75
+ bundler (~> 1.16)
76
+ rake (~> 10.0)
77
+ reckoner_cdp!
78
+ rspec (~> 3.0)
79
+
80
+ BUNDLED WITH
81
+ 1.17.2
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 katsuhito123
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,44 @@
1
+ # Reckoner CDP API Client Library for Ruby
2
+
3
+ Ruby Client Library for Reckoner CDP services.
4
+
5
+ With this gem, you can:
6
+ * stream your data to Streaming Workflow.
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem 'reckoner_cdp'
14
+ ```
15
+
16
+ And then execute:
17
+
18
+ $ bundle install
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install reckoner_cdp
23
+
24
+ ## Usage
25
+
26
+ ### Initialization
27
+
28
+ Initialize a client:
29
+
30
+ ```ruby
31
+ require 'reckoner_cdp'
32
+
33
+ client = Reckoner::Cdp::Client.new('/path/to/key.json')
34
+ ```
35
+
36
+ ### Stream Your Data to Streaming Workflow
37
+
38
+ Stream:
39
+
40
+ ```ruby
41
+ workflow_id = 1
42
+ data = [{bar: :bar1, foo: :foo1}, {bar: :bar2, foo: :foo2}]
43
+ client.streaming_bulk_insert(workflow_id, data)
44
+ ```
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 "reckoner/cdp/ruby"
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
data/client.rb ADDED
@@ -0,0 +1,14 @@
1
+ require "./lib/reckoner_cdp"
2
+
3
+ json_key_path = "/path/to/thidparty-key.json"
4
+ endpoint = "https://streaming.stg-reckoner-api.com"
5
+ client_id = "1084004246200-9rmut82u1jk3ps9mvs4fejnl73ntskh4.apps.googleusercontent.com"
6
+ client = Reckoner::Cdp::Client.new(json_key_path, endpoint: endpoint, client_id: client_id)
7
+
8
+ workflow_id = 1
9
+ data = [
10
+ {bar: :bar1, foo: :foo1},
11
+ {bar: :bar2, foo: :foo2}
12
+ ]
13
+
14
+ client.streaming_insert(workflow_id, data)
@@ -0,0 +1,28 @@
1
+ require 'msgpack'
2
+ require 'securerandom'
3
+ require 'date'
4
+
5
+ require_relative '../errors'
6
+
7
+ module Reckoner
8
+ module Cdp
9
+ module API
10
+ module Streaming
11
+ def insert(workflow_id, data)
12
+ unless data.class == Array
13
+ raise Reckoner::Cdp::InvalidArgumentError, "'data' must be an Array"
14
+ end
15
+
16
+ params = {
17
+ data: data.to_msgpack,
18
+ time: Time.now.to_i,
19
+ workflow_id: workflow_id,
20
+ record_id: SecureRandom.uuid
21
+ }
22
+ get('/api/v1/streaming', params)
23
+ end
24
+
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,90 @@
1
+ require 'faraday_middleware'
2
+ require 'time'
3
+ require 'google/apis/iamcredentials_v1'
4
+
5
+ require_relative '../errors'
6
+ require_relative 'streaming'
7
+
8
+ module Reckoner
9
+ module Cdp
10
+ module API
11
+ class StreamingCore
12
+ include Reckoner::Cdp::API::Streaming
13
+
14
+ STATUS = {
15
+ ok: 200,
16
+ unauthorized: 401,
17
+ client_error: 400..499,
18
+ server_error: 500..599,
19
+ }.freeze
20
+
21
+ def initialize(json_key_path, endpoint, client_id, connection)
22
+ @json_key_path = json_key_path
23
+ @endpoint = endpoint || Reckoner::Cdp::STREAMING_ENDPOINT
24
+ @client_id = client_id || Reckoner::Cdp::STREAMING_CLIENT_ID
25
+ @connection = connection || default_connection
26
+ end
27
+
28
+ private
29
+
30
+ def get(path, params)
31
+ res = @connection.get do |req|
32
+ req.url path, params
33
+ req.options.timeout = 5
34
+ req.options.open_timeout = 5
35
+ req.headers['Date'] = Time.now.httpdate
36
+ req.headers['Content-Type'] = 'application/json'
37
+ req.headers['Authorization'] = authorization_header(req)
38
+ end
39
+ check_error(res)
40
+ res.body
41
+ end
42
+
43
+ def check_error(res)
44
+ case res.status
45
+ when STATUS[:unauthorized]
46
+ raise Reckoner::Cdp::UnauthorizedError, res.body
47
+ when STATUS[:client_error]
48
+ raise Reckoner::Cdp::ClientError, res.body
49
+ when STATUS[:server_error]
50
+ raise Reckoner::Cdp::ServerError, res.body
51
+ else
52
+ nil
53
+ end
54
+ end
55
+
56
+ def default_connection
57
+ opt = {
58
+ headers: { Accept: 'application/json' },
59
+ url: @endpoint,
60
+ request: { params_encoder: Faraday::NestedParamsEncoder }
61
+ }
62
+ @default_connection ||= Faraday.new(opt) do |conn|
63
+ conn.request :json
64
+ conn.response :json, content_type: /\b(json|javascript)$/
65
+ conn.adapter Faraday.default_adapter
66
+ end
67
+ end
68
+
69
+ def authorization_header(req)
70
+ iamcredentials = Google::Apis::IamcredentialsV1
71
+ service = iamcredentials::IAMCredentialsService.new
72
+
73
+ scopes = ['https://www.googleapis.com/auth/iam', 'https://www.googleapis.com/auth/cloud-platform']
74
+ service.authorization = Google::Auth::ServiceAccountCredentials.make_creds(
75
+ json_key_io: File.open(@json_key_path, "r"),
76
+ scope: scopes
77
+ )
78
+
79
+ email = File.open(@json_key_path, "r") { |file| JSON.parse(file.read)["client_email"]}
80
+ resource = 'projects/-/serviceAccounts/' + email
81
+ req = iamcredentials::GenerateIdTokenRequest.new(audience: @client_id, include_email: true)
82
+ service.generate_service_account_id_token(resource, req) do |result, err|
83
+ return 'Bearer ' + result.token
84
+ end
85
+ end
86
+
87
+ end
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,29 @@
1
+ require_relative 'api/streaming_core'
2
+
3
+ module Reckoner
4
+ module Cdp
5
+ class Client
6
+ def initialize(json_key_path, endpoint: nil, client_id: nil, connection: nil)
7
+ @json_key_path = json_key_path
8
+ @endpoint = endpoint
9
+ @client_id = client_id
10
+ @connection = connection
11
+ end
12
+
13
+ def streaming_insert(workflow_id, data)
14
+ streaming_api.insert(workflow_id, data)
15
+ end
16
+
17
+ private
18
+
19
+ def streaming_api
20
+ @streaming_api ||= Reckoner::Cdp::API::StreamingCore.new(
21
+ @json_key_path,
22
+ @endpoint,
23
+ @client_id,
24
+ @connection
25
+ )
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,9 @@
1
+ module Reckoner
2
+ module Cdp
3
+ class Error < StandardError; end
4
+ class InvalidArgumentError < Error; end
5
+ class UnauthorizedError < Error; end
6
+ class ServerError < Error; end
7
+ class ClientError < Error; end
8
+ end
9
+ end
@@ -0,0 +1,5 @@
1
+ module Reckoner
2
+ module Cdp
3
+ VERSION = "0.1.1"
4
+ end
5
+ end
@@ -0,0 +1,9 @@
1
+ module Reckoner
2
+ module Cdp
3
+ STREAMING_ENDPOINT = 'https://streaming.reckoner-api.com'
4
+ STREAMING_CLIENT_ID = '40505496942-8d5b8lv8rjsipquroodnjap7kthjicp7.apps.googleusercontent.com'
5
+ end
6
+ end
7
+
8
+ require_relative 'reckoner/cdp/client'
9
+ require_relative 'reckoner/cdp/errors'
@@ -0,0 +1,30 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "reckoner/cdp/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "reckoner_cdp"
8
+ spec.version = Reckoner::Cdp::VERSION
9
+ spec.authors = ["ms03"]
10
+ spec.email = ["sasaki@3-shake.com"]
11
+
12
+ spec.summary = %q{writer to reckoner-cdp}
13
+ spec.description = spec.summary
14
+ spec.homepage = "https://github.com/3-shake/reckoner-cdp-ruby"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
18
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(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_development_dependency "bundler", "~> 1.16"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "rspec", "~> 3.0"
27
+ spec.add_dependency "faraday_middleware", "~> 0.12"
28
+ spec.add_dependency "msgpack", '~> 1.2'
29
+ spec.add_dependency "google-api-client", '~> 0.34'
30
+ end
metadata ADDED
@@ -0,0 +1,145 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: reckoner_cdp
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - ms03
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-05-13 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: faraday_middleware
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.12'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.12'
69
+ - !ruby/object:Gem::Dependency
70
+ name: msgpack
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.2'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.2'
83
+ - !ruby/object:Gem::Dependency
84
+ name: google-api-client
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.34'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.34'
97
+ description: writer to reckoner-cdp
98
+ email:
99
+ - sasaki@3-shake.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".rspec"
106
+ - ".travis.yml"
107
+ - Gemfile
108
+ - Gemfile.lock
109
+ - LICENSE.txt
110
+ - README.md
111
+ - Rakefile
112
+ - bin/console
113
+ - bin/setup
114
+ - client.rb
115
+ - lib/reckoner/cdp/api/streaming.rb
116
+ - lib/reckoner/cdp/api/streaming_core.rb
117
+ - lib/reckoner/cdp/client.rb
118
+ - lib/reckoner/cdp/errors.rb
119
+ - lib/reckoner/cdp/version.rb
120
+ - lib/reckoner_cdp.rb
121
+ - reckoner-cdp-ruby.gemspec
122
+ homepage: https://github.com/3-shake/reckoner-cdp-ruby
123
+ licenses:
124
+ - MIT
125
+ metadata: {}
126
+ post_install_message:
127
+ rdoc_options: []
128
+ require_paths:
129
+ - lib
130
+ required_ruby_version: !ruby/object:Gem::Requirement
131
+ requirements:
132
+ - - ">="
133
+ - !ruby/object:Gem::Version
134
+ version: '0'
135
+ required_rubygems_version: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - ">="
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
140
+ requirements: []
141
+ rubygems_version: 3.0.3
142
+ signing_key:
143
+ specification_version: 4
144
+ summary: writer to reckoner-cdp
145
+ test_files: []