Class: ReplTalk::Repl

Inherits:
Object
  • Object
show all
Defined in:
lib/repltalk/structures.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#authorObject (readonly)

Returns the value of attribute author.



138
139
140
# File 'lib/repltalk/structures.rb', line 138

def author
  @author
end

#descriptionObject (readonly)

Returns the value of attribute description.



138
139
140
# File 'lib/repltalk/structures.rb', line 138

def description
  @description
end

#fork_countObject (readonly)

Returns the value of attribute fork_count.



138
139
140
# File 'lib/repltalk/structures.rb', line 138

def fork_count
  @fork_count
end

#idObject (readonly)

Returns the value of attribute id.



138
139
140
# File 'lib/repltalk/structures.rb', line 138

def id
  @id
end

#img_urlObject (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_onObject (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_privateObject (readonly)

Returns the value of attribute is_private.



138
139
140
# File 'lib/repltalk/structures.rb', line 138

def is_private
  @is_private
end

#languageObject (readonly)

Returns the value of attribute language.



138
139
140
# File 'lib/repltalk/structures.rb', line 138

def language
  @language
end

#origin_urlObject (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_countObject (readonly)

Returns the value of attribute run_count.



138
139
140
# File 'lib/repltalk/structures.rb', line 138

def run_count
  @run_count
end

#sizeObject (readonly)

Returns the value of attribute size.



138
139
140
# File 'lib/repltalk/structures.rb', line 138

def size
  @size
end

#tagsObject (readonly)

Returns the value of attribute tags.



138
139
140
# File 'lib/repltalk/structures.rb', line 138

def tags
  @tags
end

#timestampObject (readonly)

Returns the value of attribute timestamp.



138
139
140
# File 'lib/repltalk/structures.rb', line 138

def timestamp
  @timestamp
end

#titleObject (readonly)

Returns the value of attribute title.



138
139
140
# File 'lib/repltalk/structures.rb', line 138

def title
  @title
end

#urlObject (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, 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) ⇒ 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_sObject



253
254
255
# File 'lib/repltalk/structures.rb', line 253

def to_s
	@title
end

#unpublishObject



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