class ReplTalk::Repl

Attributes

author[R]
description[R]
fork_count[R]
id[R]
img_url[R]
is_always_on[R]
is_private[R]
language[R]
origin_url[R]
reactions[R]
run_count[R]
size[R]
tags[R]
timestamp[R]
title[R]
url[R]

Public Class Methods

new(client, repl) click to toggle source
# File lib/repltalk/structures.rb, line 182
def initialize(client, repl)
        @client = client

        @id = repl["id"]
        @url = $BASE_URL + repl["url"]
        @title = repl["title"]
        @author = User.new(@client, repl["user"])
        @description = repl["description"]
        @timestamp = repl["timeCreated"]
        @size = repl["size"]
        @run_count = repl["runCount"]
        @fork_count = repl["publicForkCount"]
        @language = Language.new(repl["lang"])
        @image_url = repl["imageUrl"]
        @origin_url = repl["origin"] == nil ? nil : $BASE_URL + repl["origin"]["url"]

        @is_private = repl["isPrivate"]
        @is_always_on = repl["isAlwaysOn"]

        @tags = repl["tags"].map { |tag| Tag.new(@client, tag) }
        @reactions = repl["reactions"].map { |reaction| Reaction.new(reaction) }
end

Public Instance Methods

add_reaction(type) click to toggle source
# File lib/repltalk/structures.rb, line 239
def add_reaction(type)
        r = @client.graphql(
                "ReplViewReactionsToggleReactions",
                GQL::Mutations::TOGGLE_REACTION,
                input: {
                        replId: @id,
                        react: true,
                        reactionType: type
                }
        )
        if r["setReplReaction"]["reactions"] == nil
                @reactions
        else
                @reactions = r["setReplReaction"]["reactions"].map { |reaction| Reaction.new(reaction) }
        end
end
create_comment(content) click to toggle source
# File lib/repltalk/structures.rb, line 227
def create_comment(content)
        c = @client.graphql(
                "ReplViewCreateReplComment",
                GQL::Mutations::CREATE_REPL_COMMENT,
                input: {
                        replId: @id,
                        body: content
                }
        )
        ReplComment.new(@client, c["createReplComment"])
end
get_comments(count: nil, after: nil) click to toggle source
# File lib/repltalk/structures.rb, line 216
def get_comments(count: nil, after: nil)
        c = @client.graphql(
                "ReplViewComments",
                GQL::Queries::GET_REPL_COMMENTS,
                url: @url,
                count: count,
                after: after
        )
        c["repl"]["comments"]["items"].map { |comment| ReplComment.new(@client, comment) }
end
get_forks(count: 100, after: nil) click to toggle source
# File lib/repltalk/structures.rb, line 205
def get_forks(count: 100, after: nil)
        f = @client.graphql(
                "ReplViewForks",
                GQL::Queries::GET_REPL_FORKS,
                url: @url,
                count: count,
                after: after
        )
        f["repl"]["publicForks"]["items"].map { |repl| Repl.new(@client, repl) }
end
publish(description, image_url, tags, enable_comments: true) click to toggle source
# File lib/repltalk/structures.rb, line 269
def publish(description, image_url, tags, enable_comments: true)
        r = @client.graphql(
                "PublishRepl",
                GQL::Mutations::PUBLISH_REPL,
                input: {
                        replId: @id,
                        replTitle: @title,
                        description: description,
                        imageUrl: image_url,
                        tags: tags,
                        enableComments: enable_comments,
                }
        )
        Repl.new(@client, r["publishRepl"])
end
remove_reaction(type) click to toggle source
# File lib/repltalk/structures.rb, line 256
def remove_reaction(type)
        r = @client.graphql(
                "ReplViewReactionsToggleReactions",
                GQL::Mutations::TOGGLE_REACTION,
                input: {
                        replId: @id,
                        react: false,
                        reactionType: type
                }
        )
        @reactions = r["setReplReaction"]["reactions"].map { |reaction| Reaction.new(reaction) }
end
to_s() click to toggle source
# File lib/repltalk/structures.rb, line 296
def to_s
        @title
end
unpublish() click to toggle source
# File lib/repltalk/structures.rb, line 285
def unpublish
        r = @client.graphql(
                "ReplViewHeaderActionsUnpublishRepl",
                GQL::Mutations::UNPUBLISH_REPL,
                input: {
                        replId: @id
                }
        )
        Repl.new(@client, r["unpublishRepl"])
end