oil_fetcher 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 +7 -0
- data/.gitignore +2 -0
- data/.rspec +2 -0
- data/.ruby-version +1 -0
- data/Gemfile +11 -0
- data/Gemfile.lock +71 -0
- data/LICENSE.txt +21 -0
- data/README.md +90 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/lib/oil_fetcher/configuration.rb +10 -0
- data/lib/oil_fetcher/fetcher.rb +38 -0
- data/lib/oil_fetcher/oil.rb +12 -0
- data/lib/oil_fetcher/version.rb +3 -0
- data/lib/oil_fetcher.rb +24 -0
- data/oil_fetcher.gemspec +26 -0
- metadata +103 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 7fde0f5e105c424870dbc4eac5c603a807fb2f12
|
4
|
+
data.tar.gz: 50e4cffed73796b2f916ceb573569e19a9002d67
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b6374f30666a0a60d850765694d8e3f0ba7dec0eb2104e6d7ef8952ebbd313d4e60a52ac8d27d4a048794849a3afacce891c5718553e7d9f6457249727cb5032
|
7
|
+
data.tar.gz: a10e42420f35ecce98a6df6fc6a9ed7c5f6a100a6adf161d45961f5be826ce4e351103187e2ba2b0678c1a4aaf28d06c29e131ca34a6dc959f6ae278638067ec
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.2.1
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
oil_fetcher (0.1.0)
|
5
|
+
logging
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
addressable (2.3.8)
|
11
|
+
byebug (4.0.5)
|
12
|
+
columnize (= 0.9.0)
|
13
|
+
coderay (1.1.0)
|
14
|
+
columnize (0.9.0)
|
15
|
+
crack (0.4.2)
|
16
|
+
safe_yaml (~> 1.0.0)
|
17
|
+
diff-lcs (1.2.5)
|
18
|
+
docile (1.1.5)
|
19
|
+
json (1.8.3)
|
20
|
+
little-plugger (1.1.3)
|
21
|
+
logging (2.0.0)
|
22
|
+
little-plugger (~> 1.1)
|
23
|
+
multi_json (~> 1.10)
|
24
|
+
method_source (0.8.2)
|
25
|
+
multi_json (1.11.2)
|
26
|
+
pry (0.10.1)
|
27
|
+
coderay (~> 1.1.0)
|
28
|
+
method_source (~> 0.8.1)
|
29
|
+
slop (~> 3.4)
|
30
|
+
pry-byebug (3.1.0)
|
31
|
+
byebug (~> 4.0)
|
32
|
+
pry (~> 0.10)
|
33
|
+
rake (10.4.2)
|
34
|
+
rspec (3.3.0)
|
35
|
+
rspec-core (~> 3.3.0)
|
36
|
+
rspec-expectations (~> 3.3.0)
|
37
|
+
rspec-mocks (~> 3.3.0)
|
38
|
+
rspec-core (3.3.1)
|
39
|
+
rspec-support (~> 3.3.0)
|
40
|
+
rspec-expectations (3.3.0)
|
41
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
42
|
+
rspec-support (~> 3.3.0)
|
43
|
+
rspec-mocks (3.3.1)
|
44
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
45
|
+
rspec-support (~> 3.3.0)
|
46
|
+
rspec-support (3.3.0)
|
47
|
+
safe_yaml (1.0.4)
|
48
|
+
simplecov (0.10.0)
|
49
|
+
docile (~> 1.1.0)
|
50
|
+
json (~> 1.8)
|
51
|
+
simplecov-html (~> 0.10.0)
|
52
|
+
simplecov-html (0.10.0)
|
53
|
+
slop (3.6.0)
|
54
|
+
webmock (1.21.0)
|
55
|
+
addressable (>= 2.3.6)
|
56
|
+
crack (>= 0.3.2)
|
57
|
+
|
58
|
+
PLATFORMS
|
59
|
+
ruby
|
60
|
+
|
61
|
+
DEPENDENCIES
|
62
|
+
bundler (~> 1.10)
|
63
|
+
oil_fetcher!
|
64
|
+
pry-byebug
|
65
|
+
rake (~> 10.0)
|
66
|
+
rspec
|
67
|
+
simplecov
|
68
|
+
webmock
|
69
|
+
|
70
|
+
BUNDLED WITH
|
71
|
+
1.10.5
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Petrova Y
|
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,90 @@
|
|
1
|
+
# OilFetcher
|
2
|
+
|
3
|
+
Гем тащит цену на нефть [отсюда](https://www.quandl.com/api/v1/datasets/CHRIS/ICE_B1.json?rows=1)
|
4
|
+
|
5
|
+
## Установка
|
6
|
+
|
7
|
+
В Gemfile:
|
8
|
+
|
9
|
+
gem 'oil_fetcher'
|
10
|
+
|
11
|
+
Или вручную:
|
12
|
+
|
13
|
+
$ gem install oil_fetcher
|
14
|
+
|
15
|
+
## Как пользоваться
|
16
|
+
|
17
|
+
OilFetcher.call
|
18
|
+
|
19
|
+
Вернет объект:
|
20
|
+
|
21
|
+
#<OilFetcher::Oil:0x007fd9739de168 @rate=53.47, @date=#<Date: 2015-07-27 ((2457231j,0s,0n),+0s,2299161j)>>
|
22
|
+
|
23
|
+
`@rate` - цена на нефть
|
24
|
+
`@date` - дата
|
25
|
+
|
26
|
+
## Конфигурация
|
27
|
+
|
28
|
+
OilFetcher.configure |config| do
|
29
|
+
config.uri = "www.example.com"
|
30
|
+
config.logger = mylogger
|
31
|
+
end
|
32
|
+
|
33
|
+
Ожидается, что по адресу `uri` будет json вида
|
34
|
+
|
35
|
+
{
|
36
|
+
"errors": {},
|
37
|
+
"id": 11251692,
|
38
|
+
"source_name": "Wiki Continuous Futures",
|
39
|
+
"source_code": "CHRIS",
|
40
|
+
"code": "ICE_B1",
|
41
|
+
"name": "Brent Crude Futures, Continuous Contract #1 (B1) (Front Month)",
|
42
|
+
"urlize_name": "Brent-Crude-Futures-Continuous-Contract-1-B1-Front-Month",
|
43
|
+
"display_url": "http://www.ofdp.org",
|
44
|
+
"description": "Historical Futures Prices: Brent Crude Futures, Continuous Contract #1. Non-adjusted price based on spot-month continuous contract calculations. Raw data from ICE. For more on the roll algorithm used please see this page: https://www.quandl.com/collections/futures/continuous.",
|
45
|
+
"updated_at": "2015-07-28T04:25:51.455Z",
|
46
|
+
"frequency": "daily",
|
47
|
+
"from_date": "1990-08-17",
|
48
|
+
"to_date": "2015-07-27",
|
49
|
+
"column_names": [
|
50
|
+
"Date",
|
51
|
+
"Open",
|
52
|
+
"High",
|
53
|
+
"Low",
|
54
|
+
"Settle",
|
55
|
+
"Change",
|
56
|
+
"Wave",
|
57
|
+
"Volume",
|
58
|
+
"Prev. Day Open Interest",
|
59
|
+
"EFP Volume",
|
60
|
+
"EFS Volume",
|
61
|
+
"Block Volume"
|
62
|
+
],
|
63
|
+
"private": false,
|
64
|
+
"type": null,
|
65
|
+
"premium": false,
|
66
|
+
"data": [
|
67
|
+
[
|
68
|
+
"2015-07-27",
|
69
|
+
54.45,
|
70
|
+
54.89,
|
71
|
+
52.83,
|
72
|
+
53.47,
|
73
|
+
-1.15,
|
74
|
+
53.8,
|
75
|
+
217196,
|
76
|
+
313552,
|
77
|
+
3402,
|
78
|
+
null,
|
79
|
+
5775
|
80
|
+
]
|
81
|
+
]
|
82
|
+
}
|
83
|
+
|
84
|
+
По дефолту `uri = "https://www.quandl.com/api/v1/datasets/CHRIS/ICE_B1.json?rows=1"`.
|
85
|
+
|
86
|
+
|
87
|
+
## License
|
88
|
+
|
89
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
90
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "oil_fetcher"
|
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
|
data/bin/setup
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
module OilFetcher
|
4
|
+
class Fetcher
|
5
|
+
def call
|
6
|
+
json = fetch_json OilFetcher.configuration.uri
|
7
|
+
return unless json
|
8
|
+
|
9
|
+
Oil.new(extract_params(json))
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def fetch_json(uri)
|
15
|
+
uri = URI(uri)
|
16
|
+
file = Net::HTTP.get uri
|
17
|
+
return unless file
|
18
|
+
|
19
|
+
JSON.parse file
|
20
|
+
rescue *exceptions => e
|
21
|
+
OilFetcher.configuration.logger.warn e
|
22
|
+
|
23
|
+
nil
|
24
|
+
end
|
25
|
+
|
26
|
+
def extract_params(json)
|
27
|
+
{
|
28
|
+
rate: json["data"][0][4],
|
29
|
+
date: json["data"][0][0]
|
30
|
+
}
|
31
|
+
end
|
32
|
+
|
33
|
+
def exceptions
|
34
|
+
[Timeout::Error, Errno::EINVAL, Errno::ECONNRESET, Errno::ECONNREFUSED, EOFError,
|
35
|
+
Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError, JSON::ParserError]
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
data/lib/oil_fetcher.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'logging'
|
2
|
+
require 'oil_fetcher/version'
|
3
|
+
require 'oil_fetcher/fetcher'
|
4
|
+
require 'oil_fetcher/oil'
|
5
|
+
require 'oil_fetcher/configuration'
|
6
|
+
|
7
|
+
module OilFetcher
|
8
|
+
class << self
|
9
|
+
attr_writer :configuration
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.configure
|
13
|
+
yield configuration
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.configuration
|
17
|
+
@configuration ||= Configuration.new
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.call
|
21
|
+
fetcher = OilFetcher::Fetcher.new
|
22
|
+
fetcher.call
|
23
|
+
end
|
24
|
+
end
|
data/oil_fetcher.gemspec
ADDED
@@ -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 'oil_fetcher/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "oil_fetcher"
|
8
|
+
spec.version = OilFetcher::VERSION
|
9
|
+
spec.authors = ["Yana Petrova"]
|
10
|
+
spec.email = ["y.petrova@rambler-co.ru"]
|
11
|
+
|
12
|
+
spec.summary = "Fetches oil"
|
13
|
+
spec.description = "Fetches oil"
|
14
|
+
spec.homepage = "http://example.com"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
23
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
24
|
+
|
25
|
+
spec.add_dependency "logging"
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: oil_fetcher
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Yana Petrova
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-08-19 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.10'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.10'
|
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: logging
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: Fetches oil
|
56
|
+
email:
|
57
|
+
- y.petrova@rambler-co.ru
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- ".rspec"
|
64
|
+
- ".ruby-version"
|
65
|
+
- Gemfile
|
66
|
+
- Gemfile.lock
|
67
|
+
- LICENSE.txt
|
68
|
+
- README.md
|
69
|
+
- Rakefile
|
70
|
+
- bin/console
|
71
|
+
- bin/setup
|
72
|
+
- lib/oil_fetcher.rb
|
73
|
+
- lib/oil_fetcher/configuration.rb
|
74
|
+
- lib/oil_fetcher/fetcher.rb
|
75
|
+
- lib/oil_fetcher/oil.rb
|
76
|
+
- lib/oil_fetcher/version.rb
|
77
|
+
- oil_fetcher.gemspec
|
78
|
+
homepage: http://example.com
|
79
|
+
licenses:
|
80
|
+
- MIT
|
81
|
+
metadata: {}
|
82
|
+
post_install_message:
|
83
|
+
rdoc_options: []
|
84
|
+
require_paths:
|
85
|
+
- lib
|
86
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
requirements: []
|
97
|
+
rubyforge_project:
|
98
|
+
rubygems_version: 2.4.5
|
99
|
+
signing_key:
|
100
|
+
specification_version: 4
|
101
|
+
summary: Fetches oil
|
102
|
+
test_files: []
|
103
|
+
has_rdoc:
|