quandl_ruby 0.0.3 → 0.1.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 +84 -45
- data/Rakefile +0 -1
- data/lib/quandl/dataset.rb +4 -3
- data/lib/quandl/favorites.rb +4 -1
- data/lib/quandl/multiset.rb +2 -1
- data/lib/quandl/parse.rb +25 -0
- data/lib/quandl/request.rb +3 -1
- data/lib/quandl/search.rb +3 -2
- data/lib/quandl/version.rb +1 -1
- data/lib/quandl.rb +1 -1
- 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: 9275405a269d7f57d7b7f64d5dd6ace2c0ceb352
|
4
|
+
data.tar.gz: b284408ee8bc65da6d986ec06dcf8d65184196ba
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 23695cec4f2250f0087b07b4571ca9cbfec10a4972b76f0196c9c9ba5b357d69951e139d32fd2f7cb13a0615fafcaa471dfaf5cdd8e96d12fb217faa19f2219a
|
7
|
+
data.tar.gz: c4b87f47728e8c1152f13c8b625381d4044484f3b9f8d57e45c288d942575edc225b8838102c88b92ebab1228e90acb16cad3e73ecfcf1b0769e5fd14b3d9246
|
data/README.md
CHANGED
@@ -1,14 +1,8 @@
|
|
1
|
-
|
1
|
+
[](http://badge.fury.io/rb/quandl_ruby)
|
2
2
|
|
3
|
-
|
3
|
+
# Quandl Ruby
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
- Datasets
|
8
|
-
- Metadata
|
9
|
-
- Multisets
|
10
|
-
- Searches
|
11
|
-
- Favorites
|
5
|
+
A Ruby wrapper for the Quandl API (www.quandl.com).
|
12
6
|
|
13
7
|
## Installation
|
14
8
|
|
@@ -26,79 +20,124 @@ Or install it yourself as:
|
|
26
20
|
|
27
21
|
## Usage
|
28
22
|
|
29
|
-
###
|
23
|
+
### Getting Started
|
30
24
|
|
31
|
-
If you've got
|
25
|
+
If you've got an API key from Quandl, set it up as below. Feel free to otherwise skip this step.
|
32
26
|
|
33
27
|
```ruby
|
34
28
|
Quandl.configure do |config|
|
35
|
-
config.auth_token = 'your
|
29
|
+
config.auth_token = 'your quandl api key'
|
36
30
|
end
|
37
31
|
```
|
38
32
|
|
39
|
-
###
|
33
|
+
### The API
|
40
34
|
|
41
|
-
|
35
|
+
This library includes the following classes all namespaced under the `Quandl` module:
|
42
36
|
|
43
|
-
|
44
|
-
|
45
|
-
|
37
|
+
- [Dataset](http://www.quandl.com/help/api#A-Simple-Example)
|
38
|
+
- [Multiset](http://www.quandl.com/help/api#Multiple-Datasets)
|
39
|
+
- [Search](http://www.quandl.com/help/api#Doing-a-Search)
|
40
|
+
- [Metadata](http://www.quandl.com/help/api#Getting-Metadata)
|
41
|
+
- [Favorites](http://www.quandl.com/help/api#Getting-Favourites)
|
46
42
|
|
47
|
-
|
43
|
+
All the above classes have the same API:
|
48
44
|
|
49
45
|
```ruby
|
50
|
-
|
51
|
-
format: 'csv',
|
52
|
-
column: 4,
|
53
|
-
collapse: 'annual'
|
54
|
-
})
|
55
|
-
```
|
46
|
+
# Replace `Class` below with the relevant class from above.
|
56
47
|
|
48
|
+
# Query is the specific query for that class
|
49
|
+
# Options is an options hash containing data manipulation options
|
57
50
|
|
58
|
-
|
51
|
+
# Data manipulation docs:
|
52
|
+
# http://www.quandl.com/help/api#Data-Manipulation
|
59
53
|
|
60
|
-
|
54
|
+
# Creating an instance doesn't retrieve the data
|
55
|
+
# Data format options:
|
56
|
+
# `:json` => parsed JSON (default)
|
57
|
+
# `:csv` => parsed CSV into hashes
|
58
|
+
# `:xml` => a string of unparsed xml
|
59
|
+
# Set the format by providing a `:format` key in the options hash
|
60
|
+
query = Quandl::Class.new(query, options)
|
61
61
|
|
62
|
-
|
63
|
-
|
64
|
-
```
|
62
|
+
# Use instance#get to retrieve data from Quandl
|
63
|
+
data = query.get
|
65
64
|
|
65
|
+
# Instantiating and then calling the `get` method memoizes the response
|
66
|
+
# Pass in `true` to instance#get to clear the cache and reload the data
|
67
|
+
data = query.get(true)
|
66
68
|
|
67
|
-
|
69
|
+
# The following is a shortcut to Class.new(query, options).get,
|
70
|
+
# albeit with no build-in memoization:
|
71
|
+
data = Quandl::Class.get(query, options)
|
72
|
+
```
|
68
73
|
|
69
|
-
|
74
|
+
### A Simple Example
|
70
75
|
|
71
76
|
```ruby
|
72
|
-
|
77
|
+
# Get the US GDP in JSON
|
78
|
+
# Example from: http://www.quandl.com/help/api#A-Simple-Example
|
79
|
+
gdp = Quandl::Dataset.get('FRED/GDP')
|
73
80
|
```
|
74
81
|
|
75
|
-
|
82
|
+
### A Multiset Example
|
83
|
+
```ruby
|
84
|
+
# Annual percentage changes of US GDP, crude oil prices, and Apple stock for the last 10 years
|
85
|
+
# Example from: http://www.quandl.com/help/api#A-Multiset-Example
|
86
|
+
|
87
|
+
datasets = ['FRED/GDP/1', 'DOE/RWTC/1', 'WIKI/AAPL/4']
|
88
|
+
options = {
|
89
|
+
collapse: 'annual',
|
90
|
+
transformation: 'rdiff',
|
91
|
+
rows: 10
|
92
|
+
}
|
93
|
+
comparison = Quandl::Multiset.new(datasets, options)
|
94
|
+
# Unlike the official Quandl REST API, separate source, table, and column numbers
|
95
|
+
# With `/` as opposed to `.` to maintain consistency with Quandl::Dataset
|
96
|
+
```
|
76
97
|
|
98
|
+
### Doing A Search
|
77
99
|
|
78
|
-
|
100
|
+
```ruby
|
101
|
+
# Get search results for crude oil
|
102
|
+
# Example from: http://www.quandl.com/help/api#Doing-a-Search
|
103
|
+
query = 'crude oil'
|
104
|
+
options = {
|
105
|
+
per_page: 50,
|
106
|
+
page: 2
|
107
|
+
}
|
108
|
+
results = Quandl::Search.get(query, options)
|
109
|
+
```
|
79
110
|
|
80
|
-
|
111
|
+
### Getting Metadata
|
81
112
|
|
82
113
|
```ruby
|
83
|
-
|
114
|
+
# Retrieve only the metadata for a dataset
|
115
|
+
# Example from: http://www.quandl.com/help/api#Getting-Metadata
|
116
|
+
oil_metadata = Quandl::Metadata.get('NSE/OIL')
|
84
117
|
```
|
85
118
|
|
86
119
|
|
87
|
-
###
|
88
|
-
|
89
|
-
The `Quandl::Favorites` API allows you to retrieve the favorites of any user.
|
120
|
+
### Getting Favorites
|
90
121
|
|
91
122
|
```ruby
|
92
|
-
#
|
93
|
-
#
|
123
|
+
# Retrieve a user's favorites
|
124
|
+
# Example from: http://www.quandl.com/help/api#Getting-Favourites
|
94
125
|
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
126
|
+
# Defaults to getting the favorites of the user who's API key you've configured
|
127
|
+
my_favorites = Quandl::Favorites.get
|
128
|
+
|
129
|
+
# Or pass in another API key as the first argument to override your own
|
130
|
+
some_other_guys_favorites = Quandl::Favorites.get('that_guys_api_key')
|
131
|
+
|
132
|
+
# For Brits and Canucks, Quandl::Favorites is aliased as Quandl::Favourites
|
99
133
|
```
|
100
134
|
|
101
135
|
|
136
|
+
### Further Resources
|
137
|
+
|
138
|
+
Consult the [official API docs](http://www.quandl.com/help/api).
|
139
|
+
|
140
|
+
|
102
141
|
## Contributing
|
103
142
|
|
104
143
|
1. [Fork it](https://github.com/knrz/quandl/fork)
|
data/Rakefile
CHANGED
data/lib/quandl/dataset.rb
CHANGED
@@ -6,9 +6,9 @@ module Quandl
|
|
6
6
|
instance = new(params, options)
|
7
7
|
instance.get
|
8
8
|
if block_given?
|
9
|
-
yield(data)
|
9
|
+
yield(instance.data)
|
10
10
|
else
|
11
|
-
data
|
11
|
+
instance.data
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
@@ -19,10 +19,11 @@ module Quandl
|
|
19
19
|
|
20
20
|
def get(reload = false)
|
21
21
|
if !data || reload
|
22
|
-
|
22
|
+
raw_data = Quandl::Request.new('datasets', {
|
23
23
|
dataset: set,
|
24
24
|
options: options
|
25
25
|
}).get
|
26
|
+
self.data = Quandl.parse(raw_data, (options[:format] || :json).to_sym)
|
26
27
|
end
|
27
28
|
if block_given?
|
28
29
|
yield(data)
|
data/lib/quandl/favorites.rb
CHANGED
@@ -19,10 +19,11 @@ module Quandl
|
|
19
19
|
|
20
20
|
def get(reload = false)
|
21
21
|
if !data || reload
|
22
|
-
|
22
|
+
raw_data = Quandl::Request.new('current_user/collections/datasets/favourites', {
|
23
23
|
options: options,
|
24
24
|
auth_token: auth_token
|
25
25
|
}).get
|
26
|
+
self.data = Quandl.parse(raw_data, (options[:format] || :json).to_sym)
|
26
27
|
end
|
27
28
|
if block_given?
|
28
29
|
yield(data)
|
@@ -31,4 +32,6 @@ module Quandl
|
|
31
32
|
end
|
32
33
|
end
|
33
34
|
end
|
35
|
+
|
36
|
+
Favourites = Favorites
|
34
37
|
end
|
data/lib/quandl/multiset.rb
CHANGED
@@ -19,10 +19,11 @@ module Quandl
|
|
19
19
|
|
20
20
|
def get
|
21
21
|
if !data || reload
|
22
|
-
|
22
|
+
raw_data = Quandl::Request.new('multisets', {
|
23
23
|
datasets: sets,
|
24
24
|
options: options
|
25
25
|
}).get
|
26
|
+
self.data = Quandl.parse(raw_data, (options[:format] || :json).to_sym)
|
26
27
|
end
|
27
28
|
if block_given?
|
28
29
|
yield(data)
|
data/lib/quandl/parse.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'csv'
|
3
|
+
|
4
|
+
module Quandl
|
5
|
+
|
6
|
+
CSV::Converters[:blank_to_nil] = Proc.new do |field|
|
7
|
+
field && field.empty? ? nil : field
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.parse(data, format)
|
11
|
+
case format
|
12
|
+
when :json
|
13
|
+
JSON.parse(data, {
|
14
|
+
symbolize_names: true
|
15
|
+
})
|
16
|
+
when :csv
|
17
|
+
CSV.parse(data, {
|
18
|
+
headers: true,
|
19
|
+
header_converters: :symbol,
|
20
|
+
converters: [:all, :blank_to_nil]
|
21
|
+
}).map(&:to_hash)
|
22
|
+
else data
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/lib/quandl/request.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'open-uri'
|
2
|
+
|
1
3
|
module Quandl
|
2
4
|
API_URI = 'http://www.quandl.com/api/'
|
3
5
|
|
@@ -22,7 +24,7 @@ module Quandl
|
|
22
24
|
if params[:dataset]
|
23
25
|
path += "/#{params[:dataset]}"
|
24
26
|
end
|
25
|
-
path += '.' + (
|
27
|
+
path += '.' + (params[:options][:format] || 'json').to_s
|
26
28
|
@uri = URI(API_URI + path).tap do |uri|
|
27
29
|
uri.query = URI.encode_www_form(params[:options])
|
28
30
|
end
|
data/lib/quandl/search.rb
CHANGED
@@ -8,7 +8,7 @@ module Quandl
|
|
8
8
|
if block_given?
|
9
9
|
yield(instance.data)
|
10
10
|
else
|
11
|
-
data
|
11
|
+
instance.data
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
@@ -19,10 +19,11 @@ module Quandl
|
|
19
19
|
|
20
20
|
def get
|
21
21
|
if !data || reload
|
22
|
-
|
22
|
+
raw_data = Quandl::Request.new('datasets', {
|
23
23
|
query: query,
|
24
24
|
options: options
|
25
25
|
}).get
|
26
|
+
self.data = Quandl.parse(raw_data, (options[:format] || :json).to_sym)
|
26
27
|
end
|
27
28
|
if block_given?
|
28
29
|
yield(data)
|
data/lib/quandl/version.rb
CHANGED
data/lib/quandl.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
require_relative 'quandl/version'
|
2
2
|
require_relative 'quandl/configuration'
|
3
|
+
require_relative 'quandl/parse'
|
3
4
|
require_relative 'quandl/dataset'
|
4
5
|
require_relative 'quandl/metadata'
|
5
6
|
require_relative 'quandl/multiset'
|
6
7
|
require_relative 'quandl/search'
|
7
8
|
require_relative 'quandl/favorites'
|
8
9
|
require_relative 'quandl/request'
|
9
|
-
require 'open-uri'
|
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.
|
4
|
+
version: 0.1.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-08-
|
11
|
+
date: 2014-08-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -56,6 +56,7 @@ files:
|
|
56
56
|
- lib/quandl/favorites.rb
|
57
57
|
- lib/quandl/metadata.rb
|
58
58
|
- lib/quandl/multiset.rb
|
59
|
+
- lib/quandl/parse.rb
|
59
60
|
- lib/quandl/request.rb
|
60
61
|
- lib/quandl/search.rb
|
61
62
|
- lib/quandl/version.rb
|