From 42c73228e15f49db26a1952b7c898e8efacad8c3 Mon Sep 17 00:00:00 2001 From: Nic Martin Date: Sun, 17 Nov 2019 13:56:27 +0000 Subject: [PATCH 1/3] Fix problem with file persistence When writing tokens ensure encoding matches the tokens we are writing Bump gemfil --- Gemfile.lock | 16 ++++++++++------ lib/ZCRMSDK/persistence.rb | 5 +++-- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 28c3300..b9292ee 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - ZCRMSDK (0.1.0) + ZCRMSDK (1.0.0) json (~> 1.8) multipart-post (~> 2.0) rest-client (~> 2.0) @@ -10,18 +10,21 @@ GEM remote: https://rubygems.org/ specs: diff-lcs (1.3) - domain_name (0.5.20180417) + domain_name (0.5.20190701) unf (>= 0.0.5, < 1.0.0) + http-accept (1.7.0) http-cookie (1.0.3) domain_name (~> 0.5) - json (1.8.3.1) - mime-types (3.2.2) + json (1.8.6) + mime-types (3.3) mime-types-data (~> 3.2015) - mime-types-data (3.2019.0331) + mime-types-data (3.2019.1009) multipart-post (2.1.1) + mysql2 (0.5.2) netrc (0.11.0) rake (10.5.0) - rest-client (2.0.2) + rest-client (2.1.0) + http-accept (>= 1.7.0, < 2.0) http-cookie (>= 1.0.2, < 2.0) mime-types (>= 1.16, < 4.0) netrc (~> 0.8) @@ -48,6 +51,7 @@ PLATFORMS DEPENDENCIES ZCRMSDK! bundler (~> 2.0) + mysql2 (~> 0.5.2) rake (~> 10.0) rspec (~> 3.0) diff --git a/lib/ZCRMSDK/persistence.rb b/lib/ZCRMSDK/persistence.rb index d07717d..70b3dba 100644 --- a/lib/ZCRMSDK/persistence.rb +++ b/lib/ZCRMSDK/persistence.rb @@ -72,8 +72,9 @@ def save_oauth_tokens(oauth_tokens) file_obj.close arr = Marshal.load(serialized) unless serialized.nil? || serialized.empty? arr.push(oauth_tokens) - file_obj = File.open(path, 'w+') - file_obj.write(Marshal.dump(arr)) + marshalled_tokens = Marshal.dump(arr) + file_obj = File.open(path, "w:#{marshalled_tokens.encoding.to_s}") + file_obj.write(marshalled_tokens) file_obj.close end From fd4ac301dd86add0987f7e24c9430d11b8d0e397 Mon Sep 17 00:00:00 2001 From: Nic Martin Date: Wed, 20 Nov 2019 12:24:10 +0000 Subject: [PATCH 2/3] bump required version of json and version of gem --- Gemfile.lock | 6 +++--- ZCRMSDK.gemspec | 2 +- lib/ZCRMSDK/version.rb | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index b9292ee..353a30d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,8 +1,8 @@ PATH remote: . specs: - ZCRMSDK (1.0.0) - json (~> 1.8) + ZCRMSDK (1.0.1) + json (~> 2.2) multipart-post (~> 2.0) rest-client (~> 2.0) @@ -15,7 +15,7 @@ GEM http-accept (1.7.0) http-cookie (1.0.3) domain_name (~> 0.5) - json (1.8.6) + json (2.2.0) mime-types (3.3) mime-types-data (~> 3.2015) mime-types-data (3.2019.1009) diff --git a/ZCRMSDK.gemspec b/ZCRMSDK.gemspec index cb74f3c..2a6258f 100644 --- a/ZCRMSDK.gemspec +++ b/ZCRMSDK.gemspec @@ -21,7 +21,7 @@ Gem::Specification.new do |spec| spec.add_development_dependency 'bundler', '~> 2.0' spec.add_runtime_dependency 'multipart-post', '~> 2.0' spec.add_runtime_dependency 'rest-client', '~> 2.0' - spec.add_runtime_dependency 'json', '~> 1.8' + spec.add_runtime_dependency 'json', '~> 2.2' spec.add_development_dependency 'rake', '~> 10.0' spec.add_development_dependency 'rspec', '~> 3.0' spec.add_development_dependency 'mysql2', '~> 0.5.2' diff --git a/lib/ZCRMSDK/version.rb b/lib/ZCRMSDK/version.rb index f2c1ca5..0e8f0f4 100644 --- a/lib/ZCRMSDK/version.rb +++ b/lib/ZCRMSDK/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module ZCRMSDK - VERSION = '1.0.0' + VERSION = '1.0.1' end From 0ccc5f340b3ff5df34a5b7523f2521cecd3cdcf3 Mon Sep 17 00:00:00 2001 From: Nic Martin Date: Fri, 13 Dec 2019 12:58:16 +0000 Subject: [PATCH 3/3] Provide a better error with the exception Ruby Exception has a message method which can be filled with useful info. This info is used by things like Exception Notifier Gem. Populate the message with all the other details being stored in the exception, as described here: https://stackoverflow.com/questions/16106645/ruby-custom-error-classes-inheritance-of-the-message-attribute --- lib/ZCRMSDK/utility.rb | 7 +++++++ lib/ZCRMSDK/version.rb | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/ZCRMSDK/utility.rb b/lib/ZCRMSDK/utility.rb index 612d897..5e265de 100644 --- a/lib/ZCRMSDK/utility.rb +++ b/lib/ZCRMSDK/utility.rb @@ -304,6 +304,13 @@ def initialize(url, status_code, err_message, exception_code = 'error', details def self.get_instance(url, status_code, err_message, exception_code = 'error', details = nil, content = nil) ZCRMException.new(url, status_code, err_message, exception_code, details, content) end + + def to_s + "#{self.class}\n#{exception.url}\n#{exception.status_code}"\ + "- #{exception.error_message}\n"\ + "#{exception.exception_code}\n#{error_details}\n#{error_content}" + end + end end end diff --git a/lib/ZCRMSDK/version.rb b/lib/ZCRMSDK/version.rb index 0e8f0f4..dc57155 100644 --- a/lib/ZCRMSDK/version.rb +++ b/lib/ZCRMSDK/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module ZCRMSDK - VERSION = '1.0.1' + VERSION = '1.0.2' end