ringcentral-avatars 0.2.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +8 -3
- data/docs/images/ringcentral-avatars-softphone.png +0 -0
- data/lib/ringcentral-avatars.rb +1 -1
- data/lib/ringcentral-avatars/creator.rb +75 -31
- metadata +40 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: de1d875273729241a28c7c2b88024271c61d68ad
|
4
|
+
data.tar.gz: 5d2fdedfed5cbba6bd7a2d8f3815af22a980feed
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dac1b2e8fed36e6c20678e7c891d1b96de95b3e4c6b8aa563928e80c3d107289a3c253bc147406459d3167d9dde26905b1fab322d7c793b82cba8952bd293078
|
7
|
+
data.tar.gz: 10c8c9bd8cbbd2ac4bd1e150cb988084d23e5829eace6ab46e41d51a411d17eb9a85e512a6b46075c76d358554f99bbf613fc13dfd6c6901da54bc59882c61fb
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -12,7 +12,7 @@ RingCentral Avatars
|
|
12
12
|
|
13
13
|
## Overview
|
14
14
|
|
15
|
-
This library will build RingCentral avatars using Gmail-like
|
15
|
+
This library will build [RingCentral](https://ringcentral.com) avatars using Gmail-like default avatars. It can build Gmail-like avatars for the following:
|
16
16
|
|
17
17
|
* all RingCentral users (extensions) without images
|
18
18
|
* all RingCentral users, overwriting existing images (useful for testing in Sandbox accounts)
|
@@ -25,10 +25,12 @@ By default, the images will look like the following in the RingCentral softphone
|
|
25
25
|
|
26
26
|
This library uses [Avatarly](https://github.com/lucek/avatarly) to generate the avatars and can pass through any avatar option for customization purposes.
|
27
27
|
|
28
|
+
Experimental [Identicon](https://en.wikipedia.org/wiki/Identicon) support is also included via [ruby_identicon](https://github.com/chrisbranson/ruby_identicon). Please see the source for usage until it gets a bit more use.
|
29
|
+
|
28
30
|
## Pre-requisites
|
29
31
|
|
30
32
|
* ImageMagick
|
31
|
-
* A RingCentral account (production or sandbox)
|
33
|
+
* A RingCentral account (production or sandbox) with [REST API access](https://developers.ringcentral.com)
|
32
34
|
* A RingCentral administrator account is necessary to update profile images for others
|
33
35
|
|
34
36
|
Test first in sandbox. Your app needs to be graduated in order to run against your production account.
|
@@ -48,13 +50,16 @@ require 'ringcentral_sdk'
|
|
48
50
|
client = RingCentralSdk.new [...]
|
49
51
|
|
50
52
|
avatars = RingCentral::Avatars.new client # Default options
|
51
|
-
avatars = RingCentral::Avatars.new client, avatar_opts: {font_size:
|
53
|
+
avatars = RingCentral::Avatars.new client, avatar_opts: {font_size: 275} # Avatarly options
|
52
54
|
|
53
55
|
avatars.create_defaults # create default avatars only
|
54
56
|
avatars.create_all # create all avatars, overwriting existing avatars
|
55
57
|
|
56
58
|
avatars.create_mine # does not overwrite existing user avatar
|
57
59
|
avatars.create_mine overwrite: true # overwrite existing user avatar
|
60
|
+
|
61
|
+
avatars.create_avatar ext # create a default for an extension hash
|
62
|
+
avatars.create_avatar ext, overwrite: true # overwrite existing for an extension hash
|
58
63
|
```
|
59
64
|
|
60
65
|
See [Avatarly](https://github.com/lucek/avatarly) for avatar customization options. The default avatar size is `600`.
|
Binary file
|
data/lib/ringcentral-avatars.rb
CHANGED
@@ -2,14 +2,17 @@ require 'avatarly'
|
|
2
2
|
require 'faraday'
|
3
3
|
require 'mime/types'
|
4
4
|
require 'ringcentral_sdk'
|
5
|
+
require 'ruby_identicon'
|
5
6
|
require 'tempfile'
|
6
7
|
|
7
8
|
module RingCentral
|
8
9
|
module Avatars
|
9
10
|
class Creator
|
10
11
|
DEFAULT_SIZE = 600
|
12
|
+
DEFAULT_FORMAT = 'png'
|
11
13
|
|
12
14
|
attr_accessor :avatar_opts
|
15
|
+
attr_accessor :avatars
|
13
16
|
attr_accessor :client
|
14
17
|
attr_accessor :extensions
|
15
18
|
|
@@ -18,19 +21,11 @@ module RingCentral
|
|
18
21
|
# `:avatar_opts` is optional to pass-through options for Avatarly
|
19
22
|
def initialize(client, opts = {})
|
20
23
|
@client = client
|
21
|
-
|
22
|
-
|
23
|
-
end
|
24
|
-
|
25
|
-
def build_avatar_opts(avatar_opts = {})
|
26
|
-
avatar_opts = {} unless avatar_opts.is_a? Hash
|
27
|
-
unless avatar_opts.key? :size
|
28
|
-
avatar_opts[:size] = DEFAULT_SIZE
|
29
|
-
end
|
30
|
-
unless avatar_opts.key? :format
|
31
|
-
avatar_opts[:format] = 'png'
|
24
|
+
if !opts.key?(:initials_opts) && opts.key?(:avatar_opts)
|
25
|
+
opts[:initials_opts] = opts[:avatar_opts]
|
32
26
|
end
|
33
|
-
|
27
|
+
@avatars = RingCentral::Avatars::MultiAvatar.new opts
|
28
|
+
load_extensions
|
34
29
|
end
|
35
30
|
|
36
31
|
##
|
@@ -68,26 +63,16 @@ module RingCentral
|
|
68
63
|
def create_avatar(ext, opts = {})
|
69
64
|
opts[:overwrite] = false unless opts.key?(:overwrite)
|
70
65
|
return if has_avatar(ext) && !opts[:overwrite]
|
71
|
-
avatar_temp = get_avatar_tmp_file ext
|
72
66
|
url = "account/~/extension/#{ext['id']}/profile-image"
|
73
|
-
image =
|
67
|
+
image = @avatars.avatar_faraday_uploadio ext['name']
|
74
68
|
@client.http.put url, image: image
|
75
69
|
end
|
76
70
|
|
77
71
|
##
|
78
72
|
# Determines if extension has an existing avatar
|
79
|
-
# Checks by looking
|
73
|
+
# Checks by looking for the presence of the `etag` property
|
80
74
|
def has_avatar(ext)
|
81
|
-
|
82
|
-
end
|
83
|
-
|
84
|
-
def get_avatar_tmp_file(ext)
|
85
|
-
avatar_blob = Avatarly.generate_avatar(ext['name'], @avatar_opts)
|
86
|
-
avatar_temp = Tempfile.new(['avatar', avatar_extension])
|
87
|
-
avatar_temp.binmode
|
88
|
-
avatar_temp.write(avatar_blob)
|
89
|
-
avatar_temp.flush
|
90
|
-
avatar_temp
|
75
|
+
ext['profileImage'].key?('etag') ? true : false
|
91
76
|
end
|
92
77
|
|
93
78
|
def load_extensions
|
@@ -105,7 +90,7 @@ module RingCentral
|
|
105
90
|
ext = @extensions.extensions_hash[ext_id]
|
106
91
|
urls.push avatar_url(ext, opts)
|
107
92
|
end
|
108
|
-
|
93
|
+
urls
|
109
94
|
end
|
110
95
|
|
111
96
|
def my_avatar_url(opts = {})
|
@@ -119,19 +104,78 @@ module RingCentral
|
|
119
104
|
token = @client.token.to_hash[:access_token]
|
120
105
|
url = ext['profileImage']['uri']
|
121
106
|
url += "?access_token=#{token}" if opts[:include_token]
|
122
|
-
|
107
|
+
url
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
module RingCentral
|
114
|
+
module Avatars
|
115
|
+
class MultiAvatar
|
116
|
+
DEFAULT_STYLE = 'initials'
|
117
|
+
AVATARLY_DEFAULTS = {
|
118
|
+
size: 600,
|
119
|
+
format: 'png'
|
120
|
+
}
|
121
|
+
IDENTICON_DEFAULTS = {
|
122
|
+
grid_size: 5,
|
123
|
+
square_size: 70,
|
124
|
+
background_color: 0xffffffff
|
125
|
+
}
|
126
|
+
IDENTICON_DEFAULT_FORMAT = 'png'
|
127
|
+
|
128
|
+
def initialize(opts = {})
|
129
|
+
@avatarly_opts = inflate_avatarly_opts opts[:initials_opts]
|
130
|
+
@identicon_opts = inflate_identicon_opts opts[:identicon_opts]
|
131
|
+
@style = opts.key?(:style) ? opts[:style] : DEFAULT_STYLE
|
132
|
+
end
|
133
|
+
|
134
|
+
def inflate_avatarly_opts(avatarly_opts = {})
|
135
|
+
avatarly_opts = {} unless avatarly_opts.is_a? Hash
|
136
|
+
AVATARLY_DEFAULTS.merge avatarly_opts
|
137
|
+
end
|
138
|
+
|
139
|
+
def inflate_identicon_opts(identicon_opts = {})
|
140
|
+
identicon_opts = {} unless identicon_opts.is_a? Hash
|
141
|
+
IDENTICON_DEFAULTS.merge identicon_opts
|
142
|
+
end
|
143
|
+
|
144
|
+
def avatar_blob(text, style = nil)
|
145
|
+
style = @style if style.nil?
|
146
|
+
blob = @style == 'initials' \
|
147
|
+
? Avatarly.generate_avatar(text, @avatarly_opts) \
|
148
|
+
: RubyIdenticon.create(text, @identicon_opts)
|
149
|
+
end
|
150
|
+
|
151
|
+
def avatar_temp_file(text, style = nil)
|
152
|
+
blob = avatar_blob text, style
|
153
|
+
file = Tempfile.new ['avatar', avatar_extension]
|
154
|
+
file.binmode
|
155
|
+
file.write blob
|
156
|
+
file.flush
|
157
|
+
file
|
158
|
+
end
|
159
|
+
|
160
|
+
def avatar_faraday_uploadio(text, style = nil)
|
161
|
+
file = avatar_temp_file text, style
|
162
|
+
image = Faraday::UploadIO.new file.path, avatar_mime_type
|
163
|
+
end
|
164
|
+
|
165
|
+
def avatar_format
|
166
|
+
@style == 'initials' ? @avatarly_opts[:format] : IDENTICON_DEFAULT_FORMAT
|
123
167
|
end
|
124
168
|
|
125
169
|
def avatar_mime_type
|
126
|
-
types = MIME::Types.type_for
|
170
|
+
types = MIME::Types.type_for avatar_format
|
127
171
|
if types.length == 0
|
128
|
-
raise "Unknown avatar format: #{
|
172
|
+
raise "Unknown avatar format: #{avatar_format}"
|
129
173
|
end
|
130
|
-
|
174
|
+
types[0].to_s
|
131
175
|
end
|
132
176
|
|
133
177
|
def avatar_extension
|
134
|
-
".#{
|
178
|
+
".#{avatar_format}"
|
135
179
|
end
|
136
180
|
end
|
137
181
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ringcentral-avatars
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Wang
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-11-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: avatarly
|
@@ -91,76 +91,96 @@ dependencies:
|
|
91
91
|
- !ruby/object:Gem::Version
|
92
92
|
version: 1.3.4
|
93
93
|
- !ruby/object:Gem::Dependency
|
94
|
-
name:
|
94
|
+
name: ruby_identicon
|
95
95
|
requirement: !ruby/object:Gem::Requirement
|
96
96
|
requirements:
|
97
|
+
- - "~>"
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0'
|
97
100
|
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: 0.0.5
|
103
|
+
type: :runtime
|
104
|
+
prerelease: false
|
105
|
+
version_requirements: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - "~>"
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
- - ">="
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: 0.0.5
|
113
|
+
- !ruby/object:Gem::Dependency
|
114
|
+
name: coveralls
|
115
|
+
requirement: !ruby/object:Gem::Requirement
|
116
|
+
requirements:
|
117
|
+
- - "~>"
|
98
118
|
- !ruby/object:Gem::Version
|
99
119
|
version: '0'
|
100
120
|
type: :development
|
101
121
|
prerelease: false
|
102
122
|
version_requirements: !ruby/object:Gem::Requirement
|
103
123
|
requirements:
|
104
|
-
- - "
|
124
|
+
- - "~>"
|
105
125
|
- !ruby/object:Gem::Version
|
106
126
|
version: '0'
|
107
127
|
- !ruby/object:Gem::Dependency
|
108
128
|
name: mocha
|
109
129
|
requirement: !ruby/object:Gem::Requirement
|
110
130
|
requirements:
|
111
|
-
- - "
|
131
|
+
- - "~>"
|
112
132
|
- !ruby/object:Gem::Version
|
113
|
-
version: '
|
133
|
+
version: '1'
|
114
134
|
type: :development
|
115
135
|
prerelease: false
|
116
136
|
version_requirements: !ruby/object:Gem::Requirement
|
117
137
|
requirements:
|
118
|
-
- - "
|
138
|
+
- - "~>"
|
119
139
|
- !ruby/object:Gem::Version
|
120
|
-
version: '
|
140
|
+
version: '1'
|
121
141
|
- !ruby/object:Gem::Dependency
|
122
142
|
name: rake
|
123
143
|
requirement: !ruby/object:Gem::Requirement
|
124
144
|
requirements:
|
125
|
-
- - "
|
145
|
+
- - "~>"
|
126
146
|
- !ruby/object:Gem::Version
|
127
|
-
version: '
|
147
|
+
version: '11'
|
128
148
|
type: :development
|
129
149
|
prerelease: false
|
130
150
|
version_requirements: !ruby/object:Gem::Requirement
|
131
151
|
requirements:
|
132
|
-
- - "
|
152
|
+
- - "~>"
|
133
153
|
- !ruby/object:Gem::Version
|
134
|
-
version: '
|
154
|
+
version: '11'
|
135
155
|
- !ruby/object:Gem::Dependency
|
136
156
|
name: simplecov
|
137
157
|
requirement: !ruby/object:Gem::Requirement
|
138
158
|
requirements:
|
139
|
-
- - "
|
159
|
+
- - "~>"
|
140
160
|
- !ruby/object:Gem::Version
|
141
161
|
version: '0'
|
142
162
|
type: :development
|
143
163
|
prerelease: false
|
144
164
|
version_requirements: !ruby/object:Gem::Requirement
|
145
165
|
requirements:
|
146
|
-
- - "
|
166
|
+
- - "~>"
|
147
167
|
- !ruby/object:Gem::Version
|
148
168
|
version: '0'
|
149
169
|
- !ruby/object:Gem::Dependency
|
150
170
|
name: test-unit
|
151
171
|
requirement: !ruby/object:Gem::Requirement
|
152
172
|
requirements:
|
153
|
-
- - "
|
173
|
+
- - "~>"
|
154
174
|
- !ruby/object:Gem::Version
|
155
|
-
version: '
|
175
|
+
version: '3'
|
156
176
|
type: :development
|
157
177
|
prerelease: false
|
158
178
|
version_requirements: !ruby/object:Gem::Requirement
|
159
179
|
requirements:
|
160
|
-
- - "
|
180
|
+
- - "~>"
|
161
181
|
- !ruby/object:Gem::Version
|
162
|
-
version: '
|
163
|
-
description: Create RingCentral
|
182
|
+
version: '3'
|
183
|
+
description: Create RingCentral avatars using Gmail-style avatars
|
164
184
|
email: johncwang@gmail.com
|
165
185
|
executables: []
|
166
186
|
extensions: []
|
@@ -171,6 +191,7 @@ files:
|
|
171
191
|
- LICENSE.md
|
172
192
|
- README.md
|
173
193
|
- Rakefile
|
194
|
+
- docs/images/ringcentral-avatars-softphone.png
|
174
195
|
- lib/ringcentral-avatars.rb
|
175
196
|
- lib/ringcentral-avatars/creator.rb
|
176
197
|
homepage: https://github.com/grokify/
|