Class: Appwrite::Tokens
- Defined in:
- lib/appwrite/services/tokens.rb
Instance Method Summary collapse
-
#create_file_token(bucket_id:, file_id:, expire: nil) ⇒ ResourceToken
Create a new token.
-
#delete(token_id:) ⇒ Object
Delete a token by its unique ID.
-
#get(token_id:) ⇒ ResourceToken
Get a token by its unique ID.
-
#initialize(client) ⇒ Tokens
constructor
A new instance of Tokens.
-
#list(bucket_id:, file_id:, queries: nil, total: nil) ⇒ ResourceTokenList
List all the tokens created for a specific file or bucket.
-
#update(token_id:, expire: nil) ⇒ ResourceToken
Update a token by its unique ID.
Constructor Details
#initialize(client) ⇒ Tokens
Returns a new instance of Tokens.
6 7 8 |
# File 'lib/appwrite/services/tokens.rb', line 6 def initialize(client) @client = client end |
Instance Method Details
#create_file_token(bucket_id:, file_id:, expire: nil) ⇒ ResourceToken
Create a new token. A token is linked to a file. Token can be passed as a request URL search parameter.
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/appwrite/services/tokens.rb', line 60 def create_file_token(bucket_id:, file_id:, expire: nil) api_path = '/tokens/buckets/{bucketId}/files/{fileId}' .gsub('{bucketId}', bucket_id) .gsub('{fileId}', file_id) if bucket_id.nil? raise Appwrite::Exception.new('Missing required parameter: "bucketId"') end if file_id.nil? raise Appwrite::Exception.new('Missing required parameter: "fileId"') end api_params = { expire: expire, } api_headers = { "X-Appwrite-Project": @client.get_config('project'), "content-type": 'application/json', "accept": 'application/json', } @client.call( method: 'POST', path: api_path, headers: api_headers, params: api_params, response_type: Models::ResourceToken ) end |
#delete(token_id:) ⇒ Object
Delete a token by its unique ID.
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 |
# File 'lib/appwrite/services/tokens.rb', line 164 def delete(token_id:) api_path = '/tokens/{tokenId}' .gsub('{tokenId}', token_id) if token_id.nil? raise Appwrite::Exception.new('Missing required parameter: "tokenId"') end api_params = { } api_headers = { "X-Appwrite-Project": @client.get_config('project'), "content-type": 'application/json', } @client.call( method: 'DELETE', path: api_path, headers: api_headers, params: api_params, ) end |
#get(token_id:) ⇒ ResourceToken
Get a token by its unique ID.
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/appwrite/services/tokens.rb', line 98 def get(token_id:) api_path = '/tokens/{tokenId}' .gsub('{tokenId}', token_id) if token_id.nil? raise Appwrite::Exception.new('Missing required parameter: "tokenId"') end api_params = { } api_headers = { "X-Appwrite-Project": @client.get_config('project'), "accept": 'application/json', } @client.call( method: 'GET', path: api_path, headers: api_headers, params: api_params, response_type: Models::ResourceToken ) end |
#list(bucket_id:, file_id:, queries: nil, total: nil) ⇒ ResourceTokenList
List all the tokens created for a specific file or bucket. You can use the query params to filter your results.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/appwrite/services/tokens.rb', line 19 def list(bucket_id:, file_id:, queries: nil, total: nil) api_path = '/tokens/buckets/{bucketId}/files/{fileId}' .gsub('{bucketId}', bucket_id) .gsub('{fileId}', file_id) if bucket_id.nil? raise Appwrite::Exception.new('Missing required parameter: "bucketId"') end if file_id.nil? raise Appwrite::Exception.new('Missing required parameter: "fileId"') end api_params = { queries: queries, total: total, } api_headers = { "X-Appwrite-Project": @client.get_config('project'), "accept": 'application/json', } @client.call( method: 'GET', path: api_path, headers: api_headers, params: api_params, response_type: Models::ResourceTokenList ) end |
#update(token_id:, expire: nil) ⇒ ResourceToken
Update a token by its unique ID. Use this endpoint to update a token's expiry date.
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/appwrite/services/tokens.rb', line 131 def update(token_id:, expire: nil) api_path = '/tokens/{tokenId}' .gsub('{tokenId}', token_id) if token_id.nil? raise Appwrite::Exception.new('Missing required parameter: "tokenId"') end api_params = { expire: expire, } api_headers = { "X-Appwrite-Project": @client.get_config('project'), "content-type": 'application/json', "accept": 'application/json', } @client.call( method: 'PATCH', path: api_path, headers: api_headers, params: api_params, response_type: Models::ResourceToken ) end |