Class: Chatrix::Api::Push

Inherits:
ApiComponent show all
Defined in:
lib/chatrix/api/push.rb

Overview

Contains methods for accessing the "push" endpoints on the server.

Refer to the official documentation for more information about these.

Instance Method Summary collapse

Methods inherited from ApiComponent

#initialize, #make_request

Constructor Details

This class inherits a constructor from Chatrix::Api::ApiComponent

Instance Method Details

#add_rule(scope, kind, id, rule, opts = {}) ⇒ Boolean

Adds or change a push rule.

Parameters:

  • id (String)

    The rule to add or change.

  • opts (Hash{Symbol => String}) (defaults to: {})

    Additional options to pass in the query string. Note that only one of the options should be set.

  • scope (String)

    The scope to access.

  • kind (String)

    The kind of rule.

  • id (String)

    The rule to get.

Options Hash (opts):

  • :before (String)

    Add this rule as the next-most important rule with respect to the rule specified here.

  • :after (String)

    Add this rule as the next-less important rule with respect to the rule specified here.

Returns:

  • (Boolean)

    true if the operation was carried out successfully, otherwise false.



68
69
70
71
# 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) ⇒ Boolean

Deletes a push rule.

Parameters:

  • id (String)

    The rule ID to delete.

  • scope (String)

    The scope to access.

  • kind (String)

    The kind of rule.

  • id (String)

    The rule to get.

Returns:

  • (Boolean)

    true if the rule was deleted successfully, otherwise false.



50
51
52
# 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) ⇒ Boolean

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

Parameters:

  • id (String)

    The rule ID to disable.

  • scope (String)

    The scope to access.

  • kind (String)

    The kind of rule.

  • id (String)

    The rule to get.

Returns:

  • (Boolean)

    true if the rule was disabled, otherwise false.



105
106
107
# 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) ⇒ Boolean

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

Parameters:

  • id (String)

    The rule ID to modify the enable state for.

  • enabled (Boolean) (defaults to: true)

    Whether to enable or disable the rule.

  • scope (String)

    The scope to access.

  • kind (String)

    The kind of rule.

  • id (String)

    The rule to get.

Returns:

  • (Boolean)

    true if the state was modified successfully, otherwise false.



93
94
95
96
# 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) ⇒ Hash

Gets a specific rule.

Parameters:

  • scope (String)

    The scope to access.

  • kind (String)

    The kind of rule.

  • id (String)

    The rule to get.

Returns:

  • (Hash)

    Details about the rule.



40
41
42
# 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) ⇒ Hash

Gets all the push rules defined for this user, optionally limited to a specific scope.

Parameters:

  • scope (String, nil) (defaults to: nil)

    If set, only rules within that scope will be returned.

Returns:

  • (Hash)

    A list of push rules for the user.



29
30
31
32
# 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) ⇒ Boolean

Add, remove, or modify pushers for the current user.

Parameters:

  • pusher (Hash)

    Pusher information.

Returns:

  • (Boolean)

    true if the operation was carried out successfully, otherwise false.



20
21
22
# File 'lib/chatrix/api/push.rb', line 20

def modify_pusher(pusher)
  make_request(:post, '/pushers/set', content: pusher).code == 200
end

#pushersHash

Get all active pushers for the current user.

Returns:

  • (Hash)

    A list of pushers for the user.



12
13
14
# File 'lib/chatrix/api/push.rb', line 12

def pushers
  make_request(:get, '/pushers').parsed_response
end

#set_actions(scope, kind, id, actions) ⇒ Boolean

Sets or modifies the actions for a rule.

Parameters:

  • id (String)

    The rule ID to modify actions for.

  • actions (Hash)

    Actions to perform when the conditions for this rule are met.

  • scope (String)

    The scope to access.

  • kind (String)

    The kind of rule.

  • id (String)

    The rule to get.

Returns:

  • (Boolean)

    true if the actions were modified successfully, otherwise false.



81
82
83
84
# 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