quandl_client 2.7.5 → 2.7.6
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +7 -7
- data/.rspec +1 -1
- data/.travis.yml +20 -20
- data/.yardopts +2 -2
- data/Gemfile +12 -12
- data/Guardfile +8 -8
- data/LICENSE +7 -7
- data/README.md +303 -303
- data/Rakefile +31 -35
- data/UPGRADE.md +190 -213
- data/VERSION +1 -1
- data/examples/create.rb +32 -32
- data/examples/find.rb +17 -17
- data/examples/login.rb +12 -12
- data/examples/search.rb +12 -12
- data/examples/trims.rb +15 -15
- data/lib/quandl/client.rb +49 -49
- data/lib/quandl/client/base.rb +91 -91
- data/lib/quandl/client/base/attributes.rb +15 -15
- data/lib/quandl/client/base/model.rb +40 -40
- data/lib/quandl/client/base/search.rb +74 -74
- data/lib/quandl/client/base/validation.rb +101 -101
- data/lib/quandl/client/middleware.rb +9 -9
- data/lib/quandl/client/middleware/parse_json.rb +85 -85
- data/lib/quandl/client/models/dataset.rb +261 -245
- data/lib/quandl/client/models/dataset/data.rb +57 -57
- data/lib/quandl/client/models/location.rb +10 -10
- data/lib/quandl/client/models/report.rb +14 -14
- data/lib/quandl/client/models/scraper.rb +16 -16
- data/lib/quandl/client/models/sheet.rb +50 -50
- data/lib/quandl/client/models/source.rb +48 -40
- data/lib/quandl/client/models/superset.rb +59 -59
- data/lib/quandl/client/models/user.rb +7 -7
- data/lib/quandl/client/version.rb +14 -14
- data/lib/quandl/her/remove_method_data.rb +8 -8
- data/lib/quandl/pattern.rb +37 -37
- data/lib/quandl/pattern/client.rb +8 -8
- data/quandl_client.gemspec +33 -33
- data/spec/factories/dataset.rb +10 -10
- data/spec/factories/sheet.rb +7 -7
- data/spec/factories/source.rb +9 -9
- data/spec/fixtures/scraper.rb +5 -5
- data/spec/lib/quandl/client/dataset/attributes_spec.rb +63 -63
- data/spec/lib/quandl/client/dataset/data_spec.rb +92 -92
- data/spec/lib/quandl/client/dataset/location_spec.rb +65 -65
- data/spec/lib/quandl/client/dataset/persistence_spec.rb +104 -104
- data/spec/lib/quandl/client/dataset/search_spec.rb +19 -19
- data/spec/lib/quandl/client/dataset/source_spec.rb +47 -47
- data/spec/lib/quandl/client/dataset/trim_spec.rb +35 -35
- data/spec/lib/quandl/client/dataset/validation_spec.rb +68 -68
- data/spec/lib/quandl/client/dataset_spec.rb +57 -57
- data/spec/lib/quandl/client/scraper_spec.rb +71 -71
- data/spec/lib/quandl/client/sheet_spec.rb +37 -37
- data/spec/lib/quandl/client/source_spec.rb +51 -51
- data/spec/spec_helper.rb +30 -30
- metadata +27 -5
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.7.
|
1
|
+
2.7.6
|
data/examples/create.rb
CHANGED
@@ -1,32 +1,32 @@
|
|
1
|
-
$:.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
|
2
|
-
|
3
|
-
# load quandl api client
|
4
|
-
require "quandl/client"
|
5
|
-
|
6
|
-
# tools for debugging
|
7
|
-
require "quandl/fabricate"
|
8
|
-
require 'securerandom'
|
9
|
-
require 'pry'
|
10
|
-
|
11
|
-
# Make Dataset available in global namespace
|
12
|
-
include Quandl::Client
|
13
|
-
|
14
|
-
# configure quandl client
|
15
|
-
Quandl::Client.use ENV['QUANDL_TEST_URL']
|
16
|
-
Quandl::Client.token = ENV['QUANDL_TEST_TOKEN']
|
17
|
-
|
18
|
-
# set some attributes
|
19
|
-
d = Dataset.new(
|
20
|
-
code: "MY_DATASET_#{Time.now.to_i.to_s(16)}",
|
21
|
-
name: "My dataset has a name.",
|
22
|
-
description: "This is the description.",
|
23
|
-
data: [[ 2014, 1, 2 ]]
|
24
|
-
)
|
25
|
-
# POST to server
|
26
|
-
d.save
|
27
|
-
|
28
|
-
if d.saved?
|
29
|
-
puts "View your new dataset at: #{d.full_url}"
|
30
|
-
else
|
31
|
-
puts "Something went wrong:\n#{d.human_status}\n#{d.human_error_messages}"
|
32
|
-
end
|
1
|
+
$:.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
|
2
|
+
|
3
|
+
# load quandl api client
|
4
|
+
require "quandl/client"
|
5
|
+
|
6
|
+
# tools for debugging
|
7
|
+
require "quandl/fabricate"
|
8
|
+
require 'securerandom'
|
9
|
+
require 'pry'
|
10
|
+
|
11
|
+
# Make Dataset available in global namespace
|
12
|
+
include Quandl::Client
|
13
|
+
|
14
|
+
# configure quandl client
|
15
|
+
Quandl::Client.use ENV['QUANDL_TEST_URL']
|
16
|
+
Quandl::Client.token = ENV['QUANDL_TEST_TOKEN']
|
17
|
+
|
18
|
+
# set some attributes
|
19
|
+
d = Dataset.new(
|
20
|
+
code: "MY_DATASET_#{Time.now.to_i.to_s(16)}",
|
21
|
+
name: "My dataset has a name.",
|
22
|
+
description: "This is the description.",
|
23
|
+
data: [[ 2014, 1, 2 ]]
|
24
|
+
)
|
25
|
+
# POST to server
|
26
|
+
d.save
|
27
|
+
|
28
|
+
if d.saved?
|
29
|
+
puts "View your new dataset at: #{d.full_url}"
|
30
|
+
else
|
31
|
+
puts "Something went wrong:\n#{d.human_status}\n#{d.human_error_messages}"
|
32
|
+
end
|
data/examples/find.rb
CHANGED
@@ -1,18 +1,18 @@
|
|
1
|
-
$:.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
|
2
|
-
|
3
|
-
# DEBUGGING
|
4
|
-
require 'pry'
|
5
|
-
require "quandl/fabricate"
|
6
|
-
|
7
|
-
# LOAD
|
8
|
-
require "quandl/client"
|
9
|
-
include Quandl::Client
|
10
|
-
|
11
|
-
# CONFIGURE
|
12
|
-
Quandl::Client.use ENV['QUANDL_URL']
|
13
|
-
Quandl::Client.token = ENV['QUANDL_TOKEN']
|
14
|
-
|
15
|
-
# FIND
|
16
|
-
d = Dataset.find('MCX.ALMG2014')
|
17
|
-
|
1
|
+
$:.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
|
2
|
+
|
3
|
+
# DEBUGGING
|
4
|
+
require 'pry'
|
5
|
+
require "quandl/fabricate"
|
6
|
+
|
7
|
+
# LOAD
|
8
|
+
require "quandl/client"
|
9
|
+
include Quandl::Client
|
10
|
+
|
11
|
+
# CONFIGURE
|
12
|
+
Quandl::Client.use ENV['QUANDL_URL']
|
13
|
+
Quandl::Client.token = ENV['QUANDL_TOKEN']
|
14
|
+
|
15
|
+
# FIND
|
16
|
+
d = Dataset.find('MCX.ALMG2014')
|
17
|
+
|
18
18
|
binding.pry
|
data/examples/login.rb
CHANGED
@@ -1,13 +1,13 @@
|
|
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_TEST_URL']
|
9
|
-
Quandl::Client.token = ENV['QUANDL_TEST_TOKEN']
|
10
|
-
|
11
|
-
u = User.login( login: 'blakehil', password: 'example' )
|
12
|
-
|
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_TEST_URL']
|
9
|
+
Quandl::Client.token = ENV['QUANDL_TEST_TOKEN']
|
10
|
+
|
11
|
+
u = User.login( login: 'blakehil', password: 'example' )
|
12
|
+
|
13
13
|
binding.pry
|
data/examples/search.rb
CHANGED
@@ -1,13 +1,13 @@
|
|
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_TEST_URL']
|
9
|
-
Quandl::Client.token = ENV['QUANDL_TEST_TOKEN']
|
10
|
-
|
11
|
-
datasets = Dataset.query('water').all
|
12
|
-
|
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_TEST_URL']
|
9
|
+
Quandl::Client.token = ENV['QUANDL_TEST_TOKEN']
|
10
|
+
|
11
|
+
datasets = Dataset.query('water').all
|
12
|
+
|
13
13
|
binding.pry
|
data/examples/trims.rb
CHANGED
@@ -1,16 +1,16 @@
|
|
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 'http://quandl.com/api/'
|
9
|
-
Quandl::Client.token = ENV['QUANDL_TEST_TOKEN']
|
10
|
-
|
11
|
-
# create dataset
|
12
|
-
d = Dataset.find('NSE/OIL')
|
13
|
-
|
14
|
-
data = d.data.trim_start( 3.weeks.ago ).limit(10)
|
15
|
-
|
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 'http://quandl.com/api/'
|
9
|
+
Quandl::Client.token = ENV['QUANDL_TEST_TOKEN']
|
10
|
+
|
11
|
+
# create dataset
|
12
|
+
d = Dataset.find('NSE/OIL')
|
13
|
+
|
14
|
+
data = d.data.trim_start( 3.weeks.ago ).limit(10)
|
15
|
+
|
16
16
|
binding.pry
|
data/lib/quandl/client.rb
CHANGED
@@ -1,50 +1,50 @@
|
|
1
|
-
require "quandl/client/version"
|
2
|
-
|
3
|
-
require 'scope_composer'
|
4
|
-
require 'her'
|
5
|
-
require 'quandl/her/remove_method_data'
|
6
|
-
require 'quandl/logger'
|
7
|
-
require "quandl/data"
|
8
|
-
|
9
|
-
require 'quandl/pattern'
|
10
|
-
require 'quandl/pattern/client'
|
11
|
-
|
12
|
-
require 'quandl/client/middleware'
|
13
|
-
require 'quandl/client/base'
|
14
|
-
require 'quandl/client/models/dataset'
|
15
|
-
require 'quandl/client/models/sheet'
|
16
|
-
require 'quandl/client/models/source'
|
17
|
-
require 'quandl/client/models/user'
|
18
|
-
require 'quandl/client/models/location'
|
19
|
-
require 'quandl/client/models/scraper'
|
20
|
-
require 'quandl/client/models/report'
|
21
|
-
require 'quandl/client/models/superset'
|
22
|
-
|
23
|
-
module Quandl
|
24
|
-
module Client
|
25
|
-
|
26
|
-
class << self
|
27
|
-
|
28
|
-
attr_accessor :request_source, :request_version
|
29
|
-
|
30
|
-
def request_source
|
31
|
-
@request_source ||= "quandl_client"
|
32
|
-
end
|
33
|
-
|
34
|
-
def request_version
|
35
|
-
@request_version ||= Quandl::Client::VERSION
|
36
|
-
end
|
37
|
-
|
38
|
-
end
|
39
|
-
|
40
|
-
def self.use(url)
|
41
|
-
Quandl::Client::Base.use(url)
|
42
|
-
end
|
43
|
-
def self.token=(value)
|
44
|
-
Quandl::Client::Base.token = value
|
45
|
-
end
|
46
|
-
|
47
|
-
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"}
|
48
|
-
|
49
|
-
end
|
1
|
+
require "quandl/client/version"
|
2
|
+
|
3
|
+
require 'scope_composer'
|
4
|
+
require 'her'
|
5
|
+
require 'quandl/her/remove_method_data'
|
6
|
+
require 'quandl/logger'
|
7
|
+
require "quandl/data"
|
8
|
+
|
9
|
+
require 'quandl/pattern'
|
10
|
+
require 'quandl/pattern/client'
|
11
|
+
|
12
|
+
require 'quandl/client/middleware'
|
13
|
+
require 'quandl/client/base'
|
14
|
+
require 'quandl/client/models/dataset'
|
15
|
+
require 'quandl/client/models/sheet'
|
16
|
+
require 'quandl/client/models/source'
|
17
|
+
require 'quandl/client/models/user'
|
18
|
+
require 'quandl/client/models/location'
|
19
|
+
require 'quandl/client/models/scraper'
|
20
|
+
require 'quandl/client/models/report'
|
21
|
+
require 'quandl/client/models/superset'
|
22
|
+
|
23
|
+
module Quandl
|
24
|
+
module Client
|
25
|
+
|
26
|
+
class << self
|
27
|
+
|
28
|
+
attr_accessor :request_source, :request_version
|
29
|
+
|
30
|
+
def request_source
|
31
|
+
@request_source ||= "quandl_client"
|
32
|
+
end
|
33
|
+
|
34
|
+
def request_version
|
35
|
+
@request_version ||= Quandl::Client::VERSION
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.use(url)
|
41
|
+
Quandl::Client::Base.use(url)
|
42
|
+
end
|
43
|
+
def self.token=(value)
|
44
|
+
Quandl::Client::Base.token = value
|
45
|
+
end
|
46
|
+
|
47
|
+
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"}
|
48
|
+
|
49
|
+
end
|
50
50
|
end
|
data/lib/quandl/client/base.rb
CHANGED
@@ -1,92 +1,92 @@
|
|
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/base/model'
|
7
|
-
require 'quandl/client/base/attributes'
|
8
|
-
require 'quandl/client/base/validation'
|
9
|
-
require 'quandl/client/base/search'
|
10
|
-
|
11
|
-
I18n.enforce_available_locales = false
|
12
|
-
|
13
|
-
class Quandl::Client::Base
|
14
|
-
|
15
|
-
class << self
|
16
|
-
|
17
|
-
attr_accessor :url, :token
|
18
|
-
|
19
|
-
def use(url)
|
20
|
-
self.url = url
|
21
|
-
models_use_her_api!
|
22
|
-
end
|
23
|
-
|
24
|
-
def token=(token)
|
25
|
-
@token = token
|
26
|
-
models_use_her_api!
|
27
|
-
end
|
28
|
-
|
29
|
-
def her_api
|
30
|
-
Her::API.new.setup url: url_with_version do |c|
|
31
|
-
c.use TokenAuthentication
|
32
|
-
c.use TrackRequestSource
|
33
|
-
c.use Faraday::Request::Multipart
|
34
|
-
c.use Faraday::Request::UrlEncoded
|
35
|
-
c.use Quandl::Client::Middleware::ParseJSON
|
36
|
-
c.use Faraday::Adapter::NetHttp
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
def url
|
41
|
-
@url ||= "http://quandl.com/api/"
|
42
|
-
end
|
43
|
-
|
44
|
-
def url_with_version
|
45
|
-
File.join( url.to_s, Quandl::Client.api_version.to_s )
|
46
|
-
end
|
47
|
-
|
48
|
-
def inherited(subclass)
|
49
|
-
# remember models that inherit from base
|
50
|
-
models << subclass unless models.include?(subclass)
|
51
|
-
# include model behaviour
|
52
|
-
subclass.class_eval do
|
53
|
-
include Quandl::Client::Base::Model
|
54
|
-
include Quandl::Client::Base::Attributes
|
55
|
-
include Quandl::Client::Base::Validation
|
56
|
-
include Quandl::Client::Base::Search
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
def models
|
61
|
-
@@models ||= []
|
62
|
-
end
|
63
|
-
|
64
|
-
protected
|
65
|
-
|
66
|
-
def models_use_her_api!
|
67
|
-
models.each{|m|
|
68
|
-
m.url = url_with_version
|
69
|
-
m.use_api( her_api )
|
70
|
-
}
|
71
|
-
end
|
72
|
-
|
73
|
-
class TokenAuthentication < Faraday::Middleware
|
74
|
-
def call(env)
|
75
|
-
env[:request_headers]["X-API-Token"] = Quandl::Client::Base.token if Quandl::Client::Base.token.present?
|
76
|
-
@app.call(env)
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
class TrackRequestSource < Faraday::Middleware
|
81
|
-
def call(env)
|
82
|
-
env[:body] ||= {}
|
83
|
-
env[:body][:request_source] = Quandl::Client.request_source
|
84
|
-
env[:body][:request_version] = Quandl::Client.request_version
|
85
|
-
env[:body][:request_platform] = RUBY_PLATFORM
|
86
|
-
@app.call(env)
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
end
|
91
|
-
|
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/base/model'
|
7
|
+
require 'quandl/client/base/attributes'
|
8
|
+
require 'quandl/client/base/validation'
|
9
|
+
require 'quandl/client/base/search'
|
10
|
+
|
11
|
+
I18n.enforce_available_locales = false
|
12
|
+
|
13
|
+
class Quandl::Client::Base
|
14
|
+
|
15
|
+
class << self
|
16
|
+
|
17
|
+
attr_accessor :url, :token
|
18
|
+
|
19
|
+
def use(url)
|
20
|
+
self.url = url
|
21
|
+
models_use_her_api!
|
22
|
+
end
|
23
|
+
|
24
|
+
def token=(token)
|
25
|
+
@token = token
|
26
|
+
models_use_her_api!
|
27
|
+
end
|
28
|
+
|
29
|
+
def her_api
|
30
|
+
Her::API.new.setup url: url_with_version do |c|
|
31
|
+
c.use TokenAuthentication
|
32
|
+
c.use TrackRequestSource
|
33
|
+
c.use Faraday::Request::Multipart
|
34
|
+
c.use Faraday::Request::UrlEncoded
|
35
|
+
c.use Quandl::Client::Middleware::ParseJSON
|
36
|
+
c.use Faraday::Adapter::NetHttp
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def url
|
41
|
+
@url ||= "http://quandl.com/api/"
|
42
|
+
end
|
43
|
+
|
44
|
+
def url_with_version
|
45
|
+
File.join( url.to_s, Quandl::Client.api_version.to_s )
|
46
|
+
end
|
47
|
+
|
48
|
+
def inherited(subclass)
|
49
|
+
# remember models that inherit from base
|
50
|
+
models << subclass unless models.include?(subclass)
|
51
|
+
# include model behaviour
|
52
|
+
subclass.class_eval do
|
53
|
+
include Quandl::Client::Base::Model
|
54
|
+
include Quandl::Client::Base::Attributes
|
55
|
+
include Quandl::Client::Base::Validation
|
56
|
+
include Quandl::Client::Base::Search
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def models
|
61
|
+
@@models ||= []
|
62
|
+
end
|
63
|
+
|
64
|
+
protected
|
65
|
+
|
66
|
+
def models_use_her_api!
|
67
|
+
models.each{|m|
|
68
|
+
m.url = url_with_version
|
69
|
+
m.use_api( her_api )
|
70
|
+
}
|
71
|
+
end
|
72
|
+
|
73
|
+
class TokenAuthentication < Faraday::Middleware
|
74
|
+
def call(env)
|
75
|
+
env[:request_headers]["X-API-Token"] = Quandl::Client::Base.token if Quandl::Client::Base.token.present?
|
76
|
+
@app.call(env)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
class TrackRequestSource < Faraday::Middleware
|
81
|
+
def call(env)
|
82
|
+
env[:body] ||= {}
|
83
|
+
env[:body][:request_source] = Quandl::Client.request_source
|
84
|
+
env[:body][:request_version] = Quandl::Client.request_version
|
85
|
+
env[:body][:request_platform] = RUBY_PLATFORM
|
86
|
+
@app.call(env)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
91
|
+
|
92
92
|
end
|