fluent-plugin-currency 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/Gemfile +6 -0
- data/README.md +35 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/fluent-plugin-currency.gemspec +34 -0
- data/lib/fluent/plugin/currency.rb +9 -0
- data/lib/fluent/plugin/currency/version.rb +7 -0
- data/lib/fluent/plugin/filter_currency.rb +75 -0
- metadata +82 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 631c47a138fce4b173220df73b1db148805d281e
|
4
|
+
data.tar.gz: b890ac7821aa6d56eef0f759027866b1d33673a2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: aabce398d8c12e8fa86806f551286057edab7badb669f220c274e1923a00e747837abfb24a4355a8afb73478d785eac1cc7ff0395c1adff2a3d7c89990dc7a05
|
7
|
+
data.tar.gz: f6943847152e5b3e1590e32249202ed44185eb6d6ff8a0a3418c0523984f6431231b3c31deafe71a3d0fca79019309d6de32503cd56cf207ed775be9e1319573
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# Fluent::Plugin::Currency
|
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/fluent/plugin/currency`. 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 'fluent-plugin-currency'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install fluent-plugin-currency
|
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. 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/[USERNAME]/fluent-plugin-currency.
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "fluent/plugin/currency"
|
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,34 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "fluent/plugin/currency/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "fluent-plugin-currency"
|
8
|
+
spec.version = Fluent::Plugin::Currency::VERSION
|
9
|
+
spec.authors = ["Aleksey Pavlov"]
|
10
|
+
spec.email = ["pavlov@divo-games.com"]
|
11
|
+
|
12
|
+
spec.summary = "fluent-plugin-currency"
|
13
|
+
spec.description = "fluent-plugin-currency"
|
14
|
+
spec.homepage = "https://rubygems.org/gems/fluent-plugin-currency"
|
15
|
+
|
16
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
17
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
18
|
+
if spec.respond_to?(:metadata)
|
19
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
20
|
+
else
|
21
|
+
raise "RubyGems 2.0 or newer is required to protect against " \
|
22
|
+
"public gem pushes."
|
23
|
+
end
|
24
|
+
|
25
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
26
|
+
f.match(%r{^(test|spec|features)/})
|
27
|
+
end
|
28
|
+
spec.bindir = "exe"
|
29
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
30
|
+
spec.require_paths = ["lib"]
|
31
|
+
|
32
|
+
spec.add_development_dependency "bundler", "~> 1.15"
|
33
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
34
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
require 'fluent/filter'
|
2
|
+
require 'net/http'
|
3
|
+
|
4
|
+
module Fluent
|
5
|
+
class CurrencyFilter < Filter
|
6
|
+
# Register this filter as "passthru"
|
7
|
+
Fluent::Plugin.register_filter('currency', self)
|
8
|
+
|
9
|
+
# config_param works like other plugins
|
10
|
+
config_param :price_key, :integer, default: 'price'
|
11
|
+
config_param :currency_key, :string, default: 'currency'
|
12
|
+
config_param :converted_key, :string, default: 'price_usd'
|
13
|
+
config_param :base_currency, :string, default: 'USD'
|
14
|
+
config_param :converter_url, :string
|
15
|
+
|
16
|
+
def configure(conf)
|
17
|
+
super
|
18
|
+
# do the usual configuration here
|
19
|
+
testRequest()
|
20
|
+
end
|
21
|
+
|
22
|
+
def start
|
23
|
+
super
|
24
|
+
# This is the first method to be called when it starts running
|
25
|
+
# Use it to allocate resources, etc.
|
26
|
+
end
|
27
|
+
|
28
|
+
def shutdown
|
29
|
+
super
|
30
|
+
# This method is called when Fluentd is shutting down.
|
31
|
+
# Use it to free up resources, etc.
|
32
|
+
end
|
33
|
+
|
34
|
+
def filter(tag, time, record)
|
35
|
+
# This method implements the filtering logic for individual filters
|
36
|
+
# It is internal to this class and called by filter_stream unless
|
37
|
+
# the user overrides filter_stream.
|
38
|
+
#
|
39
|
+
# Since our example is a pass-thru filter, it does nothing and just
|
40
|
+
# returns the record as-is.
|
41
|
+
# If returns nil, that records are ignored.
|
42
|
+
if record[@price_key] && record[@currency_key]
|
43
|
+
price_usd = requestConverter(record[@currency_key], record[@price_key])
|
44
|
+
if price_usd
|
45
|
+
record[@converted_key] = price_usd
|
46
|
+
end
|
47
|
+
end
|
48
|
+
return record
|
49
|
+
end
|
50
|
+
|
51
|
+
def requestConverter(currency, price)
|
52
|
+
begin
|
53
|
+
url = @converter_url
|
54
|
+
url += "?currency="
|
55
|
+
url += currency
|
56
|
+
url += "&base_currency="
|
57
|
+
url += @base_currency
|
58
|
+
url += "&price="
|
59
|
+
url += price.to_s
|
60
|
+
uri = URI(url)
|
61
|
+
response = Net::HTTP.get(uri)
|
62
|
+
return response.to_f
|
63
|
+
rescue Errno::ECONNREFUSED
|
64
|
+
return 0
|
65
|
+
rescue SyntaxError
|
66
|
+
raise
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def testRequest()
|
71
|
+
uri = URI(@converter_url)
|
72
|
+
Net::HTTP.get(uri)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
metadata
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fluent-plugin-currency
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Aleksey Pavlov
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-10-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.15'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.15'
|
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
|
+
description: fluent-plugin-currency
|
42
|
+
email:
|
43
|
+
- pavlov@divo-games.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".gitignore"
|
49
|
+
- Gemfile
|
50
|
+
- README.md
|
51
|
+
- Rakefile
|
52
|
+
- bin/console
|
53
|
+
- bin/setup
|
54
|
+
- fluent-plugin-currency.gemspec
|
55
|
+
- lib/fluent/plugin/currency.rb
|
56
|
+
- lib/fluent/plugin/currency/version.rb
|
57
|
+
- lib/fluent/plugin/filter_currency.rb
|
58
|
+
homepage: https://rubygems.org/gems/fluent-plugin-currency
|
59
|
+
licenses: []
|
60
|
+
metadata:
|
61
|
+
allowed_push_host: https://rubygems.org
|
62
|
+
post_install_message:
|
63
|
+
rdoc_options: []
|
64
|
+
require_paths:
|
65
|
+
- lib
|
66
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
requirements: []
|
77
|
+
rubyforge_project:
|
78
|
+
rubygems_version: 2.6.13
|
79
|
+
signing_key:
|
80
|
+
specification_version: 4
|
81
|
+
summary: fluent-plugin-currency
|
82
|
+
test_files: []
|