lib/groupdocs/user.rb in groupdocs-1.2.8 vs lib/groupdocs/user.rb in groupdocs-1.2.9
- old
+ new
@@ -24,9 +24,42 @@
end.execute!
new(json[:user])
end
+ #
+ # Updates user account if it's created, otherwise creates new.
+ #
+ # @example
+ # user = GroupDocs::User.new
+ # user.primary_email = 'john@smith.com'
+ # user.nickname = 'johnsmith'
+ # user.first_name = 'John'
+ # user.last_name = 'Smith'
+ # # make sure to save user as it has updated attributes
+ # user = GroupDocs::User.update_account!(user)
+ #
+ # @param [GroupDocs::User] user
+ # @param [Hash] access Access credentials
+ # @option access [String] :client_id
+ # @option access [String] :private_key
+ # @return [GroupDocs::User]
+ #
+ def self.update_account!(user, access = {})
+ user.is_a?(GroupDocs::User) or raise ArgumentError,
+ "User should be GroupDocs::User object, received: #{user.inspect}"
+
+ data = user.to_hash
+ json = Api::Request.new do |request|
+ request[:access] = access
+ request[:method] = :PUT
+ request[:path] = "/mgmt/{{client_id}}/account/users/#{user.nickname}"
+ request[:request_body] = data
+ end.execute!
+
+ GroupDocs::User.new data.merge(json)
+ end
+
# @attr [Integer] id
attr_accessor :id
# @attr [String] guid
attr_accessor :guid
# @attr [String] nickname