Module: Snoo::Flair
- Defined in:
- lib/snoo/flair.rb
Overview
Flair related methods. These are used for interacting with flair in reddit. Things like giving flair, setting templates, and whatnot.
Instance Method Summary collapse
-
#clear_flair_templates(type, subreddit) ⇒ Object
Clear all the flair templates of a particular type.
-
#delete_flair_template(id, subreddit) ⇒ Object
Deletes a flair template by ID.
-
#delete_user_flair(user, subreddit) ⇒ Object
Deletes a user's flair.
-
#flair(subreddit, opts = {}) ⇒ Object
Sets flair on a thing, currently supports links and users.
-
#flair_config(subreddit, opts = {}) ⇒ Object
Configures flair options for a subreddit.
-
#flair_csv(csv, subreddit) ⇒ HTTParty::Response
Post flair in a CSV file to reddit.
-
#flair_template(subreddit, opts = {}) ⇒ Object
Create or edit a flair template.
-
#flair_toggle(enabled, subreddit) ⇒ Object
Toggle flair on and off for a subreddit.
-
#get_flair_list(subreddit, opts = {}) ⇒ Object
Downloads flair from the subreddit This is limited to 1000 per request, use before/after to get "pages".
-
#select_flair_template(template_id, subreddit, opts = {}) ⇒ Object
Select a flair template and apply it to a user or link.
Instance Method Details
#clear_flair_templates(type, subreddit) ⇒ Object
Clear all the flair templates of a particular type
13 14 15 16 |
# File 'lib/snoo/flair.rb', line 13 def clear_flair_templates type, subreddit logged_in? post('/api/clearflairtemplates', body: { flair_type: type, r: subreddit, uh: @modhash, api_type: 'json'}) end |
#delete_flair_template(id, subreddit) ⇒ Object
Deletes a flair template by ID.
32 33 34 35 |
# File 'lib/snoo/flair.rb', line 32 def delete_flair_template id, subreddit logged_in? post('/api/deleteflairtemplate', body: {flair_template_id: id, r: subreddit, uh: @modhash, api_type: 'json'}) end |
#delete_user_flair(user, subreddit) ⇒ Object
Deletes a user's flair
23 24 25 26 |
# File 'lib/snoo/flair.rb', line 23 def delete_user_flair user, subreddit logged_in? post('/api/deleteflair', body: {name: user, r: subreddit, uh: @modhash, api_type: 'json'}) end |
#flair(subreddit, opts = {}) ⇒ Object
Sets flair on a thing, currently supports links and users. Must specify either link or user, not both
46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/snoo/flair.rb', line 46 def flair subreddit, opts = {} logged_in? params = { r: subreddit, uh: @modhash, api_type: 'json' } params.merge! opts post('/api/flair', body: params) end |
#flair_config(subreddit, opts = {}) ⇒ Object
Configures flair options for a subreddit. All options are required
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/snoo/flair.rb', line 68 def flair_config subreddit, opts = {} logged_in? = { flair_enabled: true, flair_position: 'right', flair_self_assign_enabled: false, link_flair_position: 'right', link_flair_self_assign_enabled: false, uh: @modhash, r: subreddit, api_type: 'json' } .merge! opts post('/api/flairconfig', body: ) end |
#flair_csv(csv, subreddit) ⇒ HTTParty::Response
Post flair in a CSV file to reddit
90 91 92 93 |
# File 'lib/snoo/flair.rb', line 90 def flair_csv csv, subreddit logged_in? post('/api/flaircsv.json', body: {flair_csv: csv, r: subreddit, uh: @modhash}) end |
#flair_template(subreddit, opts = {}) ⇒ Object
Create or edit a flair template.
123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/snoo/flair.rb', line 123 def flair_template subreddit, opts = {} logged_in? params = { flair_type: 'USER_FLAIR', text_editable: false, uh: @modhash, r: subreddit, api_type: 'json' } params.merge! opts post('/api/flairtemplate', body: params) end |
#flair_toggle(enabled, subreddit) ⇒ Object
Toggle flair on and off for a subreddit
163 164 165 166 |
# File 'lib/snoo/flair.rb', line 163 def flair_toggle enabled, subreddit logged_in? post('/api/setflairenabled', body: {flair_enabled: enabled, uh: @modhash, r: subreddit, api_type: 'json'}) end |
#get_flair_list(subreddit, opts = {}) ⇒ Object
Downloads flair from the subreddit This is limited to 1000 per request, use before/after to get "pages"
103 104 105 106 107 108 109 110 111 |
# File 'lib/snoo/flair.rb', line 103 def get_flair_list subreddit, opts = {} logged_in? query = { limit: 1000, uh: @modhash } query.merge! opts get("/r/#{subreddit}/api/flairlist.json", query: query) end |
#select_flair_template(template_id, subreddit, opts = {}) ⇒ Object
Select a flair template and apply it to a user or link
146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/snoo/flair.rb', line 146 def select_flair_template template_id, subreddit, opts = {} logged_in? params = { flair_template_id: template_id, uh: @modhash, r: subreddit, api_type: 'json' } params.merge! opts post('/api/selectflair', body: params) end |