quandl_ruby 0.2.0 → 0.2.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 +4 -4
- data/README.md +14 -14
- data/lib/quandl/base.rb +26 -0
- data/lib/quandl/dataset.rb +2 -24
- data/lib/quandl/favorites.rb +1 -0
- data/lib/quandl/multiset.rb +1 -0
- data/lib/quandl/search.rb +9 -1
- data/lib/quandl/version.rb +1 -1
- data/lib/quandl.rb +14 -2
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: add9b14412c18ff8c852d0515ae35ef0b5444626
|
4
|
+
data.tar.gz: 741d9919e1abb3efc7abd86b78edb5d099ec1f5e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7ee77318c3c234c5e62a788a987312543db2ca7e2f342f1b77eff991f15b727506bfe5fa2713ca5773ecbcfc9b7d9396b1425514698e7260ea9c7586208b4337
|
7
|
+
data.tar.gz: c4e05e82854fab05c0d7dd76e8c6517c9d6d5d58b3ac25614e749bb81317e7f403ac94fdd693a2507eb93b60c67c8d0324956b97115a8270d23eeb9c3b739088
|
data/README.md
CHANGED
@@ -8,7 +8,7 @@ A Ruby wrapper for the Quandl API (www.quandl.com).
|
|
8
8
|
|
9
9
|
Add this line to your application's Gemfile:
|
10
10
|
|
11
|
-
gem '
|
11
|
+
gem 'quandl_ruby'
|
12
12
|
|
13
13
|
And then execute:
|
14
14
|
|
@@ -16,7 +16,11 @@ And then execute:
|
|
16
16
|
|
17
17
|
Or install it yourself as:
|
18
18
|
|
19
|
-
$ gem install
|
19
|
+
$ gem install quandl_ruby
|
20
|
+
|
21
|
+
Then at the beginning of a file:
|
22
|
+
|
23
|
+
require 'quandl_ruby'
|
20
24
|
|
21
25
|
## Usage
|
22
26
|
|
@@ -132,27 +136,23 @@ gdp = Quandl::Dataset.get('FRED/GDP')
|
|
132
136
|
# Example from: http://www.quandl.com/help/api#A-Multiset-Example
|
133
137
|
|
134
138
|
datasets = ['FRED/GDP/1', 'DOE/RWTC/1', 'WIKI/AAPL/4']
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
}
|
140
|
-
comparison = Quandl::Multiset.new(datasets, options)
|
139
|
+
comparison = Quandl::Multiset.get(datasets).
|
140
|
+
collapse(:annual).
|
141
|
+
transform(:rdiff).
|
142
|
+
limit(10)
|
141
143
|
# Unlike the official Quandl REST API, separate source, table, and column numbers
|
142
144
|
# With `/` as opposed to `.` to maintain consistency with Quandl::Dataset
|
143
145
|
```
|
144
146
|
|
145
147
|
### Doing A Search
|
146
148
|
|
149
|
+
Note that Quandl::Search does not have access to the API option-setting methods. Instead, it has #per_page and #page, which correspond with the `per_page` and `page` url parameters of the Quandl API
|
150
|
+
|
147
151
|
```ruby
|
148
152
|
# Get search results for crude oil
|
149
153
|
# Example from: http://www.quandl.com/help/api#Doing-a-Search
|
150
154
|
query = 'crude oil'
|
151
|
-
|
152
|
-
per_page: 50,
|
153
|
-
page: 2
|
154
|
-
}
|
155
|
-
results = Quandl::Search.get(query, options)
|
155
|
+
results = Quandl::Search.get(query).per_page(20).page(4)
|
156
156
|
```
|
157
157
|
|
158
158
|
### Getting Metadata
|
@@ -174,7 +174,7 @@ oil_metadata = Quandl::Metadata.get('NSE/OIL')
|
|
174
174
|
my_favorites = Quandl::Favorites.get
|
175
175
|
|
176
176
|
# Or pass in another API key as the first argument to override your own
|
177
|
-
|
177
|
+
another_guys_favorites = Quandl::Favorites.get('that_guys_api_key')
|
178
178
|
|
179
179
|
# For Brits and Canucks, Quandl::Favorites is aliased as Quandl::Favourites
|
180
180
|
```
|
data/lib/quandl/base.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
module Quandl
|
2
|
+
class Base
|
3
|
+
attr_accessor :query, :options
|
4
|
+
|
5
|
+
def self.get(*params)
|
6
|
+
new(*params)
|
7
|
+
end
|
8
|
+
|
9
|
+
def initialize(query, options = {})
|
10
|
+
@query = query
|
11
|
+
@options = options
|
12
|
+
end
|
13
|
+
|
14
|
+
[:data, :metadata].each do |data|
|
15
|
+
define_method(data) do |bust_cache = false|
|
16
|
+
cache = instance_variable_get "@#{data}"
|
17
|
+
if cache && !bust_cache
|
18
|
+
cache
|
19
|
+
else
|
20
|
+
reload!
|
21
|
+
instance_variable_get "@#{data}"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/lib/quandl/dataset.rb
CHANGED
@@ -1,30 +1,7 @@
|
|
1
1
|
module Quandl
|
2
|
-
class Dataset
|
3
|
-
attr_accessor :query, :options
|
4
|
-
|
2
|
+
class Dataset < Quandl::Base
|
5
3
|
include Quandl::Filter
|
6
4
|
|
7
|
-
def self.get(*params)
|
8
|
-
new(*params)
|
9
|
-
end
|
10
|
-
|
11
|
-
def initialize(query, options = {})
|
12
|
-
@query = query
|
13
|
-
@options = options
|
14
|
-
end
|
15
|
-
|
16
|
-
[:data, :metadata].each do |data|
|
17
|
-
define_method(data) do |bust_cache = false|
|
18
|
-
cache = instance_variable_get "@#{data}"
|
19
|
-
if cache && !bust_cache
|
20
|
-
cache
|
21
|
-
else
|
22
|
-
reload!
|
23
|
-
instance_variable_get "@#{data}"
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
5
|
def reload!
|
29
6
|
raw_data = Quandl::Request.new('datasets', {
|
30
7
|
dataset: query,
|
@@ -33,6 +10,7 @@ module Quandl
|
|
33
10
|
response = Quandl.parse(raw_data, (options[:format] || :json).to_sym)
|
34
11
|
@data = response.delete(:data)
|
35
12
|
@metadata = response
|
13
|
+
self
|
36
14
|
end
|
37
15
|
end
|
38
16
|
end
|
data/lib/quandl/favorites.rb
CHANGED
data/lib/quandl/multiset.rb
CHANGED
data/lib/quandl/search.rb
CHANGED
@@ -1,5 +1,12 @@
|
|
1
1
|
module Quandl
|
2
|
-
class Search < Quandl::
|
2
|
+
class Search < Quandl::Base
|
3
|
+
[:page, :per_page].each do |filter|
|
4
|
+
define_method(filter) do |n|
|
5
|
+
@options[filter] = n.to_i
|
6
|
+
self
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
3
10
|
def reload!
|
4
11
|
raw_data = Quandl::Request.new('datasets', {
|
5
12
|
query: query,
|
@@ -8,6 +15,7 @@ module Quandl
|
|
8
15
|
response = Quandl.parse(raw_data, (options[:format] || :json).to_sym)
|
9
16
|
@data = response.delete(:data)
|
10
17
|
@metadata = response
|
18
|
+
self
|
11
19
|
end
|
12
20
|
end
|
13
21
|
end
|
data/lib/quandl/version.rb
CHANGED
data/lib/quandl.rb
CHANGED
@@ -1,10 +1,22 @@
|
|
1
|
+
# The version
|
1
2
|
require_relative 'quandl/version'
|
3
|
+
|
4
|
+
# Configuration
|
2
5
|
require_relative 'quandl/configuration'
|
3
|
-
|
6
|
+
|
7
|
+
# Modules
|
4
8
|
require_relative 'quandl/filter'
|
9
|
+
|
10
|
+
# Module methods
|
11
|
+
require_relative 'quandl/parse'
|
12
|
+
|
13
|
+
# Base classes
|
14
|
+
require_relative 'quandl/base'
|
15
|
+
require_relative 'quandl/request'
|
16
|
+
|
17
|
+
# API classes
|
5
18
|
require_relative 'quandl/dataset'
|
6
19
|
require_relative 'quandl/metadata'
|
7
20
|
require_relative 'quandl/multiset'
|
8
21
|
require_relative 'quandl/search'
|
9
22
|
require_relative 'quandl/favorites'
|
10
|
-
require_relative 'quandl/request'
|
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.2.
|
4
|
+
version: 0.2.1
|
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-
|
11
|
+
date: 2014-11-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -51,6 +51,7 @@ files:
|
|
51
51
|
- README.md
|
52
52
|
- Rakefile
|
53
53
|
- lib/quandl.rb
|
54
|
+
- lib/quandl/base.rb
|
54
55
|
- lib/quandl/configuration.rb
|
55
56
|
- lib/quandl/dataset.rb
|
56
57
|
- lib/quandl/favorites.rb
|