quandl_client 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +90 -24
- data/lib/quandl/client/base.rb +12 -0
- data/lib/quandl/client/concerns/properties.rb +33 -0
- data/lib/quandl/client/concerns/search.rb +26 -0
- data/lib/quandl/client/concerns.rb +17 -0
- data/lib/quandl/client/her.rb +3 -0
- data/lib/quandl/client/models/dataset.rb +58 -5
- data/lib/quandl/client/models/sheet.rb +29 -19
- data/lib/quandl/client/models/source.rb +23 -19
- data/lib/quandl/client/version.rb +1 -1
- data/lib/quandl/client.rb +2 -5
- metadata +6 -4
- data/lib/quandl/client/models/dataset/properties.rb +0 -46
- data/lib/quandl/client/models/dataset/searchable.rb +0 -39
data/README.md
CHANGED
@@ -68,7 +68,7 @@ d.data_table
|
|
68
68
|
```ruby
|
69
69
|
|
70
70
|
attributes = {
|
71
|
-
code: "
|
71
|
+
code: "TEST_#{Time.now.to_i}",
|
72
72
|
source_code: 'OFDP',
|
73
73
|
name: "Test Upload #{Time.now.to_i}",
|
74
74
|
frequency: 'daily',
|
@@ -86,33 +86,51 @@ d = Dataset.create( attributes )
|
|
86
86
|
|
87
87
|
```
|
88
88
|
|
89
|
-
##### Errors
|
90
|
-
|
91
|
-
```ruby
|
92
|
-
|
93
|
-
d = Dataset.create(code: 'TEST', source_code: 'OFDP', locations_attributes: [{ type: 'http', url: 'test.com' }] )
|
94
|
-
d.errors
|
95
|
-
=> {"locations.post_data"=>["can't be blank"], "locations.cookie_url"=>["can't be blank"], "name"=>["can't be blank"], "frequency"=>["is not included in the list"]}
|
96
|
-
|
97
|
-
```
|
98
|
-
|
99
89
|
|
100
90
|
#### Update
|
101
91
|
|
102
92
|
```ruby
|
103
93
|
|
104
|
-
d = Dataset.find(
|
94
|
+
d = Dataset.find( d.full_code )
|
105
95
|
d.name = 'New Name'
|
106
96
|
d.data = Quandl::Data::Random.table.to_csv
|
107
97
|
d.save
|
108
98
|
|
109
|
-
d = Dataset.collapse(:weekly).find(
|
99
|
+
d = Dataset.collapse(:weekly).find( d.full_code )
|
110
100
|
d.data
|
111
101
|
=> [[...],...]
|
112
102
|
|
113
103
|
```
|
114
104
|
|
115
105
|
|
106
|
+
#### Delete
|
107
|
+
|
108
|
+
```ruby
|
109
|
+
|
110
|
+
Dataset.destroy_existing('SOME_SOURCE/SOME_CODE')
|
111
|
+
Dataset.destroy_existing(52352)
|
112
|
+
|
113
|
+
Dataset.find('SOME_SOURCE/SOME_CODE')
|
114
|
+
=> nil
|
115
|
+
|
116
|
+
```
|
117
|
+
|
118
|
+
|
119
|
+
#### Error Handling
|
120
|
+
|
121
|
+
```ruby
|
122
|
+
|
123
|
+
d = Dataset.create(code: 'TEST', source_code: 'OFDP', locations: [{ type: 'http', url: 'test.com' }] )
|
124
|
+
d.error_messages
|
125
|
+
=> {:name=>["can't be blank"]}
|
126
|
+
|
127
|
+
d = Dataset.create(name: 'asdfs', code: 'TEST', source_code: 'OFDP', locations: [{ type: 'http', url: 'test.com' }] )
|
128
|
+
d.error_messages
|
129
|
+
=> {"code"=>["has already been taken"], "frequency"=>["is not included in the list"]}
|
130
|
+
|
131
|
+
```
|
132
|
+
|
133
|
+
|
116
134
|
|
117
135
|
|
118
136
|
## Quandl::Client::Source
|
@@ -122,9 +140,9 @@ d.data
|
|
122
140
|
|
123
141
|
```ruby
|
124
142
|
|
125
|
-
sources = Quandl::Client::Source.query('
|
143
|
+
sources = Quandl::Client::Source.query('can').all
|
126
144
|
|
127
|
-
=> [#<Quandl::Client::Source(sources) code="
|
145
|
+
=> [#<Quandl::Client::Source(sources/413) code="STATSCAN5" datasets_count=1>...]
|
128
146
|
|
129
147
|
```
|
130
148
|
|
@@ -133,7 +151,45 @@ sources = Quandl::Client::Source.query('canada').page(2).all
|
|
133
151
|
|
134
152
|
```ruby
|
135
153
|
|
136
|
-
|
154
|
+
s = Quandl::Client::Source.find('STATSCAN5')
|
155
|
+
|
156
|
+
```
|
157
|
+
|
158
|
+
|
159
|
+
#### Create
|
160
|
+
|
161
|
+
```ruby
|
162
|
+
|
163
|
+
s = Source.create( code: 'test' )
|
164
|
+
s.valid?
|
165
|
+
s.error_messages
|
166
|
+
=> {:code=>["is invalid"], :host=>["can't be blank"], :name=>["can't be blank"]}
|
167
|
+
|
168
|
+
s = Source.create(code: %Q{TEST_#{Time.now.to_i}}, name: 'asdf', host: "http://asdf#{Time.now}.com" )
|
169
|
+
s.saved?
|
170
|
+
=> true
|
171
|
+
|
172
|
+
```
|
173
|
+
|
174
|
+
|
175
|
+
#### Update
|
176
|
+
|
177
|
+
```ruby
|
178
|
+
|
179
|
+
s = Source.find(s.code)
|
180
|
+
s.name = "Updated Name #{Time.now.to_i}"
|
181
|
+
s.code = "DATA_#{Time.now.to_i}"
|
182
|
+
s.save
|
183
|
+
|
184
|
+
```
|
185
|
+
|
186
|
+
|
187
|
+
#### Delete
|
188
|
+
|
189
|
+
```ruby
|
190
|
+
|
191
|
+
Source.destroy_existing('SOMESOURCE')
|
192
|
+
Source.destroy_existing(52352)
|
137
193
|
|
138
194
|
```
|
139
195
|
|
@@ -166,11 +222,12 @@ sheet = Quandl::Client::Sheet.find('housing/hood')
|
|
166
222
|
|
167
223
|
```ruby
|
168
224
|
|
169
|
-
|
225
|
+
s = Quandl::Client::Sheet.create( title: 'ocean' )
|
226
|
+
s = Quandl::Client::Sheet.create( full_url_title: 'ocean/river', title: 'River' )
|
227
|
+
s = Quandl::Client::Sheet.create( full_url_title: 'ocean/river/lake', title: 'Lake!' )
|
170
228
|
|
171
|
-
|
172
|
-
|
173
|
-
s = Sheet.create( full_url_title: 'ocean/river/lake', title: 'Lake!' )
|
229
|
+
Sheet.find('ocean/river/lake').title
|
230
|
+
=> 'Lake!'
|
174
231
|
|
175
232
|
Sheet.find('ocean').children.first.title
|
176
233
|
=> River
|
@@ -182,15 +239,24 @@ Sheet.find('ocean').children.first.title
|
|
182
239
|
|
183
240
|
```ruby
|
184
241
|
|
185
|
-
Quandl::Client.
|
186
|
-
|
187
|
-
s = Quandl::Client::Sheet.find_by_url_title('hi_there')
|
188
|
-
s.title = 'another title'
|
242
|
+
s = Quandl::Client::Sheet.find('ocean/river')
|
243
|
+
s.title = "River #{Time.now.to_i}"
|
189
244
|
s.save
|
190
245
|
|
191
246
|
```
|
192
247
|
|
193
248
|
|
249
|
+
#### Delete
|
250
|
+
|
251
|
+
```ruby
|
252
|
+
|
253
|
+
Quandl::Client::Sheet.destroy_existing('ocean/river/lake')
|
254
|
+
|
255
|
+
Quandl::Client::Sheet.destroy_existing(15252)
|
256
|
+
|
257
|
+
```
|
258
|
+
|
259
|
+
|
194
260
|
|
195
261
|
|
196
262
|
# Authentication
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Quandl
|
2
|
+
module Client
|
3
|
+
module Concerns
|
4
|
+
|
5
|
+
module Properties
|
6
|
+
extend ActiveSupport::Concern
|
7
|
+
|
8
|
+
included do
|
9
|
+
|
10
|
+
include Her::Model
|
11
|
+
use_api Client.her_api
|
12
|
+
|
13
|
+
before_save :halt_unless_valid!
|
14
|
+
|
15
|
+
def error_messages
|
16
|
+
valid?
|
17
|
+
m = errors.messages.to_h || {}
|
18
|
+
e = self.attributes[:errors].to_h || {}
|
19
|
+
m.deep_merge(e)
|
20
|
+
end
|
21
|
+
|
22
|
+
protected
|
23
|
+
|
24
|
+
def halt_unless_valid!
|
25
|
+
return false unless valid?
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Quandl
|
2
|
+
module Client
|
3
|
+
module Concerns
|
4
|
+
|
5
|
+
module Search
|
6
|
+
extend ActiveSupport::Concern
|
7
|
+
|
8
|
+
included do
|
9
|
+
|
10
|
+
include ScopeBuilder::Model
|
11
|
+
|
12
|
+
scope_builder_for :search
|
13
|
+
|
14
|
+
search_helper :all, ->{ connection.where(attributes).fetch }
|
15
|
+
search_helper :connection, -> { self.class.parent }
|
16
|
+
|
17
|
+
search_scope.class_eval do
|
18
|
+
delegate *Array.forwardable_methods, to: :all
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require "active_support"
|
2
|
+
require "active_support/inflector"
|
3
|
+
require "active_support/core_ext/hash"
|
4
|
+
require "active_support/core_ext/object"
|
5
|
+
|
6
|
+
require 'quandl/client/concerns/search'
|
7
|
+
require 'quandl/client/concerns/properties'
|
8
|
+
|
9
|
+
module Quandl
|
10
|
+
module Client
|
11
|
+
|
12
|
+
module Concerns
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
data/lib/quandl/client/her.rb
CHANGED
@@ -1,18 +1,71 @@
|
|
1
|
-
require 'quandl/client/models/dataset/searchable'
|
2
|
-
require 'quandl/client/models/dataset/properties'
|
3
|
-
|
4
1
|
module Quandl
|
5
2
|
module Client
|
6
3
|
|
7
4
|
class Dataset
|
8
5
|
|
9
|
-
include
|
10
|
-
include
|
6
|
+
include Concerns::Search
|
7
|
+
include Concerns::Properties
|
8
|
+
|
9
|
+
|
10
|
+
##########
|
11
|
+
# SCOPES #
|
12
|
+
##########
|
13
|
+
|
14
|
+
# SEARCH
|
15
|
+
search_scope :query, :rows
|
16
|
+
search_scope :page, ->(p){ where( page: p.to_i )}
|
17
|
+
search_scope :source_code, ->(c){ where( code: c.to_s.upcase )}
|
18
|
+
|
19
|
+
# SHOW
|
20
|
+
scope_builder_for :show
|
21
|
+
show_scope :rows, :exclude_data, :exclude_headers, :trim_start, :trim_end, :transform, :collapse
|
22
|
+
show_helper :find, ->(id){ connection.where(attributes).find( id ) }
|
23
|
+
show_helper :connection, -> { self.class.parent }
|
11
24
|
|
25
|
+
|
26
|
+
###############
|
27
|
+
# ASSOCIATIONS #
|
28
|
+
###############
|
29
|
+
|
12
30
|
def source
|
13
31
|
@source ||= Source.find(self.source_code)
|
14
32
|
end
|
15
33
|
|
34
|
+
|
35
|
+
###############
|
36
|
+
# VALIDATIONS #
|
37
|
+
###############
|
38
|
+
|
39
|
+
validates :source_code, presence: true, length: { minimum: 2 }, format: { with: /^([A-Z][A-Z0-9_]+)$/ }
|
40
|
+
validates :code, presence: true, length: { minimum: 2 }, format: { with: /^([A-Z][A-Z0-9_]+)$/ }
|
41
|
+
validates :name, presence: true
|
42
|
+
|
43
|
+
|
44
|
+
##############
|
45
|
+
# PROPERTIES #
|
46
|
+
##############
|
47
|
+
|
48
|
+
attributes :data, :source_code, :code, :name, :urlize_name,
|
49
|
+
:description, :updated_at, :frequency, :from_date,
|
50
|
+
:to_date, :column_names, :private, :type
|
51
|
+
|
52
|
+
attributes :locations_attributes
|
53
|
+
|
54
|
+
alias_method :locations, :locations_attributes
|
55
|
+
alias_method :locations=, :locations_attributes=
|
56
|
+
|
57
|
+
def full_code
|
58
|
+
@full_code ||= File.join(self.source_code, self.code)
|
59
|
+
end
|
60
|
+
|
61
|
+
def data_table
|
62
|
+
Data::Table.new( raw_data )
|
63
|
+
end
|
64
|
+
|
65
|
+
def raw_data
|
66
|
+
@raw_data ||= (self.data || Dataset.find(full_code).data || [])
|
67
|
+
end
|
68
|
+
|
16
69
|
end
|
17
70
|
|
18
71
|
end
|
@@ -1,31 +1,22 @@
|
|
1
|
-
require 'quandl/client/models/dataset/searchable'
|
2
|
-
require 'quandl/client/models/dataset/properties'
|
3
|
-
|
4
1
|
module Quandl
|
5
2
|
module Client
|
6
3
|
|
7
4
|
class Sheet
|
8
|
-
|
9
|
-
include ScopeBuilder::Model
|
10
5
|
|
11
|
-
|
6
|
+
include Concerns::Search
|
7
|
+
include Concerns::Properties
|
8
|
+
|
9
|
+
|
10
|
+
##########
|
11
|
+
# SCOPES #
|
12
|
+
##########
|
12
13
|
|
13
14
|
search_scope :query, :page, :parent_url_title
|
14
|
-
search_helper :all, ->{ connection.where(attributes).fetch.to_a }
|
15
|
-
search_helper :connection, -> { self.class.parent }
|
16
|
-
|
17
|
-
search_scope.class_eval do
|
18
|
-
delegate *Array.forwardable_methods, to: :all
|
19
|
-
end
|
20
15
|
|
21
|
-
# ORM
|
22
|
-
include Her::Model
|
23
|
-
use_api Client.her_api
|
24
|
-
attributes :title, :content, :url_title, :full_url_title
|
25
16
|
|
26
|
-
|
27
|
-
|
28
|
-
|
17
|
+
###############
|
18
|
+
# ASSOCIATIONS #
|
19
|
+
###############
|
29
20
|
|
30
21
|
def parent
|
31
22
|
@parent ||= Sheet.find(parent_url_title)
|
@@ -35,10 +26,29 @@ class Sheet
|
|
35
26
|
Sheet.parent_url_title(self.full_url_title)
|
36
27
|
end
|
37
28
|
|
29
|
+
|
30
|
+
###############
|
31
|
+
# VALIDATIONS #
|
32
|
+
###############
|
33
|
+
|
34
|
+
validates :title, presence: true
|
35
|
+
|
36
|
+
|
37
|
+
##############
|
38
|
+
# PROPERTIES #
|
39
|
+
##############
|
40
|
+
|
41
|
+
attributes :title, :content, :url_title, :full_url_title
|
42
|
+
|
43
|
+
def html
|
44
|
+
@html ||= self.attributes[:html] || Sheet.find(full_url_title).attributes[:html]
|
45
|
+
end
|
46
|
+
|
38
47
|
def parent_url_title
|
39
48
|
@parent_url_title ||= self.full_url_title.split('/')[0..-2].join()
|
40
49
|
end
|
41
50
|
|
51
|
+
|
42
52
|
end
|
43
53
|
|
44
54
|
end
|
@@ -1,38 +1,42 @@
|
|
1
|
-
require 'quandl/client/models/dataset/searchable'
|
2
|
-
require 'quandl/client/models/dataset/properties'
|
3
|
-
|
4
1
|
module Quandl
|
5
2
|
module Client
|
6
3
|
|
7
4
|
class Source
|
8
|
-
|
9
|
-
include ScopeBuilder::Model
|
10
5
|
|
11
|
-
|
6
|
+
include Concerns::Search
|
7
|
+
include Concerns::Properties
|
8
|
+
|
9
|
+
##########
|
10
|
+
# SCOPES #
|
11
|
+
##########
|
12
12
|
|
13
13
|
search_scope :query
|
14
14
|
search_scope :page, ->(p){ where( page: p.to_i )}
|
15
15
|
search_scope :code, ->(c){ where( code: c.to_s.upcase )}
|
16
16
|
|
17
|
-
search_helper :all, ->{ connection.where(attributes).fetch }
|
18
|
-
search_helper :connection, -> { self.class.parent }
|
19
|
-
|
20
|
-
search_scope.class_eval do
|
21
|
-
delegate *Array.forwardable_methods, to: :all
|
22
|
-
end
|
23
17
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
attributes :code, :datasets_count, :description, :name, :host
|
18
|
+
###############
|
19
|
+
# ASSOCIATIONS #
|
20
|
+
###############
|
28
21
|
|
29
22
|
def datasets
|
30
23
|
Dataset.source_code(code)
|
31
24
|
end
|
32
25
|
|
33
|
-
|
34
|
-
|
35
|
-
|
26
|
+
|
27
|
+
###############
|
28
|
+
# VALIDATIONS #
|
29
|
+
###############
|
30
|
+
|
31
|
+
validates :code, presence: true, length: { minimum: 2 }, format: { with: /^([A-Z][A-Z0-9_]+)$/ }
|
32
|
+
validates :host, :name, presence: true
|
33
|
+
|
34
|
+
|
35
|
+
##############
|
36
|
+
# PROPERTIES #
|
37
|
+
##############
|
38
|
+
|
39
|
+
attributes :code, :name, :host, :description, :datasets_count, :use_proxy, :type, :concurrency
|
36
40
|
|
37
41
|
end
|
38
42
|
|
data/lib/quandl/client.rb
CHANGED
@@ -5,12 +5,9 @@ require "active_support/inflector"
|
|
5
5
|
require "active_support/core_ext/hash"
|
6
6
|
require "active_support/core_ext/object"
|
7
7
|
|
8
|
-
require 'her'
|
9
|
-
require 'quandl/her/patch'
|
10
|
-
require 'scope_builder'
|
11
|
-
require "quandl/data"
|
12
|
-
|
13
8
|
require 'quandl/client/her'
|
9
|
+
require 'quandl/client/concerns'
|
10
|
+
require 'quandl/client/base'
|
14
11
|
require 'quandl/client/models'
|
15
12
|
|
16
13
|
module Quandl
|
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: 0.0.
|
4
|
+
version: 0.0.5
|
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: 2013-06-
|
12
|
+
date: 2013-06-21 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -188,11 +188,13 @@ files:
|
|
188
188
|
- Rakefile
|
189
189
|
- UPGRADE.md
|
190
190
|
- lib/quandl/client.rb
|
191
|
+
- lib/quandl/client/base.rb
|
192
|
+
- lib/quandl/client/concerns.rb
|
193
|
+
- lib/quandl/client/concerns/properties.rb
|
194
|
+
- lib/quandl/client/concerns/search.rb
|
191
195
|
- lib/quandl/client/her.rb
|
192
196
|
- lib/quandl/client/models.rb
|
193
197
|
- lib/quandl/client/models/dataset.rb
|
194
|
-
- lib/quandl/client/models/dataset/properties.rb
|
195
|
-
- lib/quandl/client/models/dataset/searchable.rb
|
196
198
|
- lib/quandl/client/models/sheet.rb
|
197
199
|
- lib/quandl/client/models/source.rb
|
198
200
|
- lib/quandl/client/version.rb
|
@@ -1,46 +0,0 @@
|
|
1
|
-
module Quandl
|
2
|
-
module Client
|
3
|
-
|
4
|
-
class Dataset
|
5
|
-
|
6
|
-
module Properties
|
7
|
-
|
8
|
-
extend ActiveSupport::Concern
|
9
|
-
|
10
|
-
included do
|
11
|
-
|
12
|
-
include Her::Model
|
13
|
-
use_api Client.her_api
|
14
|
-
|
15
|
-
attributes :data, :source_code, :code, :name, :urlize_name,
|
16
|
-
:description, :updated_at, :frequency, :from_date,
|
17
|
-
:to_date, :column_names, :private, :type
|
18
|
-
|
19
|
-
attributes :locations_attributes
|
20
|
-
|
21
|
-
alias_method :locations, :locations_attributes
|
22
|
-
alias_method :locations=, :locations_attributes=
|
23
|
-
|
24
|
-
def errors
|
25
|
-
self.attributes[:errors]
|
26
|
-
end
|
27
|
-
|
28
|
-
def full_code
|
29
|
-
@full_code ||= File.join(self.source_code, self.code)
|
30
|
-
end
|
31
|
-
|
32
|
-
def data_table
|
33
|
-
Data::Table.new( raw_data )
|
34
|
-
end
|
35
|
-
|
36
|
-
def raw_data
|
37
|
-
@raw_data ||= (self.data || Dataset.find(full_code).data || [])
|
38
|
-
end
|
39
|
-
|
40
|
-
end
|
41
|
-
|
42
|
-
end
|
43
|
-
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
@@ -1,39 +0,0 @@
|
|
1
|
-
module Quandl
|
2
|
-
module Client
|
3
|
-
|
4
|
-
class Dataset
|
5
|
-
|
6
|
-
module Searchable
|
7
|
-
|
8
|
-
extend ActiveSupport::Concern
|
9
|
-
|
10
|
-
included do
|
11
|
-
|
12
|
-
include ScopeBuilder::Model
|
13
|
-
|
14
|
-
scope_builder_for :search, :show
|
15
|
-
|
16
|
-
# SEARCH
|
17
|
-
|
18
|
-
search_scope :query, :rows
|
19
|
-
search_scope :page, ->(p){ where( page: p.to_i )}
|
20
|
-
search_scope :source_code, ->(c){ where( code: c.to_s.upcase )}
|
21
|
-
|
22
|
-
search_helper :all, ->{ connection.where(attributes).fetch }
|
23
|
-
search_helper :connection, -> { self.class.parent }
|
24
|
-
|
25
|
-
search_scope.class_eval{ delegate *Array.forwardable_methods, to: :all }
|
26
|
-
|
27
|
-
# SHOW
|
28
|
-
|
29
|
-
show_scope :rows, :exclude_data, :exclude_headers, :trim_start, :trim_end, :transform, :collapse
|
30
|
-
show_helper :find, ->(id){ connection.where(attributes).find( id ) }
|
31
|
-
show_helper :connection, -> { self.class.parent }
|
32
|
-
|
33
|
-
end
|
34
|
-
|
35
|
-
end
|
36
|
-
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|