quandl_ruby 0.0.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 +7 -0
- data/.gitignore +22 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +86 -0
- data/Rakefile +2 -0
- data/lib/quandl/version.rb +3 -0
- data/lib/quandl.rb +103 -0
- data/quandl.gemspec +23 -0
- metadata +80 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 0d2f779e7506690aabe6a2d8ed1885c7218673ac
|
4
|
+
data.tar.gz: 5331b314fe42c0546c26aa5da69916ff230f04f8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c4b1a2c92022343fe9e74ebbae78b1f4ab6aa3471288a4138c9deb7d30523ee375ce7ecad685cdbbe27c9c95d950a859de58b429560f8fb635df87e827c1c5f9
|
7
|
+
data.tar.gz: 04543fe4e82e5e527114ea4f66c6e89ba3dcb0b1dc826760d8c008fbcb12d203f428886c1f4df3103bc58ee8a92588250af25befad847c1a682525962ace1d2f
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Kash Nouroozi
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
# Quandl
|
2
|
+
|
3
|
+
Ruby wrapper for the Quandl API (www.quandle.com).
|
4
|
+
|
5
|
+
Currently supports Datasets, Metadata, and Searches.
|
6
|
+
Coming soon: Multisets and Favorites.
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add this line to your application's Gemfile:
|
11
|
+
|
12
|
+
gem 'quandl'
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install quandl
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
### Configuration
|
25
|
+
|
26
|
+
If you've got a Quandl API key, configure the Ruby API as below. If not, skip this step.
|
27
|
+
|
28
|
+
```ruby
|
29
|
+
Quandl.configure do |config|
|
30
|
+
config.auth_token = (your api key)
|
31
|
+
end
|
32
|
+
```
|
33
|
+
|
34
|
+
### Getting A Dataset
|
35
|
+
|
36
|
+
To get a dataset, create a new `Quandl::Dataset`:
|
37
|
+
|
38
|
+
```ruby
|
39
|
+
gdp = Quandl::Dataset.new('FRED/GDP')
|
40
|
+
|
41
|
+
# To pass the data to a block provide a block to Quandl::Dataset#get,
|
42
|
+
# which will otherwise return the Quandl data
|
43
|
+
# Both of the following present the same data:
|
44
|
+
gdp.get do |data|
|
45
|
+
# Do stuff with the data, by default in JSON format
|
46
|
+
end
|
47
|
+
|
48
|
+
data = gdp.get
|
49
|
+
```
|
50
|
+
|
51
|
+
`Quandl::Dataset#new` accepts an options hash as a second argument. Put anything that you would otherwise but as an argument in the url here.
|
52
|
+
|
53
|
+
```ruby
|
54
|
+
aapl = Quandl::Dataset.new('WIKI/AAPL', { format: 'csv', column: 4, collapse: 'annual' })
|
55
|
+
```
|
56
|
+
|
57
|
+
|
58
|
+
### Getting Metadata
|
59
|
+
|
60
|
+
The `Quandl::Metadata` API is exactly the same as the `Quandl::Dataset` API, except that it only returns metadata.
|
61
|
+
|
62
|
+
```ruby
|
63
|
+
oil = Quandl::Metadata.new('NSE/OIL')
|
64
|
+
|
65
|
+
oil.get # => returns metadata for 'NSE/OIL'
|
66
|
+
```
|
67
|
+
|
68
|
+
|
69
|
+
### Searching Quandl
|
70
|
+
|
71
|
+
The `Quandl::Search` API is exactly the same as the `Quandl::Dataset` API, except that it returns a query.
|
72
|
+
|
73
|
+
```ruby
|
74
|
+
results = Quandl::Search.new('crude oil')
|
75
|
+
|
76
|
+
results.get # => returns search results for 'crude oil'
|
77
|
+
```
|
78
|
+
|
79
|
+
|
80
|
+
## Contributing
|
81
|
+
|
82
|
+
1. [Fork it](https://github.com/knrz/quandl/fork)
|
83
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
84
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
85
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
86
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/lib/quandl.rb
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
require 'quandl/version'
|
2
|
+
require 'open-uri'
|
3
|
+
|
4
|
+
module Quandl
|
5
|
+
API_URI = 'http://www.quandl.com/api/'
|
6
|
+
|
7
|
+
class << self
|
8
|
+
attr_accessor :configuration
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.configuration
|
12
|
+
@configuration ||= Configuration.new
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.reset
|
16
|
+
@configuration = Configuration.new
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.configure
|
20
|
+
yield configuration
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.build_uri(params)
|
24
|
+
path = [configuration.api_version, 'datasets']
|
25
|
+
if configuration.auth_token
|
26
|
+
params[:auth_token] = configuration.auth_token
|
27
|
+
end
|
28
|
+
unless params[:query]
|
29
|
+
path << params.delete(:source)
|
30
|
+
path << params.delete(:table)
|
31
|
+
end
|
32
|
+
path = path.join('/') + '.' + (params[:options][:format] || 'json')
|
33
|
+
URI(API_URI + path).tap do |uri|
|
34
|
+
uri.query = URI.encode_www_form(params[:options])
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.get(params = {})
|
39
|
+
open(build_uri(params)).read
|
40
|
+
end
|
41
|
+
|
42
|
+
class Configuration
|
43
|
+
attr_writer :api_version
|
44
|
+
attr_accessor :auth_token
|
45
|
+
|
46
|
+
def initialize
|
47
|
+
self.api_version = 1
|
48
|
+
end
|
49
|
+
|
50
|
+
def api_version
|
51
|
+
"v#{@api_version}"
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
class Dataset
|
56
|
+
attr_accessor :source, :table, :options
|
57
|
+
def initialize(params = {}, options = {})
|
58
|
+
if params.is_a? String
|
59
|
+
match_data = params.match(/(.+)\/(.+)/)
|
60
|
+
params = {
|
61
|
+
source: match_data[1],
|
62
|
+
table: match_data[2]
|
63
|
+
}
|
64
|
+
end
|
65
|
+
@source = params[:source].upcase
|
66
|
+
@table = params[:table].upcase
|
67
|
+
@options = options
|
68
|
+
end
|
69
|
+
|
70
|
+
def get
|
71
|
+
data = Quandl.get(source: source, table: table, options: options)
|
72
|
+
if block_given?
|
73
|
+
yield(data)
|
74
|
+
else
|
75
|
+
data
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
class Metadata < Dataset
|
81
|
+
def initialize(params = {}, options = {})
|
82
|
+
options[:exclude_data] = true
|
83
|
+
super
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
class Search
|
88
|
+
attr_accessor :query, :options
|
89
|
+
def initialize(query, options = {})
|
90
|
+
@query = query
|
91
|
+
@options = options
|
92
|
+
end
|
93
|
+
|
94
|
+
def get
|
95
|
+
data = Quandl.get(query: query, options: options)
|
96
|
+
if block_given?
|
97
|
+
yield(data)
|
98
|
+
else
|
99
|
+
data
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
data/quandl.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'quandl/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'quandl_ruby'
|
8
|
+
spec.version = Quandl::VERSION
|
9
|
+
spec.authors = ['Kash Nouroozi']
|
10
|
+
spec.email = ['hi@knrz.co']
|
11
|
+
spec.summary = %q{Ruby wrapper for the Quandl API (www.quandle.com)}
|
12
|
+
spec.description = ''
|
13
|
+
spec.homepage = 'https://github.com/knrz/Quandl-Ruby'
|
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_development_dependency 'bundler', '~> 1.6'
|
22
|
+
spec.add_development_dependency 'rake', '~> 10.3'
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: quandl_ruby
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Kash Nouroozi
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-08-18 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.6'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
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.3'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.3'
|
41
|
+
description: ''
|
42
|
+
email:
|
43
|
+
- hi@knrz.co
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".gitignore"
|
49
|
+
- Gemfile
|
50
|
+
- LICENSE.txt
|
51
|
+
- README.md
|
52
|
+
- Rakefile
|
53
|
+
- lib/quandl.rb
|
54
|
+
- lib/quandl/version.rb
|
55
|
+
- quandl.gemspec
|
56
|
+
homepage: https://github.com/knrz/Quandl-Ruby
|
57
|
+
licenses:
|
58
|
+
- MIT
|
59
|
+
metadata: {}
|
60
|
+
post_install_message:
|
61
|
+
rdoc_options: []
|
62
|
+
require_paths:
|
63
|
+
- lib
|
64
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '0'
|
74
|
+
requirements: []
|
75
|
+
rubyforge_project:
|
76
|
+
rubygems_version: 2.2.2
|
77
|
+
signing_key:
|
78
|
+
specification_version: 4
|
79
|
+
summary: Ruby wrapper for the Quandl API (www.quandle.com)
|
80
|
+
test_files: []
|