quandl_ruby 0.0.1 → 0.0.3
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 +4 -4
- data/README.md +40 -18
- data/lib/quandl/configuration.rb +30 -0
- data/lib/quandl/dataset.rb +34 -0
- data/lib/quandl/favorites.rb +34 -0
- data/lib/quandl/metadata.rb +8 -0
- data/lib/quandl/multiset.rb +34 -0
- data/lib/quandl/request.rb +35 -0
- data/lib/quandl/search.rb +34 -0
- data/lib/quandl/version.rb +1 -1
- data/lib/quandl.rb +8 -102
- metadata +9 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6c2169fcb001f481bf93cdbb46ee7a9bc8e34513
|
4
|
+
data.tar.gz: 635b03bfe0a03217d23f6dcd86bdf6ecffc37fae
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8e70f2a1c36677ecd9c19a4fe22f4d59e8e94e115d9f94099afa76a0b69fcc6fcbee2bb046b6629783edeae3311816b9873bcf161190b3ad10b147bcf188a61b
|
7
|
+
data.tar.gz: e9d86debe8f31abf4f9f0decdb7e44b6a78881c5fefb96cb91011b2aa2cb673255922a2f93af1b3c5bced15c055892d227739d3a87c21229d74ff5d91a003fc8
|
data/README.md
CHANGED
@@ -2,8 +2,13 @@
|
|
2
2
|
|
3
3
|
Ruby wrapper for the Quandl API (www.quandle.com).
|
4
4
|
|
5
|
-
|
6
|
-
|
5
|
+
Supports:
|
6
|
+
|
7
|
+
- Datasets
|
8
|
+
- Metadata
|
9
|
+
- Multisets
|
10
|
+
- Searches
|
11
|
+
- Favorites
|
7
12
|
|
8
13
|
## Installation
|
9
14
|
|
@@ -27,7 +32,7 @@ If you've got a Quandl API key, configure the Ruby API as below. If not, skip th
|
|
27
32
|
|
28
33
|
```ruby
|
29
34
|
Quandl.configure do |config|
|
30
|
-
config.auth_token =
|
35
|
+
config.auth_token = 'your auth token here'
|
31
36
|
end
|
32
37
|
```
|
33
38
|
|
@@ -36,22 +41,17 @@ end
|
|
36
41
|
To get a dataset, create a new `Quandl::Dataset`:
|
37
42
|
|
38
43
|
```ruby
|
39
|
-
gdp = Quandl::Dataset.
|
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
|
44
|
+
gdp = Quandl::Dataset.get('FRED/GDP')
|
49
45
|
```
|
50
46
|
|
51
47
|
`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
48
|
|
53
49
|
```ruby
|
54
|
-
aapl = Quandl::Dataset.
|
50
|
+
aapl = Quandl::Dataset.get('WIKI/AAPL', {
|
51
|
+
format: 'csv',
|
52
|
+
column: 4,
|
53
|
+
collapse: 'annual'
|
54
|
+
})
|
55
55
|
```
|
56
56
|
|
57
57
|
|
@@ -60,20 +60,42 @@ aapl = Quandl::Dataset.new('WIKI/AAPL', { format: 'csv', column: 4, collapse: 'a
|
|
60
60
|
The `Quandl::Metadata` API is exactly the same as the `Quandl::Dataset` API, except that it only returns metadata.
|
61
61
|
|
62
62
|
```ruby
|
63
|
-
oil = Quandl::Metadata.
|
63
|
+
oil = Quandl::Metadata.get('NSE/OIL')
|
64
|
+
```
|
65
|
+
|
66
|
+
|
67
|
+
### Using Multisets
|
68
|
+
|
69
|
+
The `Quandl::Multiset` class allows you to build multisets for yourself. Accepts `options` hash as a secondary argument to the initializer.
|
64
70
|
|
65
|
-
|
71
|
+
```ruby
|
72
|
+
example = Quandl::Multiset.get(['FRED/GDP/1', 'WIKI/AAPL/4'])
|
66
73
|
```
|
67
74
|
|
75
|
+
Unlike the official Quandl API, use `/` (instead of `.`) as your delimiter for source, table, and column number to maintain consistency with `Quandl::Dataset`.
|
76
|
+
|
68
77
|
|
69
78
|
### Searching Quandl
|
70
79
|
|
71
80
|
The `Quandl::Search` API is exactly the same as the `Quandl::Dataset` API, except that it returns a query.
|
72
81
|
|
73
82
|
```ruby
|
74
|
-
results = Quandl::Search.
|
83
|
+
results = Quandl::Search.get('crude oil')
|
84
|
+
```
|
85
|
+
|
86
|
+
|
87
|
+
### Retrieving Favorites
|
88
|
+
|
89
|
+
The `Quandl::Favorites` API allows you to retrieve the favorites of any user.
|
90
|
+
|
91
|
+
```ruby
|
92
|
+
# If an authorization token was previously configured with Quandl.configure,
|
93
|
+
# then one is not required for Quandl::Favorites.get
|
75
94
|
|
76
|
-
|
95
|
+
favs = Quandl::Favorites.get(
|
96
|
+
:auth_token => 'an auth token here'
|
97
|
+
# Any other options here
|
98
|
+
)
|
77
99
|
```
|
78
100
|
|
79
101
|
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Quandl
|
2
|
+
class << self
|
3
|
+
attr_accessor :configuration
|
4
|
+
end
|
5
|
+
|
6
|
+
def self.configuration
|
7
|
+
@configuration ||= Configuration.new
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.reset
|
11
|
+
@configuration = Configuration.new
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.configure
|
15
|
+
yield configuration
|
16
|
+
end
|
17
|
+
|
18
|
+
class Configuration
|
19
|
+
attr_writer :api_version
|
20
|
+
attr_accessor :auth_token
|
21
|
+
|
22
|
+
def initialize
|
23
|
+
self.api_version = 1
|
24
|
+
end
|
25
|
+
|
26
|
+
def api_version
|
27
|
+
"v#{@api_version}"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Quandl
|
2
|
+
class Dataset
|
3
|
+
attr_accessor :set, :options, :data
|
4
|
+
|
5
|
+
def self.get(params, options = {})
|
6
|
+
instance = new(params, options)
|
7
|
+
instance.get
|
8
|
+
if block_given?
|
9
|
+
yield(data)
|
10
|
+
else
|
11
|
+
data
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def initialize(params, options = {})
|
16
|
+
@set = params
|
17
|
+
@options = options
|
18
|
+
end
|
19
|
+
|
20
|
+
def get(reload = false)
|
21
|
+
if !data || reload
|
22
|
+
self.data = Quandl::Request.new('datasets', {
|
23
|
+
dataset: set,
|
24
|
+
options: options
|
25
|
+
}).get
|
26
|
+
end
|
27
|
+
if block_given?
|
28
|
+
yield(data)
|
29
|
+
else
|
30
|
+
data
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Quandl
|
2
|
+
class Favorites
|
3
|
+
attr_reader :auth_token, :options, :data
|
4
|
+
|
5
|
+
def self.get(options = {})
|
6
|
+
instance = new(options)
|
7
|
+
instance.get
|
8
|
+
if block_given?
|
9
|
+
yield(instance.data)
|
10
|
+
else
|
11
|
+
instance.data
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def initialize(options = {})
|
16
|
+
@auth_token = options.delete(:auth_token) || Quandl.configuration.auth_token
|
17
|
+
@options = options
|
18
|
+
end
|
19
|
+
|
20
|
+
def get(reload = false)
|
21
|
+
if !data || reload
|
22
|
+
self.data = Quandl::Request.new('current_user/collections/datasets/favourites', {
|
23
|
+
options: options,
|
24
|
+
auth_token: auth_token
|
25
|
+
}).get
|
26
|
+
end
|
27
|
+
if block_given?
|
28
|
+
yield(data)
|
29
|
+
else
|
30
|
+
data
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Quandl
|
2
|
+
class Multiset
|
3
|
+
attr_accessor :sets, :options, :data
|
4
|
+
|
5
|
+
def self.get(datasets, options = {})
|
6
|
+
instance = new(datasets, options)
|
7
|
+
instance.get
|
8
|
+
if block_given?
|
9
|
+
yield(instance.data)
|
10
|
+
else
|
11
|
+
instance.data
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def initialize(datasets, options = {})
|
16
|
+
@sets = datasets
|
17
|
+
@options = options
|
18
|
+
end
|
19
|
+
|
20
|
+
def get
|
21
|
+
if !data || reload
|
22
|
+
self.data = Quandl::Request.new('multisets', {
|
23
|
+
datasets: sets,
|
24
|
+
options: options
|
25
|
+
}).get
|
26
|
+
end
|
27
|
+
if block_given?
|
28
|
+
yield(data)
|
29
|
+
else
|
30
|
+
data
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Quandl
|
2
|
+
API_URI = 'http://www.quandl.com/api/'
|
3
|
+
|
4
|
+
class Request
|
5
|
+
attr_accessor :uri
|
6
|
+
|
7
|
+
def initialize(base, params)
|
8
|
+
path = [Quandl.configuration.api_version, base]
|
9
|
+
if Quandl.configuration.auth_token
|
10
|
+
params[:auth_token] = Quandl.configuration.auth_token
|
11
|
+
end
|
12
|
+
[:source, :table].each do |param|
|
13
|
+
path << params[param] if params[param]
|
14
|
+
end
|
15
|
+
if params[:query]
|
16
|
+
params[:options][:query] = params[:query]
|
17
|
+
end
|
18
|
+
path = path.join('/')
|
19
|
+
if params[:datasets]
|
20
|
+
params[:options][:columns] = params[:datasets].map { |set| set.split('/').join('.') }
|
21
|
+
end
|
22
|
+
if params[:dataset]
|
23
|
+
path += "/#{params[:dataset]}"
|
24
|
+
end
|
25
|
+
path += '.' + ((params[:options] || {}).delete(:format) || 'json')
|
26
|
+
@uri = URI(API_URI + path).tap do |uri|
|
27
|
+
uri.query = URI.encode_www_form(params[:options])
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def get
|
32
|
+
open(uri).read
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Quandl
|
2
|
+
class Search
|
3
|
+
attr_accessor :query, :options, :data
|
4
|
+
|
5
|
+
def self.get(query, options = {})
|
6
|
+
instance = new(query, options)
|
7
|
+
instance.get
|
8
|
+
if block_given?
|
9
|
+
yield(instance.data)
|
10
|
+
else
|
11
|
+
data
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def initialize(query, options = {})
|
16
|
+
@query = query
|
17
|
+
@options = options
|
18
|
+
end
|
19
|
+
|
20
|
+
def get
|
21
|
+
if !data || reload
|
22
|
+
self.data = Quandl::Request.new('datasets', {
|
23
|
+
query: query,
|
24
|
+
options: options
|
25
|
+
}).get
|
26
|
+
end
|
27
|
+
if block_given?
|
28
|
+
yield(data)
|
29
|
+
else
|
30
|
+
data
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/lib/quandl/version.rb
CHANGED
data/lib/quandl.rb
CHANGED
@@ -1,103 +1,9 @@
|
|
1
|
-
|
1
|
+
require_relative 'quandl/version'
|
2
|
+
require_relative 'quandl/configuration'
|
3
|
+
require_relative 'quandl/dataset'
|
4
|
+
require_relative 'quandl/metadata'
|
5
|
+
require_relative 'quandl/multiset'
|
6
|
+
require_relative 'quandl/search'
|
7
|
+
require_relative 'quandl/favorites'
|
8
|
+
require_relative 'quandl/request'
|
2
9
|
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
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: quandl_ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kash Nouroozi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-08-
|
11
|
+
date: 2014-08-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -51,6 +51,13 @@ files:
|
|
51
51
|
- README.md
|
52
52
|
- Rakefile
|
53
53
|
- lib/quandl.rb
|
54
|
+
- lib/quandl/configuration.rb
|
55
|
+
- lib/quandl/dataset.rb
|
56
|
+
- lib/quandl/favorites.rb
|
57
|
+
- lib/quandl/metadata.rb
|
58
|
+
- lib/quandl/multiset.rb
|
59
|
+
- lib/quandl/request.rb
|
60
|
+
- lib/quandl/search.rb
|
54
61
|
- lib/quandl/version.rb
|
55
62
|
- quandl.gemspec
|
56
63
|
homepage: https://github.com/knrz/Quandl-Ruby
|