Class: Appwrite::Avatars

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

Instance Method Summary collapse

Methods inherited from Service

#initialize

Constructor Details

This class inherits a constructor from Appwrite::Service

Instance Method Details

#get_browser(code:, width: nil, height: nil, quality: nil) ⇒ Object

You can use this endpoint to show different browser icons to your users. The code argument receives the browser code as it appears in your user [GET /account/sessions](/docs/client/account#accountGetSessions) endpoint. Use width, height and quality arguments to change the output settings.

When one dimension is specified and the other is 0, the image is scaled with preserved aspect ratio. If both dimensions are 0, the API provides an image at source quality. If dimensions are not specified, the default size of image returned is 100x100px.

Parameters:

  • code (string)

    Browser Code.

  • width (number) (defaults to: nil)

    Image width. Pass an integer between 0 to 2000. Defaults to 100.

  • height (number) (defaults to: nil)

    Image height. Pass an integer between 0 to 2000. Defaults to 100.

  • quality (number) (defaults to: nil)

    Image quality. Pass an integer between 0 to 100. Defaults to 100.

Returns:



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/avatars.rb', line 23

def get_browser(code:, width: nil, height: nil, quality: nil)
    if code.nil?
        raise Appwrite::Exception.new('Missing required parameter: "code"')
    end

    path = '/avatars/browsers/{code}'
        .gsub('{code}', code)

    params = {
        width: width,
        height: height,
        quality: quality,
    }

    headers = {
        "content-type": 'application/json',
    }

    @client.call(
        method: 'GET',
        path: path,
        headers: headers,
        params: params,
    )
end

#get_credit_card(code:, width: nil, height: nil, quality: nil) ⇒ Object

The credit card endpoint will return you the icon of the credit card provider you need. Use width, height and quality arguments to change the output settings.

When one dimension is specified and the other is 0, the image is scaled with preserved aspect ratio. If both dimensions are 0, the API provides an image at source quality. If dimensions are not specified, the default size of image returned is 100x100px.

Parameters:

  • code (string)

    Credit Card Code. Possible values: amex, argencard, cabal, censosud, diners, discover, elo, hipercard, jcb, mastercard, naranja, targeta-shopping, union-china-pay, visa, mir, maestro.

  • width (number) (defaults to: nil)

    Image width. Pass an integer between 0 to 2000. Defaults to 100.

  • height (number) (defaults to: nil)

    Image height. Pass an integer between 0 to 2000. Defaults to 100.

  • quality (number) (defaults to: nil)

    Image quality. Pass an integer between 0 to 100. Defaults to 100.

Returns:



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

def get_credit_card(code:, width: nil, height: nil, quality: nil)
    if code.nil?
        raise Appwrite::Exception.new('Missing required parameter: "code"')
    end

    path = '/avatars/credit-cards/{code}'
        .gsub('{code}', code)

    params = {
        width: width,
        height: height,
        quality: quality,
    }

    headers = {
        "content-type": 'application/json',
    }

    @client.call(
        method: 'GET',
        path: path,
        headers: headers,
        params: params,
    )
end

#get_favicon(url:) ⇒ Object

Use this endpoint to fetch the favorite icon (AKA favicon) of any remote website URL.

Parameters:

  • url (string)

    Website URL which you want to fetch the favicon from.

Returns:



98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/appwrite/services/avatars.rb', line 98

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

    path = '/avatars/favicon'

    params = {
        url: url,
    }

    headers = {
        "content-type": 'application/json',
    }

    @client.call(
        method: 'GET',
        path: path,
        headers: headers,
        params: params,
    )
end

#get_flag(code:, width: nil, height: nil, quality: nil) ⇒ Object

You can use this endpoint to show different country flags icons to your users. The code argument receives the 2 letter country code. Use width, height and quality arguments to change the output settings.

When one dimension is specified and the other is 0, the image is scaled with preserved aspect ratio. If both dimensions are 0, the API provides an image at source quality. If dimensions are not specified, the default size of image returned is 100x100px.

Parameters:

  • code (string)

    Country Code. ISO Alpha-2 country code format.

  • width (number) (defaults to: nil)

    Image width. Pass an integer between 0 to 2000. Defaults to 100.

  • height (number) (defaults to: nil)

    Image height. Pass an integer between 0 to 2000. Defaults to 100.

  • quality (number) (defaults to: nil)

    Image quality. Pass an integer between 0 to 100. Defaults to 100.

Returns:



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

def get_flag(code:, width: nil, height: nil, quality: nil)
    if code.nil?
        raise Appwrite::Exception.new('Missing required parameter: "code"')
    end

    path = '/avatars/flags/{code}'
        .gsub('{code}', code)

    params = {
        width: width,
        height: height,
        quality: quality,
    }

    headers = {
        "content-type": 'application/json',
    }

    @client.call(
        method: 'GET',
        path: path,
        headers: headers,
        params: params,
    )
end

#get_image(url:, width: nil, height: nil) ⇒ Object

Use this endpoint to fetch a remote image URL and crop it to any image size you want. This endpoint is very useful if you need to crop and display remote images in your app or in case you want to make sure a 3rd party image is properly served using a TLS protocol.

When one dimension is specified and the other is 0, the image is scaled with preserved aspect ratio. If both dimensions are 0, the API provides an image at source quality. If dimensions are not specified, the default size of image returned is 400x400px.

Parameters:

  • url (string)

    Image URL which you want to crop.

  • width (number) (defaults to: nil)

    Resize preview image width, Pass an integer between 0 to 2000. Defaults to 400.

  • height (number) (defaults to: nil)

    Resize preview image height, Pass an integer between 0 to 2000. Defaults to 400.

Returns:



179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
# File 'lib/appwrite/services/avatars.rb', line 179

def get_image(url:, width: nil, height: nil)
    if url.nil?
        raise Appwrite::Exception.new('Missing required parameter: "url"')
    end

    path = '/avatars/image'

    params = {
        url: url,
        width: width,
        height: height,
    }

    headers = {
        "content-type": 'application/json',
    }

    @client.call(
        method: 'GET',
        path: path,
        headers: headers,
        params: params,
    )
end

#get_initials(name: nil, width: nil, height: nil, color: nil, background: nil) ⇒ Object

Use this endpoint to show your user initials avatar icon on your website or app. By default, this route will try to print your logged-in user name or email initials. You can also overwrite the user name if you pass the ‘name’ parameter. If no name is given and no user is logged, an empty avatar will be returned.

You can use the color and background params to change the avatar colors. By default, a random theme will be selected. The random theme will persist for the user’s initials when reloading the same theme will always return for the same initials.

When one dimension is specified and the other is 0, the image is scaled with preserved aspect ratio. If both dimensions are 0, the API provides an image at source quality. If dimensions are not specified, the default size of image returned is 100x100px.

Parameters:

  • name (string) (defaults to: nil)

    Full Name. When empty, current user name or email will be used. Max length: 128 chars.

  • width (number) (defaults to: nil)

    Image width. Pass an integer between 0 to 2000. Defaults to 100.

  • height (number) (defaults to: nil)

    Image height. Pass an integer between 0 to 2000. Defaults to 100.

  • color (string) (defaults to: nil)

    Changes text color. By default a random color will be picked and stay will persistent to the given name.

  • background (string) (defaults to: nil)

    Changes background color. By default a random color will be picked and stay will persistent to the given name.

Returns:



228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
# File 'lib/appwrite/services/avatars.rb', line 228

def get_initials(name: nil, width: nil, height: nil, color: nil, background: nil)
    path = '/avatars/initials'

    params = {
        name: name,
        width: width,
        height: height,
        color: color,
        background: background,
    }

    headers = {
        "content-type": 'application/json',
    }

    @client.call(
        method: 'GET',
        path: path,
        headers: headers,
        params: params,
    )
end

#get_qr(text:, size: nil, margin: nil, download: nil) ⇒ Object

Converts a given plain text to a QR code image. You can use the query parameters to change the size and style of the resulting image.

Parameters:

  • text (string)

    Plain text to be converted to QR code image.

  • size (number) (defaults to: nil)

    QR code size. Pass an integer between 1 to 1000. Defaults to 400.

  • margin (number) (defaults to: nil)

    Margin from edge. Pass an integer between 0 to 10. Defaults to 1.

  • download (boolean) (defaults to: nil)

    Return resulting image with 'Content-Disposition: attachment ' headers for the browser to start downloading it. Pass 0 for no header, or 1 for otherwise. Default value is set to 0.

Returns:



261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
# File 'lib/appwrite/services/avatars.rb', line 261

def get_qr(text:, size: nil, margin: nil, download: nil)
    if text.nil?
        raise Appwrite::Exception.new('Missing required parameter: "text"')
    end

    path = '/avatars/qr'

    params = {
        text: text,
        size: size,
        margin: margin,
        download: download,
    }

    headers = {
        "content-type": 'application/json',
    }

    @client.call(
        method: 'GET',
        path: path,
        headers: headers,
        params: params,
    )
end