diff --git a/google-api-client.gemspec b/google-api-client.gemspec index 97b2bfcef..aabbf67bc 100644 --- a/google-api-client.gemspec +++ b/google-api-client.gemspec @@ -27,5 +27,4 @@ Gem::Specification.new do |spec| spec.add_runtime_dependency 'googleauth', '~> 0.2' spec.add_runtime_dependency 'thor', '~> 0.19' spec.add_runtime_dependency 'memoist', '~> 0.11' - spec.add_runtime_dependency 'virtus', '~> 1.0' end diff --git a/lib/google/apis/core/json_representation.rb b/lib/google/apis/core/json_representation.rb index 3e353f2bb..9d2021a38 100644 --- a/lib/google/apis/core/json_representation.rb +++ b/lib/google/apis/core/json_representation.rb @@ -14,8 +14,8 @@ require 'representable/json' require 'representable/json/hash' -require 'representable/coercion' require 'base64' +require 'date' module Google module Apis @@ -72,6 +72,11 @@ module Google options[:render_filter] = ->(value, _doc, *_args) { Base64.urlsafe_encode64(value) } options[:parse_filter] = ->(fragment, _doc, *_args) { Base64.urlsafe_decode64(fragment) } end + if options[:type] == DateTime + options[:render_filter] = ->(value, _doc, *_args) { value.is_a?(DateTime) ? value.rfc3339(3) : value.to_s } + options[:parse_filter] = ->(fragment, _doc, *_args) { DateTime.parse(fragment) } + end + options[:render_nil] = true options[:getter] = getter_fn(name) options[:if] = if_fn(name) @@ -114,7 +119,6 @@ module Google # @see https://github.com/apotonick/representable class JsonRepresentation < Representable::Decorator include Representable::JSON - include Representable::Coercion feature JsonRepresentationSupport end end diff --git a/spec/google/apis/core/json_representation_spec.rb b/spec/google/apis/core/json_representation_spec.rb index 28db73dca..ebbe3e681 100644 --- a/spec/google/apis/core/json_representation_spec.rb +++ b/spec/google/apis/core/json_representation_spec.rb @@ -79,7 +79,7 @@ RSpec.describe Google::Apis::Core::JsonRepresentation do end it 'serializes date values' do - expect(json).to be_json_eql(%("2015-05-01T12:00:00+00:00")).at_path('dateValue') + expect(json).to be_json_eql(%("2015-05-01T12:00:00.000+00:00")).at_path('dateValue') end it 'serializes byte values to base64' do