quandl_client 2.12.0 → 2.13.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: bbd142f2168c56abfd65d09f7a6b3c0d3000d949
4
- data.tar.gz: 247b1975234bf1fa653365f4f584d7a3913ef787
3
+ metadata.gz: c216058327d626f746fc0107f2f0f90dbcc9bbaf
4
+ data.tar.gz: 1fbe183c0fde9cad61dd00e617620b57d0289024
5
5
  SHA512:
6
- metadata.gz: 5e2cbf227a742be61d9df1163e0f3ac4e751af8032e727e2f4e123bf4b3bd068619732c5ea829022beb8153c0afbee03198083248f342dc75f7ea45d86ec2539
7
- data.tar.gz: 8d9cd5d32c55cf39912821c1e4b6f714f6f4f13d9169761bc1c22e3943d330e69f1c25832f24fccd936a86d048d719e94572b8e6ee719460d4ccab1cf6665fb7
6
+ metadata.gz: 11cb43b358f0ef63ffe3a6e3de4988e411414c51a76f5911580e843f97d4dd306e397db753faaa62060a3689ab38bed3b97d105caf26d0b510d4efd8ea89e5f9
7
+ data.tar.gz: 8a2ea5751751a5495ae71cf980d19647149aa6f42405609fef6d8309c927f7d9207dca73740874c009c294aa7971c5261c7b637c6cc1f049eb9081fcd718016a
data/Gemfile CHANGED
@@ -1,12 +1,2 @@
1
- source "https://rubygems.org"
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
- gem 'quandl_data', path: "#{local_gem_dir}/quandl/data"
10
- gem 'quandl_operation', path: "#{local_gem_dir}/quandl/operation"
11
- gem 'quandl_babelfish', path: "#{local_gem_dir}/quandl/babelfish"
12
- end
data/UPGRADE.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 2.13.0
2
+
3
+ * Add threadsafe_token option
4
+
1
5
  ## 2.12.0
2
6
 
3
7
  * Add redirect_path attribute to Sheets
@@ -24,15 +24,13 @@ require 'quandl/client/models/superset'
24
24
 
25
25
  module Quandl
26
26
  module Client
27
-
28
27
  class << self
29
-
30
28
  attr_accessor :request_source, :request_version, :request_platform
31
-
29
+
32
30
  def request_source
33
31
  @request_source ||= "quandl_client"
34
32
  end
35
-
33
+
36
34
  def request_version
37
35
  @request_version ||= Quandl::Client::VERSION
38
36
  end
@@ -40,17 +38,22 @@ module Quandl
40
38
  def request_platform
41
39
  @request_platform ||= RUBY_PLATFORM
42
40
  end
43
-
41
+
42
+ end
43
+
44
+ def self.threadsafe_token!
45
+ Quandl::Client::Base.threadsafe_token!
44
46
  end
45
-
47
+
46
48
  def self.use(url)
47
49
  Quandl::Client::Base.use(url)
48
50
  end
51
+
49
52
  def self.token=(value)
50
53
  Quandl::Client::Base.token = value
51
54
  end
52
-
55
+
53
56
  HTTP_STATUS_CODES = {100=>"Continue", 101=>"Switching Protocols", 102=>"Processing", 200=>"OK", 201=>"Created", 202=>"Accepted", 203=>"Non-Authoritative Information", 204=>"No Content", 205=>"Reset Content", 206=>"Partial Content", 207=>"Multi-Status", 208=>"Already Reported", 226=>"IM Used", 300=>"Multiple Choices", 301=>"Moved Permanently", 302=>"Found", 303=>"See Other", 304=>"Not Modified", 305=>"Use Proxy", 306=>"Reserved", 307=>"Temporary Redirect", 308=>"Permanent Redirect", 400=>"Bad Request", 401=>"Unauthorized", 402=>"Payment Required", 403=>"Forbidden", 404=>"Not Found", 405=>"Method Not Allowed", 406=>"Not Acceptable", 407=>"Proxy Authentication Required", 408=>"Request Timeout", 409=>"Conflict", 410=>"Gone", 411=>"Length Required", 412=>"Precondition Failed", 413=>"Request Entity Too Large", 414=>"Request-URI Too Long", 415=>"Unsupported Media Type", 416=>"Requested Range Not Satisfiable", 417=>"Expectation Failed", 422=>"Unprocessable Entity", 423=>"Locked", 424=>"Failed Dependency", 425=>"Reserved for WebDAV advanced collections expired proposal", 426=>"Upgrade Required", 427=>"Unassigned", 428=>"Precondition Required", 429=>"Too Many Requests", 430=>"Unassigned", 431=>"Request Header Fields Too Large", 500=>"Internal Server Error", 501=>"Not Implemented", 502=>"Bad Gateway", 503=>"Service Unavailable", 504=>"Gateway Timeout", 505=>"HTTP Version Not Supported", 506=>"Variant Also Negotiates (Experimental)", 507=>"Insufficient Storage", 508=>"Loop Detected", 509=>"Unassigned", 510=>"Not Extended", 511=>"Network Authentication Required"}
54
-
57
+
55
58
  end
56
59
  end
@@ -11,84 +11,106 @@ require 'quandl/client/base/search'
11
11
 
12
12
  I18n.enforce_available_locales = false
13
13
 
14
- class Quandl::Client::Base
15
-
16
- class << self
17
-
18
- attr_accessor :url, :token
19
-
20
- def use(url)
21
- self.url = url
22
- models_use_her_api!
23
- end
24
-
25
- def token=(token)
26
- @token = token
27
- models_use_her_api!
28
- end
29
-
30
- def her_api
31
- Her::API.new.setup url: url_with_version do |c|
32
- c.use TokenAuthentication
33
- c.use TrackRequestSource
34
- c.use Faraday::Request::Multipart
35
- c.use Faraday::Request::UrlEncoded
36
- c.use Quandl::Client::Middleware::ParseJSON
37
- c.use Faraday::Adapter::NetHttp
38
- end
39
- end
14
+ module Quandl
15
+ module Client
16
+ class Base
17
+ TOKEN_THREAD_KEY = 'quandl_client_token'
40
18
 
41
- def url
42
- @url ||= "https://www.quandl.com/api/"
43
- end
19
+ class << self
20
+ attr_accessor :url, :token
44
21
 
45
- def url_with_version
46
- File.join( url.to_s, Quandl::Client.api_version.to_s )
47
- end
48
-
49
- def inherited(subclass)
50
- # remember models that inherit from base
51
- models << subclass unless models.include?(subclass)
52
- # include model behaviour
53
- subclass.class_eval do
54
- include Quandl::Client::Base::Model
55
- include Quandl::Client::Base::Benchmark
56
- include Quandl::Client::Base::Attributes
57
- include Quandl::Client::Base::Validation
58
- include Quandl::Client::Base::Search
59
- end
60
- end
61
-
62
- def models
63
- @@models ||= []
64
- end
65
-
66
- protected
67
-
68
- def models_use_her_api!
69
- models.each{|m|
70
- m.url = url_with_version
71
- m.use_api( her_api )
72
- }
73
- end
74
-
75
- class TokenAuthentication < Faraday::Middleware
76
- def call(env)
77
- env[:request_headers]["X-API-Token"] = Quandl::Client::Base.token if Quandl::Client::Base.token.present?
78
- @app.call(env)
79
- end
80
- end
81
-
82
- class TrackRequestSource < Faraday::Middleware
83
- def call(env)
84
- env[:body] ||= {}
85
- env[:body][:request_source] = Quandl::Client.request_source
86
- env[:body][:request_version] = Quandl::Client.request_version
87
- env[:body][:request_platform] = Quandl::Client.request_platform
88
- @app.call(env)
22
+ def threadsafe_token!
23
+ @threadsafe_token = true
24
+ end
25
+
26
+ def threadsafe_token?
27
+ @threadsafe_token || false
28
+ end
29
+
30
+ def use(url)
31
+ self.url = url
32
+ models_use_her_api!
33
+ end
34
+
35
+ def token=(token)
36
+ if threadsafe_token?
37
+ Thread.current[TOKEN_THREAD_KEY] = token
38
+ else
39
+ @token = token
40
+ end
41
+ models_use_her_api!
42
+ end
43
+
44
+ def token
45
+ if threadsafe_token?
46
+ Thread.current[TOKEN_THREAD_KEY]
47
+ else
48
+ @token
49
+ end
50
+ end
51
+
52
+ def her_api
53
+ Her::API.new.setup url: url_with_version do |c|
54
+ c.use TokenAuthentication
55
+ c.use TrackRequestSource
56
+ c.use Faraday::Request::Multipart
57
+ c.use Faraday::Request::UrlEncoded
58
+ c.use Quandl::Client::Middleware::ParseJSON
59
+ c.use Faraday::Adapter::NetHttp
60
+ end
61
+ end
62
+
63
+ def url
64
+ @url ||= "https://www.quandl.com/api/"
65
+ end
66
+
67
+ def url_with_version
68
+ File.join( url.to_s, Quandl::Client.api_version.to_s )
69
+ end
70
+
71
+ def inherited(subclass)
72
+ # remember models that inherit from base
73
+ models << subclass unless models.include?(subclass)
74
+ # include model behaviour
75
+ subclass.class_eval do
76
+ include Quandl::Client::Base::Model
77
+ include Quandl::Client::Base::Benchmark
78
+ include Quandl::Client::Base::Attributes
79
+ include Quandl::Client::Base::Validation
80
+ include Quandl::Client::Base::Search
81
+ end
82
+ end
83
+
84
+ def models
85
+ @@models ||= []
86
+ end
87
+
88
+ protected
89
+
90
+ def models_use_her_api!
91
+ models.each do |m|
92
+ m.url = url_with_version
93
+ m.use_api(her_api)
94
+ end
95
+ end
96
+
97
+ class TokenAuthentication < Faraday::Middleware
98
+ def call(env)
99
+ env[:request_headers]["X-API-Token"] = Quandl::Client::Base.token if Quandl::Client::Base.token.present?
100
+ @app.call(env)
101
+ end
102
+ end
103
+
104
+ class TrackRequestSource < Faraday::Middleware
105
+ def call(env)
106
+ env[:body] ||= {}
107
+ env[:body][:request_source] = Quandl::Client.request_source
108
+ env[:body][:request_version] = Quandl::Client.request_version
109
+ env[:body][:request_platform] = Quandl::Client.request_platform
110
+ @app.call(env)
111
+ end
112
+ end
89
113
  end
90
114
  end
91
-
92
115
  end
93
-
94
116
  end
@@ -10,7 +10,7 @@ class Quandl::Client::Dataset::Data < Quandl::Client::Base
10
10
  end
11
11
 
12
12
  scope *[:row, :rows, :limit, :offset, :accuracy, :column, :order,
13
- :transform, :collapse, :exclude_headers]
13
+ :transformation, :collapse, :exclude_headers]
14
14
 
15
15
  scope :trim_start, ->(date){ date = parse_date(date); where( trim_start: date ) if date }
16
16
  scope :trim_end, ->(date){ date = parse_date(date); where( trim_end: date ) if date }
@@ -40,7 +40,7 @@ module Quandl
40
40
  # PROPERTIES #
41
41
  ##############
42
42
 
43
- attributes :code, :name, :host, :description, :datasets_count, :use_proxy, :type, :concurrency
43
+ attributes :code, :name, :host, :description, :datasets_count, :use_proxy, :type, :concurrency, :documentation
44
44
 
45
45
  end
46
46
  end
@@ -1,6 +1,6 @@
1
1
  module Quandl
2
2
  module Client
3
- VERSION = '2.12.0'
3
+ VERSION = '2.13.0'
4
4
  API_VERSION = 'v2'
5
5
 
6
6
  class << self
@@ -5,4 +5,86 @@ describe Base do
5
5
  it "should have https in base url by default" do
6
6
  Quandl::Client::Base.url.should include 'https://www.'
7
7
  end
8
+
9
+ describe '.token' do
10
+ let(:base_token) { 'foo' }
11
+
12
+ context 'token threadsaftey disabled' do
13
+ before(:each) do
14
+ Quandl::Client::Base.token = base_token
15
+ end
16
+
17
+ context 'original thread' do
18
+ it 'should have base value' do
19
+ expect(Quandl::Client::Base.token).to eq(base_token)
20
+ end
21
+
22
+ it 'should inherit thread values' do
23
+ thread_token = 'foobar'
24
+ t = Thread.new do
25
+ Quandl::Client::Base.token = thread_token
26
+ end
27
+ t.join
28
+ expect(Quandl::Client::Base.token).to eq(thread_token)
29
+ end
30
+ end
31
+
32
+ context 'new thread' do
33
+ it 'should inherit base value' do
34
+ t = Thread.new do
35
+ expect(Quandl::Client::Base.token).to eq(base_token)
36
+ end
37
+ t.join
38
+ end
39
+
40
+ it 'should override with thread value' do
41
+ thread_token = 'foobarbaz'
42
+ t = Thread.new do
43
+ Quandl::Client::Base.token = thread_token
44
+ expect(Quandl::Client::Base.token).to eq(thread_token)
45
+ end
46
+ t.join
47
+ end
48
+ end
49
+ end
50
+
51
+
52
+ context 'token threadsafety enabled' do
53
+ before(:each) do
54
+ Quandl::Client.threadsafe_token!
55
+ Quandl::Client::Base.token = base_token
56
+ end
57
+
58
+ context 'original thread' do
59
+ it 'should have base value' do
60
+ expect(Quandl::Client::Base.token).to eq(base_token)
61
+ end
62
+
63
+ it 'should not inherit thread values' do
64
+ t = Thread.new do
65
+ Quandl::Client::Base.token = 'hello_world!'
66
+ end
67
+ t.join
68
+ expect(Quandl::Client::Base.token).to eq(base_token)
69
+ end
70
+ end
71
+ context 'new thread' do
72
+ it 'should not inherit parent value' do
73
+ t = Thread.new do
74
+ expect(Quandl::Client::Base.token).to be_nil
75
+ end
76
+ t.join
77
+ end
78
+
79
+ it 'should contain thread value for token' do
80
+ thread_token = 'this_is_a_token!'
81
+ t = Thread.new do
82
+ Quandl::Client::Base.token = thread_token
83
+ expect(Quandl::Client::Base.token).to eq(thread_token)
84
+ end
85
+ t.join
86
+ end
87
+ end
88
+ end
89
+ end
8
90
  end
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.12.0
4
+ version: 2.13.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: 2014-10-02 00:00:00.000000000 Z
11
+ date: 2015-03-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: quandl_data