Class: Appwrite::Tokens

Inherits:
Service show all
Defined in:
lib/appwrite/services/tokens.rb

Instance Method Summary collapse

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.

Parameters:

  • bucket_id (String)

    Storage bucket unique ID. You can create a new storage bucket using the Storage service [server integration](appwrite.io/docs/server/storage#createBucket).

  • file_id (String)

    File unique ID.

  • expire (String) (defaults to: nil)

    Token expiry date

Returns:

  • (ResourceToken)


57
58
59
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
# File 'lib/appwrite/services/tokens.rb', line 57

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 = {
        "content-type": '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.

Parameters:

  • token_id (String)

    Token ID.

Returns:



152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
# File 'lib/appwrite/services/tokens.rb', line 152

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 = {
        "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.

Parameters:

  • token_id (String)

    Token ID.

Returns:

  • (ResourceToken)


92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/appwrite/services/tokens.rb', line 92

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 = {
    }

    @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.

Parameters:

  • bucket_id (String)

    Storage bucket unique ID. You can create a new storage bucket using the Storage service [server integration](appwrite.io/docs/server/storage#createBucket).

  • file_id (String)

    File unique ID.

  • queries (Array) (defaults to: nil)

    Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](appwrite.io/docs/queries). Maximum of 100 queries are allowed, each 4096 characters long. You may filter on the following attributes: expire

  • []

    total When set to false, the total count returned will be 0 and will not be calculated.

Returns:

  • (ResourceTokenList)


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
# 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 = {
    }

    @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.

Parameters:

  • token_id (String)

    Token unique ID.

  • expire (String) (defaults to: nil)

    File token expiry date

Returns:

  • (ResourceToken)


122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'lib/appwrite/services/tokens.rb', line 122

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 = {
        "content-type": 'application/json',
    }

    @client.call(
        method: 'PATCH',
        path: api_path,
        headers: api_headers,
        params: api_params,
        response_type: Models::ResourceToken
    )
end