Class: Nylas::Rules
- Includes:
- ApiOperations::Delete, ApiOperations::Get, ApiOperations::Post, ApiOperations::Put
- Defined in:
- lib/nylas/resources/rules.rb
Overview
Nylas Rules API
Instance Method Summary collapse
-
#create(request_body:) ⇒ Array(Hash, String)
Create a rule.
-
#destroy(rule_id:) ⇒ Array(TrueClass, String)
Delete a rule.
-
#find(rule_id:) ⇒ Array(Hash, String, Hash)
Return a rule.
-
#list(query_params: nil) ⇒ Array(Array(Hash), String, String, Hash)
Return all rules.
-
#list_evaluations(grant_id:, query_params: nil) ⇒ Array(Array(Hash), String, String, Hash)
Return all rule evaluations for a grant.
-
#update(rule_id:, request_body:) ⇒ Array(Hash, String)
Update a rule.
Methods inherited from Resource
Constructor Details
This class inherits a constructor from Nylas::Resource
Instance Method Details
#create(request_body:) ⇒ Array(Hash, String)
Create a rule.
113 114 115 116 117 118 |
# File 'lib/nylas/resources/rules.rb', line 113 def create(request_body:) post( path: "#{api_uri}/v3/rules", request_body: request_body ) end |
#destroy(rule_id:) ⇒ Array(TrueClass, String)
Delete a rule.
136 137 138 139 140 141 142 |
# File 'lib/nylas/resources/rules.rb', line 136 def destroy(rule_id:) _, request_id = delete( path: "#{api_uri}/v3/rules/#{rule_id}" ) [true, request_id] end |
#find(rule_id:) ⇒ Array(Hash, String, Hash)
Return a rule.
103 104 105 106 107 |
# File 'lib/nylas/resources/rules.rb', line 103 def find(rule_id:) get( path: "#{api_uri}/v3/rules/#{rule_id}" ) end |
#list(query_params: nil) ⇒ Array(Array(Hash), String, String, Hash)
Return all rules.
The list endpoint returns a nested envelope ({ request_id, data: { items: [...], next_cursor } }), so the items and cursor are unwrapped here defensively rather than via the standard get_list helper, which would mis-read the nested shape.
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/nylas/resources/rules.rb', line 79 def list(query_params: nil) response = get_raw( path: "#{api_uri}/v3/rules", query_params: query_params ) data = response[:data] # Unwrap only when the envelope actually carries an :items key. Go's # ListWithCursorResult serializes a nil slice as "items": null, so coerce # that to [] rather than falling back to the envelope hash itself. items = if data.is_a?(Hash) && data.key?(:items) data[:items] || [] else data end next_cursor = data.is_a?(Hash) ? data[:next_cursor] : response[:next_cursor] [items, response[:request_id], next_cursor, response[:headers]] end |
#list_evaluations(grant_id:, query_params: nil) ⇒ Array(Array(Hash), String, String, Hash)
Return all rule evaluations for a grant.
This endpoint returns a flat array with no cursor, so the standard get_list helper is used (next_cursor is always nil).
154 155 156 157 158 159 |
# File 'lib/nylas/resources/rules.rb', line 154 def list_evaluations(grant_id:, query_params: nil) get_list( path: "#{api_uri}/v3/grants/#{grant_id}/rule-evaluations", query_params: query_params ) end |
#update(rule_id:, request_body:) ⇒ Array(Hash, String)
Update a rule. Only the provided fields are changed (partial update).
125 126 127 128 129 130 |
# File 'lib/nylas/resources/rules.rb', line 125 def update(rule_id:, request_body:) put( path: "#{api_uri}/v3/rules/#{rule_id}", request_body: request_body ) end |