diff --git a/.ruby-version b/.ruby-version new file mode 100644 index 0000000..005119b --- /dev/null +++ b/.ruby-version @@ -0,0 +1 @@ +2.4.1 diff --git a/README.md b/README.md index 17f2798..286d33b 100644 --- a/README.md +++ b/README.md @@ -8,8 +8,7 @@ A library for connecting to F-chat ( http://f-list.net ), written in Ruby. Requirements ============ -This library requires ruby 1.9.2, 1.9.3, or jruby in 1.9 mode -It is tested against ruby 1.9.3, and integration tests are run against all of the above, but are not guaranteed to work. +Ruby 2.4.1 Tutorial ======== diff --git a/Rakefile b/Rakefile index c239b53..e5a37c1 100644 --- a/Rakefile +++ b/Rakefile @@ -25,5 +25,5 @@ end RSpec::Core::RakeTask.new do |t| t.ruby_opts = '-w' - t.rspec_opts = '--color --format nested' + t.rspec_opts = '--color --format documentation' end diff --git a/lib/libfchat/fchat.rb b/lib/libfchat/fchat.rb index 02cd2e2..cbb493a 100644 --- a/lib/libfchat/fchat.rb +++ b/lib/libfchat/fchat.rb @@ -14,7 +14,7 @@ module Libfchat require 'libfchat/version' require 'libfchat/webapi' require 'pp' - + class Fchat attr_reader :ticket attr_reader :websocket @@ -22,7 +22,7 @@ class Fchat attr_reader :version attr_reader :clientname attr_reader :me - + attr_reader :chat_max attr_reader :priv_max attr_reader :lfrp_max @@ -38,7 +38,7 @@ class Fchat attr_accessor :logger ## - # Initialize the object with the name and version. + # Initialize the object with the name and version. # Default to just identifying as the library def initialize(clientname="libfchat-ruby by Jippen Faddoul ( http://github.com/jippen/libfchat-ruby )",version=Libfchat::VERSION, level=Logger::DEBUG) @@ -86,7 +86,7 @@ def parse_message(msg) def login(server,account,password,character,timeout=30) webapi = Libfchat::WebAPI.new - @ticket = webapi.get_ticket(account,password) + @ticket = webapi.getApiTicket(account,password) @me = character EM.run { @@ -123,7 +123,7 @@ def send_message(type, json) # ====================================================== # # Always respond to these # # ====================================================== # - + ## # Respond to keepalive ping messages def got_PIN(message) @@ -155,7 +155,7 @@ def got_VAR(message) raise "ERROR: Do not know how to handle VAR #{message}" end end - + ## # Store list of ops def got_ADL(message) @@ -195,7 +195,7 @@ def got_NLN(message) 'message' => "" } end - + ## # Handle user changing status def got_STA(message) @@ -205,7 +205,7 @@ def got_STA(message) 'message' => message['statusmsg'] } end - + ## # Handle user logging off def got_FLN(message) @@ -214,7 +214,7 @@ def got_FLN(message) room['characters'].delete(message['character']) end end - + ## # Store data about newly joined chatroom def got_JCH(message) @@ -271,7 +271,7 @@ def got_CIU(message) # ====================================================== # ## - # Performs an account ban against a characters account. + # Performs an account ban against a characters account. # # *This command requires chat op or higher.* def ACB(character) @@ -332,7 +332,7 @@ def CCR(channel) end ## - # This command is used by an admin or channel owner to set a new + # This command is used by an admin or channel owner to set a new # channel description. # # *This command requires channel op or higher.* @@ -533,7 +533,7 @@ def PRO(character) end ## - # Advertises the first open private channel owned by the client + # Advertises the first open private channel owned by the client # in the given channel def RAN(channel) json = {:channel => channel } diff --git a/lib/libfchat/webapi.rb b/lib/libfchat/webapi.rb index 0f8ef43..1c00948 100644 --- a/lib/libfchat/webapi.rb +++ b/lib/libfchat/webapi.rb @@ -4,13 +4,44 @@ module Libfchat rescue LoadError #I don't actually NEED rubygems, unless on 1.8 end - require 'net/http' + require 'net/https' require 'multi_json' - + class WebAPI attr_reader :ticket + attr_reader :baseurl + + def initialize(baseurl="https://www.f-list.net") + @baseurl = baseurl + end + + def post(path, params) + uri = URI(:baseurl + path) + res = Net::HTTP.post_form(uri, params) + 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) + end + + def getApiTicket(account, password) + json = self.post("/json/getApiTicket.php", + 'account' => account, + 'password' => password) + + if json['ticket'] + @ticket = json['ticket'] + return json + end + end - def get_ticket(account,password) + def bookmark_add(name) uri = URI('https://www.f-list.net/json/getApiTicket.php') res = Net::HTTP.post_form(uri, 'account' => account, diff --git a/libfchat.gemspec b/libfchat.gemspec index 6e2feaa..32046cd 100644 --- a/libfchat.gemspec +++ b/libfchat.gemspec @@ -7,7 +7,7 @@ require 'libfchat/version' Gem::Specification.new do |s| s.name = 'libfchat' s.version = Libfchat::VERSION - s.date = '2012-06-25' + s.date = '2017-07-31' s.summary = "A library for connection to F-chat" s.description = "A library for connecting to F-chat ( http://f-list.net )" s.authors = ["Ryan Gooler"] diff --git a/spec/fchat_spec.rb b/spec/fchat_spec.rb index 992df5b..218bc63 100644 --- a/spec/fchat_spec.rb +++ b/spec/fchat_spec.rb @@ -30,7 +30,7 @@ def load_user_list() end it "takes no parameters and returns a Fchat object" do - @fchat.should be_an_instance_of ::Libfchat::Fchat + expect(@fchat).to be_an_instance_of ::Libfchat::Fchat end describe "get_ADL" do @@ -38,7 +38,7 @@ def load_user_list() it "parses correctly" do data = 'ADL {"ops":["Hiro","Aniko","King Mercy","Hexxy","TestUser_1209","Feath","Becca Greene","TestUser_1206","Lothar","TestUser_880","Lambeth","Susannah","R B Nicci","TestUser_487","Neige","Natsudra","Robert Grayson","Melly Mildri","Bastogne","Rebbi"]}' @fchat.parse_message(data) - @fchat.ops.include?("Aniko").should be_true + expect(@fchat.ops.include?("Aniko")).to be_truthy end end @@ -76,8 +76,8 @@ def load_user_list() load_user_list() data = 'FLN {"character":"TestUser_1500"}' @fchat.parse_message(data) - @fchat.users.should_not include('TestUser_1500') - @fchat.users.should include('TestUser_1331') + expect(@fchat.users.include?('TestUser_1500')).to be_falsy + expect(@fchat.users.include?('TestUser_1331')).to be_truthy end end @@ -91,7 +91,7 @@ def load_user_list() it "knows its own identity" do data = 'IDN {"character":"Testbot"}' @fchat.parse_message(data) - @fchat.me.should == 'Testbot' + expect(@fchat.me).to eq('Testbot') end end @@ -109,19 +109,19 @@ def load_user_list() it "Can parse an empty list of characters" do data = 'LIS {"characters":[]}' @fchat.parse_message(data) - @fchat.users.should == {} + expect(@fchat.users).to eq({}) end it "Can parse a single block of characters" do @fchat.parse_message(%q@LIS {"characters":[["TestUser_1","Male","online",""],["TestUser_2","Female","away","Can't take it anymore. Going to bed."],["TestUser_3","Male","online",""],["TestUser_4","Male","away","Zzzzzz"],["TestUser_5","Female","online",""],["TestUser_6","None","busy","Getting the D from a sexy TestUser_11 and hot Tiefling. Yes, Noah. Heat that oven good~"],["TestUser_7","Female","looking","Looking for a male to serve~"],["TestUser_8","Female","online",""],["TestUser_9","Male","away","Sleeping or nerding out over Dark Angels"],["TestUser_10","Male","online",""],["TestUser_11","Male","busy","Head wedged between Sweet's thighs, brb."],["TestUser_12","Female","looking","Horny, my pussy needs attention as do my feet."],["TestUser_13","Female","online",""],["TestUser_14","Transgender","looking","[color=green]Human femboy looking to be a normal man's 'woman' for a cute RP, but I wouldn't mind playing with another femboy![/color]"],["TestUser_15","Herm","online",""],["TestUser_16","Male","online",""],["TestUser_17","Male","online",""],["TestUser_18","Male","looking","You've had enough of two hand touch, you want it rough. "],["TestUser_19","Female","online",""],["TestUser_20","Herm","away","Sleeps"],["TestUser_21","Male","online",""],["TestUser_22","Female","online",""],["TestUser_23","Female","online",""],["TestUser_24","Male","online",""],["TestUser_25","Female","online",""],["TestUser_26","Female","looking",""],["TestUser_27","Male","dnd","Napping. Only Kadaj, Eli, Katsu and Sai can bug me right now. "],["TestUser_28","Female","away",""],["TestUser_29","Male","online",""],["TestUser_30","Female","online",""],["TestUser_31","Male","online",""],["TestUser_32","Cunt-boy","online",""],["TestUser_33","Female","online",""],["TestUser_34","Female","looking",""],["TestUser_35","Male-Herm","online",""],["TestUser_36","Male","looking",""],["TestUser_37","Female","online",""],["TestUser_38","Male","busy",""],["TestUser_39","Male","online",""],["TestUser_40","Female","online",""],["TestUser_41","Male","online",""],["TestUser_42","Female","online",""],["TestUser_43","Transgender","looking","In a strange mood for a very naughty diaper play."],["TestUser_44","Male","online",""],["TestUser_45","Female","online",""],["TestUser_46","Female","online",""],["TestUser_47","Female","online",""],["TestUser_48","Female","online",""],["TestUser_49","Female","online",""],["TestUser_50","Male","online",""],["TestUser_51","Female","online",""],["TestUser_52","Male","online",""],["TestUser_53","Male","online",""],["TestUser_54","Male","looking","Looking for some kiddies to make some movies"],["TestUser_55","Herm","online",""],["TestUser_56","Female","online",""],["TestUser_57","Male","online",""],["TestUser_58","Male","looking",""],["TestUser_59","Female","online",""],["TestUser_60","None","dnd","ratzefatz~ *schnarch*"],["TestUser_61","Male","looking","Cheetah that feels awfully submissive tonight, is looking for a hung partner (Preferably anthro, but anything goes!) Breeding, Excessive cum, Cum inflation.. Are but a few of many naughty kinks this eager feline likes. PM me if you fancy some butt!"],["TestUser_62","Female","online",""],["TestUser_63","Female","online",""],["TestUser_64","Male","online",""],["TestUser_65","Female","online",""],["TestUser_66","Female","online",""],["TestUser_67","Female","online",""],["TestUser_68","None","dnd",""],["TestUser_69","Female","online",""],["TestUser_70","Female","away","ZzzZzzZzz"],["TestUser_71","Female","looking",""],["TestUser_72","Male","online",""],["TestUser_73","Female","looking","you find the big mare fast asleep in her bedroom. what do you do? (cheak the custom kink for details on this)"],["TestUser_74","Male","online",""],["TestUser_75","Male","online",""],["TestUser_76","Female","online","I need warm. :c"],["TestUser_77","Herm","looking",""],["TestUser_78","Male","online",""],["TestUser_79","Male","away","Gave up and went to bed, back tomorrow after dogs to vet"],["TestUser_80","Herm","online",""],["TestUser_81","Male","looking","Welcome to [session=Dream Land]ADH-301c3791840f9d9da691[/session] (On the lookout for others who might be willing to play some characters from the Kirby series for some RP ideas. Welcome chat or rp from others too)"],["TestUser_82","Male","online",""],["TestUser_83","Female","looking",""],["TestUser_84","Shemale","online",""],["TestUser_85","Male","online",""],["TestUser_86","Shemale","online",""],["TestUser_87","Male","looking","Kinky coyote wanting to try something interesting tonight..."],["TestUser_88","Shemale","busy","AWWWWWWWWWWWWWWWWWW"],["TestUser_89","Female","looking",""],["TestUser_90","Male","away",""],["TestUser_91","Herm","online",""],["TestUser_92","Female","online",""],["TestUser_93","Male","online",""],["TestUser_94","Female","online",""],["TestUser_95","Male","online","[url=http://www.youtube.com/watch?v=gA9kUMndxc8]Current Music of the Mind![/url]"],["TestUser_96","Male","online",""],["TestUser_97","Male","busy","Playing BL2, I may not be responsive."],["TestUser_98","Female","online",""],["TestUser_99","Male","looking",""],["TestUser_100","Male","online",""]]}@) - @fchat.users.should include('TestUser_100') + expect(@fchat.users.include?('TestUser_100')).to be_truthy end it "Can parse a full block of characters" do load_user_list() - @fchat.users.should include('TestUser_100') - @fchat.users.should include('TestUser_1331') - @fchat.users.length.should == 1434 + expect(@fchat.users.include?('TestUser_100')).to be_truthy + expect(@fchat.users.include?('TestUser_1331')).to be_truthy + expect(@fchat.users.length).to eq(1434) end end @@ -134,13 +134,13 @@ def load_user_list() it "can tell that a user logged in" do data = 'NLN {"status":"online","gender":"None","identity":"Testbot"}' @fchat.parse_message(data) - @fchat.users.should include('Testbot') + expect(@fchat.users.include?('Testbot')).to be_truthy end it "can identify a user's status" do data = 'NLN {"status":"online","gender":"None","identity":"Testbot"}' @fchat.parse_message(data) - @fchat.users['Testbot']['status'].should == "online" + expect(@fchat.users['Testbot']['status']).to eq("online") end end @@ -184,37 +184,37 @@ def load_user_list() it "correctly stores chat_max variable received from server" do data = 'VAR {"value":4096,"variable":"chat_max"}' @fchat.parse_message(data) - @fchat.chat_max.should == 4096 + expect(@fchat.chat_max).to eq(4096) end it "correctly stores priv_max variable received from server" do data = 'VAR {"value":50000,"variable":"priv_max"}' @fchat.parse_message(data) - @fchat.priv_max.should == 50000 + expect(@fchat.priv_max).to eq(50000) end it "correctly stores lfrp_max variable received from server" do data = 'VAR {"value":50000,"variable":"lfrp_max"}' @fchat.parse_message(data) - @fchat.lfrp_max.should == 50000 + expect(@fchat.lfrp_max).to eq(50000) end it "correctly stores lfrp_flood variable received from server" do data = 'VAR {"value":600,"variable":"lfrp_flood"}' @fchat.parse_message(data) - @fchat.lfrp_flood.should == 600 + expect(@fchat.lfrp_flood).to eq(600) end it "correctly stores msg_flood variable received from server" do data = 'VAR {"value":0.5,"variable":"msg_flood"}' @fchat.parse_message(data) - @fchat.msg_flood.should == 0.5 + expect(@fchat.msg_flood).to eq(0.5) end it "correctly stores permissions variable received from server" do data = 'VAR {"value":0,"variable":"permissions"}' @fchat.parse_message(data) - @fchat.permissions.should == 0 + expect(@fchat.permissions).to eq(0) end end diff --git a/spec/webapi_spec.rb b/spec/webapi_spec.rb index d117c8e..ad52078 100644 --- a/spec/webapi_spec.rb +++ b/spec/webapi_spec.rb @@ -6,18 +6,7 @@ end it "takes no parameters and returns a WebAPI object" do - @webapi.should be_an_instance_of ::Libfchat::WebAPI + expect(@webapi).to be_an_instance_of ::Libfchat::WebAPI end - # These checks can get me locked out - #describe "badlogins:" do - # it "raises an exception when it logs in without credentials" do - # expect {@webapi.get_ticket('','')}.to raise_error - # end - # - # it "raises an exception when it logs in with bad credentials" do - # expect {@webapi.get_ticket('jippenbots','')}.to raise_error - # end #badlogins - #end - end