class Chatrix::Api::Push

Contains methods for accessing the “push” endpoints on the server.

Refer to the official documentation for more information about these.

Public Instance Methods

add_rule(scope, kind, id, rule, opts = {}) click to toggle source

Adds or change a push rule.

@param (see get_rule) @param id [String] The rule to add or change. @param opts [Hash{Symbol => String}] Additional options to pass in

the query string. Note that only one of the options should be set.

@option opts [String] :before Add this rule as the next-most

important rule with respect to the rule specified here.

@option opts [String] :after Add this rule as the next-less

important rule with respect to the rule specified here.

@return [Boolean] `true` if the operation was carried out successfully,

otherwise `false`.
# File lib/chatrix/api/push.rb, line 68
def add_rule(scope, kind, id, rule, opts = {})
  path = "/pushrules/#{scope}/#{kind}/#{id}"
  make_request(:put, path, params: opts, content: rule).code == 200
end
delete_rule(scope, kind, id) click to toggle source

Deletes a push rule.

@param (see get_rule) @param id [String] The rule ID to delete. @return [Boolean] `true` if the rule was deleted successfully,

otherwise `false`.
# File lib/chatrix/api/push.rb, line 50
def delete_rule(scope, kind, id)
  make_request(:delete, "/pushrules/#{scope}/#{kind}/#{id}").code == 200
end
disable(scope, kind, id) click to toggle source

Disable a push rule. This is essentially an alias for enable with the last parameter as `false`.

@param (see get_rule) @param id [String] The rule ID to disable. @return [Boolean] `true` if the rule was disabled, otherwise `false`.

# File lib/chatrix/api/push.rb, line 105
def disable(scope, kind, id)
  enable(scope, kind, id, false)
end
enable(scope, kind, id, enabled = true) click to toggle source

Sets the enabled state of a rule, the default is to enable it.

@param (see get_rule) @param id [String] The rule ID to modify the enable state for. @param enabled [Boolean] Whether to enable or disable the rule. @return [Boolean] `true` if the state was modified successfully,

otherwise `false`.
# File lib/chatrix/api/push.rb, line 93
def enable(scope, kind, id, enabled = true)
  path = "/pushrules/#{scope}/#{kind}/#{id}/actions"
  make_request(:put, path, content: { enabled: enabled }).code == 200
end
get_rule(scope, kind, id) click to toggle source

Gets a specific rule.

@param scope [String] The scope to access. @param kind [String] The kind of rule. @param id [String] The rule to get. @return [Hash] Details about the rule.

# File lib/chatrix/api/push.rb, line 40
def get_rule(scope, kind, id)
  make_request(:get, "/pushrules/#{scope}/#{kind}/#{id}").parsed_response
end
get_rules(scope = nil) click to toggle source

Gets all the push rules defined for this user, optionally limited to a specific scope. @param scope [String,nil] If set, only rules within that scope will

be returned.

@return [Hash] A list of push rules for the user.

# File lib/chatrix/api/push.rb, line 29
def get_rules(scope = nil)
  path = scope ? "/pushrules/#{scope}" : '/pushrules'
  make_request(:get, path).parsed_response
end
modify_pusher(pusher) click to toggle source

Add, remove, or modify pushers for the current user. @param pusher [Hash] Pusher information. @return [Boolean] `true` if the operation was carried out successfully,

otherwise `false`.
# File lib/chatrix/api/push.rb, line 20
def modify_pusher(pusher)
  make_request(:post, '/pushers/set', content: pusher).code == 200
end
pushers() click to toggle source

Get all active pushers for the current user. @return [Hash] A list of pushers for the user.

# File lib/chatrix/api/push.rb, line 12
def pushers
  make_request(:get, '/pushers').parsed_response
end
set_actions(scope, kind, id, actions) click to toggle source

Sets or modifies the actions for a rule.

@param (see get_rule) @param id [String] The rule ID to modify actions for. @param actions [Hash] Actions to perform when the conditions for

this rule are met.

@return [Boolean] `true` if the actions were modified successfully,

otherwise `false`.
# File lib/chatrix/api/push.rb, line 81
def set_actions(scope, kind, id, actions)
  path = "/pushrules/#{scope}/#{kind}/#{id}/actions"
  make_request(:put, path, content: actions).code == 200
end