ringcentral-avatars 0.0.1 → 0.1.0
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 -1
- data/README.md +28 -9
- data/lib/ringcentral-avatars.rb +8 -6
- data/lib/ringcentral-avatars/creator.rb +84 -57
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d0de1fd59ec9b1ea838bf6e84407c95945ad7c3a
|
4
|
+
data.tar.gz: b1bc23a2801a87ef5a69b8e88c1afe8b7ac26a9e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7ab6a4431c749a1ddd8b209c5c79dda7b77742b15ae9add3fbe3db4d2eebe68bcdc21e4c8c74bdf2ab055a06f8413bdbd2574546ed91c143fcb30f5a6874109c
|
7
|
+
data.tar.gz: aafb64c078b6484f52bcb3f7ca7fb0872139406814338136fc10cb2349a31771229a19c0e042db7b2d05d4b3535bd44254212255275e9aec43bd42f855bd0b14
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,9 @@
|
|
1
1
|
CHANGELOG
|
2
2
|
---------
|
3
|
-
- **2016-10-22**: 0.0
|
3
|
+
- **2016-10-22**: 0.1.0
|
4
|
+
- Update module name
|
5
|
+
- Update method signatures for options
|
6
|
+
- **2016-10-22**: 0.0.1
|
4
7
|
- Initial release
|
5
8
|
- Add ability to create Gmail-like avatars
|
6
9
|
- Add ability to create defaults-only and optionally overwrite all
|
data/README.md
CHANGED
@@ -7,13 +7,33 @@ RingCentral Avatars
|
|
7
7
|
[![Code Climate][codeclimate-status-svg]][codeclimate-status-link]
|
8
8
|
[![Scrutinizer Code Quality][scrutinizer-status-svg]][scrutinizer-status-link]
|
9
9
|
[![Downloads][downloads-svg]][downloads-link]
|
10
|
-
[![Docs][docs-readthedocs-svg]][docs-readthedocs-link]
|
11
10
|
[![Docs][docs-rubydoc-svg]][docs-rubydoc-link]
|
12
11
|
[![License][license-svg]][license-link]
|
13
12
|
|
14
13
|
## Overview
|
15
14
|
|
16
|
-
This library will build RingCentral avatars using Gmail-like initial avatars. It
|
15
|
+
This library will build RingCentral avatars using Gmail-like initial avatars. It can build Gmail-like avatars for the following:
|
16
|
+
|
17
|
+
* all RingCentral users (extensions) without images
|
18
|
+
* all RingCentral users, overwriting existing images (useful for testing in Sandbox accounts)
|
19
|
+
* specific extensions
|
20
|
+
* authorized user extension only
|
21
|
+
|
22
|
+
The images will look like the following in the RingCentral softphone:
|
23
|
+
|
24
|
+
![](docs/images/ringcentral-avatars-softphone.png)
|
25
|
+
|
26
|
+
## Pre-requisites
|
27
|
+
|
28
|
+
* This library requires ImageMagick
|
29
|
+
* This library requires a RingCentral account
|
30
|
+
* A RingCentral administrator account is necessary to update profile images for others
|
31
|
+
|
32
|
+
## Installation
|
33
|
+
|
34
|
+
```bash
|
35
|
+
$ gem install ringcentral-avatars
|
36
|
+
```
|
17
37
|
|
18
38
|
## Usage
|
19
39
|
|
@@ -23,12 +43,13 @@ require 'ringcentral_sdk'
|
|
23
43
|
|
24
44
|
client = RingCentralSdk.new [...]
|
25
45
|
|
26
|
-
avatars =
|
46
|
+
avatars = RingCentral::Avatars.new client
|
27
47
|
|
28
|
-
avatars.
|
29
|
-
avatars.create_all
|
48
|
+
avatars.create_defaults # create default avatars only
|
49
|
+
avatars.create_all # create all avatars, overwriting existing avatars
|
30
50
|
|
31
|
-
avatars.create_mine
|
51
|
+
avatars.create_mine # does not overwrite user avatar
|
52
|
+
avatars.create_mine overwrite: true # overwrite existing user avatars
|
32
53
|
```
|
33
54
|
|
34
55
|
### Change Log
|
@@ -47,7 +68,7 @@ RingCentral Ruby SDK
|
|
47
68
|
|
48
69
|
RingCentral API Explorer
|
49
70
|
|
50
|
-
*
|
71
|
+
* https://developer.ringcentral.com/api-explorer/latest/index.html
|
51
72
|
|
52
73
|
## Contributing
|
53
74
|
|
@@ -77,8 +98,6 @@ RingCentral Avatars © 2016 by John Wang
|
|
77
98
|
[codeclimate-status-link]: https://codeclimate.com/github/ringcentral-ruby/ringcentral-avatars-ruby
|
78
99
|
[scrutinizer-status-svg]: https://scrutinizer-ci.com/g/ringcentral-ruby/ringcentral-avatars-ruby/badges/quality-score.png?b=master
|
79
100
|
[scrutinizer-status-link]: https://scrutinizer-ci.com/g/ringcentral-ruby/ringcentral-avatars-ruby/?branch=master
|
80
|
-
[docs-readthedocs-svg]: https://img.shields.io/badge/docs-readthedocs-blue.svg
|
81
|
-
[docs-readthedocs-link]: http://ringcentral-avatars-ruby.readthedocs.org/
|
82
101
|
[docs-rubydoc-svg]: https://img.shields.io/badge/docs-rubydoc-blue.svg
|
83
102
|
[docs-rubydoc-link]: http://www.rubydoc.info/gems/ringcentral-avatars/
|
84
103
|
[license-svg]: https://img.shields.io/badge/license-MIT-blue.svg
|
data/lib/ringcentral-avatars.rb
CHANGED
@@ -1,11 +1,13 @@
|
|
1
1
|
require 'ringcentral-avatars/creator'
|
2
2
|
|
3
|
-
module
|
4
|
-
|
3
|
+
module RingCentral
|
4
|
+
module Avatars
|
5
|
+
VERSION = '0.1.0'
|
5
6
|
|
6
|
-
|
7
|
-
|
8
|
-
|
7
|
+
class << self
|
8
|
+
def new(client)
|
9
|
+
RingCentral::Avatars::Creator.new client
|
10
|
+
end
|
9
11
|
end
|
10
12
|
end
|
11
|
-
end
|
13
|
+
end
|
@@ -3,76 +3,103 @@ require 'faraday'
|
|
3
3
|
require 'ringcentral_sdk'
|
4
4
|
require 'tempfile'
|
5
5
|
|
6
|
-
module
|
7
|
-
|
8
|
-
|
6
|
+
module RingCentral
|
7
|
+
module Avatars
|
8
|
+
class Creator
|
9
|
+
DEFAULT_SIZE = 600
|
9
10
|
|
10
|
-
|
11
|
-
|
11
|
+
attr_accessor :client
|
12
|
+
attr_accessor :extensions
|
12
13
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
14
|
+
def initialize(client)
|
15
|
+
@client = client
|
16
|
+
load_extensions
|
17
|
+
end
|
17
18
|
|
18
|
-
|
19
|
-
|
20
|
-
|
19
|
+
##
|
20
|
+
# Convenience method for creating default avatars for all extensions
|
21
|
+
# Defaults to not overwriting existing avatars
|
22
|
+
def create_defaults(opts = {})
|
23
|
+
opts[:overwrite] = false
|
24
|
+
create_all opts
|
21
25
|
end
|
22
|
-
load_extensions
|
23
|
-
end
|
24
26
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
27
|
+
##
|
28
|
+
# Convenience method for creating avatars for all extensions
|
29
|
+
# Defaults to overwriting existing avatar
|
30
|
+
def create_all(opts = {})
|
31
|
+
opts[:overwrite] = true unless opts.key?(:overwrite)
|
32
|
+
@extensions.extensions_hash.each do |ext_id, ext|
|
33
|
+
create_avatar ext, opts
|
34
|
+
end
|
35
|
+
load_extensions
|
36
|
+
end
|
30
37
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
+
##
|
39
|
+
# Convenience method for creating avatar for authorized extension
|
40
|
+
# Defaults to not overwriting existing avatar
|
41
|
+
def create_mine(opts = {})
|
42
|
+
res = @client.http.get 'account/~/extension/~'
|
43
|
+
create_avatar res.body, opts
|
44
|
+
load_extensions
|
45
|
+
end
|
38
46
|
|
39
|
-
|
40
|
-
|
41
|
-
|
47
|
+
##
|
48
|
+
# Create the avatar for the extension.
|
49
|
+
# Defaults to not overwriting existing avatar
|
50
|
+
def create_avatar(ext, opts = {})
|
51
|
+
opts[:overwrite] = false unless opts.key?(:overwrite)
|
52
|
+
return if has_avatar(ext) && !opts[:overwrite]
|
53
|
+
avatar_temp = get_avatar_tmp_file ext
|
54
|
+
url = "account/~/extension/#{ext['id']}/profile-image"
|
55
|
+
image = Faraday::UploadIO.new(avatar_temp.path, 'image/png')
|
56
|
+
@client.http.put url, image: image
|
57
|
+
end
|
42
58
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
avatar_temp
|
50
|
-
end
|
59
|
+
##
|
60
|
+
# Determines if extension has an existing avatar
|
61
|
+
# Checks by looking ofr the presence of the `etag` property
|
62
|
+
def has_avatar(ext)
|
63
|
+
return ext['profileImage'].key?('etag') ? true : false
|
64
|
+
end
|
51
65
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
66
|
+
def get_avatar_tmp_file(ext)
|
67
|
+
avatar_blob = Avatarly.generate_avatar(ext['name'], size: DEFAULT_SIZE)
|
68
|
+
avatar_temp = Tempfile.new(['avatar', '.png'])
|
69
|
+
avatar_temp.binmode
|
70
|
+
avatar_temp.write(avatar_blob)
|
71
|
+
avatar_temp.flush
|
72
|
+
avatar_temp
|
73
|
+
end
|
56
74
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
ext = @extensions.extensions_hash[ext_id]
|
61
|
-
urls.push avatar_url(ext, include_token)
|
75
|
+
def load_extensions
|
76
|
+
@extensions = RingCentralSdk::REST::Cache::Extensions.new client
|
77
|
+
@extensions.retrieve_all
|
62
78
|
end
|
63
|
-
return urls
|
64
|
-
end
|
65
79
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
80
|
+
##
|
81
|
+
# Returns a list of avatar URLs which can be useful for testing purposes
|
82
|
+
# Adding the current access token is optional
|
83
|
+
def avatar_urls(include_token = false)
|
84
|
+
urls = []
|
85
|
+
@extensions.extensions_hash.keys.sort.each do |ext_id|
|
86
|
+
ext = @extensions.extensions_hash[ext_id]
|
87
|
+
urls.push avatar_url(ext, include_token)
|
88
|
+
end
|
89
|
+
return urls
|
90
|
+
end
|
91
|
+
|
92
|
+
def my_avatar_url(include_token = false)
|
93
|
+
res = @client.http.get 'account/~/extension/~'
|
94
|
+
avatar_url(res.body, include_token)
|
95
|
+
end
|
70
96
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
97
|
+
def avatar_url(ext, include_token = false)
|
98
|
+
token = @client.token.to_hash[:access_token]
|
99
|
+
url = ext['profileImage']['uri']
|
100
|
+
url += "?access_token=#{token}" if include_token
|
101
|
+
return url
|
102
|
+
end
|
76
103
|
end
|
77
104
|
end
|
78
105
|
end
|