quandl_client 2.9.0 → 2.10.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +41 -185
- data/UPGRADE.md +6 -0
- data/VERSION +1 -1
- data/lib/quandl/client/models/job.rb +6 -0
- data/lib/quandl/client/models/scraper.rb +7 -1
- data/lib/quandl/client.rb +1 -0
- data/lib/quandl/her/collection.rb +14 -0
- data/spec/lib/quandl/client/source_spec.rb +1 -1
- metadata +5 -4
data/README.md
CHANGED
@@ -14,42 +14,47 @@ gem 'quandl_client'
|
|
14
14
|
```
|
15
15
|
|
16
16
|
|
17
|
-
|
18
|
-
|
19
17
|
## Configuration
|
20
18
|
|
21
19
|
```ruby
|
22
20
|
|
23
21
|
require 'quandl/client'
|
24
22
|
|
25
|
-
Quandl::Client.use 'http://
|
23
|
+
Quandl::Client.use 'http://quandl.com/api/'
|
26
24
|
Quandl::Client.token = ENV['QUANDL_AUTH_TOKEN']
|
27
25
|
|
28
26
|
|
29
27
|
```
|
30
28
|
|
31
29
|
|
32
|
-
|
33
|
-
|
34
30
|
## Usage
|
35
31
|
|
36
32
|
|
37
33
|
### Quandl::Client::Dataset
|
38
34
|
|
39
35
|
|
40
|
-
#### Search
|
41
|
-
|
42
|
-
scope :rows, :exclude_data, :exclude_headers, :trim_start, :trim_end, :transform, :collapse
|
36
|
+
#### Dataset Search
|
43
37
|
|
44
38
|
```ruby
|
45
39
|
|
46
|
-
datasets = Quandl::Client::Dataset.query('
|
47
|
-
|
40
|
+
datasets = Quandl::Client::Dataset.query('oil').where(frequency: 'annual', source_code: 'OFDP', page: 2).all
|
41
|
+
datasets.first.data.limit(10).to_a
|
42
|
+
=> [[Tue, 22 Oct 1974, 40.45, 41.5, 40.45, 41.35, 191.0, 262.0], ... ]
|
48
43
|
|
49
44
|
```
|
50
45
|
|
46
|
+
Available parameters:
|
47
|
+
|
48
|
+
query
|
49
|
+
source_code
|
50
|
+
frequency
|
51
|
+
page
|
52
|
+
per_page
|
53
|
+
owner
|
51
54
|
|
52
|
-
|
55
|
+
|
56
|
+
|
57
|
+
#### Dataset Data
|
53
58
|
|
54
59
|
attributes :data, :source_code, :code, :name, :urlize_name,
|
55
60
|
:description, :updated_at, :frequency, :from_date,
|
@@ -58,18 +63,25 @@ attributes :data, :source_code, :code, :name, :urlize_name,
|
|
58
63
|
```ruby
|
59
64
|
|
60
65
|
d = Quandl::Client::Dataset.find('OFDP/COBALT_51')
|
61
|
-
d.
|
62
|
-
|
63
|
-
|
66
|
+
d.data.first
|
67
|
+
=> [Wed, 14 May 2014, 29500.0, 30500.0, 30000.0]
|
64
68
|
|
65
|
-
d = Quandl::Client::Dataset.
|
66
|
-
d.data
|
69
|
+
d = Quandl::Client::Dataset.find('OFDP/COBALT_51')
|
70
|
+
d.data.collapse('weekly').trim_start("2012-03-31").trim_end("2013-06-30").first
|
71
|
+
=> [Sun, 30 Jun 2013, 31050.0, 32550.0, 31800.0]
|
67
72
|
|
73
|
+
```
|
68
74
|
|
69
|
-
|
70
|
-
d.data
|
75
|
+
Available parameters:
|
71
76
|
|
72
|
-
|
77
|
+
collapse
|
78
|
+
transformation
|
79
|
+
trim_start
|
80
|
+
trim_end
|
81
|
+
rows
|
82
|
+
exclude_headers
|
83
|
+
row
|
84
|
+
limit
|
73
85
|
|
74
86
|
|
75
87
|
#### Create
|
@@ -77,19 +89,9 @@ d.data
|
|
77
89
|
```ruby
|
78
90
|
|
79
91
|
attributes = {
|
80
|
-
code: "
|
81
|
-
source_code: 'OFDP',
|
82
|
-
name: "Test Upload #{Time.now.to_i}",
|
92
|
+
code: "TEST_DATASET",
|
83
93
|
frequency: 'daily',
|
84
|
-
|
85
|
-
[
|
86
|
-
{
|
87
|
-
type: 'http',
|
88
|
-
url: 'http://test.com',
|
89
|
-
post_data: '[magic]',
|
90
|
-
cookie_url: 'http://cookies.com'
|
91
|
-
}
|
92
|
-
]
|
94
|
+
data: '2012,10,20',
|
93
95
|
}
|
94
96
|
d = Dataset.create( attributes )
|
95
97
|
|
@@ -100,15 +102,11 @@ d = Dataset.create( attributes )
|
|
100
102
|
|
101
103
|
```ruby
|
102
104
|
|
103
|
-
d = Dataset.find(
|
105
|
+
d = Dataset.find("TEST_DATASET")
|
104
106
|
d.name = 'New Name'
|
105
|
-
d.data =
|
107
|
+
d.data = [['2014',10,20],['2013',20,30]]
|
106
108
|
d.save
|
107
109
|
|
108
|
-
d = Dataset.collapse(:weekly).find( d.full_code )
|
109
|
-
d.data
|
110
|
-
=> [[...],...]
|
111
|
-
|
112
110
|
```
|
113
111
|
|
114
112
|
|
@@ -116,11 +114,8 @@ d.data
|
|
116
114
|
|
117
115
|
```ruby
|
118
116
|
|
119
|
-
Dataset.
|
120
|
-
|
121
|
-
|
122
|
-
Dataset.find('SOME_SOURCE/SOME_CODE')
|
123
|
-
=> nil
|
117
|
+
d = Dataset.find('TEST_DATASET')
|
118
|
+
d.destroy
|
124
119
|
|
125
120
|
```
|
126
121
|
|
@@ -129,7 +124,7 @@ Dataset.find('SOME_SOURCE/SOME_CODE')
|
|
129
124
|
|
130
125
|
```ruby
|
131
126
|
|
132
|
-
d = Dataset.find('
|
127
|
+
d = Dataset.find('TEST_DATASET')
|
133
128
|
d.delete_data
|
134
129
|
d.data
|
135
130
|
=> nil
|
@@ -141,23 +136,6 @@ d.data
|
|
141
136
|
```
|
142
137
|
|
143
138
|
|
144
|
-
#### Error Handling
|
145
|
-
|
146
|
-
```ruby
|
147
|
-
|
148
|
-
d = Dataset.create(code: 'TEST', source_code: 'OFDP', locations: [{ type: 'http', url: 'test.com' }] )
|
149
|
-
d.error_messages
|
150
|
-
=> {:name=>["can't be blank"]}
|
151
|
-
|
152
|
-
d = Dataset.create(name: 'asdfs', code: 'TEST', source_code: 'OFDP', locations: [{ type: 'http', url: 'test.com' }] )
|
153
|
-
d.error_messages
|
154
|
-
=> {"code"=>["has already been taken"], "frequency"=>["is not included in the list"]}
|
155
|
-
|
156
|
-
```
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
139
|
### Quandl::Client::Source
|
162
140
|
|
163
141
|
|
@@ -165,7 +143,7 @@ d.error_messages
|
|
165
143
|
|
166
144
|
```ruby
|
167
145
|
|
168
|
-
sources = Quandl::Client::Source.query('
|
146
|
+
sources = Quandl::Client::Source.query('oil').all
|
169
147
|
|
170
148
|
=> [#<Quandl::Client::Source(sources/413) code="STATSCAN5" datasets_count=1>...]
|
171
149
|
|
@@ -176,128 +154,6 @@ sources = Quandl::Client::Source.query('can').all
|
|
176
154
|
|
177
155
|
```ruby
|
178
156
|
|
179
|
-
s = Quandl::Client::Source.find('
|
180
|
-
|
181
|
-
```
|
182
|
-
|
183
|
-
|
184
|
-
#### Create
|
185
|
-
|
186
|
-
```ruby
|
187
|
-
|
188
|
-
s = Source.create( code: 'test' )
|
189
|
-
s.valid?
|
190
|
-
s.error_messages
|
191
|
-
=> {:code=>["is invalid"], :host=>["can't be blank"], :name=>["can't be blank"]}
|
192
|
-
|
193
|
-
s = Source.create(code: %Q{TEST_#{Time.now.to_i}}, name: 'asdf', host: "http://asdf#{Time.now}.com" )
|
194
|
-
s.saved?
|
195
|
-
=> true
|
196
|
-
|
197
|
-
```
|
198
|
-
|
199
|
-
|
200
|
-
#### Update
|
201
|
-
|
202
|
-
```ruby
|
203
|
-
|
204
|
-
s = Source.find(s.code)
|
205
|
-
s.name = "Updated Name #{Time.now.to_i}"
|
206
|
-
s.code = "DATA_#{Time.now.to_i}"
|
207
|
-
s.save
|
208
|
-
|
209
|
-
```
|
210
|
-
|
211
|
-
|
212
|
-
#### Delete
|
213
|
-
|
214
|
-
```ruby
|
215
|
-
|
216
|
-
Source.destroy_existing('SOMESOURCE')
|
217
|
-
Source.destroy_existing(52352)
|
218
|
-
|
219
|
-
```
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
### Quandl::Client::Sheet
|
225
|
-
|
226
|
-
|
227
|
-
#### Search
|
228
|
-
|
229
|
-
```ruby
|
230
|
-
|
231
|
-
sheets = Quandl::Client::Sheet.query('canada').all
|
232
|
-
=> [[#<Quandl::Client::Sheet(sheets) title="La Canada Flintridge>,...]
|
233
|
-
|
234
|
-
```
|
235
|
-
|
236
|
-
|
237
|
-
#### Show
|
238
|
-
|
239
|
-
```ruby
|
240
|
-
|
241
|
-
sheet = Quandl::Client::Sheet.find('housing/hood')
|
242
|
-
|
243
|
-
```
|
244
|
-
|
245
|
-
|
246
|
-
#### Create
|
247
|
-
|
248
|
-
```ruby
|
249
|
-
|
250
|
-
s = Quandl::Client::Sheet.create( title: 'ocean' )
|
251
|
-
s = Quandl::Client::Sheet.create( full_url_title: 'ocean/river', title: 'River' )
|
252
|
-
s = Quandl::Client::Sheet.create( full_url_title: 'ocean/river/lake', title: 'Lake!' )
|
253
|
-
|
254
|
-
Sheet.find('ocean/river/lake').title
|
255
|
-
=> 'Lake!'
|
256
|
-
|
257
|
-
Sheet.find('ocean').children.first.title
|
258
|
-
=> River
|
259
|
-
|
260
|
-
```
|
261
|
-
|
262
|
-
|
263
|
-
#### Update
|
264
|
-
|
265
|
-
```ruby
|
266
|
-
|
267
|
-
s = Quandl::Client::Sheet.find('ocean/river')
|
268
|
-
s.title = "River #{Time.now.to_i}"
|
269
|
-
s.save
|
270
|
-
|
271
|
-
```
|
272
|
-
|
273
|
-
|
274
|
-
#### Delete
|
275
|
-
|
276
|
-
```ruby
|
277
|
-
|
278
|
-
Quandl::Client::Sheet.destroy_existing('ocean/river/lake')
|
279
|
-
|
280
|
-
Quandl::Client::Sheet.destroy_existing(15252)
|
281
|
-
|
282
|
-
```
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
### Authentication
|
288
|
-
|
289
|
-
```ruby
|
290
|
-
|
291
|
-
require 'quandl/client'
|
292
|
-
|
293
|
-
Quandl::Client.use 'http://localhost:3000/api/'
|
294
|
-
Quandl::Client.token = 'xyz'
|
295
|
-
|
296
|
-
|
297
|
-
s = Quandl::Client::Sheet.find_by_url_title('testing')
|
298
|
-
s.title = 'more testing'
|
299
|
-
s.save
|
300
|
-
=> true
|
301
|
-
|
302
|
-
```
|
157
|
+
s = Quandl::Client::Source.find('NSE')
|
303
158
|
|
159
|
+
```
|
data/UPGRADE.md
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
2.10.0
|
@@ -3,6 +3,8 @@ module Client
|
|
3
3
|
|
4
4
|
class Scraper < Quandl::Client::Base
|
5
5
|
|
6
|
+
has_many :jobs
|
7
|
+
|
6
8
|
attributes :id, :name, :scraper, :scraper_url, :git_url, :git_reference, :created_at, :updated_at,
|
7
9
|
:type, :schedule_at, :schedule_run_time, :schedule_next
|
8
10
|
|
@@ -11,7 +13,11 @@ class Scraper < Quandl::Client::Base
|
|
11
13
|
def scraper=(value)
|
12
14
|
write_attribute(:scraper, Faraday::UploadIO.new(value, 'text/plain') )
|
13
15
|
end
|
14
|
-
|
16
|
+
|
17
|
+
def run_now
|
18
|
+
jobs.create
|
19
|
+
end
|
20
|
+
|
15
21
|
end
|
16
22
|
|
17
23
|
end
|
data/lib/quandl/client.rb
CHANGED
@@ -18,6 +18,7 @@ require 'quandl/client/models/source'
|
|
18
18
|
require 'quandl/client/models/user'
|
19
19
|
require 'quandl/client/models/location'
|
20
20
|
require 'quandl/client/models/scraper'
|
21
|
+
require 'quandl/client/models/job'
|
21
22
|
require 'quandl/client/models/report'
|
22
23
|
require 'quandl/client/models/superset'
|
23
24
|
|
@@ -1,6 +1,20 @@
|
|
1
1
|
module Her
|
2
2
|
module Model
|
3
3
|
module Attributes
|
4
|
+
def initialize(attributes={})
|
5
|
+
if attributes.is_a?(Integer)
|
6
|
+
attributes = { id: attributes }
|
7
|
+
end
|
8
|
+
attributes ||= {}
|
9
|
+
@metadata = attributes.delete(:_metadata) || {}
|
10
|
+
@response_errors = attributes.delete(:_errors) || {}
|
11
|
+
@destroyed = attributes.delete(:_destroyed) || false
|
12
|
+
|
13
|
+
attributes = self.class.default_scope.apply_to(attributes)
|
14
|
+
assign_attributes(attributes)
|
15
|
+
run_callbacks :initialize
|
16
|
+
end
|
17
|
+
|
4
18
|
def self.initialize_collection(klass, parsed_data={})
|
5
19
|
arr = klass.extract_array(parsed_data)
|
6
20
|
arr = [] unless arr.is_a?(Array)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: quandl_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.10.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-05-
|
12
|
+
date: 2014-05-23 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: quandl_data
|
@@ -247,6 +247,7 @@ files:
|
|
247
247
|
- lib/quandl/client/middleware/parse_json.rb
|
248
248
|
- lib/quandl/client/models/dataset.rb
|
249
249
|
- lib/quandl/client/models/dataset/data.rb
|
250
|
+
- lib/quandl/client/models/job.rb
|
250
251
|
- lib/quandl/client/models/location.rb
|
251
252
|
- lib/quandl/client/models/report.rb
|
252
253
|
- lib/quandl/client/models/scraper.rb
|
@@ -293,7 +294,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
293
294
|
version: '0'
|
294
295
|
segments:
|
295
296
|
- 0
|
296
|
-
hash:
|
297
|
+
hash: 608725837555586379
|
297
298
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
298
299
|
none: false
|
299
300
|
requirements:
|
@@ -302,7 +303,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
302
303
|
version: '0'
|
303
304
|
segments:
|
304
305
|
- 0
|
305
|
-
hash:
|
306
|
+
hash: 608725837555586379
|
306
307
|
requirements: []
|
307
308
|
rubyforge_project:
|
308
309
|
rubygems_version: 1.8.23
|