quandl_client 2.1.4 → 2.2.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2bf0070f8faa49f7f0c8d37861dda9dffb18dea7
4
- data.tar.gz: 1d4dbd6dbb1b4bf94c49186cb844527e5ea06693
3
+ metadata.gz: 30cfb6f556fd81ee4c6f6b0ed1ba51404e924c10
4
+ data.tar.gz: 9728c368e51fcb51fcb4cafb7774d73d9e873260
5
5
  SHA512:
6
- metadata.gz: 6a1eae0d8c8dcbff92ee02ad5b200f7102d3ba259970da50dce72d738c657bfeb65e1df04f61ad4ddc6d799f1d8bd7dd7d201c4237b8eaa4efca52952260d254
7
- data.tar.gz: 8cb7c9a46f8c6e10f88ef161c2503a11646c5afef7aeeec4ac95e5873b437946132770b69281738a8d8097cc673981398e217ca2878529f12b944f3e9e0bc33e
6
+ metadata.gz: 5afdf7eaa1d4a948fd2821fc8551b8b3111b89eb8a3422555f8f7b077e39c42da40062e57caac23268354d787737812518bb4f3a6cf20a59e9b9347f0827939c
7
+ data.tar.gz: 8c2b4941f33058a13cb0a7d9381ef1ececd39a12d15650b49dd26ac724202386e669bf9e1b6b0cf83f43e21d7b43cd76e4705f82cf27faeff0558c111b8940f8
data/Gemfile CHANGED
@@ -1,2 +1,9 @@
1
1
  source "https://rubygems.org"
2
2
  gemspec
3
+
4
+ use_local_gems = ENV['BUNDLE_LOCAL_GEMS'] == "true" && ENV['BUNDLE_LOCAL_DIR']
5
+ local_gem_dir = ENV['BUNDLE_LOCAL_DIR']
6
+
7
+ if use_local_gems
8
+ gem 'her', path: "#{local_gem_dir}/her"
9
+ end
data/UPGRADE.md CHANGED
@@ -1,3 +1,15 @@
1
+ ## 2.2.0
2
+
3
+ * add specs for Dataset.query
4
+ * Dataset.query.all.metadata should pass
5
+
6
+
7
+ ## 2.1.4
8
+
9
+ * add specs for Dataset.query(term).all; make specs pass
10
+
11
+
12
+
1
13
  ## 2.1.3
2
14
 
3
15
  * add specs for data scopes
@@ -7,7 +7,7 @@ require 'securerandom'
7
7
 
8
8
  include Quandl::Client
9
9
 
10
- Quandl::Client.use 'http://quandl.com/api/'
10
+ Quandl::Client.use ENV['QUANDL_API_HOST']
11
11
  Quandl::Client.token = ENV['QUANDL_USER_TOKEN']
12
12
 
13
13
  # create dataset
@@ -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(attributes).fetch }
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(attributes[:id])
31
+ find(attributes_with_scopes[:id])
32
32
  end
33
33
 
34
34
  def find(id)
35
- attrs = attributes.merge(scope_attributes)
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 ||= '{}'
@@ -1,6 +1,9 @@
1
1
  class Quandl::Client::Dataset < Quandl::Client::Base
2
2
 
3
3
  require 'quandl/client/models/dataset/data'
4
+
5
+ # parse_root_in_json true
6
+ # root_element :docs
4
7
 
5
8
  ##########
6
9
  # SCOPES #
@@ -1,6 +1,6 @@
1
1
  module Quandl
2
2
  module Client
3
- VERSION = '2.1.4'
3
+ VERSION = '2.2.0'
4
4
  API_VERSION = 'v2'
5
5
 
6
6
  class << self
@@ -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.7"
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.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 16" do
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(0.75)
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.1.4
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-25 00:00:00.000000000 Z
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.7
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.7
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.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.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/client.rb
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