quandl_client 2.1.4 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +7 -0
- data/UPGRADE.md +12 -0
- data/examples/{client.rb → create.rb} +1 -1
- data/examples/search.rb +14 -0
- data/lib/quandl/client/base/search.rb +8 -5
- data/lib/quandl/client/middleware/parse_json.rb +24 -1
- data/lib/quandl/client/models/dataset.rb +3 -0
- data/lib/quandl/client/version.rb +1 -1
- data/quandl_client.gemspec +2 -2
- data/spec/lib/quandl/client/dataset/data_spec.rb +3 -3
- data/spec/lib/quandl/client/dataset_spec.rb +17 -1
- data/spec/spec_helper.rb +1 -1
- metadata +10 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 30cfb6f556fd81ee4c6f6b0ed1ba51404e924c10
|
4
|
+
data.tar.gz: 9728c368e51fcb51fcb4cafb7774d73d9e873260
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5afdf7eaa1d4a948fd2821fc8551b8b3111b89eb8a3422555f8f7b077e39c42da40062e57caac23268354d787737812518bb4f3a6cf20a59e9b9347f0827939c
|
7
|
+
data.tar.gz: 8c2b4941f33058a13cb0a7d9381ef1ececd39a12d15650b49dd26ac724202386e669bf9e1b6b0cf83f43e21d7b43cd76e4705f82cf27faeff0558c111b8940f8
|
data/Gemfile
CHANGED
data/UPGRADE.md
CHANGED
data/examples/search.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
$:.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
|
2
|
+
|
3
|
+
require 'pry'
|
4
|
+
require "quandl/client"
|
5
|
+
|
6
|
+
include Quandl::Client
|
7
|
+
|
8
|
+
Quandl::Client.use ENV['QUANDL_API_HOST']
|
9
|
+
# Quandl::Client.use 'http://staging.quandl.com/api/'
|
10
|
+
Quandl::Client.token = ENV['QUANDL_USER_TOKEN']
|
11
|
+
|
12
|
+
datasets = Dataset.query('water').all
|
13
|
+
|
14
|
+
binding.pry
|
@@ -16,7 +16,7 @@ module Search
|
|
16
16
|
has_scope_composer
|
17
17
|
|
18
18
|
scope :with_id, ->(value) { where( id: value.to_i )}
|
19
|
-
scope_helper :all, ->{ connection.where(
|
19
|
+
scope_helper :all, ->{ connection.where(attributes_with_scopes).fetch }
|
20
20
|
scope_helper :connection, -> { self.class.parent }
|
21
21
|
|
22
22
|
scope.class_eval do
|
@@ -28,16 +28,19 @@ module Search
|
|
28
28
|
end
|
29
29
|
|
30
30
|
def fetch
|
31
|
-
find(
|
31
|
+
find(attributes_with_scopes[:id])
|
32
32
|
end
|
33
33
|
|
34
34
|
def find(id)
|
35
|
-
|
36
|
-
result = self.class.parent.where( attrs ).find(id)
|
35
|
+
result = self.class.parent.where( attributes_with_scopes ).find(id)
|
37
36
|
result = self.class.parent.new(id: id) if result.nil?
|
38
37
|
result
|
39
38
|
end
|
40
|
-
|
39
|
+
|
40
|
+
def attributes_with_scopes
|
41
|
+
attributes.merge(scope_attributes)
|
42
|
+
end
|
43
|
+
|
41
44
|
end
|
42
45
|
|
43
46
|
end
|
@@ -12,9 +12,13 @@ class ParseJSON < Faraday::Response::Middleware
|
|
12
12
|
parse(env[:body], env)
|
13
13
|
end
|
14
14
|
end
|
15
|
-
|
15
|
+
|
16
16
|
def parse(body, env)
|
17
17
|
json = parse_json(body, env)
|
18
|
+
json.has_key?(:docs) ? format_collection( json, env ) : format_record( json, env )
|
19
|
+
end
|
20
|
+
|
21
|
+
def format_record(json, env)
|
18
22
|
errors = json.delete(:errors) || {}
|
19
23
|
metadata = json.delete(:metadata) || {}
|
20
24
|
# collect some response data
|
@@ -31,6 +35,25 @@ class ParseJSON < Faraday::Response::Middleware
|
|
31
35
|
env[:status] = 200
|
32
36
|
object
|
33
37
|
end
|
38
|
+
|
39
|
+
def format_collection(json, env)
|
40
|
+
errors = json.delete(:errors) || {}
|
41
|
+
metadata = json.delete(:metadata) || {}
|
42
|
+
docs = json.delete(:docs)
|
43
|
+
# collect some response data
|
44
|
+
metadata.merge!(json).merge!({
|
45
|
+
status: env[:status],
|
46
|
+
headers: env[:response_headers],
|
47
|
+
})
|
48
|
+
# return object
|
49
|
+
object = {
|
50
|
+
:data => docs,
|
51
|
+
:errors => errors,
|
52
|
+
:metadata => metadata
|
53
|
+
}
|
54
|
+
env[:status] = 200
|
55
|
+
object
|
56
|
+
end
|
34
57
|
|
35
58
|
def parse_json(body = nil, env)
|
36
59
|
body ||= '{}'
|
data/quandl_client.gemspec
CHANGED
@@ -24,11 +24,11 @@ Gem::Specification.new do |s|
|
|
24
24
|
s.add_development_dependency "pry"
|
25
25
|
|
26
26
|
s.add_runtime_dependency "activesupport", ">= 3.0.0"
|
27
|
-
s.add_runtime_dependency "her", "0.6
|
27
|
+
s.add_runtime_dependency "her", "~> 0.6"
|
28
28
|
s.add_runtime_dependency "yajl-ruby", "~> 1.1.0"
|
29
29
|
s.add_runtime_dependency 'json', '~> 1.7.7'
|
30
30
|
|
31
31
|
s.add_runtime_dependency "scope_composer", "~> 0.3"
|
32
|
-
s.add_runtime_dependency "quandl_data", "~> 1.
|
32
|
+
s.add_runtime_dependency "quandl_data", "~> 1.2"
|
33
33
|
|
34
34
|
end
|
@@ -63,10 +63,10 @@ describe Quandl::Client::Dataset::Data do
|
|
63
63
|
describe "#delete_rows" do
|
64
64
|
subject{ Dataset.find( dataset.id ) }
|
65
65
|
|
66
|
-
let(:dates_slice){ dataset.data.to_h.keys[5..8] }
|
66
|
+
let(:dates_slice){ dataset.data.to_date.to_h.keys[5..8] }
|
67
67
|
|
68
68
|
it "should have the dates" do
|
69
|
-
dates = Dataset.find( dataset.id ).data.to_h.keys
|
69
|
+
dates = Dataset.find( dataset.id ).data.to_date.to_h.keys
|
70
70
|
dates_slice.each{|date| dates.include?(date).should be_true }
|
71
71
|
end
|
72
72
|
|
@@ -74,7 +74,7 @@ describe Quandl::Client::Dataset::Data do
|
|
74
74
|
|
75
75
|
before(:each){ subject.delete_rows(dates_slice) }
|
76
76
|
|
77
|
-
it "data count should be
|
77
|
+
it "data count should be 6" do
|
78
78
|
Dataset.find( dataset.id ).data.count.should eq 6
|
79
79
|
end
|
80
80
|
|
@@ -8,10 +8,26 @@ describe Dataset do
|
|
8
8
|
describe ".touch_existing(:id)" do
|
9
9
|
it "should touch the dataset" do
|
10
10
|
dataset.updated_at
|
11
|
-
sleep(
|
11
|
+
sleep(1)
|
12
12
|
Dataset.touch_existing(subject.id).should eq true
|
13
13
|
Dataset.find(subject.id).updated_at.should_not eq dataset.updated_at
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
+
describe ".query" do
|
18
|
+
let(:datasets){ Quandl::Client::Dataset.query('oil').all }
|
19
|
+
subject{ datasets }
|
20
|
+
|
21
|
+
its(:first){ should be_a Quandl::Client::Dataset }
|
22
|
+
|
23
|
+
describe "#metadata" do
|
24
|
+
subject{ OpenStruct.new(datasets.metadata) }
|
25
|
+
its(:total_count){ should > 1 }
|
26
|
+
its(:per_page){ should eq 20 }
|
27
|
+
its(:sources){ should be_present }
|
28
|
+
its(:status){ should eq 200 }
|
29
|
+
its(:current_page){ should eq 1 }
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
17
33
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -11,11 +11,11 @@ require "quandl/client"
|
|
11
11
|
require "quandl/fabricate"
|
12
12
|
|
13
13
|
include Quandl::Client
|
14
|
+
Quandl::Client.token = ENV['QUANDL_AUTH_TOKEN']
|
14
15
|
Quandl::Client.use ENV['QUANDL_API_HOST']
|
15
16
|
# Quandl::Client.use 'http://staging.quandl.com/api/'
|
16
17
|
# Quandl::Client.use 'http://67.202.27.116:8080/api/'
|
17
18
|
# Quandl::Client.use 'http://quandl.com/api/'
|
18
|
-
Quandl::Client.token = ENV['QUANDL_AUTH_TOKEN']
|
19
19
|
|
20
20
|
RSpec.configure do |config|
|
21
21
|
config.include FactoryGirl::Syntax::Methods
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: quandl_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Blake Hilscher
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-11-
|
11
|
+
date: 2013-11-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -98,16 +98,16 @@ dependencies:
|
|
98
98
|
name: her
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
|
-
- -
|
101
|
+
- - ~>
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version: 0.6
|
103
|
+
version: '0.6'
|
104
104
|
type: :runtime
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
|
-
- -
|
108
|
+
- - ~>
|
109
109
|
- !ruby/object:Gem::Version
|
110
|
-
version: 0.6
|
110
|
+
version: '0.6'
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
112
|
name: yajl-ruby
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
@@ -156,14 +156,14 @@ dependencies:
|
|
156
156
|
requirements:
|
157
157
|
- - ~>
|
158
158
|
- !ruby/object:Gem::Version
|
159
|
-
version: '1.
|
159
|
+
version: '1.2'
|
160
160
|
type: :runtime
|
161
161
|
prerelease: false
|
162
162
|
version_requirements: !ruby/object:Gem::Requirement
|
163
163
|
requirements:
|
164
164
|
- - ~>
|
165
165
|
- !ruby/object:Gem::Version
|
166
|
-
version: '1.
|
166
|
+
version: '1.2'
|
167
167
|
description: An orm for the cassinatra rest interface.
|
168
168
|
email:
|
169
169
|
- blake@hilscher.ca
|
@@ -180,7 +180,8 @@ files:
|
|
180
180
|
- README.md
|
181
181
|
- Rakefile
|
182
182
|
- UPGRADE.md
|
183
|
-
- examples/
|
183
|
+
- examples/create.rb
|
184
|
+
- examples/search.rb
|
184
185
|
- examples/trims.rb
|
185
186
|
- lib/quandl/client.rb
|
186
187
|
- lib/quandl/client/base.rb
|