From ceee14e3db518ebe437abcc18d7f5e4c45f6956f Mon Sep 17 00:00:00 2001 From: Ryan Gooler Date: Thu, 31 Aug 2017 02:47:11 -0700 Subject: [PATCH] Version 2.0 --- .travis.yml | 4 +- bin/testbot.rb | 0 lib/libfchat/fchat.rb | 2 +- lib/libfchat/version.rb | 2 +- lib/libfchat/webapi.rb | 108 +++++++++++++++++++++++++++++++++++----- 5 files changed, 98 insertions(+), 18 deletions(-) mode change 100644 => 100755 bin/testbot.rb diff --git a/.travis.yml b/.travis.yml index 566b34c..a01d453 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,3 @@ language: ruby rvm: - - 1.9.2 - - 1.9.3 - - jruby-19mode # JRuby in 1.9 mode + - 2.4.1 diff --git a/bin/testbot.rb b/bin/testbot.rb old mode 100644 new mode 100755 diff --git a/lib/libfchat/fchat.rb b/lib/libfchat/fchat.rb index cbb493a..f773855 100644 --- a/lib/libfchat/fchat.rb +++ b/lib/libfchat/fchat.rb @@ -86,7 +86,7 @@ def parse_message(msg) def login(server,account,password,character,timeout=30) webapi = Libfchat::WebAPI.new - @ticket = webapi.getApiTicket(account,password) + @ticket = webapi.getApiTicket(account, password) @me = character EM.run { diff --git a/lib/libfchat/version.rb b/lib/libfchat/version.rb index 0eb9c1c..499bb05 100644 --- a/lib/libfchat/version.rb +++ b/lib/libfchat/version.rb @@ -2,5 +2,5 @@ module Libfchat # We're doing this because we might write tests that deal # with other versions of Libfchat and we are unsure how to # handle this better. - VERSION = "1.9" unless defined?(::Libfchat::VERSION) + VERSION = "2.0" unless defined?(::Libfchat::VERSION) end diff --git a/lib/libfchat/webapi.rb b/lib/libfchat/webapi.rb index 1c00948..71a4cf1 100644 --- a/lib/libfchat/webapi.rb +++ b/lib/libfchat/webapi.rb @@ -15,8 +15,11 @@ def initialize(baseurl="https://www.f-list.net") @baseurl = baseurl end - def post(path, params) - uri = URI(:baseurl + path) + def post(endpoint, params) + uri = URI("#{@baseurl}#{endpoint}") + if @ticket + params['ticket'] = @ticket + end res = Net::HTTP.post_form(uri, params) json = MultiJson.load(res.body) if json['error'] != "" @@ -25,6 +28,16 @@ def post(path, params) return json end + def get(endpoint) + uri = URI(@baseurl) + res = Net::HTTP.get(uri) + json = MultiJson.load(res.body) + if json['error'] != "" + raise json['error'] + end + return json + end + def get_ticket(account, password) # Deprecated return self.getApiTicket(account, password) @@ -41,19 +54,88 @@ def getApiTicket(account, password) end end + # Bookmarks def bookmark_add(name) - uri = URI('https://www.f-list.net/json/getApiTicket.php') - res = Net::HTTP.post_form(uri, - 'account' => account, - 'password' => password) + return self.post("/json/api/bookmark-add.php", + 'name' => name) + end - json = MultiJson.load(res.body) - if json['ticket'] - @ticket = json['ticket'] - else - raise json['error'] - end - return json + def bookmark_list() + return self.get("/json/api/bookmark-list.php") + end + + def bookmark_remove(name) + return self.post("/json/api/bookmark-remove.php", + 'name' => name) + end + + # Character data + def character_data(name) + return self.post("/json/api/character-data.php", + 'name' => name) + end + + def character_list() + return self.get("/json/api/character-list.php") + end + + # Misc data + def group_list() + return self.get("/json/api/group-list.php") + end + + def ignore_list() + return self.get("/json/api/ignore-list.php") + end + + def info_list() + return self.get("/json/api/info-list.php") + end + + def kink_list() + return self.get("/json/api/kink-list.php") + end + + def mapping_list() + return self.get("/json/api/mapping-list.php") + end + + # Handling friend requests, friend list data + def friend_list() + return self.get("/json/api/friend-list.php") + end + + def friend_remove(source_name, dest_name) + return self.post("/json/api/friend-remove.php", + "source_name" => source_name, + "dest_name" => dest_name) + end + + def request_accept(request_id) + return self.post("/json/api/request-accept.php", + "request_id" => request_id) + end + + def request_cancel(request_id) + return self.post("/json/api/request-cancel.php", + "request_id" => request_id) + end + + def request_deny(request_id) + return self.post("/json/api/request-deny.php", + "request_id" => request_id) + end + + def request_list() + return self.get("/json/api/request-list.php") + end + + def request_pending() + return self.get("/json/api/request-pending.php") + end + + def request_send() + return self.get("/json/api/request-send.php") end end