ringcentral-avatars 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d0de1fd59ec9b1ea838bf6e84407c95945ad7c3a
4
- data.tar.gz: b1bc23a2801a87ef5a69b8e88c1afe8b7ac26a9e
3
+ metadata.gz: 6ddb51ed74a787bcf1d66710f68078c96b8ed57f
4
+ data.tar.gz: 9632d38f8214ceb65d443571e74d7ad784a125f6
5
5
  SHA512:
6
- metadata.gz: 7ab6a4431c749a1ddd8b209c5c79dda7b77742b15ae9add3fbe3db4d2eebe68bcdc21e4c8c74bdf2ab055a06f8413bdbd2574546ed91c143fcb30f5a6874109c
7
- data.tar.gz: aafb64c078b6484f52bcb3f7ca7fb0872139406814338136fc10cb2349a31771229a19c0e042db7b2d05d4b3535bd44254212255275e9aec43bd42f855bd0b14
6
+ metadata.gz: d3389e05df79a6c3b8618fec0be7b55c3005147c1f9543181faa7e5939bc5f096a903d98484cca2a841be7adab0598b227c23c94b365e06a03b7e166bbd38186
7
+ data.tar.gz: d924730e79e29bb6e71a14f7cbf99cc25ba69c36bcb9413b047f3da49ac808cf08395e197e65ff563be747eb8ae745ad74b56410b86d9b5eeb08465087465855
data/CHANGELOG.md CHANGED
@@ -1,6 +1,9 @@
1
1
  CHANGELOG
2
2
  ---------
3
- - **2016-10-22**: 0.1.0
3
+ - **2016-10-23**: 0.2.0
4
+ - Add avatar customization options
5
+ - Update avatar URLs method signature for options
6
+ - **2016-10-23**: 0.1.0
4
7
  - Update module name
5
8
  - Update method signatures for options
6
9
  - **2016-10-22**: 0.0.1
data/README.md CHANGED
@@ -19,16 +19,20 @@ This library will build RingCentral avatars using Gmail-like initial avatars. It
19
19
  * specific extensions
20
20
  * authorized user extension only
21
21
 
22
- The images will look like the following in the RingCentral softphone:
22
+ By default, the images will look like the following in the RingCentral softphone:
23
23
 
24
24
  ![](docs/images/ringcentral-avatars-softphone.png)
25
25
 
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
+
26
28
  ## Pre-requisites
27
29
 
28
- * This library requires ImageMagick
29
- * This library requires a RingCentral account
30
+ * ImageMagick
31
+ * A RingCentral account (production or sandbox)
30
32
  * A RingCentral administrator account is necessary to update profile images for others
31
33
 
34
+ Test first in sandbox. Your app needs to be graduated in order to run against your production account.
35
+
32
36
  ## Installation
33
37
 
34
38
  ```bash
@@ -43,15 +47,18 @@ require 'ringcentral_sdk'
43
47
 
44
48
  client = RingCentralSdk.new [...]
45
49
 
46
- avatars = RingCentral::Avatars.new client
50
+ avatars = RingCentral::Avatars.new client # Default options
51
+ avatars = RingCentral::Avatars.new client, avatar_opts: {font_size: 250} # Avatarly options
47
52
 
48
53
  avatars.create_defaults # create default avatars only
49
54
  avatars.create_all # create all avatars, overwriting existing avatars
50
55
 
51
- avatars.create_mine # does not overwrite user avatar
52
- avatars.create_mine overwrite: true # overwrite existing user avatars
56
+ avatars.create_mine # does not overwrite existing user avatar
57
+ avatars.create_mine overwrite: true # overwrite existing user avatar
53
58
  ```
54
59
 
60
+ See [Avatarly](https://github.com/lucek/avatarly) for avatar customization options. The default avatar size is `600`.
61
+
55
62
  ### Change Log
56
63
 
57
64
  See [CHANGELOG.md](CHANGELOG.md)
@@ -2,11 +2,11 @@ require 'ringcentral-avatars/creator'
2
2
 
3
3
  module RingCentral
4
4
  module Avatars
5
- VERSION = '0.1.0'
5
+ VERSION = '0.2.0'
6
6
 
7
7
  class << self
8
- def new(client)
9
- RingCentral::Avatars::Creator.new client
8
+ def new(client, opts = {})
9
+ RingCentral::Avatars::Creator.new client, opts
10
10
  end
11
11
  end
12
12
  end
@@ -1,5 +1,6 @@
1
1
  require 'avatarly'
2
2
  require 'faraday'
3
+ require 'mime/types'
3
4
  require 'ringcentral_sdk'
4
5
  require 'tempfile'
5
6
 
@@ -8,14 +9,30 @@ module RingCentral
8
9
  class Creator
9
10
  DEFAULT_SIZE = 600
10
11
 
12
+ attr_accessor :avatar_opts
11
13
  attr_accessor :client
12
14
  attr_accessor :extensions
13
15
 
14
- def initialize(client)
16
+ ##
17
+ # Requires RingCentralSdk instance
18
+ # `:avatar_opts` is optional to pass-through options for Avatarly
19
+ def initialize(client, opts = {})
15
20
  @client = client
21
+ @avatar_opts = build_avatar_opts opts[:avatar_opts]
16
22
  load_extensions
17
23
  end
18
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'
32
+ end
33
+ return avatar_opts
34
+ end
35
+
19
36
  ##
20
37
  # Convenience method for creating default avatars for all extensions
21
38
  # Defaults to not overwriting existing avatars
@@ -39,9 +56,10 @@ module RingCentral
39
56
  # Convenience method for creating avatar for authorized extension
40
57
  # Defaults to not overwriting existing avatar
41
58
  def create_mine(opts = {})
42
- res = @client.http.get 'account/~/extension/~'
43
- create_avatar res.body, opts
59
+ res_ext = @client.http.get 'account/~/extension/~'
60
+ res_av = create_avatar res_ext.body, opts
44
61
  load_extensions
62
+ res_av
45
63
  end
46
64
 
47
65
  ##
@@ -52,7 +70,7 @@ module RingCentral
52
70
  return if has_avatar(ext) && !opts[:overwrite]
53
71
  avatar_temp = get_avatar_tmp_file ext
54
72
  url = "account/~/extension/#{ext['id']}/profile-image"
55
- image = Faraday::UploadIO.new(avatar_temp.path, 'image/png')
73
+ image = Faraday::UploadIO.new avatar_temp.path, avatar_mime_type
56
74
  @client.http.put url, image: image
57
75
  end
58
76
 
@@ -64,8 +82,8 @@ module RingCentral
64
82
  end
65
83
 
66
84
  def get_avatar_tmp_file(ext)
67
- avatar_blob = Avatarly.generate_avatar(ext['name'], size: DEFAULT_SIZE)
68
- avatar_temp = Tempfile.new(['avatar', '.png'])
85
+ avatar_blob = Avatarly.generate_avatar(ext['name'], @avatar_opts)
86
+ avatar_temp = Tempfile.new(['avatar', avatar_extension])
69
87
  avatar_temp.binmode
70
88
  avatar_temp.write(avatar_blob)
71
89
  avatar_temp.flush
@@ -80,26 +98,41 @@ module RingCentral
80
98
  ##
81
99
  # Returns a list of avatar URLs which can be useful for testing purposes
82
100
  # Adding the current access token is optional
83
- def avatar_urls(include_token = false)
101
+ def avatar_urls(opts = {})
102
+ opts[:include_token] = false unless opts.key? :include_token
84
103
  urls = []
85
104
  @extensions.extensions_hash.keys.sort.each do |ext_id|
86
105
  ext = @extensions.extensions_hash[ext_id]
87
- urls.push avatar_url(ext, include_token)
106
+ urls.push avatar_url(ext, opts)
88
107
  end
89
108
  return urls
90
109
  end
91
110
 
92
- def my_avatar_url(include_token = false)
111
+ def my_avatar_url(opts = {})
112
+ opts[:include_token] = false unless opts.key? :include_token
93
113
  res = @client.http.get 'account/~/extension/~'
94
- avatar_url(res.body, include_token)
114
+ avatar_url(res.body, opts)
95
115
  end
96
116
 
97
- def avatar_url(ext, include_token = false)
117
+ def avatar_url(ext, opts = {})
118
+ opts[:include_token] = false unless opts.key? :include_token
98
119
  token = @client.token.to_hash[:access_token]
99
120
  url = ext['profileImage']['uri']
100
- url += "?access_token=#{token}" if include_token
121
+ url += "?access_token=#{token}" if opts[:include_token]
101
122
  return url
102
123
  end
124
+
125
+ def avatar_mime_type
126
+ types = MIME::Types.type_for @avatar_opts[:format]
127
+ if types.length == 0
128
+ raise "Unknown avatar format: #{@avatar_opts[:format]}"
129
+ end
130
+ return types[0].to_s
131
+ end
132
+
133
+ def avatar_extension
134
+ ".#{@avatar_opts[:format]}"
135
+ end
103
136
  end
104
137
  end
105
138
  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.1.0
4
+ version: 0.2.0
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-10-22 00:00:00.000000000 Z
11
+ date: 2016-10-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: avatarly
@@ -50,6 +50,26 @@ dependencies:
50
50
  - - ">="
51
51
  - !ruby/object:Gem::Version
52
52
  version: '0.9'
53
+ - !ruby/object:Gem::Dependency
54
+ name: mime-types
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - "~>"
58
+ - !ruby/object:Gem::Version
59
+ version: '3.0'
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: '3.1'
63
+ type: :runtime
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '3.0'
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: '3.1'
53
73
  - !ruby/object:Gem::Dependency
54
74
  name: ringcentral_sdk
55
75
  requirement: !ruby/object:Gem::Requirement