Fix logins to be more persistent, A few other cleanups

Prior to this change ( setting the Mobiquo_is_login: true header ),
the official android client would do many login calls - one every
other API call, more or less. This makes us persistent instead.
This commit is contained in:
Nick Thomas
2013-09-28 00:05:12 +01:00
parent c7f4cc2694
commit 4a0aa9d681

View File

@@ -5,6 +5,8 @@ require 'json'
require 'pp'
require 'chronic'
PUSH_TYPES = "ann,conv,pm,sub,like,thank,quote,newtopic,tag"
CONFIG = YAML.load(
File.read(
File.join(
@@ -33,13 +35,20 @@ set :tapatalk_api_key, CONFIG.fetch( 'tapatalk_api_key', nil )
before do
# Pass through all cookies to the discourse instance
discourse( request.cookies )
# TODO: Override on auth failures, cookie timeouts, etc. to set this to false
mobiquo_login_header!( request.cookies.has_key?("_t") )
end
helpers do
def mobiquo_login_header!( val )
headers "Mobiquo_is_login" => val.to_s
end
# Use this as our entry point
def dispatch
xml = @request.body.read
xml = fixup_tapatalk_xml( @request.body.read )
fixup_tapatalk_xml( xml )
@@ -50,7 +59,7 @@ helpers do
method = "xmlrpc_#{method.gsub(/([A-Z])/, '_ ').downcase}"
puts "method = #{method}, args = #{ method =~ /login/ ? "*REDACTED*" : arguments.inspect }"
# Check if method exists
if(respond_to?(method))
content_type("text/xml", :charset => "utf-8")
@@ -64,7 +73,8 @@ helpers do
# Apparently, tapatalk formats booleans contrary to the XMLRPC standard.
# https://github.com/svdgraaf/django-tapatalk/blob/master/tapatalk/dispatcher.py
def fixup_tapatalk_xml( text )
text.gsub( '<boolean>true</boolean>', '<boolean>1</boolean>' )
text.gsub( '<boolean>true</boolean>', '<boolean>1</boolean>' ).
gsub( '<boolean>false</boolean>', '<boolean>0</boolean>' )
end
def make_xmlrpc_datetime( string )
@@ -157,7 +167,12 @@ helpers do
end
def respond_xmlrpc( rsp )
XMLRPC::Marshal.dump_response( rsp )
data = XMLRPC::Marshal.dump_response( rsp )
data.gsub!( '<?xml version="1.0" ?>', '<?xml version="1.0" encoding="UTF-8"?>' )
data.tr!("\n", "")
data
end
## http://tapatalk.com/api/api_section.php ##
@@ -166,6 +181,7 @@ helpers do
# First function called by tapatalk, apparently we should always return the
# whole hash.
def xmlrpc_get_config( name = nil )
mobiquo_login_header!( false )
result = {
# Uncontroversial
@@ -202,7 +218,7 @@ helpers do
"min_search_length" => 3, # Boring default
"alert" => "0", # TODO
"direct_unsubscribe" => "0", # TODO
# "push_type" => "ann,conv,pm,sub,like,thank,quote,newtopic,tag",
# "push_type" => PUSH_TYPES,
# "ban_delete_type" => "none", # TODO
"inappreg" => "0", # TODO
@@ -261,7 +277,7 @@ helpers do
end
def xmlrpc_login( user = nil, pass = nil, anonymous = false, push = '1' )
mobiquo_login_header!( false )
return respond_xmlrpc(
'result' => false,
'result_text' => binary_xmlrpc( 'Anonymous login not supported' )
@@ -307,7 +323,10 @@ helpers do
# can_whosonline => true, # api level 4
# can_profile => true, # api level 4
'can_upload_avatar' => false, # TODO
# push_type ...
# Don't enable push if the user has disabled it
# FIXME: bool or string 1/0 ?
# 'push_type' => PUSH_TYPES.split(",").collect {|type| { 'name' => type, 'value' => push } }
)
end
@@ -342,7 +361,15 @@ helpers do
'new_post' => true, # TODO
"is_protected" => false, # Not required, apparently
'description' => binary_xmlrpc( hsh['description'].to_s ),
"child" => []
"child" => [],
# These are returned by some others
'new_post' => false,
'url' => '',
'logo_url' => '',
'unread_count' => 0, # TODO
}
# FIXME: may not be right?