appfuel 0.5.2 → 0.5.3

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: 259df454a7a765d3b8bb73cbb7f0c512ef507e9e
4
- data.tar.gz: ead4fce377496bf073d1cf08a19fa2aa3cc41de8
3
+ metadata.gz: bccec5e07ac5df9b023b7b6df825ec5267a54f3b
4
+ data.tar.gz: 263e81d457c6e413467e228ac4d47d5e97e3be97
5
5
  SHA512:
6
- metadata.gz: 9ec7d761b53d31b9751f47e6b54d5cbd99d7a93aa40af9b00501fd33f52ab55aff255ffd60cb6850013cba81cac5ef0ed7c3606c1375c6567b77d4732d6d21c7
7
- data.tar.gz: 54bb42b0bffe6c7a2d81e0d736c57ab6bc7aea25d1ec32dbdfa751a43e80da6f42ec843d27a6ca85db99726fdae442ddc5e9f3b7f966aa9b692743fec4b37954
6
+ metadata.gz: 299cdbec29d85211e5cf4a54609ed4af6bdb90a18846c7626bf537c630d22a4dfcfb7a9318000f3ac6b017545c71a8bd257f5f7bc4792639e152e2b67b024004
7
+ data.tar.gz: 9c7c6e7a4e8281a3dedc20ccbc7f5934a3f75614b9986f1a2fb5f9297421d776ec6f01f4fd431e33cd5c4ec642876a831342d4353fe758f9261216ff054f8afe
data/CHANGELOG.md CHANGED
@@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file. (Pending ap
5
5
 
6
6
 
7
7
  # Releases
8
+ ## [[0.5.2]] (https://github.com/rsb/appfuel/releases/tag/0.5.3) 2017-07-10
9
+ ### Fixed
10
+ - response object not working when `ok` key is a string
11
+
8
12
  ## [[0.5.2]] (https://github.com/rsb/appfuel/releases/tag/0.5.2) 2017-07-03
9
13
  ### Fixed
10
14
  - aws initialization fails when no endpoint
@@ -10,9 +10,28 @@ module Appfuel
10
10
  # @param result Hash the successfull resultset
11
11
  # @reuturn Response
12
12
  def ok(result = nil)
13
+ result = ok_data(result) if ok_key?(result)
13
14
  self.new(ok: result)
14
15
  end
15
16
 
17
+ def ok_key?(data)
18
+ return false unless data.is_a?(Hash)
19
+ data.key?(:ok) || data.key?("ok")
20
+ end
21
+
22
+ def error_key?(data)
23
+ return false unless data.is_a?(Hash)
24
+ data.key?(:errors) || data.key?("errors")
25
+ end
26
+
27
+ def ok_data(data)
28
+ data[:ok] || data['ok']
29
+ end
30
+
31
+ def error_data(data)
32
+ data[:errors] || data['errors']
33
+ end
34
+
16
35
  # Convience method for creating an error response. It understands
17
36
  # how to handle a SpCore::Error object. Any thing that
18
37
  # is not a hash or can't be converted to a hash is assumed to be
@@ -45,18 +64,16 @@ module Appfuel
45
64
  # @return [Response]
46
65
  def initialize(data = {})
47
66
  result = format_result_hash(data)
48
-
49
- # when no ok key and no errors key the assume
67
+ # when no ok key and no errors key then assume
50
68
  # it is a successfull response
51
- if !result.key?(:ok) && !result.key?(:errors)
52
- result = {ok: result}
53
- end
54
-
55
- @ok = result[:ok]
69
+ @ok = nil
56
70
  @errors = nil
57
- if result.key?(:errors)
58
- @ok = nil
59
- @errors = Errors.new(result[:errors])
71
+ if self.class.ok_key?(result)
72
+ @ok = self.class.ok_data(result)
73
+ elsif self.class.error_key?(result)
74
+ @errors = Errors.new(self.class.error_data(result))
75
+ else
76
+ @ok = result
60
77
  end
61
78
  end
62
79
 
@@ -7,8 +7,15 @@ module Appfuel
7
7
  end
8
8
 
9
9
  def create_response(data)
10
- return data if response?(data)
11
- return error(data) if error_data?(data)
10
+ if response?(data)
11
+ return data
12
+ end
13
+
14
+ if error_data?(data)
15
+ return error(data)
16
+ end
17
+
18
+ # TODO normalize ok key symbol or string here
12
19
  ok(data)
13
20
  end
14
21
 
@@ -1,3 +1,3 @@
1
1
  module Appfuel
2
- VERSION = "0.5.2"
2
+ VERSION = "0.5.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: appfuel
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.2
4
+ version: 0.5.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Scott-Buccleuch
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-07-03 00:00:00.000000000 Z
11
+ date: 2017-07-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord