Share your repls and programming experiences

← Back to all posts
ReplTalk Gem
h
CodingCactus (4367)

Hi replers!
Today I present you with a super duper easy way to interact with repltalk using code. Using none of that horrible web scraping or anything, it uses the proper api endpoint that most of replit uses aka replit.com/graphql!

It's for Ruby, so if you don't already know Ruby, make sure to learn it, it's amazing!

I have added every general user query and mutation (that I could find) so you can do pretty much anything you want to.


Set up:

Simply add gem "repltalk" to your Gemfile and add require "repltalk" to the top of your main.rb (or whatever file you are using it in).

Next you need to initialize the client which is also super simple. All you need to do is add client = ReplTalk::Client.new to your main.rb.

# main.rb
require "repltalk"

client = ReplTalk::Client.new

Code Snippets

You can do so many things with this, here are only a few of possibly unlimited examples.

Get CodingCactus' posts from the top 100 posts:

client.get_posts(order: "votes", count: 100).select { |post| post.author.username == "CodingCactus" }

Get the 10 most recent ruby post's URLs

client.get_posts(count: 10, languages: ['ruby']).map { |post| post.url }

See how many people have forked CodingCactus' classrooms repl

client.get_repl("/@CodingCactus/classrooms").get_forks(count: 999999999).length

See how many comments in a post mention CodingCactus

mentions = 0
client.get_post(33995).get_comments(count: 999999999).each do |comment|
	mentions += 1 if comment.content.include?("@CodingCactus")
	comment.get_comments.each { |child_comment| mentions += 1 if child_comment.content.include?("@CodingCactus") }
	sleep 0.25 # need to be careful with rate limits
end

See what position CodingCactus is in the all time leaderboard

position = 0
client.get_leaderboard.each_with_index { |user, index| position = index + 1 if user.username == "CodingCactus" }

See how many repls of each language CodingCactus has

lang_count = client.get_user("CodingCactus").get_repls(count: 999999).reduce(Hash.new(0)) do |langs, repl|
  langs[repl.language.id] += 1
  langs
end

If you want to see it in action, check out https://github.com/Coding-Cactus/ReplTalk-Bot

To see the full documentation check out the GitHub repo: https://github.com/Coding-Cactus/repltalk
Suggest any new queries to be added in an issue, or even add it yourself and make a pull request.
And don't forget to star! : )

I hope you all like this lol, I certainly do! I learnt so much from making it: Ruby, GQL etc.

Thanks, cya next time!

Comments
hotnewtop
20092RuthAnggie (1)

But, it is WONDERFUL! Good job

JacobMcPherson1 (239)

Everything was installing ok, but then I got an error

CodingCactus (4367)

@JacobMcPherson1 your repl appears to work, did you fix it?

JacobMcPherson1 (239)

@CodingCactus No, I haven't touched it since I commented. That's strange...

CodingCactus (4367)

@JacobMcPherson1 I think it was probably a replit bug then

KPKri (0)

When I click the links, it is showing about:blank thing

CodingCactus (4367)

@darkdarcool if that's just some dodgy spelling of "cool" then thanks!

Jakman (449)

Nice. Very nice.

20092RuthAnggie (1)

I can't understand yours

darkdarcool (132)

This is really kewl!!

[deleted]

Finally since im banned i delete my accunt and re do it again so pls dont report me AND THIS IS NOT ADVERTISHING THIS IS A NOTE TO YOU GUYS.

[deleted]

@CodingCactus ahh pls dont do it

Whippingdot (662)

awwwww why is it ruby

Whippingdot (662)

make it in elixir too or smthing. Ima learn elixir in the future so...please @CodingCactus

CodingCactus (4367)

@Whippingdot well maybe when you're learning elixir, you can make it as a learning exercise

Whippingdot (662)

🤦‍♀️ fine it is actually good for me as I will be more experienced in elixir if I try converting it. Anyway good proj even though I haven't tried it @CodingCactus

RayhanADev (2528)

Beautiful, I was wondering when there might be a ReplTalk post for this :)

Using none of that horrible web scraping or anything

I feel that's targeted at someone xD, you know what I think I'll make a post for my Replit API after it's refactored. Anyways, good luck with your Gem it's very nice!

CodingCactus (4367)

I feel that's targeted at someone xD

@RayhanADev yeah i saw someone made a post the other day which used web scraping was super slow and stuff, can't remember who, and i just wanted to make sure people new it was a proper api wrapper.

CodingCactus (4367)

I was wondering when there might be a ReplTalk post for this

@RayhanADev I wasn't sure if rt would appreciate it, its a bit of a deviation from the standard python console/html games

RayhanADev (2528)

@CodingCactus lol true, true I just don't really post to repltalk either unless it's a game because nobody ever cares about it so i guess I feel you in some aspect

RayhanADev (2528)

@ch1ck3n jb and dark (and technically you too)'s module before I came and helped ya'll with graphql lol

ch1ck3n (2088)

@RayhanADev i started it with graphql excuse me

RayhanADev (2528)

@ch1ck3n ah but I was the one who actually added the request and query so ya'll could use it

ch1ck3n (2088)

@RayhanADev i was the one who added the whole base of the module and classes and fields

RayhanADev (2528)

@ch1ck3n okay ƪ(˘⌣˘)ʃ then you did it and you did it well because the module is awesome :)

ch1ck3n (2088)

@RayhanADev it doesn't use async madness

CodingCactus (4367)

@RayhanADev I don't speak American, but I believe you are supposed to say "y'all" not "ya'll" as it is "you all" not "ya will" 🤣

CodingCactus (4367)

i was the one who added the whole base of the module and classes and fields

@ch1ck3n was it you that I gave them all to?

ch1ck3n (2088)

@CodingCactus ok fine

i made the program function better than just a billion different functions

RayhanADev (2528)

@CodingCactus

I don't speak American, but I believe you are supposed to say "y'all" not "ya'll" as it is "you all" not "ya will" 🤣

hahahahaha maybe, but I live in Texas not America there's obviously a difference and like everything we think we're so special so it's ya'll xD

ch1ck3n (2088)

hi i was using my repltalk client and saw this lol

CodingCactus (4367)

@ch1ck3n oh nice, what features does it have

ch1ck3n (2088)

@CodingCactus eh i just started working on it yesterday
https://jam-1-replapi-project.ch1ck3n.repl.co/
it takes a while to load

all i can do is view the hot posts (for now) :D

CodingCactus (4367)

@ch1ck3n nice, what are you using for it to take so long?

ch1ck3n (2088)

@CodingCactus OH MY GOD it had en error (i fixed it now it should load)

ch1ck3n (2088)

@CodingCactus slps head im stupid yes the one made by mat

CodingCactus (4367)

@ch1ck3n hm it still shouldn't be that slow, I'll take a look to see where the efficiency is dying

ch1ck3n (2088)

@CodingCactus i'm currently not usnig that one, if you look in jam/repl.py I'm using mat's api

CodingCactus (4367)

@ch1ck3n yeah it looks like it is just his module being slow which is odd. My one for ruby is a lot faster, I'll take a look at the actual module code I'm not sure why it is so slow

CodingCactus (4367)

@Bunnytoes thank you very much, it took quite some time to make!