Class: NeonRAW::Objects::User

Inherits:
Thing
  • Object
show all
Includes:
Thing::Createable, Thing::Refreshable
Defined in:
lib/NeonRAW/objects/user.rb

Overview

The user object.

Direct Known Subclasses

Me

Instance Attribute Summary collapse

Attributes inherited from Thing

#id, #name

Listings collapse

Instance Method Summary collapse

Methods included from Thing::Refreshable

#refresh!

Methods included from Thing::Createable

#created, #created_utc

Constructor Details

#initialize(client, data) ⇒ User

Returns a new instance of User.

Parameters:

  • client (NeonRAW::Clients::Web/Installed/Script)

    The client object.

  • data (Hash)

    The object data.



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/NeonRAW/objects/user.rb', line 32

def initialize(client, data)
  @client = client
  data.each do |key, value|
    value = nil if ['', [], {}].include?(value)
    instance_variable_set(:"@#{key}", value)
    next if key == :created || key == :created_utc
    self.class.send(:attr_reader, key)
  end
  class << self
    alias_method :friend?, :is_friend
    alias_method :gold?, :is_gold
    alias_method :moderator?, :is_mod
    alias_method :verified_email?, :has_verified_email
    alias_method :hide_from_robots?, :hide_from_robots
  end
end

Instance Attribute Details

#comment_karmaInteger (readonly)

Returns the comment karma of the user.

Returns:

  • (Integer)

    Returns the comment karma of the user.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'lib/NeonRAW/objects/user.rb', line 24

class User < Thing
  include Thing::Createable
  include Thing::Refreshable

  # @!method initialize(client, data)
  # @param client [NeonRAW::Clients::Web/Installed/Script] The client
  #   object.
  # @param data [Hash] The object data.
  def initialize(client, data)
    @client = client
    data.each do |key, value|
      value = nil if ['', [], {}].include?(value)
      instance_variable_set(:"@#{key}", value)
      next if key == :created || key == :created_utc
      self.class.send(:attr_reader, key)
    end
    class << self
      alias_method :friend?, :is_friend
      alias_method :gold?, :is_gold
      alias_method :moderator?, :is_mod
      alias_method :verified_email?, :has_verified_email
      alias_method :hide_from_robots?, :hide_from_robots
    end
  end

  # @!group Listings
  # Fetches a listing from a user.
  # @!method overview(params = { limit: 25 })
  # @!method comments(params = { limit: 25 })
  # @!method submitted(params = { limit: 25 })
  # @!method gilded(params = { limit: 25 })
  # @!method upvoted(params = { limit: 25 })
  # @!method downvoted(params = { limit: 25 })
  # @!method hidden(params = { limit: 25 })
  # @!method saved(params = { limit: 25 })
  # @param params [Hash] The parameters for the request.
  # @option params :show [String] Show a listing type [overview, comments,
  #   submitted, gilded, upvoted, downvoted, hidden, saved]
  # @option params :sort [String] The sorting algorithm [hot, new, top,
  #   controversial]
  # @option params :t [String] The time for the relevance sort [hour, day,
  #   week, month, year, all]
  # @option params :username [String] The username of an existing user.
  # @option params :after [String] The name of the next data block.
  # @option params :before [String] The name of the previous data block.
  # @option params :count [Integer] The number of items already in the
  #   listing.
  # @option params :limit [1..1000] The number of listing items to fetch.
  # @return [NeonRAW::Objects::Listing] Returns the listing object.
  %w(overview comments submitted gilded upvoted downvoted
     hidden saved).each do |type|
    define_method :"#{type}" do |params = { limit: 25 }|
      path = "/user/#{name}/#{type}/.json"
      @client.send(:build_listing, path, params)
    end
  end
  # @!endgroup

  # Give gold to a user.
  # @!method give_gold(months)
  # @param months [1..36] The number of months worth of gold to give.
  def give_gold(months)
    params = { months: months }
    @client.request_data("/api/v1/gold/give/#{name}", :post, params)
    refresh!
  end

  # Send a PM to a user.
  # @!method message(subject, text, opts = {})
  # @param subject [String] The subject of the message (100 characters
  #   maximum).
  # @param text [String] The text body of the message.
  # @param opts [Hash] Optional parameters.
  # @option opts :from_subreddit [String] The subreddit to send the message
  #   from.
  def message(subject, text, opts = {})
    params = { api_type: 'json', from_sr: opts[:from_subreddit], text: text,
               subject: subject, to: name }
    @client.request_data('/api/compose', :post, params)
  end

  # Fetches the user's multireddits.
  # @!method multireddits
  # @return [Array<NeonRAW::Objects::MultiReddit>] Returns a list of
  #   multireddits.
  def multireddits
    data_arr = []
    params = { expand_srs: false }
    data = @client.request_data("/api/multi/user/#{name}", :get, params)
    data.each do |multireddit|
      data_arr << MultiReddit.new(@client, multireddit[:data])
    end
    data_arr
  end

  # Add the user to your friends list.
  # @!method friend
  def friend
    body = { 'name' => name }.to_json
    @client.request_data("/api/v1/me/friends/#{name}", :put, {}, body)
  end

  # Remove the user from your friends list.
  # @!method unfriend
  def unfriend
    params = { id: name }
    @client.request_nonjson("/api/v1/me/friends/#{name}", :delete, params)
  end

  # Fetches the user's trophies.
  # @!method trophies
  # @return [Array<NeonRAW::Objects::Trophy>] Returns a list of trophies.
  def trophies
    data_arr = []
    path = "/api/v1/user/#{name}/trophies"
    data = @client.request_data(path, :get)[:data]
    data[:trophies].each do |trophy|
      data_arr << Trophy.new(trophy[:data])
    end
    data_arr
  end
end

#friend?Boolean (readonly)

Returns whether or not the user is a friend.

Returns:

  • (Boolean)

    Returns whether or not the user is a friend.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'lib/NeonRAW/objects/user.rb', line 24

class User < Thing
  include Thing::Createable
  include Thing::Refreshable

  # @!method initialize(client, data)
  # @param client [NeonRAW::Clients::Web/Installed/Script] The client
  #   object.
  # @param data [Hash] The object data.
  def initialize(client, data)
    @client = client
    data.each do |key, value|
      value = nil if ['', [], {}].include?(value)
      instance_variable_set(:"@#{key}", value)
      next if key == :created || key == :created_utc
      self.class.send(:attr_reader, key)
    end
    class << self
      alias_method :friend?, :is_friend
      alias_method :gold?, :is_gold
      alias_method :moderator?, :is_mod
      alias_method :verified_email?, :has_verified_email
      alias_method :hide_from_robots?, :hide_from_robots
    end
  end

  # @!group Listings
  # Fetches a listing from a user.
  # @!method overview(params = { limit: 25 })
  # @!method comments(params = { limit: 25 })
  # @!method submitted(params = { limit: 25 })
  # @!method gilded(params = { limit: 25 })
  # @!method upvoted(params = { limit: 25 })
  # @!method downvoted(params = { limit: 25 })
  # @!method hidden(params = { limit: 25 })
  # @!method saved(params = { limit: 25 })
  # @param params [Hash] The parameters for the request.
  # @option params :show [String] Show a listing type [overview, comments,
  #   submitted, gilded, upvoted, downvoted, hidden, saved]
  # @option params :sort [String] The sorting algorithm [hot, new, top,
  #   controversial]
  # @option params :t [String] The time for the relevance sort [hour, day,
  #   week, month, year, all]
  # @option params :username [String] The username of an existing user.
  # @option params :after [String] The name of the next data block.
  # @option params :before [String] The name of the previous data block.
  # @option params :count [Integer] The number of items already in the
  #   listing.
  # @option params :limit [1..1000] The number of listing items to fetch.
  # @return [NeonRAW::Objects::Listing] Returns the listing object.
  %w(overview comments submitted gilded upvoted downvoted
     hidden saved).each do |type|
    define_method :"#{type}" do |params = { limit: 25 }|
      path = "/user/#{name}/#{type}/.json"
      @client.send(:build_listing, path, params)
    end
  end
  # @!endgroup

  # Give gold to a user.
  # @!method give_gold(months)
  # @param months [1..36] The number of months worth of gold to give.
  def give_gold(months)
    params = { months: months }
    @client.request_data("/api/v1/gold/give/#{name}", :post, params)
    refresh!
  end

  # Send a PM to a user.
  # @!method message(subject, text, opts = {})
  # @param subject [String] The subject of the message (100 characters
  #   maximum).
  # @param text [String] The text body of the message.
  # @param opts [Hash] Optional parameters.
  # @option opts :from_subreddit [String] The subreddit to send the message
  #   from.
  def message(subject, text, opts = {})
    params = { api_type: 'json', from_sr: opts[:from_subreddit], text: text,
               subject: subject, to: name }
    @client.request_data('/api/compose', :post, params)
  end

  # Fetches the user's multireddits.
  # @!method multireddits
  # @return [Array<NeonRAW::Objects::MultiReddit>] Returns a list of
  #   multireddits.
  def multireddits
    data_arr = []
    params = { expand_srs: false }
    data = @client.request_data("/api/multi/user/#{name}", :get, params)
    data.each do |multireddit|
      data_arr << MultiReddit.new(@client, multireddit[:data])
    end
    data_arr
  end

  # Add the user to your friends list.
  # @!method friend
  def friend
    body = { 'name' => name }.to_json
    @client.request_data("/api/v1/me/friends/#{name}", :put, {}, body)
  end

  # Remove the user from your friends list.
  # @!method unfriend
  def unfriend
    params = { id: name }
    @client.request_nonjson("/api/v1/me/friends/#{name}", :delete, params)
  end

  # Fetches the user's trophies.
  # @!method trophies
  # @return [Array<NeonRAW::Objects::Trophy>] Returns a list of trophies.
  def trophies
    data_arr = []
    path = "/api/v1/user/#{name}/trophies"
    data = @client.request_data(path, :get)[:data]
    data[:trophies].each do |trophy|
      data_arr << Trophy.new(trophy[:data])
    end
    data_arr
  end
end

#gold?Boolean (readonly)

Returns whether or not the user has gold.

Returns:

  • (Boolean)

    Returns whether or not the user has gold.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'lib/NeonRAW/objects/user.rb', line 24

class User < Thing
  include Thing::Createable
  include Thing::Refreshable

  # @!method initialize(client, data)
  # @param client [NeonRAW::Clients::Web/Installed/Script] The client
  #   object.
  # @param data [Hash] The object data.
  def initialize(client, data)
    @client = client
    data.each do |key, value|
      value = nil if ['', [], {}].include?(value)
      instance_variable_set(:"@#{key}", value)
      next if key == :created || key == :created_utc
      self.class.send(:attr_reader, key)
    end
    class << self
      alias_method :friend?, :is_friend
      alias_method :gold?, :is_gold
      alias_method :moderator?, :is_mod
      alias_method :verified_email?, :has_verified_email
      alias_method :hide_from_robots?, :hide_from_robots
    end
  end

  # @!group Listings
  # Fetches a listing from a user.
  # @!method overview(params = { limit: 25 })
  # @!method comments(params = { limit: 25 })
  # @!method submitted(params = { limit: 25 })
  # @!method gilded(params = { limit: 25 })
  # @!method upvoted(params = { limit: 25 })
  # @!method downvoted(params = { limit: 25 })
  # @!method hidden(params = { limit: 25 })
  # @!method saved(params = { limit: 25 })
  # @param params [Hash] The parameters for the request.
  # @option params :show [String] Show a listing type [overview, comments,
  #   submitted, gilded, upvoted, downvoted, hidden, saved]
  # @option params :sort [String] The sorting algorithm [hot, new, top,
  #   controversial]
  # @option params :t [String] The time for the relevance sort [hour, day,
  #   week, month, year, all]
  # @option params :username [String] The username of an existing user.
  # @option params :after [String] The name of the next data block.
  # @option params :before [String] The name of the previous data block.
  # @option params :count [Integer] The number of items already in the
  #   listing.
  # @option params :limit [1..1000] The number of listing items to fetch.
  # @return [NeonRAW::Objects::Listing] Returns the listing object.
  %w(overview comments submitted gilded upvoted downvoted
     hidden saved).each do |type|
    define_method :"#{type}" do |params = { limit: 25 }|
      path = "/user/#{name}/#{type}/.json"
      @client.send(:build_listing, path, params)
    end
  end
  # @!endgroup

  # Give gold to a user.
  # @!method give_gold(months)
  # @param months [1..36] The number of months worth of gold to give.
  def give_gold(months)
    params = { months: months }
    @client.request_data("/api/v1/gold/give/#{name}", :post, params)
    refresh!
  end

  # Send a PM to a user.
  # @!method message(subject, text, opts = {})
  # @param subject [String] The subject of the message (100 characters
  #   maximum).
  # @param text [String] The text body of the message.
  # @param opts [Hash] Optional parameters.
  # @option opts :from_subreddit [String] The subreddit to send the message
  #   from.
  def message(subject, text, opts = {})
    params = { api_type: 'json', from_sr: opts[:from_subreddit], text: text,
               subject: subject, to: name }
    @client.request_data('/api/compose', :post, params)
  end

  # Fetches the user's multireddits.
  # @!method multireddits
  # @return [Array<NeonRAW::Objects::MultiReddit>] Returns a list of
  #   multireddits.
  def multireddits
    data_arr = []
    params = { expand_srs: false }
    data = @client.request_data("/api/multi/user/#{name}", :get, params)
    data.each do |multireddit|
      data_arr << MultiReddit.new(@client, multireddit[:data])
    end
    data_arr
  end

  # Add the user to your friends list.
  # @!method friend
  def friend
    body = { 'name' => name }.to_json
    @client.request_data("/api/v1/me/friends/#{name}", :put, {}, body)
  end

  # Remove the user from your friends list.
  # @!method unfriend
  def unfriend
    params = { id: name }
    @client.request_nonjson("/api/v1/me/friends/#{name}", :delete, params)
  end

  # Fetches the user's trophies.
  # @!method trophies
  # @return [Array<NeonRAW::Objects::Trophy>] Returns a list of trophies.
  def trophies
    data_arr = []
    path = "/api/v1/user/#{name}/trophies"
    data = @client.request_data(path, :get)[:data]
    data[:trophies].each do |trophy|
      data_arr << Trophy.new(trophy[:data])
    end
    data_arr
  end
end

#hide_from_robots?Boolean (readonly)

Returns whether or not the user doesn’t want web crawlers indexing their profile page.

Returns:

  • (Boolean)

    Returns whether or not the user doesn’t want web crawlers indexing their profile page.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'lib/NeonRAW/objects/user.rb', line 24

class User < Thing
  include Thing::Createable
  include Thing::Refreshable

  # @!method initialize(client, data)
  # @param client [NeonRAW::Clients::Web/Installed/Script] The client
  #   object.
  # @param data [Hash] The object data.
  def initialize(client, data)
    @client = client
    data.each do |key, value|
      value = nil if ['', [], {}].include?(value)
      instance_variable_set(:"@#{key}", value)
      next if key == :created || key == :created_utc
      self.class.send(:attr_reader, key)
    end
    class << self
      alias_method :friend?, :is_friend
      alias_method :gold?, :is_gold
      alias_method :moderator?, :is_mod
      alias_method :verified_email?, :has_verified_email
      alias_method :hide_from_robots?, :hide_from_robots
    end
  end

  # @!group Listings
  # Fetches a listing from a user.
  # @!method overview(params = { limit: 25 })
  # @!method comments(params = { limit: 25 })
  # @!method submitted(params = { limit: 25 })
  # @!method gilded(params = { limit: 25 })
  # @!method upvoted(params = { limit: 25 })
  # @!method downvoted(params = { limit: 25 })
  # @!method hidden(params = { limit: 25 })
  # @!method saved(params = { limit: 25 })
  # @param params [Hash] The parameters for the request.
  # @option params :show [String] Show a listing type [overview, comments,
  #   submitted, gilded, upvoted, downvoted, hidden, saved]
  # @option params :sort [String] The sorting algorithm [hot, new, top,
  #   controversial]
  # @option params :t [String] The time for the relevance sort [hour, day,
  #   week, month, year, all]
  # @option params :username [String] The username of an existing user.
  # @option params :after [String] The name of the next data block.
  # @option params :before [String] The name of the previous data block.
  # @option params :count [Integer] The number of items already in the
  #   listing.
  # @option params :limit [1..1000] The number of listing items to fetch.
  # @return [NeonRAW::Objects::Listing] Returns the listing object.
  %w(overview comments submitted gilded upvoted downvoted
     hidden saved).each do |type|
    define_method :"#{type}" do |params = { limit: 25 }|
      path = "/user/#{name}/#{type}/.json"
      @client.send(:build_listing, path, params)
    end
  end
  # @!endgroup

  # Give gold to a user.
  # @!method give_gold(months)
  # @param months [1..36] The number of months worth of gold to give.
  def give_gold(months)
    params = { months: months }
    @client.request_data("/api/v1/gold/give/#{name}", :post, params)
    refresh!
  end

  # Send a PM to a user.
  # @!method message(subject, text, opts = {})
  # @param subject [String] The subject of the message (100 characters
  #   maximum).
  # @param text [String] The text body of the message.
  # @param opts [Hash] Optional parameters.
  # @option opts :from_subreddit [String] The subreddit to send the message
  #   from.
  def message(subject, text, opts = {})
    params = { api_type: 'json', from_sr: opts[:from_subreddit], text: text,
               subject: subject, to: name }
    @client.request_data('/api/compose', :post, params)
  end

  # Fetches the user's multireddits.
  # @!method multireddits
  # @return [Array<NeonRAW::Objects::MultiReddit>] Returns a list of
  #   multireddits.
  def multireddits
    data_arr = []
    params = { expand_srs: false }
    data = @client.request_data("/api/multi/user/#{name}", :get, params)
    data.each do |multireddit|
      data_arr << MultiReddit.new(@client, multireddit[:data])
    end
    data_arr
  end

  # Add the user to your friends list.
  # @!method friend
  def friend
    body = { 'name' => name }.to_json
    @client.request_data("/api/v1/me/friends/#{name}", :put, {}, body)
  end

  # Remove the user from your friends list.
  # @!method unfriend
  def unfriend
    params = { id: name }
    @client.request_nonjson("/api/v1/me/friends/#{name}", :delete, params)
  end

  # Fetches the user's trophies.
  # @!method trophies
  # @return [Array<NeonRAW::Objects::Trophy>] Returns a list of trophies.
  def trophies
    data_arr = []
    path = "/api/v1/user/#{name}/trophies"
    data = @client.request_data(path, :get)[:data]
    data[:trophies].each do |trophy|
      data_arr << Trophy.new(trophy[:data])
    end
    data_arr
  end
end

Returns the link karma of the user.

Returns:

  • (Integer)

    Returns the link karma of the user.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'lib/NeonRAW/objects/user.rb', line 24

class User < Thing
  include Thing::Createable
  include Thing::Refreshable

  # @!method initialize(client, data)
  # @param client [NeonRAW::Clients::Web/Installed/Script] The client
  #   object.
  # @param data [Hash] The object data.
  def initialize(client, data)
    @client = client
    data.each do |key, value|
      value = nil if ['', [], {}].include?(value)
      instance_variable_set(:"@#{key}", value)
      next if key == :created || key == :created_utc
      self.class.send(:attr_reader, key)
    end
    class << self
      alias_method :friend?, :is_friend
      alias_method :gold?, :is_gold
      alias_method :moderator?, :is_mod
      alias_method :verified_email?, :has_verified_email
      alias_method :hide_from_robots?, :hide_from_robots
    end
  end

  # @!group Listings
  # Fetches a listing from a user.
  # @!method overview(params = { limit: 25 })
  # @!method comments(params = { limit: 25 })
  # @!method submitted(params = { limit: 25 })
  # @!method gilded(params = { limit: 25 })
  # @!method upvoted(params = { limit: 25 })
  # @!method downvoted(params = { limit: 25 })
  # @!method hidden(params = { limit: 25 })
  # @!method saved(params = { limit: 25 })
  # @param params [Hash] The parameters for the request.
  # @option params :show [String] Show a listing type [overview, comments,
  #   submitted, gilded, upvoted, downvoted, hidden, saved]
  # @option params :sort [String] The sorting algorithm [hot, new, top,
  #   controversial]
  # @option params :t [String] The time for the relevance sort [hour, day,
  #   week, month, year, all]
  # @option params :username [String] The username of an existing user.
  # @option params :after [String] The name of the next data block.
  # @option params :before [String] The name of the previous data block.
  # @option params :count [Integer] The number of items already in the
  #   listing.
  # @option params :limit [1..1000] The number of listing items to fetch.
  # @return [NeonRAW::Objects::Listing] Returns the listing object.
  %w(overview comments submitted gilded upvoted downvoted
     hidden saved).each do |type|
    define_method :"#{type}" do |params = { limit: 25 }|
      path = "/user/#{name}/#{type}/.json"
      @client.send(:build_listing, path, params)
    end
  end
  # @!endgroup

  # Give gold to a user.
  # @!method give_gold(months)
  # @param months [1..36] The number of months worth of gold to give.
  def give_gold(months)
    params = { months: months }
    @client.request_data("/api/v1/gold/give/#{name}", :post, params)
    refresh!
  end

  # Send a PM to a user.
  # @!method message(subject, text, opts = {})
  # @param subject [String] The subject of the message (100 characters
  #   maximum).
  # @param text [String] The text body of the message.
  # @param opts [Hash] Optional parameters.
  # @option opts :from_subreddit [String] The subreddit to send the message
  #   from.
  def message(subject, text, opts = {})
    params = { api_type: 'json', from_sr: opts[:from_subreddit], text: text,
               subject: subject, to: name }
    @client.request_data('/api/compose', :post, params)
  end

  # Fetches the user's multireddits.
  # @!method multireddits
  # @return [Array<NeonRAW::Objects::MultiReddit>] Returns a list of
  #   multireddits.
  def multireddits
    data_arr = []
    params = { expand_srs: false }
    data = @client.request_data("/api/multi/user/#{name}", :get, params)
    data.each do |multireddit|
      data_arr << MultiReddit.new(@client, multireddit[:data])
    end
    data_arr
  end

  # Add the user to your friends list.
  # @!method friend
  def friend
    body = { 'name' => name }.to_json
    @client.request_data("/api/v1/me/friends/#{name}", :put, {}, body)
  end

  # Remove the user from your friends list.
  # @!method unfriend
  def unfriend
    params = { id: name }
    @client.request_nonjson("/api/v1/me/friends/#{name}", :delete, params)
  end

  # Fetches the user's trophies.
  # @!method trophies
  # @return [Array<NeonRAW::Objects::Trophy>] Returns a list of trophies.
  def trophies
    data_arr = []
    path = "/api/v1/user/#{name}/trophies"
    data = @client.request_data(path, :get)[:data]
    data[:trophies].each do |trophy|
      data_arr << Trophy.new(trophy[:data])
    end
    data_arr
  end
end

#moderator?Boolean (readonly)

Returns whether or not the user is a moderator.

Returns:

  • (Boolean)

    Returns whether or not the user is a moderator.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'lib/NeonRAW/objects/user.rb', line 24

class User < Thing
  include Thing::Createable
  include Thing::Refreshable

  # @!method initialize(client, data)
  # @param client [NeonRAW::Clients::Web/Installed/Script] The client
  #   object.
  # @param data [Hash] The object data.
  def initialize(client, data)
    @client = client
    data.each do |key, value|
      value = nil if ['', [], {}].include?(value)
      instance_variable_set(:"@#{key}", value)
      next if key == :created || key == :created_utc
      self.class.send(:attr_reader, key)
    end
    class << self
      alias_method :friend?, :is_friend
      alias_method :gold?, :is_gold
      alias_method :moderator?, :is_mod
      alias_method :verified_email?, :has_verified_email
      alias_method :hide_from_robots?, :hide_from_robots
    end
  end

  # @!group Listings
  # Fetches a listing from a user.
  # @!method overview(params = { limit: 25 })
  # @!method comments(params = { limit: 25 })
  # @!method submitted(params = { limit: 25 })
  # @!method gilded(params = { limit: 25 })
  # @!method upvoted(params = { limit: 25 })
  # @!method downvoted(params = { limit: 25 })
  # @!method hidden(params = { limit: 25 })
  # @!method saved(params = { limit: 25 })
  # @param params [Hash] The parameters for the request.
  # @option params :show [String] Show a listing type [overview, comments,
  #   submitted, gilded, upvoted, downvoted, hidden, saved]
  # @option params :sort [String] The sorting algorithm [hot, new, top,
  #   controversial]
  # @option params :t [String] The time for the relevance sort [hour, day,
  #   week, month, year, all]
  # @option params :username [String] The username of an existing user.
  # @option params :after [String] The name of the next data block.
  # @option params :before [String] The name of the previous data block.
  # @option params :count [Integer] The number of items already in the
  #   listing.
  # @option params :limit [1..1000] The number of listing items to fetch.
  # @return [NeonRAW::Objects::Listing] Returns the listing object.
  %w(overview comments submitted gilded upvoted downvoted
     hidden saved).each do |type|
    define_method :"#{type}" do |params = { limit: 25 }|
      path = "/user/#{name}/#{type}/.json"
      @client.send(:build_listing, path, params)
    end
  end
  # @!endgroup

  # Give gold to a user.
  # @!method give_gold(months)
  # @param months [1..36] The number of months worth of gold to give.
  def give_gold(months)
    params = { months: months }
    @client.request_data("/api/v1/gold/give/#{name}", :post, params)
    refresh!
  end

  # Send a PM to a user.
  # @!method message(subject, text, opts = {})
  # @param subject [String] The subject of the message (100 characters
  #   maximum).
  # @param text [String] The text body of the message.
  # @param opts [Hash] Optional parameters.
  # @option opts :from_subreddit [String] The subreddit to send the message
  #   from.
  def message(subject, text, opts = {})
    params = { api_type: 'json', from_sr: opts[:from_subreddit], text: text,
               subject: subject, to: name }
    @client.request_data('/api/compose', :post, params)
  end

  # Fetches the user's multireddits.
  # @!method multireddits
  # @return [Array<NeonRAW::Objects::MultiReddit>] Returns a list of
  #   multireddits.
  def multireddits
    data_arr = []
    params = { expand_srs: false }
    data = @client.request_data("/api/multi/user/#{name}", :get, params)
    data.each do |multireddit|
      data_arr << MultiReddit.new(@client, multireddit[:data])
    end
    data_arr
  end

  # Add the user to your friends list.
  # @!method friend
  def friend
    body = { 'name' => name }.to_json
    @client.request_data("/api/v1/me/friends/#{name}", :put, {}, body)
  end

  # Remove the user from your friends list.
  # @!method unfriend
  def unfriend
    params = { id: name }
    @client.request_nonjson("/api/v1/me/friends/#{name}", :delete, params)
  end

  # Fetches the user's trophies.
  # @!method trophies
  # @return [Array<NeonRAW::Objects::Trophy>] Returns a list of trophies.
  def trophies
    data_arr = []
    path = "/api/v1/user/#{name}/trophies"
    data = @client.request_data(path, :get)[:data]
    data[:trophies].each do |trophy|
      data_arr << Trophy.new(trophy[:data])
    end
    data_arr
  end
end

#verified_email?Boolean (readonly)

Returns whether or not the user has a verified email.

Returns:

  • (Boolean)

    Returns whether or not the user has a verified email.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'lib/NeonRAW/objects/user.rb', line 24

class User < Thing
  include Thing::Createable
  include Thing::Refreshable

  # @!method initialize(client, data)
  # @param client [NeonRAW::Clients::Web/Installed/Script] The client
  #   object.
  # @param data [Hash] The object data.
  def initialize(client, data)
    @client = client
    data.each do |key, value|
      value = nil if ['', [], {}].include?(value)
      instance_variable_set(:"@#{key}", value)
      next if key == :created || key == :created_utc
      self.class.send(:attr_reader, key)
    end
    class << self
      alias_method :friend?, :is_friend
      alias_method :gold?, :is_gold
      alias_method :moderator?, :is_mod
      alias_method :verified_email?, :has_verified_email
      alias_method :hide_from_robots?, :hide_from_robots
    end
  end

  # @!group Listings
  # Fetches a listing from a user.
  # @!method overview(params = { limit: 25 })
  # @!method comments(params = { limit: 25 })
  # @!method submitted(params = { limit: 25 })
  # @!method gilded(params = { limit: 25 })
  # @!method upvoted(params = { limit: 25 })
  # @!method downvoted(params = { limit: 25 })
  # @!method hidden(params = { limit: 25 })
  # @!method saved(params = { limit: 25 })
  # @param params [Hash] The parameters for the request.
  # @option params :show [String] Show a listing type [overview, comments,
  #   submitted, gilded, upvoted, downvoted, hidden, saved]
  # @option params :sort [String] The sorting algorithm [hot, new, top,
  #   controversial]
  # @option params :t [String] The time for the relevance sort [hour, day,
  #   week, month, year, all]
  # @option params :username [String] The username of an existing user.
  # @option params :after [String] The name of the next data block.
  # @option params :before [String] The name of the previous data block.
  # @option params :count [Integer] The number of items already in the
  #   listing.
  # @option params :limit [1..1000] The number of listing items to fetch.
  # @return [NeonRAW::Objects::Listing] Returns the listing object.
  %w(overview comments submitted gilded upvoted downvoted
     hidden saved).each do |type|
    define_method :"#{type}" do |params = { limit: 25 }|
      path = "/user/#{name}/#{type}/.json"
      @client.send(:build_listing, path, params)
    end
  end
  # @!endgroup

  # Give gold to a user.
  # @!method give_gold(months)
  # @param months [1..36] The number of months worth of gold to give.
  def give_gold(months)
    params = { months: months }
    @client.request_data("/api/v1/gold/give/#{name}", :post, params)
    refresh!
  end

  # Send a PM to a user.
  # @!method message(subject, text, opts = {})
  # @param subject [String] The subject of the message (100 characters
  #   maximum).
  # @param text [String] The text body of the message.
  # @param opts [Hash] Optional parameters.
  # @option opts :from_subreddit [String] The subreddit to send the message
  #   from.
  def message(subject, text, opts = {})
    params = { api_type: 'json', from_sr: opts[:from_subreddit], text: text,
               subject: subject, to: name }
    @client.request_data('/api/compose', :post, params)
  end

  # Fetches the user's multireddits.
  # @!method multireddits
  # @return [Array<NeonRAW::Objects::MultiReddit>] Returns a list of
  #   multireddits.
  def multireddits
    data_arr = []
    params = { expand_srs: false }
    data = @client.request_data("/api/multi/user/#{name}", :get, params)
    data.each do |multireddit|
      data_arr << MultiReddit.new(@client, multireddit[:data])
    end
    data_arr
  end

  # Add the user to your friends list.
  # @!method friend
  def friend
    body = { 'name' => name }.to_json
    @client.request_data("/api/v1/me/friends/#{name}", :put, {}, body)
  end

  # Remove the user from your friends list.
  # @!method unfriend
  def unfriend
    params = { id: name }
    @client.request_nonjson("/api/v1/me/friends/#{name}", :delete, params)
  end

  # Fetches the user's trophies.
  # @!method trophies
  # @return [Array<NeonRAW::Objects::Trophy>] Returns a list of trophies.
  def trophies
    data_arr = []
    path = "/api/v1/user/#{name}/trophies"
    data = @client.request_data(path, :get)[:data]
    data[:trophies].each do |trophy|
      data_arr << Trophy.new(trophy[:data])
    end
    data_arr
  end
end

Instance Method Details

#comments(params = { limit: 25 }) ⇒ NeonRAW::Objects::Listing

Fetches a listing from a user.

Parameters:

  • params (Hash) (defaults to: { limit: 25 })

    The parameters for the request.

Options Hash (params):

  • :show (String)

    Show a listing type [overview, comments, submitted, gilded, upvoted, downvoted, hidden, saved]

  • :sort (String)

    The sorting algorithm [hot, new, top, controversial]

  • :t (String)

    The time for the relevance sort [hour, day, week, month, year, all]

  • :username (String)

    The username of an existing user.

  • :after (String)

    The name of the next data block.

  • :before (String)

    The name of the previous data block.

  • :count (Integer)

    The number of items already in the listing.

  • :limit (1..1000)

    The number of listing items to fetch.

Returns:



73
74
75
76
77
78
79
# File 'lib/NeonRAW/objects/user.rb', line 73

%w(overview comments submitted gilded upvoted downvoted
   hidden saved).each do |type|
  define_method :"#{type}" do |params = { limit: 25 }|
    path = "/user/#{name}/#{type}/.json"
    @client.send(:build_listing, path, params)
  end
end

#downvoted(params = { limit: 25 }) ⇒ NeonRAW::Objects::Listing

Fetches a listing from a user.

Parameters:

  • params (Hash) (defaults to: { limit: 25 })

    The parameters for the request.

Options Hash (params):

  • :show (String)

    Show a listing type [overview, comments, submitted, gilded, upvoted, downvoted, hidden, saved]

  • :sort (String)

    The sorting algorithm [hot, new, top, controversial]

  • :t (String)

    The time for the relevance sort [hour, day, week, month, year, all]

  • :username (String)

    The username of an existing user.

  • :after (String)

    The name of the next data block.

  • :before (String)

    The name of the previous data block.

  • :count (Integer)

    The number of items already in the listing.

  • :limit (1..1000)

    The number of listing items to fetch.

Returns:



73
74
75
76
77
78
79
# File 'lib/NeonRAW/objects/user.rb', line 73

%w(overview comments submitted gilded upvoted downvoted
   hidden saved).each do |type|
  define_method :"#{type}" do |params = { limit: 25 }|
    path = "/user/#{name}/#{type}/.json"
    @client.send(:build_listing, path, params)
  end
end

#friendObject

Add the user to your friends list.



121
122
123
124
# File 'lib/NeonRAW/objects/user.rb', line 121

def friend
  body = { 'name' => name }.to_json
  @client.request_data("/api/v1/me/friends/#{name}", :put, {}, body)
end

#gilded(params = { limit: 25 }) ⇒ NeonRAW::Objects::Listing

Fetches a listing from a user.

Parameters:

  • params (Hash) (defaults to: { limit: 25 })

    The parameters for the request.

Options Hash (params):

  • :show (String)

    Show a listing type [overview, comments, submitted, gilded, upvoted, downvoted, hidden, saved]

  • :sort (String)

    The sorting algorithm [hot, new, top, controversial]

  • :t (String)

    The time for the relevance sort [hour, day, week, month, year, all]

  • :username (String)

    The username of an existing user.

  • :after (String)

    The name of the next data block.

  • :before (String)

    The name of the previous data block.

  • :count (Integer)

    The number of items already in the listing.

  • :limit (1..1000)

    The number of listing items to fetch.

Returns:



73
74
75
76
77
78
79
# File 'lib/NeonRAW/objects/user.rb', line 73

%w(overview comments submitted gilded upvoted downvoted
   hidden saved).each do |type|
  define_method :"#{type}" do |params = { limit: 25 }|
    path = "/user/#{name}/#{type}/.json"
    @client.send(:build_listing, path, params)
  end
end

#give_gold(months) ⇒ Object

Give gold to a user.

Parameters:

  • months (1..36)

    The number of months worth of gold to give.



85
86
87
88
89
# File 'lib/NeonRAW/objects/user.rb', line 85

def give_gold(months)
  params = { months: months }
  @client.request_data("/api/v1/gold/give/#{name}", :post, params)
  refresh!
end

#hidden(params = { limit: 25 }) ⇒ NeonRAW::Objects::Listing

Fetches a listing from a user.

Parameters:

  • params (Hash) (defaults to: { limit: 25 })

    The parameters for the request.

Options Hash (params):

  • :show (String)

    Show a listing type [overview, comments, submitted, gilded, upvoted, downvoted, hidden, saved]

  • :sort (String)

    The sorting algorithm [hot, new, top, controversial]

  • :t (String)

    The time for the relevance sort [hour, day, week, month, year, all]

  • :username (String)

    The username of an existing user.

  • :after (String)

    The name of the next data block.

  • :before (String)

    The name of the previous data block.

  • :count (Integer)

    The number of items already in the listing.

  • :limit (1..1000)

    The number of listing items to fetch.

Returns:



73
74
75
76
77
78
79
# File 'lib/NeonRAW/objects/user.rb', line 73

%w(overview comments submitted gilded upvoted downvoted
   hidden saved).each do |type|
  define_method :"#{type}" do |params = { limit: 25 }|
    path = "/user/#{name}/#{type}/.json"
    @client.send(:build_listing, path, params)
  end
end

#message(subject, text, opts = {}) ⇒ Object

Send a PM to a user.

Parameters:

  • subject (String)

    The subject of the message (100 characters maximum).

  • text (String)

    The text body of the message.

  • opts (Hash) (defaults to: {})

    Optional parameters.

Options Hash (opts):

  • :from_subreddit (String)

    The subreddit to send the message from.



99
100
101
102
103
# File 'lib/NeonRAW/objects/user.rb', line 99

def message(subject, text, opts = {})
  params = { api_type: 'json', from_sr: opts[:from_subreddit], text: text,
             subject: subject, to: name }
  @client.request_data('/api/compose', :post, params)
end

#multiredditsArray<NeonRAW::Objects::MultiReddit>

Fetches the user’s multireddits.

Returns:



109
110
111
112
113
114
115
116
117
# File 'lib/NeonRAW/objects/user.rb', line 109

def multireddits
  data_arr = []
  params = { expand_srs: false }
  data = @client.request_data("/api/multi/user/#{name}", :get, params)
  data.each do |multireddit|
    data_arr << MultiReddit.new(@client, multireddit[:data])
  end
  data_arr
end

#overview(params = { limit: 25 }) ⇒ NeonRAW::Objects::Listing

Fetches a listing from a user.

Parameters:

  • params (Hash) (defaults to: { limit: 25 })

    The parameters for the request.

Options Hash (params):

  • :show (String)

    Show a listing type [overview, comments, submitted, gilded, upvoted, downvoted, hidden, saved]

  • :sort (String)

    The sorting algorithm [hot, new, top, controversial]

  • :t (String)

    The time for the relevance sort [hour, day, week, month, year, all]

  • :username (String)

    The username of an existing user.

  • :after (String)

    The name of the next data block.

  • :before (String)

    The name of the previous data block.

  • :count (Integer)

    The number of items already in the listing.

  • :limit (1..1000)

    The number of listing items to fetch.

Returns:



73
74
75
76
77
78
79
# File 'lib/NeonRAW/objects/user.rb', line 73

%w(overview comments submitted gilded upvoted downvoted
   hidden saved).each do |type|
  define_method :"#{type}" do |params = { limit: 25 }|
    path = "/user/#{name}/#{type}/.json"
    @client.send(:build_listing, path, params)
  end
end

#saved(params = { limit: 25 }) ⇒ NeonRAW::Objects::Listing

Fetches a listing from a user.

Parameters:

  • params (Hash) (defaults to: { limit: 25 })

    The parameters for the request.

Options Hash (params):

  • :show (String)

    Show a listing type [overview, comments, submitted, gilded, upvoted, downvoted, hidden, saved]

  • :sort (String)

    The sorting algorithm [hot, new, top, controversial]

  • :t (String)

    The time for the relevance sort [hour, day, week, month, year, all]

  • :username (String)

    The username of an existing user.

  • :after (String)

    The name of the next data block.

  • :before (String)

    The name of the previous data block.

  • :count (Integer)

    The number of items already in the listing.

  • :limit (1..1000)

    The number of listing items to fetch.

Returns:



73
74
75
76
77
78
79
# File 'lib/NeonRAW/objects/user.rb', line 73

%w(overview comments submitted gilded upvoted downvoted
   hidden saved).each do |type|
  define_method :"#{type}" do |params = { limit: 25 }|
    path = "/user/#{name}/#{type}/.json"
    @client.send(:build_listing, path, params)
  end
end

#submitted(params = { limit: 25 }) ⇒ NeonRAW::Objects::Listing

Fetches a listing from a user.

Parameters:

  • params (Hash) (defaults to: { limit: 25 })

    The parameters for the request.

Options Hash (params):

  • :show (String)

    Show a listing type [overview, comments, submitted, gilded, upvoted, downvoted, hidden, saved]

  • :sort (String)

    The sorting algorithm [hot, new, top, controversial]

  • :t (String)

    The time for the relevance sort [hour, day, week, month, year, all]

  • :username (String)

    The username of an existing user.

  • :after (String)

    The name of the next data block.

  • :before (String)

    The name of the previous data block.

  • :count (Integer)

    The number of items already in the listing.

  • :limit (1..1000)

    The number of listing items to fetch.

Returns:



73
74
75
76
77
78
79
# File 'lib/NeonRAW/objects/user.rb', line 73

%w(overview comments submitted gilded upvoted downvoted
   hidden saved).each do |type|
  define_method :"#{type}" do |params = { limit: 25 }|
    path = "/user/#{name}/#{type}/.json"
    @client.send(:build_listing, path, params)
  end
end

#trophiesArray<NeonRAW::Objects::Trophy>

Fetches the user’s trophies.

Returns:



136
137
138
139
140
141
142
143
144
# File 'lib/NeonRAW/objects/user.rb', line 136

def trophies
  data_arr = []
  path = "/api/v1/user/#{name}/trophies"
  data = @client.request_data(path, :get)[:data]
  data[:trophies].each do |trophy|
    data_arr << Trophy.new(trophy[:data])
  end
  data_arr
end

#unfriendObject

Remove the user from your friends list.



128
129
130
131
# File 'lib/NeonRAW/objects/user.rb', line 128

def unfriend
  params = { id: name }
  @client.request_nonjson("/api/v1/me/friends/#{name}", :delete, params)
end

#upvoted(params = { limit: 25 }) ⇒ NeonRAW::Objects::Listing

Fetches a listing from a user.

Parameters:

  • params (Hash) (defaults to: { limit: 25 })

    The parameters for the request.

Options Hash (params):

  • :show (String)

    Show a listing type [overview, comments, submitted, gilded, upvoted, downvoted, hidden, saved]

  • :sort (String)

    The sorting algorithm [hot, new, top, controversial]

  • :t (String)

    The time for the relevance sort [hour, day, week, month, year, all]

  • :username (String)

    The username of an existing user.

  • :after (String)

    The name of the next data block.

  • :before (String)

    The name of the previous data block.

  • :count (Integer)

    The number of items already in the listing.

  • :limit (1..1000)

    The number of listing items to fetch.

Returns:



73
74
75
76
77
78
79
# File 'lib/NeonRAW/objects/user.rb', line 73

%w(overview comments submitted gilded upvoted downvoted
   hidden saved).each do |type|
  define_method :"#{type}" do |params = { limit: 25 }|
    path = "/user/#{name}/#{type}/.json"
    @client.send(:build_listing, path, params)
  end
end