quandl_cassinatra 0.1.14 → 0.1.15

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.
data/UPGRADE.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## 0.1.15
2
+
3
+ * add status, blank?, saved?, exists?
4
+ * fail gracefully when parse_json receives nil body due to api throwing 500 error
5
+
1
6
  ## 0.1.14
2
7
 
3
8
  * add Dataset#trim_start, Dataset#trim_end
@@ -11,10 +11,10 @@ module Properties
11
11
  use_api Quandl::Cassinatra.her_api
12
12
 
13
13
  before_save :touch_save_time
14
- before_save :halt_unless_valid!
15
-
16
14
  after_save :log_save_time
17
15
 
16
+ before_save :halt_unless_valid!
17
+
18
18
  def valid_with_server?
19
19
  return false unless valid?
20
20
  return false unless errors_params.blank?
@@ -26,6 +26,30 @@ module Properties
26
26
  save
27
27
  end
28
28
 
29
+ def blank?
30
+ !present?
31
+ end
32
+
33
+ def exists?
34
+ present?
35
+ end
36
+
37
+ def present?
38
+ status >= 200 && status < 300
39
+ end
40
+
41
+ def saved?
42
+ status >= 200 && status <= 210
43
+ end
44
+
45
+ def status
46
+ metadata[:status].to_i
47
+ end
48
+
49
+ def parse_error
50
+ error_messages[:response_errors].try( :[], :parse_error )
51
+ end
52
+
29
53
  def error_messages
30
54
  valid?
31
55
  errors_client.deep_merge(errors_server).deep_merge(errors_params)
@@ -36,7 +60,9 @@ module Properties
36
60
  end
37
61
 
38
62
  def errors_server
39
- self.attributes[:errors] || {}
63
+ messages = self.attributes[:errors] || {}
64
+ messages[:message] = self.error if self.respond_to?(:error) && self.error.present?
65
+ messages
40
66
  end
41
67
 
42
68
  def errors_params
@@ -14,7 +14,7 @@ class ParseJSON < Faraday::Response::Middleware
14
14
  end
15
15
 
16
16
  def parse(body, env)
17
- json = parse_json(body)
17
+ json = parse_json(body, env)
18
18
  errors = json.delete(:errors) || {}
19
19
  metadata = json.delete(:metadata) || {}
20
20
  # collect some response data
@@ -32,14 +32,22 @@ class ParseJSON < Faraday::Response::Middleware
32
32
  object
33
33
  end
34
34
 
35
- def parse_json(body = nil)
35
+ def parse_json(body = nil, env)
36
36
  body ||= '{}'
37
- message = "Response from the API must behave like a Hash or an Array (last JSON response was #{body.inspect})"
38
-
39
37
  json = begin
40
38
  Yajl.load(body, :symbolize_keys => true)
41
39
  rescue Yajl::ParseError
42
- { id: 1, errors: { parse_error: message } }
40
+ nil
41
+ end
42
+ # invalid json body?
43
+ if json.blank?
44
+ # fallback to error message
45
+ json = {
46
+ id: 1,
47
+ errors: {
48
+ parse_error: "Invalid Cassinatra API response. status: #{env[:status]} (last JSON response was #{body.inspect})"
49
+ }
50
+ }
43
51
  end
44
52
  json
45
53
  end
@@ -1,5 +1,5 @@
1
1
  module Quandl
2
2
  module Cassinatra
3
- VERSION = '0.1.14'
3
+ VERSION = '0.1.15'
4
4
  end
5
5
  end
@@ -30,7 +30,6 @@ describe Dataset do
30
30
  subject.column_ids.count.should eq 3
31
31
  end
32
32
  it "should each be present" do
33
- puts "subject.column_ids #{subject.column_ids}"
34
33
  subject.column_ids.each{|cid| cid.present?.should be_true }
35
34
  end
36
35
  end
data/spec/spec_helper.rb CHANGED
@@ -15,6 +15,6 @@ end
15
15
  # LOAD GEM
16
16
 
17
17
  require "quandl/cassinatra"
18
- # Quandl::Cassinatra.use 'http://192.168.33.10:8983/wikiposit_cassandra/'
19
- Quandl::Cassinatra.use 'http://localhost:9292/'
18
+ Quandl::Cassinatra.use 'http://192.168.33.10:8983/wikiposit_cassandra/'
19
+ # Quandl::Cassinatra.use 'http://localhost:9292/'
20
20
  include Quandl::Cassinatra
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: quandl_cassinatra
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.14
4
+ version: 0.1.15
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-08-15 00:00:00.000000000 Z
12
+ date: 2013-09-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake