From 6eff1c481040bd3f20b21345442164dbcc1b693a Mon Sep 17 00:00:00 2001 From: Nick Thomas Date: Sat, 28 Sep 2013 21:57:47 +0100 Subject: [PATCH] Move to a non-standard format for dateTime objects returned to Tapatalk clients This fixes interactions with the iPhone client. Win. --- lib/tapatalker.rb | 39 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/lib/tapatalker.rb b/lib/tapatalker.rb index 99b08ad..c1b1de0 100644 --- a/lib/tapatalker.rb +++ b/lib/tapatalker.rb @@ -1,5 +1,6 @@ require 'sinatra' require 'xmlrpc/marshal' +require 'xmlrpc/create' require 'discourse_api' require 'json' require 'pp' @@ -8,6 +9,40 @@ require 'base64' require 'net/https' +# TODO: monkey-patch XMLRPC requests to support tapatalk's invalid bools. +# The hack below works, ish. + +# We need to monkey-patch our XMLRPC responses to have invalid(!) responses for +# dateTime.iso8601 objects + +module Tapatalk + + class Time < ::Time + + end + +end + +module XMLRPC + class Create + + private + + alias_method :real_conv2value, :conv2value + + def conv2value( param ) + if param.is_a?(::Tapatalk::Time ) + value = @writer.tag( "dateTime.iso8601", param.iso8601 ) # includes the timezone + @writer.ele("value", value) + else + real_conv2value( param ) + end + end + + end +end + + PUSH_TYPES = "ann,conv,pm,sub,like,thank,quote,newtopic,tag" CONFIG = YAML.load( @@ -95,8 +130,8 @@ helpers do end def make_xmlrpc_datetime( string ) - obj = Chronic.parse( string ) - XMLRPC::DateTime.new( obj.year, obj.month, obj.day, obj.hour, obj.min, obj.sec ) + t = Chronic.parse( string ) + ::Tapatalk::Time.new( t.year, t.month, t.day, t.hour, t.min, t.sec, t.utc_offset ) end def binary_xmlrpc( string )