class RingCentral::Avatars::Creator
Constants
- DEFAULT_FORMAT
- DEFAULT_SIZE
- PNG_DEFAULT_METADATA
Attributes
avatar_opts[RW]
avatars[RW]
client[RW]
extensions[RW]
png_metadata[RW]
retry[RW]
Public Class Methods
new(client, opts = {})
click to toggle source
Requires RingCentralSdk instance `:avatar_opts` is optional to pass-through options for Avatarly
# File lib/ringcentral-avatars/creator.rb, line 31 def initialize(client, opts = {}) @client = client if !opts.key?(:initials_opts) && opts.key?(:avatar_opts) opts[:initials_opts] = opts[:avatar_opts] end if opts.key? :png_metadata opts[:png_metadata] = PNG_DEFAULT_METADATA.merge(opts[:png_metadata]) else opts[:png_metadata] = PNG_DEFAULT_METADATA end opts[:logger] = @client.config.logger @retry = opts.key?(:retry) && opts[:retry] ? true : false opts[:retry] = @retry @avatars = RingCentral::Avatars::MultiAvatar.new opts @retry_util = FaradayMiddleware::Request::RetryUtil.new logger: client.config.logger load_extensions end
Public Instance Methods
avatar?(ext)
click to toggle source
Determines if extension has an existing avatar Checks by looking for the presence of the `etag` property
# File lib/ringcentral-avatars/creator.rb, line 108 def avatar?(ext) ext['profileImage'].key?('etag') ? true : false end
avatar_url(ext, opts = {})
click to toggle source
# File lib/ringcentral-avatars/creator.rb, line 136 def avatar_url(ext, opts = {}) opts[:include_token] = false unless opts.key? :include_token token = @client.token.to_hash[:access_token] url = ext['profileImage']['uri'] url += "?access_token=#{token}" if opts[:include_token] url end
avatar_urls(opts = {})
click to toggle source
Returns a list of avatar URLs which can be useful for testing purposes Adding the current access token is optional
# File lib/ringcentral-avatars/creator.rb, line 120 def avatar_urls(opts = {}) opts[:include_token] = false unless opts.key? :include_token urls = [] @extensions.extensions_hash.keys.sort.each do |ext_id| ext = @extensions.extensions_hash[ext_id] urls.push avatar_url(ext, opts) end urls end
create_all(opts = {})
click to toggle source
Convenience method for creating avatars for all extensions Defaults to overwriting existing avatar
# File lib/ringcentral-avatars/creator.rb, line 60 def create_all(opts = {}) opts[:overwrite] = true unless opts.key?(:overwrite) @extensions.extensions_hash.each do |_ext_id, ext| create_avatar ext, opts end load_extensions end
create_avatar(ext, opts = {})
click to toggle source
Create the avatar for the extension. Defaults to not overwriting existing avatar
# File lib/ringcentral-avatars/creator.rb, line 84 def create_avatar(ext, opts = {}) opts[:overwrite] = false unless opts.key?(:overwrite) if avatar?(ext) && !opts[:overwrite] return nil end url = "account/~/extension/#{ext['id']}/profile-image" res_avt = nil try_req = true while try_req image = @avatars.avatar_faraday_uploadio ext['name'] res_avt = @client.http.put url, image: image try_req = retry_status res_avt end res_avt end
create_defaults(opts = {})
click to toggle source
Convenience method for creating default avatars for all extensions Defaults to not overwriting existing avatars
# File lib/ringcentral-avatars/creator.rb, line 52 def create_defaults(opts = {}) opts[:overwrite] = false create_all opts end
create_mine(opts = {})
click to toggle source
Convenience method for creating avatar for authorized extension Defaults to not overwriting existing avatar
# File lib/ringcentral-avatars/creator.rb, line 71 def create_mine(opts = {}) try_req = true while try_req res_ext = @client.http.get 'account/~/extension/~' try_req = retry_status res_ext end res_avt = create_avatar res_ext.body, opts res_avt end
load_extensions()
click to toggle source
# File lib/ringcentral-avatars/creator.rb, line 112 def load_extensions @extensions = RingCentralSdk::REST::Cache::Extensions.new client @extensions.retrieve_all end
my_avatar_url(opts = {})
click to toggle source
# File lib/ringcentral-avatars/creator.rb, line 130 def my_avatar_url(opts = {}) opts[:include_token] = false unless opts.key? :include_token res = @client.http.get 'account/~/extension/~' avatar_url(res.body, opts) end
retry_status(res)
click to toggle source
# File lib/ringcentral-avatars/creator.rb, line 100 def retry_status(res) return false unless @retry @retry_util.retry_status(res.status, res.headers['Retry-After']) end