quandl_client 0.0.14 → 0.0.15

Sign up to get free protection for your applications and to get access to all the features.
@@ -22,6 +22,18 @@ module Properties
22
22
  true
23
23
  end
24
24
 
25
+ def saved?
26
+ status == 200 || status == 201
27
+ end
28
+
29
+ def status
30
+ metadata[:status].to_i
31
+ end
32
+
33
+ def parse_error
34
+ error_messages[:response_errors].try( :[], :parse_error )
35
+ end
36
+
25
37
  def error_messages
26
38
  valid?
27
39
  errors_client.deep_merge(errors_server).deep_merge(errors_params)
@@ -30,7 +30,7 @@ module Client
30
30
  end
31
31
 
32
32
  def rest_url
33
- @rest_url ||= "http://www.quandl.com/api/#{API_VERSION}/"
33
+ @rest_url ||= "http://localhost:3000/api/#{API_VERSION}/"
34
34
  end
35
35
 
36
36
  def rest_url=(url)
@@ -45,27 +45,6 @@ module Client
45
45
  Models.use_api( her_api )
46
46
  end
47
47
 
48
- class Parser < Faraday::Response::Middleware
49
- def on_complete(env)
50
- json = MultiJson.load(env[:body], symbolize_keys: true)
51
- errors = []
52
- if json.is_a?(Hash) && json.has_key?(:docs)
53
- errors = [json.delete(:error)]
54
- data = json.delete(:docs)
55
- metadata = json
56
- else
57
- errors = [json.delete(:error)] if json.is_a?(Hash) && json.has_key?(:error)
58
- data = json.present? ? json : {}
59
- metadata = {}
60
- end
61
- env[:body] = {
62
- data: data,
63
- errors: errors,
64
- metadata: metadata
65
- }
66
- end
67
- end
68
-
69
48
  class TokenAuthentication < Faraday::Middleware
70
49
  def call(env)
71
50
  env[:request_headers]["X-API-Token"] = Quandl::Client.token if Quandl::Client.token.present?
@@ -23,11 +23,13 @@ class ParseJSON < Faraday::Response::Middleware
23
23
  headers: env[:response_headers],
24
24
  })
25
25
  # return object
26
- {
26
+ object = {
27
27
  :data => json,
28
28
  :errors => errors,
29
29
  :metadata => metadata
30
30
  }
31
+ env[:status] = 200
32
+ object
31
33
  end
32
34
 
33
35
  def parse_json(body = nil)
@@ -37,10 +39,11 @@ class ParseJSON < Faraday::Response::Middleware
37
39
  json = begin
38
40
  Yajl.load(body, :symbolize_keys => true)
39
41
  rescue Yajl::ParseError
40
- raise Her::Errors::ParseError, message
42
+ { id: 1, errors: { parse_error: message } }
43
+
44
+ # raise Her::Errors::ParseError, message
41
45
  end
42
-
43
- raise Her::Errors::ParseError, message unless json.is_a?(Hash) or json.is_a?(Array)
46
+ # raise Her::Errors::ParseError, message unless json.is_a?(Hash) or json.is_a?(Array)
44
47
 
45
48
  json
46
49
  end
@@ -1,6 +1,6 @@
1
1
  module Quandl
2
2
  module Client
3
- VERSION = '0.0.14'
3
+ VERSION = '0.0.15'
4
4
  API_VERSION = 'v1'
5
5
 
6
6
  class << self
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.14
5
+ version: 0.0.15
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-11 00:00:00.000000000 Z
12
+ date: 2013-07-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake