Module: NeonRAW::Objects::Thing::Refreshable

Included in:
Comment, Submission, Subreddit, User
Defined in:
lib/NeonRAW/objects/thing/refreshable.rb

Overview

Methods for things that can be refreshed.

Instance Method Summary collapse

Instance Method Details

#refresh!Object

Refreshes the data of a comment/submission/subreddit object.



8
9
10
11
12
13
14
15
16
17
# File 'lib/NeonRAW/objects/thing/refreshable.rb', line 8

def refresh!
  params = { id: name }
  path = "/r/#{display_name}/api/info" if /t5_/ =~ name
  path = "/r/#{subreddit}/api/info" unless /t5_/ =~ name
  data = @client.request_data(path, :get, params)
  data[:data][:children][0][:data].each do |key, value|
    value = nil if ['', [], {}].include?(value)
    instance_variable_set(:"@#{key}", value)
  end
end