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:
@@ -5,6 +5,8 @@ require 'json'
|
|||||||
require 'pp'
|
require 'pp'
|
||||||
require 'chronic'
|
require 'chronic'
|
||||||
|
|
||||||
|
PUSH_TYPES = "ann,conv,pm,sub,like,thank,quote,newtopic,tag"
|
||||||
|
|
||||||
CONFIG = YAML.load(
|
CONFIG = YAML.load(
|
||||||
File.read(
|
File.read(
|
||||||
File.join(
|
File.join(
|
||||||
@@ -33,13 +35,20 @@ set :tapatalk_api_key, CONFIG.fetch( 'tapatalk_api_key', nil )
|
|||||||
before do
|
before do
|
||||||
# Pass through all cookies to the discourse instance
|
# Pass through all cookies to the discourse instance
|
||||||
discourse( request.cookies )
|
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
|
end
|
||||||
|
|
||||||
helpers do
|
helpers do
|
||||||
|
|
||||||
|
def mobiquo_login_header!( val )
|
||||||
|
headers "Mobiquo_is_login" => val.to_s
|
||||||
|
end
|
||||||
|
|
||||||
# Use this as our entry point
|
# Use this as our entry point
|
||||||
def dispatch
|
def dispatch
|
||||||
xml = @request.body.read
|
xml = fixup_tapatalk_xml( @request.body.read )
|
||||||
|
|
||||||
fixup_tapatalk_xml( xml )
|
fixup_tapatalk_xml( xml )
|
||||||
|
|
||||||
@@ -50,7 +59,7 @@ helpers do
|
|||||||
|
|
||||||
method = "xmlrpc_#{method.gsub(/([A-Z])/, '_ ').downcase}"
|
method = "xmlrpc_#{method.gsub(/([A-Z])/, '_ ').downcase}"
|
||||||
puts "method = #{method}, args = #{ method =~ /login/ ? "*REDACTED*" : arguments.inspect }"
|
puts "method = #{method}, args = #{ method =~ /login/ ? "*REDACTED*" : arguments.inspect }"
|
||||||
|
|
||||||
# Check if method exists
|
# Check if method exists
|
||||||
if(respond_to?(method))
|
if(respond_to?(method))
|
||||||
content_type("text/xml", :charset => "utf-8")
|
content_type("text/xml", :charset => "utf-8")
|
||||||
@@ -64,7 +73,8 @@ helpers do
|
|||||||
# Apparently, tapatalk formats booleans contrary to the XMLRPC standard.
|
# Apparently, tapatalk formats booleans contrary to the XMLRPC standard.
|
||||||
# https://github.com/svdgraaf/django-tapatalk/blob/master/tapatalk/dispatcher.py
|
# https://github.com/svdgraaf/django-tapatalk/blob/master/tapatalk/dispatcher.py
|
||||||
def fixup_tapatalk_xml( text )
|
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
|
end
|
||||||
|
|
||||||
def make_xmlrpc_datetime( string )
|
def make_xmlrpc_datetime( string )
|
||||||
@@ -157,7 +167,12 @@ helpers do
|
|||||||
end
|
end
|
||||||
|
|
||||||
def respond_xmlrpc( rsp )
|
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
|
end
|
||||||
|
|
||||||
## http://tapatalk.com/api/api_section.php ##
|
## http://tapatalk.com/api/api_section.php ##
|
||||||
@@ -166,6 +181,7 @@ helpers do
|
|||||||
# First function called by tapatalk, apparently we should always return the
|
# First function called by tapatalk, apparently we should always return the
|
||||||
# whole hash.
|
# whole hash.
|
||||||
def xmlrpc_get_config( name = nil )
|
def xmlrpc_get_config( name = nil )
|
||||||
|
mobiquo_login_header!( false )
|
||||||
result = {
|
result = {
|
||||||
|
|
||||||
# Uncontroversial
|
# Uncontroversial
|
||||||
@@ -202,7 +218,7 @@ helpers do
|
|||||||
"min_search_length" => 3, # Boring default
|
"min_search_length" => 3, # Boring default
|
||||||
"alert" => "0", # TODO
|
"alert" => "0", # TODO
|
||||||
"direct_unsubscribe" => "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
|
# "ban_delete_type" => "none", # TODO
|
||||||
|
|
||||||
"inappreg" => "0", # TODO
|
"inappreg" => "0", # TODO
|
||||||
@@ -261,7 +277,7 @@ helpers do
|
|||||||
end
|
end
|
||||||
|
|
||||||
def xmlrpc_login( user = nil, pass = nil, anonymous = false, push = '1' )
|
def xmlrpc_login( user = nil, pass = nil, anonymous = false, push = '1' )
|
||||||
|
mobiquo_login_header!( false )
|
||||||
return respond_xmlrpc(
|
return respond_xmlrpc(
|
||||||
'result' => false,
|
'result' => false,
|
||||||
'result_text' => binary_xmlrpc( 'Anonymous login not supported' )
|
'result_text' => binary_xmlrpc( 'Anonymous login not supported' )
|
||||||
@@ -307,7 +323,10 @@ helpers do
|
|||||||
# can_whosonline => true, # api level 4
|
# can_whosonline => true, # api level 4
|
||||||
# can_profile => true, # api level 4
|
# can_profile => true, # api level 4
|
||||||
'can_upload_avatar' => false, # TODO
|
'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
|
end
|
||||||
|
|
||||||
@@ -342,7 +361,15 @@ helpers do
|
|||||||
'new_post' => true, # TODO
|
'new_post' => true, # TODO
|
||||||
"is_protected" => false, # Not required, apparently
|
"is_protected" => false, # Not required, apparently
|
||||||
'description' => binary_xmlrpc( hsh['description'].to_s ),
|
'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?
|
# FIXME: may not be right?
|
||||||
|
Reference in New Issue
Block a user