Module: Mastodon::REST::Filters

Includes:
Utils
Included in:
API
Defined in:
lib/mastodon/rest/filters.rb

Instance Method Summary collapse

Methods included from Utils

#array_param, #perform_request, #perform_request_with_collection, #perform_request_with_object

Instance Method Details

#create_filter(options = {}) ⇒ Object

Create a new filter

Parameters:

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

Options Hash (options):

  • :phrase (String)
  • :context (Array<String>)
  • :irreversible (Boolean)
  • :whole_word (Boolean)
  • :expires_in (Integer)


19
20
21
22
23
24
25
26
# File 'lib/mastodon/rest/filters.rb', line 19

def create_filter(options = {})
  context = options.delete(:context)
  context = [ context ] unless context.kind_of? Array
  options['context[]'] = context
  
  perform_request_with_object(:post, '/api/v1/filters',
                              options, Mastodon::Filter)
end

#delete_filter(id) ⇒ Object

Delete a filter

Parameters:

  • id (Integer)


64
65
66
# File 'lib/mastodon/rest/filters.rb', line 64

def delete_filter(id)
  !perform_request(:delete, "/api/v1/filters/#{id}").nil?
end

#filter(id) ⇒ Object

Gets a filter

Parameters:

  • id (Integer)


31
32
33
34
# File 'lib/mastodon/rest/filters.rb', line 31

def filter(id)
  perform_request_with_object(:get, "/api/v1/filters/#{id}",
                              {}, Mastodon::Filter)
end

#filtersObject

Gets all filters



38
39
40
41
# File 'lib/mastodon/rest/filters.rb', line 38

def filters
  perform_request_with_collection(:get, '/api/v1/filters',
                                  {}, Mastodon::Filter)
end

#update_filter(id, options = {}) ⇒ Object

Update an existing filter

Parameters:

  • id (Integer)
  • options (Hash) (defaults to: {})

Options Hash (options):

  • :phrase (String)
  • :context (Array<String>)
  • :irreversible (Boolean)
  • :whole_word (Boolean)
  • :expires_in (Integer)


52
53
54
55
56
57
58
59
# File 'lib/mastodon/rest/filters.rb', line 52

def update_filter(id, options = {})
  context = options.delete(:context)
  context = [ context ] unless context.kind_of? Array
  options['context[]'] = context
  
  perform_request_with_object(:put, "/api/v1/filters/#{id}",
                              options, Mastodon::Filter)
end