eod_data_client 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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 0da35ab665550b45ef0f2e15f8646546a771ff5f06e57305fd8ddd2cd94d9e8e
4
+ data.tar.gz: 8a787344921d862b47d83c0838406e0fc41a2b3ef39f756fba3008cff21138ce
5
+ SHA512:
6
+ metadata.gz: 435f1448ddfa0286b24e20cc0dfb6bb24325c39671a03a19f6934fbab589d8d8434510c1a8d7cfbe24f6f2721a57c57ae3f95be13976b65580cac8edf66bac29
7
+ data.tar.gz: c0fb997bae54b3889d77008296a31b377e6d5cc7215c29a042a9a81c43d82c2dc44f7f755d9b7b2569faa9959385041e4e5a04900105d634a7c1413cd10b8a03
@@ -0,0 +1,55 @@
1
+ version: 2
2
+
3
+ jobs:
4
+ build:
5
+ docker:
6
+ # specify the version you desire here
7
+ - image: circleci/ruby:2.6.3
8
+
9
+ working_directory: ~/eod_data
10
+
11
+ steps:
12
+ - checkout
13
+
14
+ # Download and cache dependencies
15
+ - restore_cache:
16
+ keys:
17
+ - v1-dependencies-{{ checksum "Gemfile.lock" }}
18
+
19
+ - run:
20
+ name: install dependencies
21
+ command: |
22
+ bundle install --jobs=4 --retry=3 --path vendor/bundle
23
+
24
+ - run:
25
+ name: Setup Code Climate test-reporter
26
+ command: |
27
+ curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
28
+ chmod +x ./cc-test-reporter
29
+ - save_cache:
30
+ paths:
31
+ - ./vendor/bundle
32
+ key: v1-dependencies-{{ checksum "Gemfile.lock" }}
33
+
34
+ # run tests!
35
+ - run:
36
+ name: run tests
37
+ command: |
38
+ ./cc-test-reporter before-build
39
+ mkdir /tmp/test-results
40
+ TEST_FILES="$(circleci tests glob "spec/**/*_spec.rb" | circleci tests split --split-by=timings)"
41
+
42
+ bundle exec rspec --format progress \
43
+ --format RspecJunitFormatter \
44
+ --out /tmp/test-results/rspec.xml \
45
+ --format progress \
46
+ -- \
47
+ $TEST_FILES
48
+ ./cc-test-reporter after-build --coverage-input-type simplecov --exit-code $?
49
+
50
+ # collect reports
51
+ - store_test_results:
52
+ path: /tmp/test-results
53
+ - store_artifacts:
54
+ path: /tmp/test-results
55
+ destination: test-results
data/.codeclimate.yml ADDED
@@ -0,0 +1,4 @@
1
+ plugins:
2
+ rubocop:
3
+ enabled: true
4
+ channel: rubocop-0-76
data/.env.sample ADDED
@@ -0,0 +1,3 @@
1
+ EOD_PASSWORD=
2
+ EOD_USERNAME=
3
+ EOD_URL=http://ws.eoddata.com/
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ .env
2
+ /.bundle/
3
+ /.yardoc
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,28 @@
1
+ AllCops:
2
+ Exclude:
3
+ - 'bin/*'
4
+ TargetRubyVersion: 2.5
5
+ Lint/HandleExceptions:
6
+ Exclude:
7
+ - 'Rakefile'
8
+ Metrics/AbcSize:
9
+ Exclude:
10
+ Metrics/BlockLength:
11
+ Exclude:
12
+ - 'eod_data.gemspec'
13
+ - 'spec/**/*'
14
+ Metrics/ClassLength:
15
+ Enabled: true
16
+ Metrics/LineLength:
17
+ Exclude:
18
+ Metrics/MethodLength:
19
+ Exclude:
20
+ Naming/MemoizedInstanceVariableName:
21
+ Exclude:
22
+ Style/AndOr:
23
+ EnforcedStyle: 'conditionals'
24
+ Style/Documentation:
25
+ Exclude:
26
+ - 'spec/**/*'
27
+ Style/SignalException:
28
+ EnforcedStyle: 'semantic'
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-2.6
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at joe@westernmilling.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
6
+
7
+ # Specify your gem's dependencies in eod_data.gemspec
8
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,111 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ eod_data_client (0.1.0)
5
+ dotenv (= 2.7.5)
6
+ gli (= 2.19.0)
7
+ savon (= 2.12.0)
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ addressable (2.7.0)
13
+ public_suffix (>= 2.0.2, < 5.0)
14
+ akami (1.3.1)
15
+ gyoku (>= 0.4.0)
16
+ nokogiri
17
+ ast (2.4.0)
18
+ builder (3.2.4)
19
+ concurrent-ruby (1.1.5)
20
+ crack (0.4.3)
21
+ safe_yaml (~> 1.0.0)
22
+ diff-lcs (1.3)
23
+ docile (1.3.2)
24
+ dotenv (2.7.5)
25
+ faker (2.10.1)
26
+ i18n (>= 1.6, < 2)
27
+ gli (2.19.0)
28
+ gyoku (1.3.1)
29
+ builder (>= 2.1.2)
30
+ hashdiff (1.0.0)
31
+ httpi (2.4.4)
32
+ rack
33
+ socksify
34
+ i18n (1.8.2)
35
+ concurrent-ruby (~> 1.0)
36
+ jaro_winkler (1.5.4)
37
+ json (2.3.0)
38
+ mini_portile2 (2.4.0)
39
+ nokogiri (1.10.7)
40
+ mini_portile2 (~> 2.4.0)
41
+ nori (2.6.0)
42
+ parallel (1.19.1)
43
+ parser (2.7.0.2)
44
+ ast (~> 2.4.0)
45
+ public_suffix (4.0.3)
46
+ rack (2.1.2)
47
+ rainbow (3.0.0)
48
+ rake (10.5.0)
49
+ rspec (3.7.0)
50
+ rspec-core (~> 3.7.0)
51
+ rspec-expectations (~> 3.7.0)
52
+ rspec-mocks (~> 3.7.0)
53
+ rspec-core (3.7.1)
54
+ rspec-support (~> 3.7.0)
55
+ rspec-expectations (3.7.0)
56
+ diff-lcs (>= 1.2.0, < 2.0)
57
+ rspec-support (~> 3.7.0)
58
+ rspec-mocks (3.7.0)
59
+ diff-lcs (>= 1.2.0, < 2.0)
60
+ rspec-support (~> 3.7.0)
61
+ rspec-support (3.7.1)
62
+ rspec_junit_formatter (0.4.1)
63
+ rspec-core (>= 2, < 4, != 2.12.0)
64
+ rubocop (0.76.0)
65
+ jaro_winkler (~> 1.5.1)
66
+ parallel (~> 1.10)
67
+ parser (>= 2.6)
68
+ rainbow (>= 2.2.2, < 4.0)
69
+ ruby-progressbar (~> 1.7)
70
+ unicode-display_width (>= 1.4.0, < 1.7)
71
+ ruby-progressbar (1.10.1)
72
+ safe_yaml (1.0.5)
73
+ savon (2.12.0)
74
+ akami (~> 1.2)
75
+ builder (>= 2.1.2)
76
+ gyoku (~> 1.2)
77
+ httpi (~> 2.3)
78
+ nokogiri (>= 1.8.1)
79
+ nori (~> 2.4)
80
+ wasabi (~> 3.4)
81
+ simplecov (0.17.1)
82
+ docile (~> 1.1)
83
+ json (>= 1.8, < 3)
84
+ simplecov-html (~> 0.10.0)
85
+ simplecov-html (0.10.2)
86
+ socksify (1.7.1)
87
+ unicode-display_width (1.6.1)
88
+ wasabi (3.5.0)
89
+ httpi (~> 2.0)
90
+ nokogiri (>= 1.4.2)
91
+ webmock (3.8.0)
92
+ addressable (>= 2.3.6)
93
+ crack (>= 0.3.2)
94
+ hashdiff (>= 0.4.0, < 2.0.0)
95
+
96
+ PLATFORMS
97
+ ruby
98
+
99
+ DEPENDENCIES
100
+ bundler (~> 1.16)
101
+ eod_data_client!
102
+ faker (= 2.10.1)
103
+ rake (~> 10.0)
104
+ rspec (~> 3.0)
105
+ rspec_junit_formatter (= 0.4.1)
106
+ rubocop (= 0.76.0)
107
+ simplecov (= 0.17.1)
108
+ webmock (= 3.8.0)
109
+
110
+ BUNDLED WITH
111
+ 1.17.3
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020 Western Milling LLC
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 all
13
+ 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 THE
21
+ SOFTWARE.
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Western Milling LLC
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,60 @@
1
+ [![CircleCI](https://circleci.com/gh/westernmilling/eod_data.svg?style=svg&circle-token=a84f70c542ef4cacffe34d412933c62d4a9998b6)](https://circleci.com/gh/westernmilling/eod_data)
2
+ [![Maintainability](https://api.codeclimate.com/v1/badges/c2db47a62be7a8e73282/maintainability)](https://codeclimate.com/github/westernmilling/eod_data/maintainability)
3
+ [![Test Coverage](https://api.codeclimate.com/v1/badges/c2db47a62be7a8e73282/test_coverage)](https://codeclimate.com/github/westernmilling/eod_data/test_coverage)
4
+
5
+ # EODData
6
+ A basic and incomplete Ruby client library for the EODData Web Services.
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem 'eod_data'
14
+ ```
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install eod_data
23
+
24
+ ## Usage
25
+
26
+ ```ruby
27
+ EODData::Client.configure do |config|
28
+ config.symbol_price_uoms = {
29
+ ZC: 'Bushel'
30
+ ZM: 'Ton'
31
+ }
32
+ end
33
+
34
+ client = EODData::Client.new(
35
+ base_url: 'http://ws.eoddata.com/',
36
+ logger: Logger.new(STDOUT),
37
+ password: 'password',
38
+ username: 'username'
39
+ )
40
+
41
+ quote = client.quote('CBOT', 'ZC')
42
+ ```
43
+
44
+ ## Development
45
+
46
+ 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.
47
+
48
+ 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).
49
+
50
+ ## Contributing
51
+
52
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/eod_data. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
53
+
54
+ ## License
55
+
56
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
57
+
58
+ ## Code of Conduct
59
+
60
+ Everyone interacting in the EodData project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/eod_data/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
data/bin/cli ADDED
@@ -0,0 +1,118 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # frozen_string_literal: true
4
+
5
+ require 'dotenv/load'
6
+ require 'gli'
7
+ require 'eod_data/version'
8
+ require 'eod_data/client'
9
+
10
+ module EODData
11
+ class CLI # :nodoc:
12
+ extend GLI::App
13
+
14
+ arguments :strict
15
+ program_desc 'EODData CLI'
16
+ subcommand_option_handling :normal
17
+ version EODData::VERSION
18
+
19
+ desc 'Login to EODData Financial Information Web Service ' \
20
+ 'and return a Login Token.'
21
+ command :token do |cmd|
22
+ cmd.action do
23
+ eod_client = EODData::Client.new
24
+
25
+ EODData::Client.logger.info("Login Token: #{eod_client.token}")
26
+ end
27
+ end
28
+
29
+ desc 'Returns an end of day quote for a specific symbol.'
30
+ arg_name 'exchange'
31
+ arg_name 'symbol'
32
+ command :quote do |cmd|
33
+ cmd.action do |_global_options, _options, args|
34
+ eod_client = EODData::Client.new
35
+
36
+ exchange = args.shift
37
+ symbol = args.shift
38
+
39
+ EODData::Client.logger.info("Exchange: #{exchange}")
40
+ EODData::Client.logger.info("Symbol: #{symbol}")
41
+
42
+ result = eod_client.quote(exchange, symbol)
43
+
44
+ EODData::Client.logger.info("Symbol: #{result.quote.symbol}")
45
+ EODData::Client.logger.info("Close (adjusted): #{result.quote.adjusted_close}")
46
+ EODData::Client.logger.info("Close: #{result.quote.close}")
47
+ end
48
+ end
49
+
50
+ desc 'Returns latest end of day quotes for a list of symbols ' \
51
+ 'of a specific exchange.'
52
+ arg_name 'exchange'
53
+ arg_name 'symbols'
54
+ command :quotes do |cmd|
55
+ cmd.action do |_global_options, _options, args|
56
+ eod_client = EODData::Client.new
57
+
58
+ exchange = args.shift
59
+ symbols = args.shift.split(',')
60
+
61
+ EODData::Client.logger.info("Exchange: #{exchange}")
62
+ EODData::Client.logger.info("Symbols: #{symbols}")
63
+
64
+ result = eod_client.quotes(exchange, symbols)
65
+
66
+ result.quotes.each do |quote|
67
+ EODData::Client.logger.info("Quote: #{quote.symbol} - #{quote.close}")
68
+ end
69
+ end
70
+ end
71
+
72
+ desc 'Returns a complete list of end of day quotes for an ' \
73
+ 'entire exchange and a specific date.'
74
+ arg_name 'exchange'
75
+ arg_name 'quote_date'
76
+ command :quotes_by_date do |cmd|
77
+ cmd.action do |_global_options, _options, args|
78
+ eod_client = EODData::Client.new
79
+ logger = EODData::Client.logger
80
+
81
+ exchange = args.shift
82
+ quote_date = Date.parse(args.shift)
83
+
84
+ logger.info("Exchange: #{exchange}")
85
+ logger.info("Quote Date: #{quote_date}")
86
+
87
+ result = eod_client.quotes_by_date(exchange, quote_date)
88
+
89
+ result.quotes.each do |quote|
90
+ logger.info("Quote: #{quote.symbol} - #{quote.adjusted_close}")
91
+ end
92
+ end
93
+ end
94
+
95
+
96
+ pre do |_global, _command, _options, _args|
97
+ logger = Logger.new(STDOUT)
98
+
99
+ EODData::Client.configure do |config|
100
+ config.base_url = ENV.fetch('EOD_URL')
101
+ config.logger = logger
102
+ config.password = ENV.fetch('EOD_PASSWORD')
103
+ config.request_type = EODData::Client::SavonRequest
104
+ config.symbol_price_uoms = {
105
+ KE: 'Bushel',
106
+ MW: 'Bushel',
107
+ ZC: 'Bushel',
108
+ ZM: 'Ton'
109
+ }
110
+ config.username = ENV.fetch('EOD_USERNAME')
111
+ end
112
+
113
+ true
114
+ end
115
+ end
116
+ end
117
+
118
+ exit EODData::CLI.run(ARGV)
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "eod_data"
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/eod_data.gemspec ADDED
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'eod_data/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'eod_data_client'
9
+ spec.version = EODData::VERSION
10
+ spec.authors = ['Joseph Bridgwater-Rowe']
11
+ spec.email = ['joe@westernmilling.com']
12
+
13
+ spec.summary = 'EODData Web Service Client'
14
+ spec.homepage = 'https://github.com/westernmilling/eod_data'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = 'bin'
21
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
22
+ spec.require_paths = ['lib']
23
+
24
+ spec.add_runtime_dependency 'dotenv', '2.7.5'
25
+ spec.add_runtime_dependency 'gli', '2.19.0'
26
+ spec.add_runtime_dependency 'savon', '2.12.0'
27
+
28
+ spec.add_development_dependency 'bundler', '~> 1.16'
29
+ spec.add_development_dependency 'faker', '2.10.1'
30
+ spec.add_development_dependency 'rake', '~> 10.0'
31
+ spec.add_development_dependency 'rspec', '~> 3.0'
32
+ spec.add_development_dependency 'rspec_junit_formatter', '0.4.1'
33
+ spec.add_development_dependency 'rubocop', '0.76.0'
34
+ spec.add_development_dependency 'simplecov', '0.17.1'
35
+ spec.add_development_dependency 'webmock', '3.8.0'
36
+ end
data/lib/eod_data.rb ADDED
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eod_data/version'
4
+
5
+ module EODData # :nodoc:
6
+ end
@@ -0,0 +1,303 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'savon'
4
+
5
+ module EODData
6
+ class Client # :nodoc:
7
+ class << self
8
+ attr_accessor :base_url,
9
+ :logger,
10
+ :password,
11
+ :proxy_url,
12
+ :request_type,
13
+ :symbol_price_uoms,
14
+ :username
15
+
16
+ # ```ruby
17
+ # EODData::Client.configure do |config|
18
+ # config.base_url = 'http://localhost:3000'
19
+ # config.logger = Logger.new(STDOUT)
20
+ # config.password = 'password'
21
+ # config.symbol_price_uoms = {
22
+ # ZC: 'Bushel'
23
+ # ZM: 'Ton'
24
+ # }
25
+ # config.username = 'username'
26
+ # end
27
+ # ```
28
+ # elsewhere
29
+ #
30
+ # ```ruby
31
+ # client = EODData::Client.new
32
+ # ```
33
+ def configure
34
+ yield self
35
+ true
36
+ end
37
+ end
38
+
39
+ def initialize(options = {})
40
+ options = default_options.merge(options)
41
+
42
+ @base_url = options[:base_url]
43
+ @logger = options.compact.fetch(:logger, Logger.new(STDOUT))
44
+ @proxy_url = options[:proxy_url]
45
+ @password = options[:password]
46
+ @username = options[:username]
47
+ @request = SavonRequest.new(@base_url, @logger, @proxy_url)
48
+ end
49
+
50
+ def login
51
+ message = { Username: @username, Password: @password }
52
+
53
+ response = @request.perform_request(:login, message: message)
54
+
55
+ LoginResponse.new(response).result
56
+ end
57
+
58
+ def quote(exchange, symbol)
59
+ message = { Exchange: exchange, Symbol: symbol, Token: token }
60
+
61
+ response = @request.perform_request(:quote_get, message: message)
62
+
63
+ QuoteGetResponse.new(response).result
64
+ end
65
+
66
+ def quotes(exchange, symbols)
67
+ message = { Exchange: exchange, Symbols: symbols.join(','), Token: token }
68
+
69
+ response = @request.perform_request(:quote_list2, message: message)
70
+
71
+ QuoteList2Response.new(response).result
72
+ end
73
+
74
+ def quotes_by_date(exchange, quote_date)
75
+ message = {
76
+ Exchange: exchange,
77
+ QuoteDate: quote_date.strftime('%Y%m%d'),
78
+ Token: token
79
+ }
80
+
81
+ response = @request.perform_request(:quote_list_by_date, message: message)
82
+
83
+ QuoteListByDateResponse.new(response).result
84
+ end
85
+
86
+ ##
87
+ #
88
+ #
89
+ # @return [String] Login Token
90
+ def token
91
+ return @token if @token
92
+
93
+ @token = login.token
94
+ end
95
+
96
+ protected
97
+
98
+ ##
99
+ # Default options
100
+ # A {Hash} of default options populate by attributes set during
101
+ # configuration.
102
+ #
103
+ # @return [Hash] containing the default options
104
+ def default_options
105
+ {
106
+ base_url: EODData::Client.base_url,
107
+ logger: EODData::Client.logger,
108
+ proxy_url: EODData::Client.proxy_url,
109
+ password: EODData::Client.password,
110
+ username: EODData::Client.username
111
+ }
112
+ end
113
+
114
+ class TonPrice # :nodoc:
115
+ def initialize(price)
116
+ @price = price
117
+ end
118
+
119
+ def call
120
+ @price
121
+ end
122
+ end
123
+
124
+ class BushelPrice # :nodoc:
125
+ def initialize(price)
126
+ @price = price
127
+ end
128
+
129
+ def call
130
+ components = @price.strip.split('.')
131
+ fraction_amount = components[1] || 0
132
+
133
+ "#{components[0]}.#{fraction_amount}".to_f / 100
134
+ end
135
+ end
136
+
137
+ class Response # :nodoc:
138
+ def initialize(response)
139
+ @response = response.body["#{response_name}_response".to_sym]
140
+ end
141
+
142
+ def result
143
+ @result ||= result_class.new(
144
+ @response["#{response_name}_result".to_sym]
145
+ )
146
+ end
147
+
148
+ protected
149
+
150
+ def result_class
151
+ @result_class ||= begin
152
+ result_class_name = self.class.name.sub('Response', 'Result')
153
+
154
+ Object.const_get("EODData::Client::#{result_class_name}")
155
+ end
156
+ end
157
+
158
+ def response_name
159
+ @response_name ||= self
160
+ .class
161
+ .name
162
+ .chomp('Response')
163
+ .split('::')
164
+ .last
165
+ .gsub(/(.)([A-Z])/, '\1_\2')
166
+ .downcase
167
+ end
168
+ end
169
+
170
+ class Result # :nodoc:
171
+ def initialize(response)
172
+ @response = response
173
+ end
174
+
175
+ def data
176
+ @response
177
+ end
178
+
179
+ def data_value
180
+ data["@#{__callee__}".to_sym]
181
+ end
182
+
183
+ def message
184
+ @response[:@message]
185
+ end
186
+
187
+ def result
188
+ @response ? :success : :failure
189
+ end
190
+
191
+ def success?
192
+ result == :success
193
+ end
194
+ end
195
+
196
+ class LoginResponse < Response; end
197
+
198
+ class LoginResult < Result # :nodoc:
199
+ alias token data_value
200
+ end
201
+
202
+ class Quote < OpenStruct # :nodoc:
203
+ def adjusted_price
204
+ price = send(__callee__.to_s.sub('adjusted_', '').to_sym)
205
+
206
+ convert_price(price)
207
+ end
208
+
209
+ alias adjusted_ask adjusted_price
210
+ alias adjusted_change adjusted_price
211
+ alias adjusted_close adjusted_price
212
+ alias adjusted_high adjusted_price
213
+ alias adjusted_low adjusted_price
214
+ alias adjusted_open adjusted_price
215
+ alias adjusted_previous adjusted_price
216
+
217
+ protected
218
+
219
+ def convert_price(price)
220
+ symbol_symbol = symbol[0, 2].to_sym
221
+
222
+ converter_klass = Object.const_get(
223
+ [
224
+ 'EODData::Client',
225
+ "#{EODData::Client.symbol_price_uoms[symbol_symbol]}Price"
226
+ ].join('::')
227
+ )
228
+
229
+ converter_klass.new(price).call
230
+ end
231
+ end
232
+
233
+ class QuoteGetResponse < Response; end
234
+
235
+ class QuoteGetResult < Result # :nodoc:
236
+ def quote
237
+ @quote ||= Quote.new(
238
+ data.transform_keys { |key| key.to_s.sub('@', '') }
239
+ )
240
+ end
241
+
242
+ def data
243
+ @response[:quote]
244
+ end
245
+ end
246
+
247
+ class QuoteList2Response < Response; end
248
+ class QuoteListByDateResponse < Response; end
249
+
250
+ class QuoteList2Result < Result # :nodoc:
251
+ def quotes
252
+ @quotes ||= data.map do |quote_data|
253
+ Quote.new(quote_data.transform_keys { |key| key.to_s.sub('@', '') })
254
+ end
255
+ end
256
+
257
+ protected
258
+
259
+ def data
260
+ return [] if @response.fetch(:quotes, nil).nil?
261
+
262
+ [@response[:quotes][:quote]].flatten
263
+ end
264
+ end
265
+ class QuoteListByDateResult < QuoteList2Result; end
266
+
267
+ class SavonRequest # :nodoc:
268
+ def initialize(base_url, logger, proxy_url = nil)
269
+ @base_url = base_url
270
+ @logger = logger
271
+ @proxy_url = proxy_url
272
+ end
273
+
274
+ def perform_request(name, message)
275
+ @logger.info("SavonRequest#perform_request #{name}, #{message}")
276
+
277
+ response = client.call(name, message)
278
+
279
+ response
280
+ end
281
+
282
+ protected
283
+
284
+ def client
285
+ options = {
286
+ wsdl: wsdl,
287
+ convert_request_keys_to: :none,
288
+ raise_errors: false,
289
+ logger: @logger,
290
+ log: true,
291
+ log_level: :debug
292
+ }
293
+ options = options.merge(proxy: @proxy_url) unless @proxy_url.to_s == ''
294
+
295
+ Savon.client(options)
296
+ end
297
+
298
+ def wsdl
299
+ "#{@base_url}/data.asmx?WSDL"
300
+ end
301
+ end
302
+ end
303
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EODData
4
+ VERSION = '0.1.0'
5
+ end
metadata ADDED
@@ -0,0 +1,221 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: eod_data_client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Joseph Bridgwater-Rowe
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-01-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: dotenv
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '='
18
+ - !ruby/object:Gem::Version
19
+ version: 2.7.5
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: 2.7.5
27
+ - !ruby/object:Gem::Dependency
28
+ name: gli
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '='
32
+ - !ruby/object:Gem::Version
33
+ version: 2.19.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '='
39
+ - !ruby/object:Gem::Version
40
+ version: 2.19.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: savon
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '='
46
+ - !ruby/object:Gem::Version
47
+ version: 2.12.0
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '='
53
+ - !ruby/object:Gem::Version
54
+ version: 2.12.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.16'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.16'
69
+ - !ruby/object:Gem::Dependency
70
+ name: faker
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '='
74
+ - !ruby/object:Gem::Version
75
+ version: 2.10.1
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '='
81
+ - !ruby/object:Gem::Version
82
+ version: 2.10.1
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '10.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '10.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '3.0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '3.0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rspec_junit_formatter
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '='
116
+ - !ruby/object:Gem::Version
117
+ version: 0.4.1
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - '='
123
+ - !ruby/object:Gem::Version
124
+ version: 0.4.1
125
+ - !ruby/object:Gem::Dependency
126
+ name: rubocop
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - '='
130
+ - !ruby/object:Gem::Version
131
+ version: 0.76.0
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - '='
137
+ - !ruby/object:Gem::Version
138
+ version: 0.76.0
139
+ - !ruby/object:Gem::Dependency
140
+ name: simplecov
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - '='
144
+ - !ruby/object:Gem::Version
145
+ version: 0.17.1
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - '='
151
+ - !ruby/object:Gem::Version
152
+ version: 0.17.1
153
+ - !ruby/object:Gem::Dependency
154
+ name: webmock
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - '='
158
+ - !ruby/object:Gem::Version
159
+ version: 3.8.0
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - '='
165
+ - !ruby/object:Gem::Version
166
+ version: 3.8.0
167
+ description:
168
+ email:
169
+ - joe@westernmilling.com
170
+ executables:
171
+ - cli
172
+ - console
173
+ - setup
174
+ extensions: []
175
+ extra_rdoc_files: []
176
+ files:
177
+ - ".circleci/config.yml"
178
+ - ".codeclimate.yml"
179
+ - ".env.sample"
180
+ - ".gitignore"
181
+ - ".rspec"
182
+ - ".rubocop.yml"
183
+ - ".ruby-version"
184
+ - CODE_OF_CONDUCT.md
185
+ - Gemfile
186
+ - Gemfile.lock
187
+ - LICENSE
188
+ - LICENSE.txt
189
+ - README.md
190
+ - Rakefile
191
+ - bin/cli
192
+ - bin/console
193
+ - bin/setup
194
+ - eod_data.gemspec
195
+ - lib/eod_data.rb
196
+ - lib/eod_data/client.rb
197
+ - lib/eod_data/version.rb
198
+ homepage: https://github.com/westernmilling/eod_data
199
+ licenses:
200
+ - MIT
201
+ metadata: {}
202
+ post_install_message:
203
+ rdoc_options: []
204
+ require_paths:
205
+ - lib
206
+ required_ruby_version: !ruby/object:Gem::Requirement
207
+ requirements:
208
+ - - ">="
209
+ - !ruby/object:Gem::Version
210
+ version: '0'
211
+ required_rubygems_version: !ruby/object:Gem::Requirement
212
+ requirements:
213
+ - - ">="
214
+ - !ruby/object:Gem::Version
215
+ version: '0'
216
+ requirements: []
217
+ rubygems_version: 3.0.6
218
+ signing_key:
219
+ specification_version: 4
220
+ summary: EODData Web Service Client
221
+ test_files: []