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.



5
6
7
# File 'lib/appwrite/services/tokens.rb', line 5

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.

  • file_id (String) —

    File unique ID.

  • expire (String) (defaults to: nil) —

    Token expiry date

Returns:

  • (ResourceToken)


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
92
93
94
95
96
97
# File 'lib/appwrite/services/tokens.rb', line 63

def create_file_token(
    bucket_id:,
    file_id:,
    expire: nil
)
    if bucket_id.nil? || bucket_id == ''
        raise Appwrite::Exception.new('Missing required parameter: "bucketId"')
    end

    if file_id.nil? || file_id == ''
        raise Appwrite::Exception.new('Missing required parameter: "fileId"')
    end

    api_path = '/tokens/buckets/{bucketId}/files/{fileId}'
        .gsub('{bucketId}', @client.encode_path(bucket_id))
        .gsub('{fileId}', @client.encode_path(file_id))

    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.

Parameters:

  • token_id (String) —

    Token ID.

Returns:

  • []



172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
# File 'lib/appwrite/services/tokens.rb', line 172

def delete(
    token_id:
)
    if token_id.nil? || token_id == ''
        raise Appwrite::Exception.new('Missing required parameter: "tokenId"')
    end

    api_path = '/tokens/{tokenId}'
        .gsub('{tokenId}', @client.encode_path(token_id))

    api_params = {}

    api_headers = {
        "X-Appwrite-Project": @client.get_config('project'),
        "content-type": 'application/json',
        "accept": '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)


104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/appwrite/services/tokens.rb', line 104

def get(
    token_id:
)
    if token_id.nil? || token_id == ''
        raise Appwrite::Exception.new('Missing required parameter: "tokenId"')
    end

    api_path = '/tokens/{tokenId}'
        .gsub('{tokenId}', @client.encode_path(token_id))

    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.

Parameters:

  • bucket_id (String) —

    Storage bucket unique ID. You can create a new storage bucket using the Storage service server integration.

  • 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. 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)


18
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
51
52
53
# File 'lib/appwrite/services/tokens.rb', line 18

def list(
    bucket_id:,
    file_id:,
    queries: nil,
    total: nil
)
    if bucket_id.nil? || bucket_id == ''
        raise Appwrite::Exception.new('Missing required parameter: "bucketId"')
    end

    if file_id.nil? || file_id == ''
        raise Appwrite::Exception.new('Missing required parameter: "fileId"')
    end

    api_path = '/tokens/buckets/{bucketId}/files/{fileId}'
        .gsub('{bucketId}', @client.encode_path(bucket_id))
        .gsub('{fileId}', @client.encode_path(file_id))

    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.

Parameters:

  • token_id (String) —

    Token unique ID.

  • expire (String) (defaults to: nil) —

    File token expiry date

Returns:

  • (ResourceToken)


137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# File 'lib/appwrite/services/tokens.rb', line 137

def update(
    token_id:,
    expire: nil
)
    if token_id.nil? || token_id == ''
        raise Appwrite::Exception.new('Missing required parameter: "tokenId"')
    end

    api_path = '/tokens/{tokenId}'
        .gsub('{tokenId}', @client.encode_path(token_id))

    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