quandl_client 0.0.13 → 0.0.14

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -2,4 +2,6 @@
2
2
  /pkg
3
3
  /tmp
4
4
  quandl_client-*
5
- .rvmrc
5
+ .rvmrc
6
+ *.gem
7
+ *.log
data/lib/quandl/client.rb CHANGED
@@ -5,6 +5,7 @@ require "active_support/inflector"
5
5
  require "active_support/core_ext/hash"
6
6
  require "active_support/core_ext/object"
7
7
 
8
+ require 'quandl/client/middleware'
8
9
  require 'quandl/client/her'
9
10
  require 'quandl/client/concerns'
10
11
  require 'quandl/client/base'
@@ -8,7 +8,7 @@ require 'quandl/client/concerns/properties'
8
8
 
9
9
  module Quandl
10
10
  module Client
11
-
11
+
12
12
  module Concerns
13
13
 
14
14
  end
@@ -11,7 +11,7 @@ module Client
11
11
 
12
12
  def token
13
13
  @token
14
- end
14
+ end
15
15
  def token=(token)
16
16
  @token = token
17
17
  reload_models
@@ -23,7 +23,8 @@ module Client
23
23
  api.setup url: rest_url do |c|
24
24
  c.use TokenAuthentication
25
25
  c.use Faraday::Request::UrlEncoded
26
- c.use Parser
26
+ # c.use Her::Middleware::DefaultParseJSON
27
+ c.use Quandl::Client::Middleware::ParseJSON
27
28
  c.use Faraday::Adapter::NetHttp
28
29
  end
29
30
  end
@@ -0,0 +1,10 @@
1
+ require 'faraday'
2
+ require 'quandl/client/middleware/parse_json'
3
+
4
+ module Quandl
5
+ module Client
6
+ module Middleware
7
+
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,52 @@
1
+ module Quandl
2
+ module Client
3
+ module Middleware
4
+
5
+ class ParseJSON < Faraday::Response::Middleware
6
+
7
+ def on_complete(env)
8
+ env[:body] = case env[:status]
9
+ when 204
10
+ parse('{}', env)
11
+ else
12
+ parse(env[:body], env)
13
+ end
14
+ end
15
+
16
+ def parse(body, env)
17
+ json = parse_json(body)
18
+ errors = json.delete(:errors) || {}
19
+ metadata = json.delete(:metadata) || {}
20
+ # collect some response data
21
+ metadata.merge!({
22
+ status: env[:status],
23
+ headers: env[:response_headers],
24
+ })
25
+ # return object
26
+ {
27
+ :data => json,
28
+ :errors => errors,
29
+ :metadata => metadata
30
+ }
31
+ end
32
+
33
+ def parse_json(body = nil)
34
+ body ||= '{}'
35
+ message = "Response from the API must behave like a Hash or an Array (last JSON response was #{body.inspect})"
36
+
37
+ json = begin
38
+ Yajl.load(body, :symbolize_keys => true)
39
+ rescue Yajl::ParseError
40
+ raise Her::Errors::ParseError, message
41
+ end
42
+
43
+ raise Her::Errors::ParseError, message unless json.is_a?(Hash) or json.is_a?(Array)
44
+
45
+ json
46
+ end
47
+
48
+ end
49
+
50
+ end
51
+ end
52
+ end
@@ -36,8 +36,8 @@ class Dataset
36
36
  # VALIDATIONS #
37
37
  ###############
38
38
 
39
- validates :source_code, presence: true, length: { minimum: 2 }, format: { with: /([A-Z][A-Z0-9_]+)/ }
40
- validates :code, presence: true, length: { minimum: 2 }, format: { with: /([A-Z][A-Z0-9_]+)/ }
39
+ validates :source_code, presence: true, length: { minimum: 2 }, format: { with: /([A-Z0-9_]+)/ }
40
+ validates :code, presence: true, length: { minimum: 2 }, format: { with: /([A-Z0-9_]+)/ }
41
41
  validates :name, presence: true
42
42
 
43
43
 
@@ -28,7 +28,7 @@ class Source
28
28
  # VALIDATIONS #
29
29
  ###############
30
30
 
31
- validates :code, presence: true, length: { minimum: 2 }, format: { with: /([A-Z][A-Z0-9_]+)/ }
31
+ validates :code, presence: true, length: { minimum: 2 }, format: { with: /([A-Z0-9_]+)/ }
32
32
  validates :host, :name, presence: true
33
33
 
34
34
 
@@ -1,6 +1,6 @@
1
1
  module Quandl
2
2
  module Client
3
- VERSION = '0.0.13'
3
+ VERSION = '0.0.14'
4
4
  API_VERSION = 'v1'
5
5
 
6
6
  class << self
@@ -8,23 +8,4 @@ module Her
8
8
  remove_method :data=
9
9
  end
10
10
  end
11
- module Middleware
12
- class ParseJSON < Faraday::Response::Middleware
13
- # @private
14
- def parse_json(body = nil)
15
- body ||= '{}'
16
- message = "Response from the API must behave like a Hash or an Array (last JSON response was #{body.inspect})"
17
-
18
- json = begin
19
- Yajl.load(body, :symbolize_keys => true)
20
- rescue MultiJson::LoadError
21
- raise Her::Errors::ParseError, message
22
- end
23
-
24
- raise Her::Errors::ParseError, message unless json.is_a?(Hash) or json.is_a?(Array)
25
-
26
- json
27
- end
28
- end
29
- end
30
11
  end
metadata CHANGED
@@ -2,14 +2,14 @@
2
2
  name: quandl_client
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.13
5
+ version: 0.0.14
6
6
  platform: ruby
7
7
  authors:
8
8
  - Blkae Hilscher
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-07-10 00:00:00.000000000 Z
12
+ date: 2013-07-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -193,6 +193,8 @@ files:
193
193
  - lib/quandl/client/concerns/properties.rb
194
194
  - lib/quandl/client/concerns/search.rb
195
195
  - lib/quandl/client/her.rb
196
+ - lib/quandl/client/middleware.rb
197
+ - lib/quandl/client/middleware/parse_json.rb
196
198
  - lib/quandl/client/models.rb
197
199
  - lib/quandl/client/models/dataset.rb
198
200
  - lib/quandl/client/models/sheet.rb