Class: Appwrite::Tokens

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

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ 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 header or request get parameter.



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

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.



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

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.



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) ⇒ ResourceTokenList

List all the tokens created for a specific file or bucket. You can use the query params to filter your results.



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

def list(bucket_id:, file_id:, queries: 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,
    }
    
    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.



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

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