updox 0.11.0 → 0.12.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
  SHA256:
3
- metadata.gz: 8604746ac781e33f667d93387c089f6924718494b9da372a0b3b1637b62ead92
4
- data.tar.gz: 0ea57587a39511f7560cb74e5924bf753e9b3d2553b48c03e3cdcfe2c108f0a9
3
+ metadata.gz: fd8b2034246435b98b4d29ec70697b0d89d8d2ff6ec802cea01eb8ae70084eed
4
+ data.tar.gz: 07ce5cb4a144d0c244b975105795e561e0006e2ec9e355b563cd680355302a4f
5
5
  SHA512:
6
- metadata.gz: 62ec208b18f8140c4c29266545102378c0358c9d78ac9c8bbb3c1af1cb9e929a6e687904ba406aff55460a0471af7c7dbe62a70efb444c32c623d6f9bba30a42
7
- data.tar.gz: b5803af828e248c116bb323f5b69c271431bc4eaf734d14ce88ceeb70ff861b6a76881b3d79ff5a752694577e672c28387dc6d044dad1642cec1effb5a73a5a6
6
+ metadata.gz: da03e1b1cf8aa70cb65e1e91b0147b2680f7e5307695c9ad071dd0f08d546ba122b43c3c5576b40d7699196d2121d0cffa9365822bca4c0b5a77b2def5f4c567
7
+ data.tar.gz: 9afd1c083421450366536f88212a27ae2142dafff9c9f5928b9976a2faa3c2896ac7ede4cf18bdc16bc49001804f0ba415f23191d8960f427b3697553a7e805d
@@ -4,6 +4,15 @@ All notable changes to this project will be documented in this file.
4
4
  The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
5
5
  and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
6
6
 
7
+ ## [0.12.0] - [2020-02-21]
8
+ ### Added
9
+ - Configuration to `raise` on non-success response
10
+ - Configuration to call a lambda on non-success response
11
+
12
+ ### Fixed
13
+ - Bug with `as_json` method
14
+ - Bug when no date returns on statuses
15
+
7
16
  ## [0.11.0] - [2020-02-19]
8
17
  ### Added
9
18
  - More fields to User model
data/README.md CHANGED
@@ -161,6 +161,7 @@ Updox.configure do |c|
161
161
  c.application_password = ENV['UPDOX_APP_PASS']
162
162
  c.api_endpoint = 'http://hello.com' # Defaults to Updox endpoint
163
163
  c.parse_responses = false # Defaults to true
164
+ c.failure_response = :raise # Defaults to do nothing and allows lambdas
164
165
  end
165
166
  ```
166
167
 
@@ -19,6 +19,7 @@ require 'updox/models/user'
19
19
  module Updox
20
20
  class Configuration
21
21
  attr_accessor :application_id, :application_password, :parse_responses
22
+ attr_reader :failure_action
22
23
 
23
24
  alias_method :parse_responses?, :parse_responses
24
25
 
@@ -26,6 +27,12 @@ module Updox
26
27
  @application_id = nil
27
28
  @application_password = nil
28
29
  @parse_responses = true
30
+ @failure_action = nil
31
+ end
32
+
33
+ def failure_action=(value)
34
+ raise "Failure action must be 'nil', ':raise' or callable object!" unless value.nil? || value.respond_to?(:call) || :raise == value
35
+ @failure_action = value
29
36
  end
30
37
 
31
38
  def api_endpoint=(endpoint)
@@ -41,7 +48,8 @@ module Updox
41
48
  application_id: @application_id,
42
49
  application_password: @application_password,
43
50
  api_endpoint: api_endpoint,
44
- parse_responses: @parse_responses
51
+ parse_responses: @parse_responses,
52
+ failure_action: @failure_action
45
53
  }
46
54
  end
47
55
 
@@ -50,6 +58,7 @@ module Updox
50
58
  self.application_password = h[:application_password]
51
59
  self.api_endpoint = h[:api_endpoint]
52
60
  self.parse_responses = h[:parse_responses]
61
+ self.failure_action = h[:failure_action]
53
62
 
54
63
  return self
55
64
  end
@@ -33,7 +33,10 @@ module Updox
33
33
 
34
34
  result
35
35
  end
36
- alias_method :as_json, :to_h
36
+
37
+ def as_json(args)
38
+ self.to_h
39
+ end
37
40
 
38
41
  def save(account_id: )
39
42
  self.class.sync([self], account_id: account_id)
@@ -103,7 +103,17 @@ module Updox
103
103
  model.item = data
104
104
  end
105
105
 
106
- model.updox_status = data&.select {|k,v| ['successful', 'responseMessage', 'responseCode'].include?(k)} || {}
106
+ if (data.is_a?(Hash))
107
+ model.updox_status = data&.select {|k,v| ['successful', 'responseMessage', 'responseCode'].include?(k)} || {}
108
+
109
+ if false == model.successful? && false == Updox.configuration.failure_action.nil?
110
+ if Updox.configuration.failure_action.respond_to?(:call)
111
+ Updox.configuration.failure_action.call(model)
112
+ elsif :raise == Updox.configuration.failure_action
113
+ raise UpdoxException.from_response(response, msg: 'request')
114
+ end
115
+ end
116
+ end
107
117
  else
108
118
  raise UpdoxException.from_response(response)
109
119
  end
@@ -3,7 +3,7 @@ module Updox
3
3
  class Reminder < Model
4
4
  property :reminderId
5
5
  property :reminderStatus
6
- property :reminderStatusDate, transform_with: ->(v) { DateTime.strptime(v, DATETIME_OTHER_FORMAT) }
6
+ property :reminderStatusDate, transform_with: ->(v) { DateTime.strptime(v, DATETIME_OTHER_FORMAT) unless v.nil? || v.empty? }
7
7
  property :reminderType
8
8
 
9
9
  alias_method :reminder_id, :reminderId
@@ -1,27 +1,30 @@
1
1
  module Updox
2
2
  class UpdoxException < Exception
3
3
  def self.from_response(response, msg: nil)
4
+ data = {}
4
5
  exception_msg = "Failed #{msg}:"
5
- exception_msg << " HTTP code: #{response.code}"
6
+ data['HTTP_CODE'] = response.code
6
7
 
7
8
  begin
8
9
  error_response = JSON.parse(response.body)
9
10
 
10
11
  if error_response.is_a?(Hash)
11
12
  if error_response.include?('responseMessage')
12
- exception_msg << " MSG: #{error_response['responseMessage']}"
13
+ data['MSG'] = error_response['responseMessage']
13
14
  end
14
15
 
15
16
  if error_response.include?('responseCode')
16
- exception_msg << " UPDOX CODE: #{error_response['responseCode']}"
17
+ data['UPDOX_CODE'] = error_response['responseCode']
17
18
  end
18
19
  else
19
- exception_msg << " MSG: #{error_response}"
20
+ data['MSG'] = error_response
20
21
  end
21
22
  rescue JSON::ParserError
22
- exception_msg << " MSG: #{response.body}"
23
+ data['MSG'] = response.body
23
24
  end
24
25
 
26
+ data.each {|k,v| exception_msg << " #{k} '#{v}'" }
27
+
25
28
  return UpdoxException.new(exception_msg)
26
29
  end
27
30
  end
@@ -1,3 +1,3 @@
1
1
  module Updox
2
- VERSION = '0.11.0'.freeze
2
+ VERSION = '0.12.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: updox
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.0
4
+ version: 0.12.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Crockett
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-02-20 00:00:00.000000000 Z
11
+ date: 2020-02-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty