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.

  • file_id (String) —

    File unique ID.

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

    Token expiry date

Returns:

  • (ResourceToken)


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

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:

  • []



156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
# File 'lib/appwrite/services/tokens.rb', line 156

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)


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

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.

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


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
# 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)


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

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