Class: ReplTalk::Repl
- Inherits:
-
Object
- Object
- ReplTalk::Repl
- Defined in:
- lib/repltalk/structures.rb
Instance Attribute Summary collapse
-
#author ⇒ Object
readonly
Returns the value of attribute author.
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#fork_count ⇒ Object
readonly
Returns the value of attribute fork_count.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#img_url ⇒ Object
readonly
Returns the value of attribute img_url.
-
#is_always_on ⇒ Object
readonly
Returns the value of attribute is_always_on.
-
#is_private ⇒ Object
readonly
Returns the value of attribute is_private.
-
#language ⇒ Object
readonly
Returns the value of attribute language.
-
#origin_url ⇒ Object
readonly
Returns the value of attribute origin_url.
-
#run_count ⇒ Object
readonly
Returns the value of attribute run_count.
-
#size ⇒ Object
readonly
Returns the value of attribute size.
-
#tags ⇒ Object
readonly
Returns the value of attribute tags.
-
#timestamp ⇒ Object
readonly
Returns the value of attribute timestamp.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
- #add_reaction(type) ⇒ Object
- #create_comment(content) ⇒ Object
- #get_comments(count: nil, after: nil) ⇒ Object
- #get_forks(count: 100, after: nil) ⇒ Object
-
#initialize(client, repl) ⇒ Repl
constructor
A new instance of Repl.
- #publish(description, image_url, tags, enable_comments: true) ⇒ Object
- #remove_reaction(type) ⇒ Object
- #to_s ⇒ Object
- #unpublish ⇒ Object
Constructor Details
#initialize(client, repl) ⇒ Repl
Returns a new instance of Repl.
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/repltalk/structures.rb', line 140 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"].to_s @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) } end |
Instance Attribute Details
#author ⇒ Object (readonly)
Returns the value of attribute author.
138 139 140 |
# File 'lib/repltalk/structures.rb', line 138 def @author end |
#description ⇒ Object (readonly)
Returns the value of attribute description.
138 139 140 |
# File 'lib/repltalk/structures.rb', line 138 def description @description end |
#fork_count ⇒ Object (readonly)
Returns the value of attribute fork_count.
138 139 140 |
# File 'lib/repltalk/structures.rb', line 138 def fork_count @fork_count end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
138 139 140 |
# File 'lib/repltalk/structures.rb', line 138 def id @id end |
#img_url ⇒ Object (readonly)
Returns the value of attribute img_url.
138 139 140 |
# File 'lib/repltalk/structures.rb', line 138 def img_url @img_url end |
#is_always_on ⇒ Object (readonly)
Returns the value of attribute is_always_on.
138 139 140 |
# File 'lib/repltalk/structures.rb', line 138 def is_always_on @is_always_on end |
#is_private ⇒ Object (readonly)
Returns the value of attribute is_private.
138 139 140 |
# File 'lib/repltalk/structures.rb', line 138 def is_private @is_private end |
#language ⇒ Object (readonly)
Returns the value of attribute language.
138 139 140 |
# File 'lib/repltalk/structures.rb', line 138 def language @language end |
#origin_url ⇒ Object (readonly)
Returns the value of attribute origin_url.
138 139 140 |
# File 'lib/repltalk/structures.rb', line 138 def origin_url @origin_url end |
#run_count ⇒ Object (readonly)
Returns the value of attribute run_count.
138 139 140 |
# File 'lib/repltalk/structures.rb', line 138 def run_count @run_count end |
#size ⇒ Object (readonly)
Returns the value of attribute size.
138 139 140 |
# File 'lib/repltalk/structures.rb', line 138 def size @size end |
#tags ⇒ Object (readonly)
Returns the value of attribute tags.
138 139 140 |
# File 'lib/repltalk/structures.rb', line 138 def @tags end |
#timestamp ⇒ Object (readonly)
Returns the value of attribute timestamp.
138 139 140 |
# File 'lib/repltalk/structures.rb', line 138 def @timestamp end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
138 139 140 |
# File 'lib/repltalk/structures.rb', line 138 def title @title end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
138 139 140 |
# File 'lib/repltalk/structures.rb', line 138 def url @url end |
Instance Method Details
#add_reaction(type) ⇒ Object
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 |
# File 'lib/repltalk/structures.rb', line 196 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) ⇒ Object
184 185 186 187 188 189 190 191 192 193 194 |
# File 'lib/repltalk/structures.rb', line 184 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) ⇒ Object
173 174 175 176 177 178 179 180 181 182 |
# File 'lib/repltalk/structures.rb', line 173 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) ⇒ Object
162 163 164 165 166 167 168 169 170 171 |
# File 'lib/repltalk/structures.rb', line 162 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) ⇒ Object
226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 |
# File 'lib/repltalk/structures.rb', line 226 def publish(description, image_url, , enable_comments: true) r = @client.graphql( "PublishRepl", GQL::Mutations::PUBLISH_REPL, input: { replId: @id, replTitle: @title, description: description, imageUrl: image_url, tags: , enableComments: enable_comments, } ) Repl.new(@client, r["publishRepl"]) end |
#remove_reaction(type) ⇒ Object
213 214 215 216 217 218 219 220 221 222 223 224 |
# File 'lib/repltalk/structures.rb', line 213 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 ⇒ Object
253 254 255 |
# File 'lib/repltalk/structures.rb', line 253 def to_s @title end |
#unpublish ⇒ Object
242 243 244 245 246 247 248 249 250 251 |
# File 'lib/repltalk/structures.rb', line 242 def unpublish r = @client.graphql( "ReplViewHeaderActionsUnpublishRepl", GQL::Mutations::UNPUBLISH_REPL, input: { replId: @id } ) Repl.new(@client, r["unpublishRepl"]) end |