Class: Appwrite::Proxy

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

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Proxy

Returns a new instance of Proxy.



6
7
8
# File 'lib/appwrite/services/proxy.rb', line 6

def initialize(client)
    @client = client
end

Instance Method Details

#create_api_rule(domain:) ⇒ ProxyRule

Create a new proxy rule for serving Appwrite's API on custom domain.

Rule ID is automatically generated as MD5 hash of a rule domain for performance purposes.

Parameters:

  • domain (String)

    Domain name.

Returns:

  • (ProxyRule)


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

def create_api_rule(domain:)
    api_path = '/proxy/rules/api'

    if domain.nil?
      raise Appwrite::Exception.new('Missing required parameter: "domain"')
    end

    api_params = {
        domain: domain,
    }
    
    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::ProxyRule
    )

end

#create_function_rule(domain:, function_id:, branch: nil) ⇒ ProxyRule

Create a new proxy rule for executing Appwrite Function on custom domain.

Rule ID is automatically generated as MD5 hash of a rule domain for performance purposes.

Parameters:

  • domain (String)

    Domain name.

  • function_id (String)

    ID of function to be executed.

  • branch (String) (defaults to: nil)

    Name of VCS branch to deploy changes automatically

Returns:

  • (ProxyRule)


129
130
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
158
159
160
# File 'lib/appwrite/services/proxy.rb', line 129

def create_function_rule(domain:, function_id:, branch: nil)
    api_path = '/proxy/rules/function'

    if domain.nil?
      raise Appwrite::Exception.new('Missing required parameter: "domain"')
    end

    if function_id.nil?
      raise Appwrite::Exception.new('Missing required parameter: "functionId"')
    end

    api_params = {
        domain: domain,
        functionId: function_id,
        branch: branch,
    }
    
    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::ProxyRule
    )

end

#create_invalidation(domain:, type:, reference: nil) ⇒ ProxyInvalidation

Create a new CDN cache invalidation for a domain. Executes a hard purge of cached content.

Depending on type, the invalidation purges a single cache tag, a single URL path, or all cached content for the domain.

Parameters:

  • domain (String)

    Domain name.

  • type (InvalidationType)

    Type of reference passed. Allowed values are: tag, path, all

  • reference (String) (defaults to: nil)

    Reference to invalidate. Depending on type this can be: cache tag name (up to 128 characters), URL path (up to 2048 characters). Not required when type is all.

Returns:

  • (ProxyInvalidation)


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

def create_invalidation(domain:, type:, reference: nil)
    api_path = '/proxy/invalidations'

    if domain.nil?
      raise Appwrite::Exception.new('Missing required parameter: "domain"')
    end

    if type.nil?
      raise Appwrite::Exception.new('Missing required parameter: "type"')
    end

    api_params = {
        domain: domain,
        type: type,
        reference: reference,
    }
    
    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::ProxyInvalidation
    )

end

#create_redirect_rule(domain:, url:, status_code:, resource_id:, resource_type:) ⇒ ProxyRule

Create a new proxy rule for to redirect from custom domain to another domain.

Rule ID is automatically generated as MD5 hash of a rule domain for performance purposes.

Parameters:

  • domain (String)

    Domain name.

  • url (String)

    Target URL of redirection

  • status_code (StatusCode)

    Status code of redirection

  • resource_id (String)

    ID of parent resource.

  • resource_type (ProxyResourceType)

    Type of parent resource.

Returns:

  • (ProxyRule)


175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
# File 'lib/appwrite/services/proxy.rb', line 175

def create_redirect_rule(domain:, url:, status_code:, resource_id:, resource_type:)
    api_path = '/proxy/rules/redirect'

    if domain.nil?
      raise Appwrite::Exception.new('Missing required parameter: "domain"')
    end

    if url.nil?
      raise Appwrite::Exception.new('Missing required parameter: "url"')
    end

    if status_code.nil?
      raise Appwrite::Exception.new('Missing required parameter: "statusCode"')
    end

    if resource_id.nil?
      raise Appwrite::Exception.new('Missing required parameter: "resourceId"')
    end

    if resource_type.nil?
      raise Appwrite::Exception.new('Missing required parameter: "resourceType"')
    end

    api_params = {
        domain: domain,
        url: url,
        statusCode: status_code,
        resourceId: resource_id,
        resourceType: resource_type,
    }
    
    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::ProxyRule
    )

end

#create_site_rule(domain:, site_id:, branch: nil) ⇒ ProxyRule

Create a new proxy rule for serving Appwrite Site on custom domain.

Rule ID is automatically generated as MD5 hash of a rule domain for performance purposes.

Parameters:

  • domain (String)

    Domain name.

  • site_id (String)

    ID of site to be executed.

  • branch (String) (defaults to: nil)

    Name of VCS branch to deploy changes automatically

Returns:

  • (ProxyRule)


232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
# File 'lib/appwrite/services/proxy.rb', line 232

def create_site_rule(domain:, site_id:, branch: nil)
    api_path = '/proxy/rules/site'

    if domain.nil?
      raise Appwrite::Exception.new('Missing required parameter: "domain"')
    end

    if site_id.nil?
      raise Appwrite::Exception.new('Missing required parameter: "siteId"')
    end

    api_params = {
        domain: domain,
        siteId: site_id,
        branch: branch,
    }
    
    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::ProxyRule
    )

end

#delete_rule(rule_id:) ⇒ Object

Delete a proxy rule by its unique ID.

Parameters:

  • rule_id (String)

    Rule ID.

Returns:

  • []



301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
# File 'lib/appwrite/services/proxy.rb', line 301

def delete_rule(rule_id:)
    api_path = '/proxy/rules/{ruleId}'
        .gsub('{ruleId}', rule_id)

    if rule_id.nil?
      raise Appwrite::Exception.new('Missing required parameter: "ruleId"')
    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_rule(rule_id:) ⇒ ProxyRule

Get a proxy rule by its unique ID.

Parameters:

  • rule_id (String)

    Rule ID.

Returns:

  • (ProxyRule)


270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
# File 'lib/appwrite/services/proxy.rb', line 270

def get_rule(rule_id:)
    api_path = '/proxy/rules/{ruleId}'
        .gsub('{ruleId}', rule_id)

    if rule_id.nil?
      raise Appwrite::Exception.new('Missing required parameter: "ruleId"')
    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::ProxyRule
    )

end

#list_rules(queries: nil, total: nil) ⇒ ProxyRuleList

Get a list of all the proxy rules. You can use the query params to filter your results.

Parameters:

  • 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: domain, type, trigger, deploymentResourceType, deploymentResourceId, deploymentId, deploymentVcsProviderBranch

  • []

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

Returns:

  • (ProxyRuleList)


61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/appwrite/services/proxy.rb', line 61

def list_rules(queries: nil, total: nil)
    api_path = '/proxy/rules'

    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::ProxyRuleList
    )

end

#update_rule_status(rule_id:) ⇒ ProxyRule

If not succeeded yet, retry verification process of a proxy rule domain. This endpoint triggers domain verification by checking DNS records. If verification is successful, a TLS certificate will be automatically provisioned for the domain asynchronously in the background.

Parameters:

  • rule_id (String)

    Rule ID.

Returns:

  • (ProxyRule)


334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
# File 'lib/appwrite/services/proxy.rb', line 334

def update_rule_status(rule_id:)
    api_path = '/proxy/rules/{ruleId}/status'
        .gsub('{ruleId}', rule_id)

    if rule_id.nil?
      raise Appwrite::Exception.new('Missing required parameter: "ruleId"')
    end

    api_params = {
    }
    
    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::ProxyRule
    )

end