A bunch of little format changes

This commit is contained in:
Nick Thomas
2013-09-28 01:18:43 +01:00
parent 4a0aa9d681
commit 0352671fda

View File

@@ -78,7 +78,8 @@ helpers do
end end
def make_xmlrpc_datetime( string ) def make_xmlrpc_datetime( string )
Chronic.parse( string ) obj = Chronic.parse( string )
XMLRPC::DateTime.new( obj.year, obj.month, obj.day, obj.hour, obj.min, obj.sec )
end end
def binary_xmlrpc( string ) def binary_xmlrpc( string )
@@ -104,22 +105,27 @@ helpers do
def build_tapatalk_topic( discourse_topic, extra = {} ) def build_tapatalk_topic( discourse_topic, extra = {} )
result = { result = {
'forum_id' => discourse_topic["category_id"].to_s, 'forum_id' => discourse_topic["category_id"].to_s,
'forum_name' => binary_xmlrpc( "" ), # TODO
'topic_id' => discourse_topic["id"].to_s, 'topic_id' => discourse_topic["id"].to_s,
'topic_title' => binary_xmlrpc( discourse_topic["title"].to_s ), 'topic_title' => binary_xmlrpc( discourse_topic["title"].to_s ),
# 'prefix' => binary_xmlrpc( "" ), # optional # 'prefix' => binary_xmlrpc( "" ), # optional
'post_author_name' => binary_xmlrpc( "" ), 'post_author_name' => binary_xmlrpc( "" ),
'topic_author_name' => binary_xmlrpc( "" ), # override later
'topic_author_display_name' => binary_xmlrpc( "" ), # also
# 'post_author_id' => 0, # required, Int (apparently), level 4 # 'post_author_id' => 0, # required, Int (apparently), level 4
# 'is_subscribed' => false, # optional 'is_subscribed' => false, # TODO
# 'can_subscribe' => false, # optiona; 'can_subscribe' => false, # TODO
# 'is_closed' => false, # optional 'is_closed' => false, # TODO
# 'icon_url' => "" # optional 'icon_url' => "", # optional, overriden later
# participated_uids # optional, level 4 # participated_uids # optional, level 4
'post_time' => make_xmlrpc_datetime( discourse_topic['last_posted_at'] ), 'post_time' => make_xmlrpc_datetime( discourse_topic['last_posted_at'] ), # one of these is not like the other
'last_reply_time' => make_xmlrpc_datetime( discourse_topic['last_posted_at'] ),
'reply_number' => discourse_topic['posts_count'].to_i, # reply_count ? 'reply_number' => discourse_topic['posts_count'].to_i, # reply_count ?
'new_post' => !!discourse_topic['unseen'], 'new_post' => !!discourse_topic['unseen'],
'view_number' => discourse_topic['views'].to_i, 'view_number' => discourse_topic['views'].to_i,
'new_post' => false, # TODO
# 'short_content' => binary_xmlrpc( "" ) # api level 4, not provided by discourse in some calls # 'short_content' => binary_xmlrpc( "" ) # api level 4, not provided by discourse in some calls, TODO
} }
@@ -133,10 +139,13 @@ helpers do
orig_poster = discourse_topic["posters"].find {|hsh| hsh['description'].to_s =~ /Original Poster/i } orig_poster = discourse_topic["posters"].find {|hsh| hsh['description'].to_s =~ /Original Poster/i }
result["post_author_id"] = orig_poster["user_id"] if orig_poster result["post_author_id"] = orig_poster["user_id"] if orig_poster
if extra[:users] && result["post_author_id"] if extra[:users] && result["post_author_id"]
user = extra[:users].find {|hsh| hsh["id"] == result["post_author_id"] } user = extra[:users].find {|hsh| hsh["id"] == result["post_author_id"] }
if user if user
result["post_author_name"] = binary_xmlrpc( user["username"].to_s ) result["post_author_name"] = binary_xmlrpc( user["username"].to_s )
result["topic_author_name"] = binary_xmlrpc( user["username"].to_s )
result["topic_author_display_name"] = binary_xmlrpc( user["username"].to_s ) # TODO
result["icon_url"] = make_avatar_url( user["avatar_template"] ) result["icon_url"] = make_avatar_url( user["avatar_template"] )
end end
end end
@@ -458,7 +467,6 @@ helpers do
} }
result = { result = {
'total_topic_num' => category['topic_count'].to_i,
'forum_id' => category['id'].to_s, 'forum_id' => category['id'].to_s,
'forum_name' => binary_xmlrpc( category['name'].to_s ), 'forum_name' => binary_xmlrpc( category['name'].to_s ),
# 'unread_sticky_count' => 0, # TODO - api level 4 # 'unread_sticky_count' => 0, # TODO - api level 4
@@ -471,7 +479,7 @@ helpers do
'prefix_display_name' => binary_xmlrpc( "" ), 'prefix_display_name' => binary_xmlrpc( "" ),
'can_post' => !!category['can_create_topic'], # FIXME: may not be correct! 'can_post' => !!category['can_create_topic'], # FIXME: may not be correct!
'can_upload' => false, 'can_upload' => false,
# 'require_prefix' => false, # api level 4 'require_prefix' => false, # api level 4
} }
topic_list = forum_info.fetch( "topic_list" ) topic_list = forum_info.fetch( "topic_list" )
@@ -479,6 +487,8 @@ helpers do
result['topics'] = topic_list.fetch( "topics" ).collect {|hsh| result['topics'] = topic_list.fetch( "topics" ).collect {|hsh|
build_tapatalk_topic( hsh, :users => users, :categories => categories ) build_tapatalk_topic( hsh, :users => users, :categories => categories )
} }
result['total_topic_num'] = result['topics'].count
respond_xmlrpc( result ) respond_xmlrpc( result )
end end