diff --git a/lib/tapatalker.rb b/lib/tapatalker.rb index e9f2969..7cf21a4 100644 --- a/lib/tapatalker.rb +++ b/lib/tapatalker.rb @@ -78,7 +78,8 @@ helpers do end 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 def binary_xmlrpc( string ) @@ -104,22 +105,27 @@ helpers do def build_tapatalk_topic( discourse_topic, extra = {} ) result = { 'forum_id' => discourse_topic["category_id"].to_s, + 'forum_name' => binary_xmlrpc( "" ), # TODO 'topic_id' => discourse_topic["id"].to_s, 'topic_title' => binary_xmlrpc( discourse_topic["title"].to_s ), # 'prefix' => binary_xmlrpc( "" ), # optional '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 - # 'is_subscribed' => false, # optional - # 'can_subscribe' => false, # optiona; - # 'is_closed' => false, # optional - # 'icon_url' => "" # optional + 'is_subscribed' => false, # TODO + 'can_subscribe' => false, # TODO + 'is_closed' => false, # TODO + 'icon_url' => "", # optional, overriden later # 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 ? 'new_post' => !!discourse_topic['unseen'], '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 } result["post_author_id"] = orig_poster["user_id"] if orig_poster + if extra[:users] && result["post_author_id"] user = extra[:users].find {|hsh| hsh["id"] == result["post_author_id"] } if user 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"] ) end end @@ -458,7 +467,6 @@ helpers do } result = { - 'total_topic_num' => category['topic_count'].to_i, 'forum_id' => category['id'].to_s, 'forum_name' => binary_xmlrpc( category['name'].to_s ), # 'unread_sticky_count' => 0, # TODO - api level 4 @@ -471,7 +479,7 @@ helpers do 'prefix_display_name' => binary_xmlrpc( "" ), 'can_post' => !!category['can_create_topic'], # FIXME: may not be correct! 'can_upload' => false, - # 'require_prefix' => false, # api level 4 + 'require_prefix' => false, # api level 4 } topic_list = forum_info.fetch( "topic_list" ) @@ -479,6 +487,8 @@ helpers do result['topics'] = topic_list.fetch( "topics" ).collect {|hsh| build_tapatalk_topic( hsh, :users => users, :categories => categories ) } + + result['total_topic_num'] = result['topics'].count respond_xmlrpc( result ) end