Skip to content

Commit

Permalink
Version 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan Gooler committed Aug 31, 2017
1 parent 1b5ff5f commit ceee14e
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 18 deletions.
4 changes: 1 addition & 3 deletions .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
Empty file modified bin/testbot.rb 100644 → 100755
Empty file.
2 changes: 1 addition & 1 deletion lib/libfchat/fchat.rb
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion lib/libfchat/version.rb
Expand Up @@ -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
108 changes: 95 additions & 13 deletions lib/libfchat/webapi.rb
Expand Up @@ -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'] != ""
Expand All @@ -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)
Expand All @@ -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
Expand Down

0 comments on commit ceee14e

Please sign in to comment.