five9 0.0.13 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ ZjFjY2M4ZWE2YTBiMTU5YzFhYWFmMTQ4MDY4NTE3YTcyN2YyNzIzMw==
5
+ data.tar.gz: !binary |-
6
+ ZmE5ZGQ2ODc2ZmIwOGYyYmI2ZjI4MzVlMWIzMDRmOWFjOWZhYWY0NA==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ MmU0MmFlMzVlNmUyYWQxYjQxN2Q5YjU1ZjNmZDg1MDdkMDU4NzIyYjM0YWM4
10
+ ZmZkZDI0ZWFhZGI1MTcxN2Q3MDQ3MjgzYWU5ZDg2MDZiZDJiZWY4OGZjMzQ2
11
+ YWY2Y2M4YTUwNmI5MTk4ODBhOTU1NDUwMWI5NTg2YWYwZDYyMzI=
12
+ data.tar.gz: !binary |-
13
+ NTMzMzRhMzQwZTU0MDJiNDM2MDExZjMyOTdmOTg4MzRkNWI2MjczMjQ3ZDNk
14
+ OTc5NjljODFkNWE4OTExOGMyMmIwOWY3NDM3YzQzZmJiODY3YjA2NzRhMzkw
15
+ Y2U2YTE4MjQ1MmY1ZDQwMGMxYzNlNmZiMTA2M2MxY2EzZmQwOTI=
@@ -11,10 +11,11 @@ Gem::Specification.new do |gem|
11
11
  gem.description = %q{Rubygem integration with five9 API}
12
12
  gem.summary = %q{Write a gem summary}
13
13
  gem.homepage = "https://github.com/CTA/five9"
14
-
14
+ gem.license = "MIT"
15
15
  gem.files = `git ls-files`.split($/)
16
16
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
17
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
18
  gem.require_paths = ["lib"]
19
19
  gem.add_dependency('savon', '~> 2.2.0')
20
+ gem.add_dependency('accessible_hash')
20
21
  end
@@ -1,3 +1,4 @@
1
+ require "accessible_hash"
1
2
  require "five9/version"
2
3
  require "five9/base"
3
4
  require "five9/user_management"
@@ -5,7 +6,9 @@ require "five9/statistics"
5
6
  require "five9/agent_stats.rb"
6
7
  require "five9/inbound_campaign_stats.rb"
7
8
  require "five9/acd_status.rb"
8
-
9
+ require "five9/user_management.rb"
10
+ require "five9/user.rb"
11
+ require "five9/user_resources/skill_array.rb"
9
12
 
10
13
  module Five9
11
14
  end
@@ -7,7 +7,8 @@ module Five9
7
7
  @client = Savon.client do
8
8
  wsdl "#{given_wsdl}#{username}"
9
9
  basic_auth [username, password]
10
- end
11
- end
12
- end
10
+ log false
11
+ end
12
+ end
13
+ end
13
14
  end
@@ -0,0 +1,82 @@
1
+ module Five9
2
+ class User
3
+ attr_reader :general_info, :roles, :skills
4
+ def initialize(args)
5
+ @user_info = args.make_accessible
6
+ @general_info = @user_info[:general_info].make_accessible
7
+ @roles = @user_info[:roles].make_accessible
8
+ @skills = SkillArray.new(args[:skills])
9
+ end
10
+
11
+ def to_h
12
+ @user_info[:general_info] = @general_info
13
+ @user_info[:roles] = @roles
14
+ @user_info[:skills] = @skills.to_a
15
+ @user_info
16
+ end
17
+
18
+ def save
19
+ UserManagement.modify_user(build_modify_hash)
20
+ @skills.update!
21
+ self
22
+ end
23
+
24
+ def delete!
25
+ UserManagement.delete_user user_name
26
+ end
27
+
28
+ def update(args)
29
+ if args[:general_info]
30
+ @user_info = to_h.merge(args)
31
+ @general_info = @user_info[:general_info].make_accessible
32
+ @roles = @user_info[:roles].make_accessible
33
+ @skills = SkillArray.new(args[:skills])
34
+ @user_info
35
+ else
36
+ merge! args
37
+ end
38
+ end
39
+
40
+ def update!(args)
41
+ update args
42
+ save
43
+ end
44
+
45
+ def method_missing(method_name, *args)
46
+ @general_info.send(method_name, *args)
47
+ end
48
+
49
+ def self.exist?(username)
50
+ not UserManagement.get_users_info(username)[:general_info].nil?
51
+ end
52
+
53
+ def self.create!(args)
54
+ new UserManagement.create_user(args)
55
+ end
56
+
57
+ def self.find(username)
58
+ new(UserManagement.get_users_info(username)) if exist?(username)
59
+ end
60
+
61
+ def self.all
62
+ UserManagement.get_users_info.map do |user_info|
63
+ new(user_info)
64
+ end
65
+ end
66
+
67
+ def self.where(args)
68
+ all.keep_if do |user|
69
+ user.merge(args).to_hash == user.to_hash
70
+ end
71
+ end
72
+
73
+ private
74
+ def build_modify_hash
75
+ result = {}
76
+ @general_info["EMail"] ||= @general_info.e_mail
77
+ result[:userGeneralInfo] = @general_info.to_hash
78
+ result
79
+ # TODO configure rolesToSet and rolesToRemove
80
+ end
81
+ end
82
+ end
@@ -1,128 +1,101 @@
1
1
  module Five9
2
- class UserManagement < Base
3
- # This class is essentially a cut-paste of the User Management methods
4
- # from the Five9 API. Arguments to the methods should be hashes of the
5
- # data values required in the API, unless otherwise specified.
6
-
7
- def initialize(adminuser, password)
8
- # arguments should be strings
9
- super(adminuser, password,
10
- "https://api.five9.com/wsadmin/v2/AdminWebService?wsdl&user=")
11
- end
2
+ module UserManagement
3
+ class << self
4
+ def establish_connection adminuser, password
5
+ @client = Base.new(adminuser, password,
6
+ "https://api.five9.com/wsadmin/v2/AdminWebService?wsdl&user=")
7
+ .instance_variable_get :@client
8
+ @connected = true
9
+ end
12
10
 
13
- def create_user(args = {})
14
- # Use this method to create a user.
15
- # An exception is thrown if the user already exists, if the limit number of users is reached, or if user attributes are invalid.
16
- begin
17
- @client.call :create_user, message: args
18
- rescue => error
19
- puts error.to_s.inspect
20
- return false
11
+ def connected?
12
+ @connected
21
13
  end
22
- end
23
14
 
24
- def delete_user(username)
25
- # Use this method to delete the specified user.
26
- # An exception is thrown if the user does not exist.
27
- # username is a string
28
- begin
29
- @client.call :delete_user, message: { user_name: username }
30
- rescue => error
31
- puts error.to_s.inspect
32
- return false
15
+ def create_user user_info = {}
16
+ validate_connection do
17
+ response = @client.call :create_user, { message: {
18
+ userInfo: user_info } }
19
+ process_return_hash response, :create_user_response
20
+ end
33
21
  end
34
- end
35
22
 
36
- def get_users_general_info(username_pattern = nil)
37
- # Use this method to obtain general information about each user name that matches a pattern.
38
- # username_pattern should be a regular expression.
39
- # If omitted or equal to an empty string, all objects are returned.
40
- # For example, a pattern may be the first characters of the user name.
41
- begin
42
- @client.call :get_users_general_info, message: { userNamePattern: username_pattern }
43
- rescue => error
44
- puts error.to_s.inspect
45
- return false
23
+ def delete_user username
24
+ validate_connection do
25
+ response = @client.call :delete_user, message: { user_name: username }
26
+ process_return_hash response, :delete_user_response
27
+ end
46
28
  end
47
- end
48
29
 
49
- def get_users_info(username_pattern = nil)
50
- # Use this method to obtain information about roles and skills
51
- # in addition to general information for the user,
52
- # for each user name that matches a pattern.
53
- # username_pattern should be a regular expression
54
- begin
55
- @client.call :get_users_info, message: { userNamePattern: username_pattern }
56
- rescue => error
57
- puts error.to_s.inspect
58
- return false
30
+ def get_users_general_info username_pattern = nil
31
+ validate_connection do
32
+ response = @client.call :get_users_general_info,
33
+ message: { userNamePattern: username_pattern }
34
+ process_return_hash response, :get_users_general_info_response
35
+ end
59
36
  end
60
- end
61
37
 
62
- def modify_user(args = {})
63
- # Use this method to modify user attributes
64
- # args may include userGeneralInfo, rolesToSet, and rolesToRemove
65
- begin
66
- @client.call :modify_user, message: args
67
- rescue => error
68
- puts error.to_s.inspect
69
- return false
38
+ def get_users_info username_pattern = nil
39
+ validate_connection do
40
+ response = @client.call :get_users_info,
41
+ message: { userNamePattern: username_pattern }
42
+ process_return_hash response, :get_users_info_response
43
+ end
70
44
  end
71
- end
72
45
 
73
- def modify_user_canned_reports(args = {})
74
- # Use this method to modify the list of canned reports associated with a specific user.
75
- # args may incldue user, cannedReportsToAdd, and cannedReportsToRemove
76
- begin
77
- @client.call :modify_user_canned_reports, message: args
78
- rescue => error
79
- puts error.to_s.inspect
80
- return false
46
+ def modify_user args
47
+ validate_connection do
48
+ response = @client.call :modify_user, message: args
49
+ process_return_hash response, :modify_user_response
50
+ end
81
51
  end
82
- end
83
52
 
84
- def add_user_skill(user_skill)
85
- # user_skill is a userSkill hash
86
- affect_user_skill(:user_skill_add, user_skill)
87
- # begin
88
- # @client.call :userSkillAdd, message: { userSkill: user_skill }
89
- # rescue => error
90
- # puts error.to_s.inspect
91
- # return false
92
- # end
93
- end
53
+ def user_skill_add skill
54
+ validate_connection do
55
+ response = @client.call :user_skill_add, message: skill
56
+ process_return_hash response, :user_skill_add_response
57
+ end
58
+ end
94
59
 
95
- def modify_user_skill(user_skill)
96
- # user_skill is a userSkill hash
97
- affect_user_skill(:user_skill_modify, user_skill)
98
- # begin
99
- # @client.call :userSkillModify, message: { userSkill: user_skill }
100
- # rescue => error
101
- # puts error.to_s.inspect
102
- # return false
103
- # end
104
- end
60
+ def user_skill_modify skill
61
+ validate_connection do
62
+ response = @client.call :user_skill_modify, message: skill
63
+ process_return_hash response, :user_skill_modify_response
64
+ end
65
+ end
105
66
 
106
- def remove_user_skill(user_skill)
107
- # user_skill is a userSkill hash
108
- affect_user_skill(:user_skill_remove, user_skill)
109
- # begin
110
- # @client.call :userSkillRemove, message: { userSkill: user_skill }
111
- # rescue => error
112
- # puts error.to_s.inspect
113
- # return false
114
- # end
115
- end
67
+ def user_skill_remove skill
68
+ validate_connection do
69
+ response = @client.call :user_skill_remove, message: skill
70
+ process_return_hash response, :user_skill_remove_response
71
+ end
72
+ end
116
73
 
117
- private
74
+ private
75
+ def process_return_hash response, method_response_key
76
+ response_hash = response.to_hash
77
+ if response_hash[method_response_key].class == Hash
78
+ unless response_hash[method_response_key][:return].class == NilClass
79
+ return response_hash[method_response_key][:return]
80
+ else
81
+ return response_hash[method_response_key]
82
+ end
83
+ else
84
+ return response_hash
85
+ end
86
+ end
118
87
 
119
- def affect_user_skill(affect, user_skill)
120
- begin
121
- @client.call affect, message: { userSkill: user_skill }
122
- rescue => error
123
- puts error.to_s.inspect
124
- return false
88
+ def validate_connection &block
89
+ if @connected
90
+ begin
91
+ block.call if block
92
+ rescue Wasabi::Resolver::HTTPError
93
+ raise "Something went wrong! Please insure the connection is established with the proper credentials."
94
+ end
95
+ else
96
+ raise "Connection to Five9 not established!"
97
+ end
125
98
  end
126
- end
127
- end
128
- end
99
+ end
100
+ end
101
+ end
@@ -0,0 +1,40 @@
1
+ module Five9
2
+ class Profile
3
+ attr_reader :attributes
4
+ def initialize(args)
5
+ @attributes = AccessibleHash.new(args)
6
+ end
7
+
8
+ def save
9
+ ProfileManagement.modify_user_profile(self.to_h)
10
+ end
11
+ alias_method :update!, :save
12
+
13
+ def method_missing(method_name, *args)
14
+ @attributes.send(method_name, *args)
15
+ end
16
+
17
+ def self.create!(args)
18
+ self.new(ProfileManagement.create_user_profile(args))
19
+ end
20
+
21
+ def self.find(profile_name)
22
+ self.new(matching_profile(all, profile_name))
23
+ end
24
+
25
+ def self.all
26
+ ProfileManagement.get_user_profiles.map do |profile_info|
27
+ self.new(profile_info)
28
+ end
29
+ end
30
+
31
+ private
32
+ def self.matching_profile(all_profiles, profile_name)
33
+ matching_profile = all_profiles.select do |profile|
34
+ profile[:name] == profile_name
35
+ end
36
+ raise "No matching profiles were found!" if matching_profile.first.nil?
37
+ matching_profile.first
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,100 @@
1
+ module Five9
2
+ module ProfileManagement
3
+ class << self
4
+ def establish_connection adminuser, password
5
+ @client = Base.new(adminuser, password,
6
+ "https://api.five9.com/wsadmin/v2/AdminWebService?wsdl&user=")
7
+ .instance_variable_get :@client
8
+ @connected = true
9
+ end
10
+
11
+ def connected?
12
+ @connected
13
+ end
14
+
15
+ def create_user_profile args
16
+ validate_connection do
17
+ response = @client.call :create_user_profile,
18
+ message: { userProfile: args }
19
+ process_return_hash response, :create_user_profile_response
20
+ end
21
+ end
22
+
23
+ def get_user_profile profile_name
24
+ validate_connection do
25
+ response = @client.call :get_user_profiles,
26
+ message: { userProfileName: profile_name }
27
+ process_return_hash response, :get_user_profiles_response
28
+ end
29
+ end
30
+
31
+ def get_user_profiles profile_name = nil
32
+ validate_connection do
33
+ response = @client.call :get_user_profiles,
34
+ message: { userProfileNamePattern: profile_name }
35
+ process_return_hash response, :get_user_profiles_response
36
+ end
37
+ end
38
+
39
+ def delete_user_profile profile_name
40
+ validate_connection do
41
+ response = @client.call :delete_user_profile,
42
+ message: { userProfileName: profile_name }
43
+ process_return_hash response, :delete_user_profile_response
44
+ end
45
+ end
46
+
47
+ def modify_user_profile profile_info
48
+ validate_connection do
49
+ response = @client.call :modify_user_profile,
50
+ message: { userProfile: profile_info }
51
+ process_return_hash response, :modify_user_profile_response
52
+ end
53
+ end
54
+
55
+ def modify_user_profile_skills profile_name, skills_to_add=nil, skills_to_remove=nil
56
+ validate_connection do
57
+ response = @client.call :modify_user_profile_skills,
58
+ message: { userProfileName: profile_name,
59
+ addSkills: skills_to_add, removeSkills: skills_to_remove }
60
+ process_return_hash response, :modify_user_profile_skills_response
61
+ end
62
+ end
63
+
64
+ def modify_user_profile_user_list profile_name, users_to_add=nil, users_to_remove=nil
65
+ validate_connection do
66
+ response = @client.call :modify_user_profile_user_list,
67
+ message: { userProfileName: profile_name,
68
+ addUsers: users_to_add, removeUsers: users_to_remove }
69
+ process_return_hash response, :modify_user_profile_user_list_response
70
+ end
71
+ end
72
+
73
+ private
74
+ def validate_connection &block
75
+ if @connected
76
+ begin
77
+ block.call if block
78
+ rescue Wasabi::Resolver::HTTPError
79
+ raise "Something went wrong! Please insure the connection is established with the proper credentials."
80
+ end
81
+ else
82
+ raise "Connection to Five9 not established!"
83
+ end
84
+ end
85
+
86
+ def process_return_hash response, method_response_key
87
+ response_hash = response.to_hash
88
+ if response_hash[method_response_key].class == Hash
89
+ unless response_hash[method_response_key][:return].class == NilClass
90
+ return response_hash[method_response_key][:return]
91
+ else
92
+ return response_hash[method_response_key]
93
+ end
94
+ else
95
+ return response_hash
96
+ end
97
+ end
98
+ end
99
+ end
100
+ end
@@ -0,0 +1,58 @@
1
+ module Five9
2
+ class SkillArray
3
+ attr_accessor :skills
4
+ def initialize(args)
5
+ @skills = []
6
+ set_initial_skills(args)
7
+ @old_skills = @skills
8
+ end
9
+
10
+ def to_a
11
+ @skills
12
+ end
13
+
14
+ def add(skill)
15
+ @skills << skill unless @skills.include? skill
16
+ end
17
+
18
+ def add!(skill=nil)
19
+ add(skill) if skill
20
+ (@skills - @old_skills).each do |new_skill|
21
+ UserManagement.user_skill_add new_skill
22
+ @old_skills << new_skill
23
+ end
24
+ end
25
+
26
+ def remove(skill)
27
+ @skills.delete(skill)
28
+ end
29
+
30
+ def remove!(skill=nil)
31
+ remove(skill) if skill
32
+ (@old_skills - @skills).each do |old_skill|
33
+ UserManagement.user_skill_remove old_skill
34
+ @old_skills.delete old_skill
35
+ end
36
+ end
37
+
38
+ def update!
39
+ add! ; remove!
40
+ end
41
+
42
+ def method_missing(method_name, *args)
43
+ @skills.send(method_name, *args)
44
+ end
45
+
46
+ private
47
+ def set_initial_skills(args)
48
+ if args.class == Array
49
+ args.each do |skill|
50
+ @skills << skill.make_accessible
51
+ end
52
+ elsif args.class == NilClass
53
+ else
54
+ @skills << args.make_accessible
55
+ end
56
+ end
57
+ end
58
+ end
@@ -1,3 +1,3 @@
1
1
  module Five9
2
- VERSION = "0.0.13"
2
+ VERSION = "0.1.0"
3
3
  end
metadata CHANGED
@@ -1,20 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: five9
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.13
5
- prerelease:
4
+ version: 0.1.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - David Hahn
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-07-15 00:00:00.000000000 Z
11
+ date: 2013-09-16 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: savon
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
17
  - - ~>
20
18
  - !ruby/object:Gem::Version
@@ -22,11 +20,24 @@ dependencies:
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
24
  - - ~>
28
25
  - !ruby/object:Gem::Version
29
26
  version: 2.2.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: accessible_hash
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
30
41
  description: Rubygem integration with five9 API
31
42
  email:
32
43
  - dhahn@ctatechs.com
@@ -47,30 +58,34 @@ files:
47
58
  - lib/five9/base.rb
48
59
  - lib/five9/inbound_campaign_stats.rb
49
60
  - lib/five9/statistics.rb
61
+ - lib/five9/user.rb
50
62
  - lib/five9/user_management.rb
63
+ - lib/five9/user_resources/profile.rb
64
+ - lib/five9/user_resources/profile_management.rb
65
+ - lib/five9/user_resources/skill_array.rb
51
66
  - lib/five9/version.rb
52
67
  homepage: https://github.com/CTA/five9
53
- licenses: []
68
+ licenses:
69
+ - MIT
70
+ metadata: {}
54
71
  post_install_message:
55
72
  rdoc_options: []
56
73
  require_paths:
57
74
  - lib
58
75
  required_ruby_version: !ruby/object:Gem::Requirement
59
- none: false
60
76
  requirements:
61
77
  - - ! '>='
62
78
  - !ruby/object:Gem::Version
63
79
  version: '0'
64
80
  required_rubygems_version: !ruby/object:Gem::Requirement
65
- none: false
66
81
  requirements:
67
82
  - - ! '>='
68
83
  - !ruby/object:Gem::Version
69
84
  version: '0'
70
85
  requirements: []
71
86
  rubyforge_project:
72
- rubygems_version: 1.8.25
87
+ rubygems_version: 2.0.6
73
88
  signing_key:
74
- specification_version: 3
89
+ specification_version: 4
75
90
  summary: Write a gem summary
76
91
  test_files: []