quandl_client 2.2.2 → 2.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e81aaa8f303bf326b11226513522ddfe29c7e408
4
- data.tar.gz: dc1c441e7569562647ce575105ee7ee9fa689858
3
+ metadata.gz: 96bcb5f9ffb52af6a7448692809d6a6780353eea
4
+ data.tar.gz: 3c54dcbb44783c244fab3635dd5386b15a45edd9
5
5
  SHA512:
6
- metadata.gz: 6dff6e5349a2e01375699d7a953c24569d849c3d113e5d32d7caa24e25f8f486139cc4d1db58dc8fabda7f9c355c14ef7f96121f14028e784215092a56d5f83b
7
- data.tar.gz: 6698073bfb90697f063c2562b35f37cb0017b6210c1fef9803d50a7671125aed03a3ce7f37cbabad04291978c4376d03a7111c8ec7d22b8a4cb3e22ca94ca05c
6
+ metadata.gz: 2a5687a55d8381f1e6dbcf80c8d722a74c9681da244c6f7d44659d8ab77b9f245c8f67bca8ec9eb33a796e49b29996d483ccac85f5f8c40a7beca9d1543c778e
7
+ data.tar.gz: 2189f13d9f07eab27de81362e2554180cc964034d48c89ab127ac260beb2758fd3906f88577272da91c9e8730444d1c1aa4840d059f217a7cbf75a8b7f3e7494
data/UPGRADE.md CHANGED
@@ -1,3 +1,12 @@
1
+ ## 2.3.0
2
+
3
+ * add auth_token attribute to user
4
+ * add Quandl::Client::User, .login for authenticating
5
+ * full_url outputs the quandl link instead of the api link. Add human_status and HTTP_STATUS_CODES
6
+ * should validate display_url as a url
7
+ * add reference_url alias for display_url. reference_url will automatically add http when missing
8
+
9
+
1
10
  ## 2.2.1
2
11
 
3
12
  * full_code: dont assume that source_code is present
data/examples/login.rb ADDED
@@ -0,0 +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_API_HOST']
9
+ Quandl::Client.token = ENV['QUANDL_USER_TOKEN']
10
+
11
+ u = User.login( login: 'blakehil', password: 'example' )
12
+
13
+ binding.pry
@@ -38,6 +38,10 @@ module Validation
38
38
  status > 0
39
39
  end
40
40
 
41
+ def human_status
42
+ Quandl::Client::HTTP_STATUS_CODES[status]
43
+ end
44
+
41
45
  def status
42
46
  metadata[:status].to_i
43
47
  end
@@ -70,6 +74,21 @@ module Validation
70
74
  def halt_unless_valid!
71
75
  return false unless valid?
72
76
  end
77
+
78
+ class UrlValidator < ActiveModel::EachValidator
79
+ def validate_each(record, attribute, value)
80
+ begin
81
+ uri = URI.parse(value)
82
+ resp = uri.kind_of?(URI::HTTP)
83
+
84
+ rescue URI::InvalidURIError
85
+ resp = false
86
+ end
87
+ unless resp == true
88
+ record.errors[attribute] << (options[:message] || "is not an url")
89
+ end
90
+ end
91
+ end
73
92
 
74
93
  end
75
94
  end
@@ -15,7 +15,7 @@ class Quandl::Client::Base
15
15
  attr_accessor :url, :token
16
16
 
17
17
  def use(url)
18
- self.url = File.join( url, Quandl::Client.api_version )
18
+ self.url = url
19
19
  models_use_her_api!
20
20
  end
21
21
 
@@ -25,7 +25,7 @@ class Quandl::Client::Base
25
25
  end
26
26
 
27
27
  def her_api
28
- Her::API.new.setup url: url do |c|
28
+ Her::API.new.setup url: url_with_version do |c|
29
29
  c.use TokenAuthentication
30
30
  c.use Faraday::Request::UrlEncoded
31
31
  c.use Quandl::Client::Middleware::ParseJSON
@@ -34,7 +34,11 @@ class Quandl::Client::Base
34
34
  end
35
35
 
36
36
  def url
37
- @url ||= "http://localhost:3000/api/#{Quandl::Client.api_version}/"
37
+ @url ||= "http://quandl.com/api/"
38
+ end
39
+
40
+ def url_with_version
41
+ File.join( url.to_s, Quandl::Client.api_version.to_s )
38
42
  end
39
43
 
40
44
  def inherited(subclass)
@@ -57,7 +61,7 @@ class Quandl::Client::Base
57
61
 
58
62
  def models_use_her_api!
59
63
  models.each{|m|
60
- m.url = url
64
+ m.url = url_with_version
61
65
  m.use_api( her_api )
62
66
  }
63
67
  end
@@ -10,7 +10,7 @@ class Quandl::Client::Dataset < Quandl::Client::Base
10
10
  ##########
11
11
 
12
12
  def self.touch_existing(id)
13
- put(File.join(Quandl::Client::Base.url, "datasets/#{id}/touch")).exists?
13
+ put(File.join(Quandl::Client::Base.url_with_version, "datasets/#{id}/touch")).exists?
14
14
  end
15
15
 
16
16
  # SEARCH
@@ -31,7 +31,7 @@ class Quandl::Client::Dataset < Quandl::Client::Base
31
31
  ###############
32
32
 
33
33
  validates :code, presence: true, format: { with: /[A-Z0-9_]+/ }
34
- validates :name, presence: true, :length => { :maximum => 1000 }
34
+ validates :display_url, allow_blank: true, url: true
35
35
 
36
36
 
37
37
  ##############
@@ -49,8 +49,15 @@ class Quandl::Client::Dataset < Quandl::Client::Base
49
49
  alias_method :locations, :locations_attributes
50
50
  alias_method :locations=, :locations_attributes=
51
51
 
52
+ def reference_url
53
+ self.display_url
54
+ end
55
+ def reference_url=(value)
56
+ self.display_url = value
57
+ end
58
+
52
59
  def full_url
53
- File.join(Quandl::Client::Dataset.url, 'datasets', full_code)
60
+ File.join(Quandl::Client::Base.url.gsub('api/', ''), full_code)
54
61
  end
55
62
 
56
63
  def full_code
@@ -0,0 +1,7 @@
1
+ class Quandl::Client::User < Quandl::Client::Base
2
+
3
+ custom_post :login
4
+
5
+ attributes :auth_token
6
+
7
+ end
@@ -1,6 +1,6 @@
1
1
  module Quandl
2
2
  module Client
3
- VERSION = '2.2.2'
3
+ VERSION = '2.3.0'
4
4
  API_VERSION = 'v2'
5
5
 
6
6
  class << self
data/lib/quandl/client.rb CHANGED
@@ -11,9 +11,11 @@ require 'quandl/client/base'
11
11
  require 'quandl/client/models/dataset'
12
12
  require 'quandl/client/models/sheet'
13
13
  require 'quandl/client/models/source'
14
+ require 'quandl/client/models/user'
14
15
 
15
16
  module Quandl
16
17
  module Client
18
+
17
19
  def self.use(url)
18
20
  Quandl::Client::Base.use(url)
19
21
  end
@@ -21,5 +23,7 @@ module Quandl
21
23
  Quandl::Client::Base.token = value
22
24
  end
23
25
 
26
+ 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"}
27
+
24
28
  end
25
29
  end
@@ -22,16 +22,14 @@ Gem::Specification.new do |s|
22
22
  s.add_development_dependency "factory_girl_rails"
23
23
  s.add_development_dependency "fivemat", "~> 1.2"
24
24
  s.add_development_dependency "pry"
25
+ s.add_development_dependency "guard"
26
+ s.add_development_dependency "guard-rspec"
27
+
28
+ s.add_runtime_dependency "quandl_data", "~> 1.2"
25
29
 
26
30
  s.add_runtime_dependency "activesupport", ">= 3.0.0"
27
31
  s.add_runtime_dependency "her", "~> 0.6"
28
32
  s.add_runtime_dependency "yajl-ruby", "~> 1.1.0"
29
33
  s.add_runtime_dependency 'json', '~> 1.7.7'
30
-
31
34
  s.add_runtime_dependency "scope_composer", "~> 0.3"
32
- s.add_runtime_dependency "quandl_data", "~> 1.2"
33
-
34
-
35
- s.add_development_dependency "guard"
36
- s.add_development_dependency "guard-rspec"
37
35
  end
@@ -10,6 +10,26 @@ describe Dataset do
10
10
  }
11
11
  subject{ create(:dataset, source_code: source.code, private: true ) }
12
12
 
13
+ describe "#reference_url" do
14
+ let(:url){ "http://website.com/path/to/reference" }
15
+ let(:dataset){ Dataset.new( reference_url: url, code: "VALID" ) }
16
+ subject{ dataset }
17
+
18
+ its(:reference_url){ should eq url }
19
+ its(:valid?){ should be_true }
20
+
21
+ context "partial url" do
22
+ let(:url){ "website.com/path/to/reference" }
23
+ its(:valid?){ should be_false }
24
+ end
25
+
26
+ context "invalid url" do
27
+ let(:url){ "website" }
28
+ its(:valid?){ should be_false }
29
+ end
30
+
31
+ end
32
+
13
33
  describe "#private" do
14
34
 
15
35
  it "should update to false" do
@@ -7,6 +7,7 @@ describe Dataset do
7
7
  subject{ dataset }
8
8
 
9
9
  context "admin user" do
10
+
10
11
  its(:saved?){ should be_true }
11
12
  its(:source_code){ should be_present }
12
13
 
@@ -15,11 +15,12 @@ describe Dataset do
15
15
  end
16
16
 
17
17
  it "should change url" do
18
+ original_url = Quandl::Client::Base.url
18
19
  Quandl::Client.use('http://url.com/')
19
20
  Quandl::Client::Dataset.url.should eq 'http://url.com/v2'
20
21
  Quandl::Client.use('http://url.com/2/')
21
22
  Quandl::Client::Dataset.url.should eq 'http://url.com/2/v2'
22
- Quandl::Client.use ENV['QUANDL_API_HOST']
23
+ Quandl::Client.use original_url
23
24
  end
24
25
 
25
26
  describe ".query" do
data/spec/spec_helper.rb CHANGED
@@ -10,6 +10,14 @@ Dir.glob( factory_dir ).each{|f| require(f); puts f }
10
10
  require "quandl/client"
11
11
  require "quandl/fabricate"
12
12
 
13
+ # Expects two env variables:
14
+
15
+ # administrator:
16
+ # ENV['QUANDL_AUTH_TOKEN']
17
+
18
+ # user:
19
+ # ENV['QUANDL_USER_TOKEN']
20
+
13
21
  include Quandl::Client
14
22
  Quandl::Client.token = ENV['QUANDL_AUTH_TOKEN']
15
23
  Quandl::Client.use ENV['QUANDL_API_HOST']
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.2.2
4
+ version: 2.3.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-29 00:00:00.000000000 Z
11
+ date: 2013-12-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -81,117 +81,117 @@ dependencies:
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
- name: activesupport
84
+ name: guard
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - '>='
88
88
  - !ruby/object:Gem::Version
89
- version: 3.0.0
90
- type: :runtime
89
+ version: '0'
90
+ type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - '>='
95
95
  - !ruby/object:Gem::Version
96
- version: 3.0.0
96
+ version: '0'
97
97
  - !ruby/object:Gem::Dependency
98
- name: her
98
+ name: guard-rspec
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - ~>
101
+ - - '>='
102
102
  - !ruby/object:Gem::Version
103
- version: '0.6'
104
- type: :runtime
103
+ version: '0'
104
+ type: :development
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'
111
111
  - !ruby/object:Gem::Dependency
112
- name: yajl-ruby
112
+ name: quandl_data
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
115
  - - ~>
116
116
  - !ruby/object:Gem::Version
117
- version: 1.1.0
117
+ version: '1.2'
118
118
  type: :runtime
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
122
  - - ~>
123
123
  - !ruby/object:Gem::Version
124
- version: 1.1.0
124
+ version: '1.2'
125
125
  - !ruby/object:Gem::Dependency
126
- name: json
126
+ name: activesupport
127
127
  requirement: !ruby/object:Gem::Requirement
128
128
  requirements:
129
- - - ~>
129
+ - - '>='
130
130
  - !ruby/object:Gem::Version
131
- version: 1.7.7
131
+ version: 3.0.0
132
132
  type: :runtime
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
- - - ~>
136
+ - - '>='
137
137
  - !ruby/object:Gem::Version
138
- version: 1.7.7
138
+ version: 3.0.0
139
139
  - !ruby/object:Gem::Dependency
140
- name: scope_composer
140
+ name: her
141
141
  requirement: !ruby/object:Gem::Requirement
142
142
  requirements:
143
143
  - - ~>
144
144
  - !ruby/object:Gem::Version
145
- version: '0.3'
145
+ version: '0.6'
146
146
  type: :runtime
147
147
  prerelease: false
148
148
  version_requirements: !ruby/object:Gem::Requirement
149
149
  requirements:
150
150
  - - ~>
151
151
  - !ruby/object:Gem::Version
152
- version: '0.3'
152
+ version: '0.6'
153
153
  - !ruby/object:Gem::Dependency
154
- name: quandl_data
154
+ name: yajl-ruby
155
155
  requirement: !ruby/object:Gem::Requirement
156
156
  requirements:
157
157
  - - ~>
158
158
  - !ruby/object:Gem::Version
159
- version: '1.2'
159
+ version: 1.1.0
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.2'
166
+ version: 1.1.0
167
167
  - !ruby/object:Gem::Dependency
168
- name: guard
168
+ name: json
169
169
  requirement: !ruby/object:Gem::Requirement
170
170
  requirements:
171
- - - '>='
171
+ - - ~>
172
172
  - !ruby/object:Gem::Version
173
- version: '0'
174
- type: :development
173
+ version: 1.7.7
174
+ type: :runtime
175
175
  prerelease: false
176
176
  version_requirements: !ruby/object:Gem::Requirement
177
177
  requirements:
178
- - - '>='
178
+ - - ~>
179
179
  - !ruby/object:Gem::Version
180
- version: '0'
180
+ version: 1.7.7
181
181
  - !ruby/object:Gem::Dependency
182
- name: guard-rspec
182
+ name: scope_composer
183
183
  requirement: !ruby/object:Gem::Requirement
184
184
  requirements:
185
- - - '>='
185
+ - - ~>
186
186
  - !ruby/object:Gem::Version
187
- version: '0'
188
- type: :development
187
+ version: '0.3'
188
+ type: :runtime
189
189
  prerelease: false
190
190
  version_requirements: !ruby/object:Gem::Requirement
191
191
  requirements:
192
- - - '>='
192
+ - - ~>
193
193
  - !ruby/object:Gem::Version
194
- version: '0'
194
+ version: '0.3'
195
195
  description: An orm for the cassinatra rest interface.
196
196
  email:
197
197
  - blake@hilscher.ca
@@ -210,6 +210,7 @@ files:
210
210
  - Rakefile
211
211
  - UPGRADE.md
212
212
  - examples/create.rb
213
+ - examples/login.rb
213
214
  - examples/search.rb
214
215
  - examples/trims.rb
215
216
  - lib/quandl/client.rb
@@ -224,6 +225,7 @@ files:
224
225
  - lib/quandl/client/models/dataset/data.rb
225
226
  - lib/quandl/client/models/sheet.rb
226
227
  - lib/quandl/client/models/source.rb
228
+ - lib/quandl/client/models/user.rb
227
229
  - lib/quandl/client/version.rb
228
230
  - lib/quandl/her/remove_method_data.rb
229
231
  - quandl_client.gemspec