Class: KineticSdk::Discussions

Inherits:
Object
  • Object
show all
Includes:
Utils::KineticHttpUtils
Defined in:
lib/kinetic_sdk/discussions/discussions-sdk.rb,
lib/kinetic_sdk/discussions/lib/meta.rb,
lib/kinetic_sdk/discussions/lib/messages.rb,
lib/kinetic_sdk/discussions/lib/discussions.rb,
lib/kinetic_sdk/discussions/lib/invitations.rb,
lib/kinetic_sdk/discussions/lib/participants.rb,
lib/kinetic_sdk/discussions/lib/related_items.rb

Overview

Discussions is a Ruby class that acts as a wrapper for the Kinetic Discussions REST API without having to make explicit HTTP requests.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utils::KineticHttpUtils

#default_headers, default_headers, #default_jwt_headers, default_jwt_headers, #delete, #encode, #gateway_retry_delay, #gateway_retry_limit, #get, #head, #header_accept_json, header_accept_json, #header_basic_auth, header_basic_auth, header_bearer_auth, #header_bearer_auth, #header_content_json, header_content_json, header_user_agent, #header_user_agent, #max_redirects, #mimetype, #patch, #post, #post_multipart, #put, #redirect_url, #stream_download_to_file

Constructor Details

#initialize(opts) ⇒ Discussions

Initalize the Discussions SDK with the web server URL and configuration user credentials, along with any custom option values.

Example: using a configuration file

KineticSdk::Discussions.new({
  config_file: "/opt/config1.yaml"
})

Example: space user properties hash

KineticSdk::Discussions.new({
  app_server_url: "http://localhost:8080",
  space: "foo",
  username: "admin",
  password: "admin",
  options: {
    log_level: "debug",
    export_directory: "/opt/exports/discussions",
    oauth_client_id: "my-oauth-client-id",
    oauth_client_secret: "secret",
    ssl_verify_mode: "peer",
    ssl_ca_file: "/usr/local/self_signing_ca.pem"
  }
})

Example: system user properties hash

KineticSdk::Discussions.new({
  app_server_url: "http://localhost:8080",
  username: "admin",
  password: "password",
  options: {
      log_level: "debug",
      oauth_client_id: "my-oauth-client-id",
      oauth_client_secret: "secret",
      ssl_verify_mode: "peer",
      ssl_ca_file: "/usr/local/self_signing_ca.pem"
  }
})

If the +config_file+ option is present, it will be loaded first, and any additional options will overwrite any values in the config file

Parameters:

  • opts (Hash)

    Kinetic Discussions properties

Options Hash (opts):

  • :config_file (String)

    optional - path to the YAML configuration file

    • Ex: /opt/config/discussions-configuration1.yaml
  • :app_server_url (String)

    the URL to the Kinetic Request CE web space

  • :space_slug (String)

    the slug that identifies the Space

  • :username (String)

    the username for the user

  • :password (String)

    the password for the user

  • :options (Hash<Symbol, Object>) — default: {}

    optional settings

    • :export_directory (String) (example: /opt/exports/discussions) directory to write file attachments when exporting,
    • :gateway_retry_limit (FixNum) (defaults to: 5) max number of times to retry a bad gateway
    • :gateway_retry_delay (Float) (defaults to: 1.0) number of seconds to delay before retrying a bad gateway
    • :log_level (String) (defaults to: off) level of logging - off | error | warn | info | debug
    • :log_output (String) (defaults to: STDOUT) where to send output - STDOUT | STDERR
    • :max_redirects (Fixnum) (defaults to: 5) maximum number of redirects to follow
    • :oauth_client_id (String) id of the Kinetic Core oauth client
    • :oauth_client_secret (String) secret of the Kinetic Core oauth client
    • :ssl_ca_file (String) full path to PEM certificate used to verify the server
    • :ssl_verify_mode (String) (defaults to: none) - none | peer


88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'lib/kinetic_sdk/discussions/discussions-sdk.rb', line 88

def initialize(opts)
  # initialize any variables
  options = {}

  # process the configuration file if it was provided
  unless opts[:config_file].nil?
    options.merge!(YAML::load_file opts[:config_file])
  end

  # process the configuration hash if it was provided
  options.merge!(opts)

  # allow either :app_server_url or :space_server_url, but not both
  if options[:app_server_url] && options[:space_server_url]
    raise StandardError.new "Expecting one of :app_server_url or :space_server_url, but not both."
  end
  if options[:app_server_url].nil? && options[:space_server_url].nil?
    raise StandardError.new "Expecting one of :app_server_url or :space_server_url."
  end

  # process any individual options
  @options = options[:options] || {}
  # setup logging
  log_level = @options[:log_level] || @options["log_level"]
  log_output = @options[:log_output] || @options["log_output"]
  @logger = KineticSdk::Utils::KLogger.new(log_level, log_output)

  @username = options[:username]
  @space_slug = options[:space_slug]

  if options[:topics_server_url]
    @topics_ws_server = "#{options[:topics_server_url].gsub("http", "ws")}/#{@space_slug}/socket"
  end

  if options[:discussions_server_url]
    @server = options[:discussions_server_url].chomp("/")
    @api_url = "#{@server}/#{@space_slug}/app/api/v1"
    if @topics_ws_server.nil?
      @topics_ws_server = "#{@server.gsub("http", "ws")}/app/topics/socket"
    end
  elsif options[:app_server_url]
    @server = options[:app_server_url].chomp("/")
    @api_url = "#{@server}/#{@space_slug}/app/api/v1"
    if @topics_ws_server.nil?
      @topics_ws_server = "#{@server.gsub("http", "ws")}/#{@space_slug}/app/topics/socket"
    end
  else
    raise StandardError.new "The :space_slug option is required when using the :space_server_url option" if @space_slug.nil?
    @server = options[:space_server_url].chomp("/")
    @api_url = "#{@server}/app/discussions/api/v1"
    if @topics_ws_server.nil?
      @topics_ws_server = "#{@server.gsub("http", "ws")}/app/topics/socket"
    end
  end
  @jwt = @space_slug.nil? ? nil : generate_jwt(options)
  @version = 1
end

Instance Attribute Details

#api_urlObject (readonly)

Returns the value of attribute api_url.



13
14
15
# File 'lib/kinetic_sdk/discussions/discussions-sdk.rb', line 13

def api_url
  @api_url
end

#jwtObject (readonly)

Returns the value of attribute jwt.



13
14
15
# File 'lib/kinetic_sdk/discussions/discussions-sdk.rb', line 13

def jwt
  @jwt
end

#loggerObject (readonly)

Returns the value of attribute logger.



13
14
15
# File 'lib/kinetic_sdk/discussions/discussions-sdk.rb', line 13

def logger
  @logger
end

#optionsObject (readonly)

Returns the value of attribute options.



13
14
15
# File 'lib/kinetic_sdk/discussions/discussions-sdk.rb', line 13

def options
  @options
end

#serverObject (readonly)

Returns the value of attribute server.



13
14
15
# File 'lib/kinetic_sdk/discussions/discussions-sdk.rb', line 13

def server
  @server
end

#space_slugObject (readonly)

Returns the value of attribute space_slug.



13
14
15
# File 'lib/kinetic_sdk/discussions/discussions-sdk.rb', line 13

def space_slug
  @space_slug
end

#topics_ws_serverObject (readonly)

Returns the value of attribute topics_ws_server.



13
14
15
# File 'lib/kinetic_sdk/discussions/discussions-sdk.rb', line 13

def topics_ws_server
  @topics_ws_server
end

#usernameObject (readonly)

Returns the value of attribute username.



13
14
15
# File 'lib/kinetic_sdk/discussions/discussions-sdk.rb', line 13

def username
  @username
end

#versionObject (readonly)

Returns the value of attribute version.



13
14
15
# File 'lib/kinetic_sdk/discussions/discussions-sdk.rb', line 13

def version
  @version
end

Instance Method Details

#add_discussion(properties = {}, headers = default_jwt_headers) ⇒ KineticSdk::Utils::KineticHttpResponse

Add a Discussion

Parameters:

  • properties (Hash) (defaults to: {})

    discussion properties

    • +title+ [String]
    • +description+ [String]
    • +joinPolicy+ [String] name of the security policy that defines who can join
    • +owningUsers+ [Array] array of user usernames
    • +owningTeams+ [Array] array of team names
  • headers (Hash) (defaults to: default_jwt_headers)

    hash of headers to send, default is bearer authentication and accept JSON content type

Returns:



14
15
16
17
# File 'lib/kinetic_sdk/discussions/lib/discussions.rb', line 14

def add_discussion(properties={}, headers=default_jwt_headers)
  @logger.info("Adding the #{properties['title']} discussion")
  post("#{@api_url}/discussions", properties, headers)
end

#add_invitation_by_email(discussion_id, email, message = nil, headers = default_jwt_headers) ⇒ KineticSdk::Utils::KineticHttpResponse

Invite an email that doesn't have a user account

Parameters:

  • discussion_id (String)

    id of the discussion

  • email (String)

    email to invite

  • message (String) (defaults to: nil)

    message sent with the invitation

  • headers (Hash) (defaults to: default_jwt_headers)

    hash of headers to send, default is bearer authentication and accept JSON content type

Returns:



11
12
13
14
15
16
# File 'lib/kinetic_sdk/discussions/lib/invitations.rb', line 11

def add_invitation_by_email(discussion_id, email, message=nil, headers=default_jwt_headers)
  payload = { "email" => email }
  payload["message"] = message unless message.nil?
  @logger.info("Inviting #{email} to the #{discussion_id} Discussion")
  post("#{@api_url}/discussions/#{discussion_id}/invitations", payload, headers)
end

#add_invitation_by_username(discussion_id, username, message = nil, headers = default_jwt_headers) ⇒ KineticSdk::Utils::KineticHttpResponse

Invite a user that already has an account

Parameters:

  • discussion_id (String)

    id of the discussion

  • username (String)

    username to invite

  • message (String) (defaults to: nil)

    message sent with the invitation

  • headers (Hash) (defaults to: default_jwt_headers)

    hash of headers to send, default is bearer authentication and accept JSON content type

Returns:



25
26
27
28
29
30
# File 'lib/kinetic_sdk/discussions/lib/invitations.rb', line 25

def add_invitation_by_username(discussion_id, username, message=nil, headers=default_jwt_headers)
  payload = { "user" => { "username" => username } }
  payload["message"] = message unless message.nil?
  @logger.info("Inviting #{username} to the #{discussion_id} Discussion")
  post("#{@api_url}/discussions/#{discussion_id}/invitations", payload, headers)
end

#add_message(discussion_id, message, headers = default_jwt_headers) ⇒ KineticSdk::Utils::KineticHttpResponse

Add a Message without attachments

If message parameter is a Hash, it assumes the message contains the content property set to an array of the expected tokens (type and value properties).

If message parameter is an Array, it assumes the message contains the array of expected tokens (type and value properties).

If message parameter is a string, it builds up the message content property as a single text token with the value of the message parameter.

Parameters:

  • discussion_id (String)

    id of the discussion

  • message (String | Hash | Array)

    message

  • headers (Hash) (defaults to: default_jwt_headers)

    hash of headers to send, default is bearer authentication and accept JSON content type

Returns:



21
22
23
24
25
# File 'lib/kinetic_sdk/discussions/lib/messages.rb', line 21

def add_message(discussion_id, message, headers=default_jwt_headers)
  payload = message_content(message)
  @logger.info("Adding a message to the #{discussion_id} Discussion")
  post("#{@api_url}/discussions/#{discussion_id}/messages", payload, headers)
end

#add_message_with_attachments(discussion_id, properties = {}, headers = default_jwt_headers) ⇒ KineticSdk::Utils::KineticHttpResponse

Add a Message with attachments

If properties['message'] parameter is a Hash, it assumes the message contains the content property set to an array of the expected tokens (type and value properties).

If properties['message'] parameter is an Array, it assumes the message contains the array of expected tokens (type and value properties).

If properties['message'] parameter is a string, it builds up the message content property as a single text token with the value of the properties['message'] parameter.

Parameters:

  • discussion_id (String)

    id of the discussion

  • properties (Hash) (defaults to: {})

    message properties

    • +message+ [String | Hash | Array] message
    • +attachments+ [File[]]
  • headers (Hash) (defaults to: default_jwt_headers)

    hash of headers to send, default is bearer authentication and accept JSON content type

Returns:



46
47
48
49
50
51
# File 'lib/kinetic_sdk/discussions/lib/messages.rb', line 46

def add_message_with_attachments(discussion_id, properties={}, headers=default_jwt_headers)
  payload = message_content(properties['message'])
  payload["attachments"] = properties['attachments']
  @logger.info("Adding a message to the #{discussion_id} Discussion")
  post_multipart("#{@api_url}/discussions/#{discussion_id}/messages", payload, headers)
end

#add_participant(discussion_id, username, headers = default_jwt_headers) ⇒ KineticSdk::Utils::KineticHttpResponse

Create a participant for an existing user

Parameters:

  • discussion_id (String)

    id of the discussion

  • username (String)

    username of the user

  • headers (Hash) (defaults to: default_jwt_headers)

    hash of headers to send, default is bearer authentication and accept JSON content type

Returns:



10
11
12
13
14
# File 'lib/kinetic_sdk/discussions/lib/participants.rb', line 10

def add_participant(discussion_id, username, headers=default_jwt_headers)
  payload = { "username" => username }
  @logger.info("Participant #{username} joining the #{discussion_id} Discussion")
  post("#{@api_url}/discussions/#{discussion_id}/participants", payload, headers)
end

Add a Related Item to a discussion

Parameters:

  • discussion_id (String)

    id of the discussion

  • type (String)

    type of related item

  • key (String)

    key that identifies the related item

  • headers (Hash) (defaults to: default_jwt_headers)

    hash of headers to send, default is bearer authentication and accept JSON content type

Returns:



11
12
13
14
15
# File 'lib/kinetic_sdk/discussions/lib/related_items.rb', line 11

def add_related_item(discussion_id, type, key, headers=default_jwt_headers)
  payload = {"type": type, "key": key}
  @logger.info("Adding a related item of type #{type} and key #{key} to the #{discussion_id} Discussion")
  post("#{@api_url}/discussions/#{discussion_id}/relatedItems", payload, headers)
end

#app_version(headers = header_accept_json) ⇒ KineticSdk::Utils::KineticHttpResponse

Retrieve Discussions application version

Parameters:

  • headers (Hash) (defaults to: header_accept_json)

    hash of headers to send, default is accept JSON content type

Returns:



8
9
10
11
# File 'lib/kinetic_sdk/discussions/lib/meta.rb', line 8

def app_version(headers=header_accept_json)
  @logger.info("Retrieving Discussions application version.")
  get("#{@api_url}/version", {}, headers)
end

#delete_discussion(discussion_id, headers = header_bearer_auth) ⇒ KineticSdk::Utils::KineticHttpResponse

Delete a Discussion

Parameters:

  • discussion_id (String)

    discussion_id of the discussion

  • headers (Hash) (defaults to: header_bearer_auth)

    hash of headers to send, default is bearer authentication

Returns:



24
25
26
27
# File 'lib/kinetic_sdk/discussions/lib/discussions.rb', line 24

def delete_discussion(discussion_id, headers=header_bearer_auth)
  @logger.info("Deleting Discussion \"#{discussion_id}\"")
  delete("#{@api_url}/discussions/#{discussion_id}", headers)
end

#delete_invitation_by_email(discussion_id, email, headers = header_bearer_auth) ⇒ KineticSdk::Utils::KineticHttpResponse

Delete an email invitation

Parameters:

  • discussion_id (String)

    id of the discussion

  • email (String)

    email the invitation was sent to

  • headers (Hash) (defaults to: header_bearer_auth)

    hash of headers to send, default is bearer authentication

Returns:



38
39
40
41
# File 'lib/kinetic_sdk/discussions/lib/invitations.rb', line 38

def delete_invitation_by_email(discussion_id, email, headers=header_bearer_auth)
  @logger.info("Deleting the email invitation to the #{discussion_id} Discussion for #{email}")
  delete("#{@api_url}/discussions/#{discussion_id}/invitations/#{encode(email)}?email=true", headers)
end

#delete_invitation_by_username(discussion_id, username, headers = header_bearer_auth) ⇒ KineticSdk::Utils::KineticHttpResponse

Delete a user invitation

Parameters:

  • discussion_id (String)

    id of the discussion

  • username (String)

    username the invitation was sent to

  • headers (Hash) (defaults to: header_bearer_auth)

    hash of headers to send, default is bearer authentication

Returns:



49
50
51
52
# File 'lib/kinetic_sdk/discussions/lib/invitations.rb', line 49

def delete_invitation_by_username(discussion_id, username, headers=header_bearer_auth)
  @logger.info("Deleting the user invitation to the #{discussion_id} Discussion for #{username}")
  delete("#{@api_url}/discussions/#{discussion_id}/invitations/#{encode(username)}", headers)
end

#delete_participant(discussion_id, username, headers = header_bearer_auth) ⇒ KineticSdk::Utils::KineticHttpResponse

Delete a participant

Parameters:

  • discussion_id (String)

    id of the discussion

  • username (String)

    username of the participant

  • headers (Hash) (defaults to: header_bearer_auth)

    hash of headers to send, default is bearer authentication

Returns:



22
23
24
25
# File 'lib/kinetic_sdk/discussions/lib/participants.rb', line 22

def delete_participant(discussion_id, username, headers=header_bearer_auth)
  @logger.info("Participant #{username} is leaving the #{discussion_id} Discussion")
  delete("#{@api_url}/discussions/#{discussion_id}/participants/#{encode(username)}", headers)
end

Delete a Related Item from a discussion

Parameters:

  • discussion_id (String)

    id of the discussion

  • type (String)

    type of related item

  • key (String)

    key that identifies the related item

  • headers (Hash) (defaults to: header_bearer_auth)

    hash of headers to send, default is bearer authentication

Returns:



24
25
26
27
# File 'lib/kinetic_sdk/discussions/lib/related_items.rb', line 24

def delete_related_item(discussion_id, type, key, headers=header_bearer_auth)
  @logger.info("Deleting related item of type #{type} and key #{key} from the #{discussion_id} Discussion")
  delete("#{@api_url}/discussions/#{discussion_id}/relatedItems/#{encode(type)}/#{encode(key)}", payload, headers)
end

#download_message_attachment(discussion_id, message_id, document_id, filename, params = {}, headers = header_bearer_auth) ⇒ KineticSdk::Utils::KineticHttpResponse

Download a message attachment

WARNING This method downloads the entire attachment into memory. This may cause problems with large files. To stream the attachment in chunks to avoid consuming large amounts of memory, see the #export_message_attachment method.

Parameters:

  • discussion_id (String)

    id of the discussion

  • message_id (String)

    id of the message

  • document_id (String)

    id of the document in the filestore

  • filename (String)

    default name to use for the downloaded file

  • params (Hash) (defaults to: {})

    Query parameters that are added to the URL, such as +include+

  • headers (Hash) (defaults to: header_bearer_auth)

    hash of headers to send, default is bearer authentication

Returns:



139
140
141
142
# File 'lib/kinetic_sdk/discussions/lib/messages.rb', line 139

def download_message_attachment(discussion_id, message_id, document_id, filename, params={}, headers=header_bearer_auth)
  @logger.info("Downloading the #{filename} file attachment in the #{discussion_id} Discussion")
  get("#{@api_url}/discussions/#{discussion_id}/messages/#{message_id}/files/#{document_id}/#{filename}", params, headers)
end

#export_discussion_attachments(discussion_id, params = {}, headers = header_bearer_auth) ⇒ Object

Export all discussion attachments

This method streams the attachments in chunks to avoid consuming large amounts of memory.

The message attachments will be saved to the {export_directory}/{discussion_id}/files/{message_id} directory, where:

  • +export_directory+: the directory specified in the SDK configuration
  • +discussion_id+: the id of the discussion
  • +message_id+: the id of the message that contains the attachment

Parameters:

  • discussion_id (String)

    id of the discussion

  • params (Hash) (defaults to: {})

    Query parameters that are added to the URL, such as +include+

  • headers (Hash) (defaults to: header_bearer_auth)

    hash of headers to send, default is bearer authentication



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/kinetic_sdk/discussions/lib/discussions.rb', line 82

def export_discussion_attachments(discussion_id, params={}, headers=header_bearer_auth)
  raise StandardError.new "An export directory must be defined to export a file attachment." if @options[:export_directory].nil?
  @logger.info("Exporting all file attachments in the #{discussion_id} Discussion.")
  @logger.info("This may take a while.")
  # File Counter
  counter = 0
  # write the files
  find_messages(discussion_id, params, headers).content['messages'].each do |m|
    message_id = m['id']
    updated_at = m['updatedAt']
    m['content'].each do |item|
      if (item['type'] == "attachment")
        document_id = item['value']['documentId']
        filename = item['value']['filename']
        # count the files
        counter = counter + 1
        # export the file attachments
        export_message_attachment(discussion_id, message_id, document_id, filename, params, headers)
      end
    end
  end
  @logger.info("Exported #{counter} file attachments for the #{discussion_id} Discussion")
end

#export_message_attachment(discussion_id, message_id, document_id, filename, params = {}, headers = header_bearer_auth) ⇒ Object

Export a message attachment

This method streams the attachment in chunks to avoid consuming large amounts of memory.

The message attachment will be saved to the {export_directory}/{discussion_id}/files/{message_id} directory, where:

  • +export_directory+: the directory specified in the SDK configuration
  • +discussion_id+: the id of the discussion
  • +message_id+: the id of the message that contains the attachment

If you want to work with the attachment in code rather than automatically save it to a file, see the #download_message_attachment method.

Parameters:

  • discussion_id (String)

    id of the discussion

  • message_id (String)

    id of the message

  • document_id (String)

    id of the document in the filestore

  • filename (String)

    default name to use for the downloaded file

  • params (Hash) (defaults to: {})

    Query parameters that are added to the URL, such as +include+

  • headers (Hash) (defaults to: header_bearer_auth)

    hash of headers to send, default is bearer authentication



165
166
167
168
169
170
171
172
173
# File 'lib/kinetic_sdk/discussions/lib/messages.rb', line 165

def export_message_attachment(discussion_id, message_id, document_id, filename, params={}, headers=header_bearer_auth)
  raise StandardError.new "An export directory must be defined to export a file attachment." if @options[:export_directory].nil?
  @logger.info("Exporting the #{filename} file attachment in the #{discussion_id} Discussion")
  # Create the export directory if it doesn't yet exist
  export_dir = FileUtils::mkdir_p(File.join(@options[:export_directory], discussion_id, "files", message_id))
  export_file = File.join(export_dir, filename)
  url = "#{@api_url}/discussions/#{discussion_id}/messages/#{message_id}/files/#{document_id}/#{filename}"
  stream_download_to_file(export_file, url, params, headers)
end

#find_discussion(discussion_id, params = {}, headers = default_jwt_headers) ⇒ KineticSdk::Utils::KineticHttpResponse

Find a Discussion

Parameters:

  • discussion_id (String)

    id of the Discussion

  • params (Hash) (defaults to: {})

    Query parameters that are added to the URL, such as +include+

  • headers (Hash) (defaults to: default_jwt_headers)

    hash of headers to send, default is bearer authentication and accept JSON content type

Returns:



45
46
47
48
# File 'lib/kinetic_sdk/discussions/lib/discussions.rb', line 45

def find_discussion(discussion_id, params={}, headers=default_jwt_headers)
  @logger.info("Finding the \"#{discussion_id}\" Discussion.")
  get("#{@api_url}/discussions/#{discussion_id}", params, headers)
end

#find_discussions(params = {}, headers = default_jwt_headers) ⇒ KineticSdk::Utils::KineticHttpResponse

Find Discussions

Parameters:

  • params (Hash) (defaults to: {})

    Query parameters that are added to the URL, such as +include+

  • headers (Hash) (defaults to: default_jwt_headers)

    hash of headers to send, default is bearer authentication and accept JSON content type

Returns:



34
35
36
37
# File 'lib/kinetic_sdk/discussions/lib/discussions.rb', line 34

def find_discussions(params={}, headers=default_jwt_headers)
  @logger.info("Finding Discussions.")
  get("#{@api_url}/discussions", params, headers)
end

#find_invitation_by_email(discussion_id, email, params = {}, headers = default_jwt_headers) ⇒ KineticSdk::Utils::KineticHttpResponse

Find an invitation in a discussion by email

Parameters:

  • discussion_id (String)

    id of the discussion

  • email (String)

    email the invitation was sent to

  • params (Hash) (defaults to: {})

    Query parameters that are added to the URL, such as +include+

  • headers (Hash) (defaults to: default_jwt_headers)

    hash of headers to send, default is bearer authentication and accept JSON content type

Returns:



72
73
74
75
76
# File 'lib/kinetic_sdk/discussions/lib/invitations.rb', line 72

def find_invitation_by_email(discussion_id, email, params={}, headers=default_jwt_headers)
  params['email'] = 'true' if params['email'].nil?
  @logger.info("Finding the Invitation for email #{email} in the #{discussion_id} Discussion")
  get("#{@api_url}/discussions/#{discussion_id}/invitations/#{encode(email)}", params, headers)
end

#find_invitation_by_username(discussion_id, username, params = {}, headers = default_jwt_headers) ⇒ KineticSdk::Utils::KineticHttpResponse

Find an invitation in a discussion by username

Parameters:

  • discussion_id (String)

    id of the discussion

  • username (String)

    username of the invitation

  • params (Hash) (defaults to: {})

    Query parameters that are added to the URL, such as +include+

  • headers (Hash) (defaults to: default_jwt_headers)

    hash of headers to send, default is bearer authentication and accept JSON content type

Returns:



85
86
87
88
89
# File 'lib/kinetic_sdk/discussions/lib/invitations.rb', line 85

def find_invitation_by_username(discussion_id, username, params={}, headers=default_jwt_headers)
  params.delete('email')
  @logger.info("Finding the Invitation for user #{username} in the #{discussion_id} Discussion")
  get("#{@api_url}/discussions/#{discussion_id}/invitations/#{encode(username)}", params, headers)
end

#find_invitations(discussion_id, params = {}, headers = default_jwt_headers) ⇒ KineticSdk::Utils::KineticHttpResponse

Find invitations in a discussion

Parameters:

  • discussion_id (String)

    id of the discussion

  • params (Hash) (defaults to: {})

    Query parameters that are added to the URL, such as +include+

  • headers (Hash) (defaults to: default_jwt_headers)

    hash of headers to send, default is bearer authentication and accept JSON content type

Returns:



60
61
62
63
# File 'lib/kinetic_sdk/discussions/lib/invitations.rb', line 60

def find_invitations(discussion_id, params={}, headers=default_jwt_headers)
  @logger.info("Finding Invitations in the #{discussion_id} Discussion")
  get("#{@api_url}/discussions/#{discussion_id}/invitations", params, headers)
end

#find_message(discussion_id, message_id, params = {}, headers = default_jwt_headers) ⇒ KineticSdk::Utils::KineticHttpResponse

Find a Message in a Discussion

Parameters:

  • discussion_id (String)

    id of the discussion

  • message_id (String)

    id of the message

  • params (Hash) (defaults to: {})

    Query parameters that are added to the URL, such as +include+

  • headers (Hash) (defaults to: default_jwt_headers)

    hash of headers to send, default is bearer authentication and accept JSON content type

Returns:



71
72
73
74
# File 'lib/kinetic_sdk/discussions/lib/messages.rb', line 71

def find_message(discussion_id, message_id, params={}, headers=default_jwt_headers)
  @logger.info("Finding the #{message_id} message in the #{discussion_id} Discussion")
  get("#{@api_url}/discussions/#{discussion_id}/messages/#{message_id}", params, headers)
end

#find_messages(discussion_id, params = {}, headers = default_jwt_headers) ⇒ KineticSdk::Utils::KineticHttpResponse

Find Messages in a Discussion

Parameters:

  • discussion_id (String)

    id of the discussion

  • params (Hash) (defaults to: {})

    Query parameters that are added to the URL, such as +include+

  • headers (Hash) (defaults to: default_jwt_headers)

    hash of headers to send, default is bearer authentication and accept JSON content type

Returns:



59
60
61
62
# File 'lib/kinetic_sdk/discussions/lib/messages.rb', line 59

def find_messages(discussion_id, params={}, headers=default_jwt_headers)
  @logger.info("Finding messages in the #{discussion_id} Discussion")
  get("#{@api_url}/discussions/#{discussion_id}/messages", params, headers)
end

#find_participant(discussion_id, username, params = {}, headers = default_jwt_headers) ⇒ KineticSdk::Utils::KineticHttpResponse

Find a participant in a discussion

Parameters:

  • discussion_id (String)

    id of the discussion

  • username (String)

    username of the participant

  • params (Hash) (defaults to: {})

    Query parameters that are added to the URL, such as +include+

  • headers (Hash) (defaults to: default_jwt_headers)

    hash of headers to send, default is bearer authentication and accept JSON content type

Returns:



45
46
47
48
# File 'lib/kinetic_sdk/discussions/lib/participants.rb', line 45

def find_participant(discussion_id, username, params={}, headers=default_jwt_headers)
  @logger.info("Finding the #{username} Participant in the #{discussion_id} Discussion")
  get("#{@api_url}/discussions/#{discussion_id}/participants/#{encode(username)}", params, headers)
end

#find_participants(discussion_id, params = {}, headers = default_jwt_headers) ⇒ KineticSdk::Utils::KineticHttpResponse

Find participants in a discussion

Parameters:

  • discussion_id (String)

    id of the discussion

  • params (Hash) (defaults to: {})

    Query parameters that are added to the URL, such as +include+

  • headers (Hash) (defaults to: default_jwt_headers)

    hash of headers to send, default is bearer authentication and accept JSON content type

Returns:



33
34
35
36
# File 'lib/kinetic_sdk/discussions/lib/participants.rb', line 33

def find_participants(discussion_id, params={}, headers=default_jwt_headers)
  @logger.info("Finding Participants in the #{discussion_id} Discussion")
  get("#{@api_url}/discussions/#{discussion_id}/participants", params, headers)
end

Find a Related Item in a Discussion

Parameters:

  • discussion_id (String)

    id of the discussion

  • type (String)

    type of the related item

  • key (String)

    key that identifies the related item

  • params (Hash) (defaults to: {})

    Query parameters that are added to the URL, such as +include+

  • headers (Hash) (defaults to: default_jwt_headers)

    hash of headers to send, default is bearer authentication and accept JSON content type

Returns:



48
49
50
51
# File 'lib/kinetic_sdk/discussions/lib/related_items.rb', line 48

def find_related_item(discussion_id, type, key, params={}, headers=default_jwt_headers)
  @logger.info("Finding the related item of type #{type} and key #{key} in the #{discussion_id} Discussion")
  get("#{@api_url}/discussions/#{discussion_id}/relatedItems/#{encode(type)}/#{encode(key)}", params, headers)
end

Find Related Items in a Discussion

Parameters:

  • discussion_id (String)

    id of the discussion

  • params (Hash) (defaults to: {})

    Query parameters that are added to the URL, such as +include+

  • headers (Hash) (defaults to: default_jwt_headers)

    hash of headers to send, default is bearer authentication and accept JSON content type

Returns:



35
36
37
38
# File 'lib/kinetic_sdk/discussions/lib/related_items.rb', line 35

def find_related_items(discussion_id, params={}, headers=default_jwt_headers)
  @logger.info("Finding related items in the #{discussion_id} Discussion")
  get("#{@api_url}/discussions/#{discussion_id}/relatedItems", params, headers)
end

#generate_jwt(options = {}) ⇒ Object

Generate a JWT for bearer authentication based on the user credentials, and oauth client configuration.



148
149
150
151
152
153
154
# File 'lib/kinetic_sdk/discussions/discussions-sdk.rb', line 148

def generate_jwt(options = {})
  oauth_client_id = options[:options][:oauth_client_id]
  oauth_client_secret = options[:options][:oauth_client_secret]

  jwt_response = kinetic_core_sdk(options).jwt_token(oauth_client_id, oauth_client_secret)
  jwt_response.content["access_token"]
end

#kinetic_core_sdk(options) ⇒ Object

Creates a reference to the Kinetic Request CE SDK



157
158
159
160
161
162
163
164
165
166
167
168
169
170
# File 'lib/kinetic_sdk/discussions/discussions-sdk.rb', line 157

def kinetic_core_sdk(options)
  kinetic_core_options = {
    space_slug: options[:space_slug],
    username: options[:username],
    password: options[:password],
    options: options[:options] || {},
  }
  if options[:app_server_url]
    kinetic_core_options[:app_server_url] = options[:app_server_url]
  else
    kinetic_core_options[:space_server_url] = options[:space_server_url]
  end
  KineticSdk::Core.new(kinetic_core_options)
end

#resend_invitation_by_email(discussion_id, email, message, headers = default_jwt_headers) ⇒ KineticSdk::Utils::KineticHttpResponse

Resend an email invitation

Parameters:

  • discussion_id (String)

    id of the discussion

  • email (String)

    email the invitation was sent to

  • message (String)

    updated message to send with the invitation

  • headers (Hash) (defaults to: default_jwt_headers)

    hash of headers to send, default is bearer authentication and accept JSON content type

Returns:



98
99
100
101
102
103
# File 'lib/kinetic_sdk/discussions/lib/invitations.rb', line 98

def resend_invitation_by_email(discussion_id, email, message, headers=default_jwt_headers)
  payload = {}
  payload["message"] = message unless message.nil?
  @logger.info("Reinviting #{email} to the #{discussion_id} Discussion")
  put("#{@api_url}/discussions/#{discussion_id}/invitations/#{encode(email)}?email=true", payload, headers)
end

#resend_invitation_by_username(discussion_id, username, message, headers = default_jwt_headers) ⇒ KineticSdk::Utils::KineticHttpResponse

Resend a user invitation

Parameters:

  • discussion_id (String)

    id of the discussion

  • username (String)

    username the invitation was sent to

  • message (String)

    updated message to send with the invitation

  • headers (Hash) (defaults to: default_jwt_headers)

    hash of headers to send, default is bearer authentication and accept JSON content type

Returns:



112
113
114
115
116
117
# File 'lib/kinetic_sdk/discussions/lib/invitations.rb', line 112

def resend_invitation_by_username(discussion_id, username, message, headers=default_jwt_headers)
  payload = {}
  payload["message"] = message unless message.nil?
  @logger.info("Reinviting #{username} to the #{discussion_id} Discussion")
  put("#{@api_url}/discussions/#{discussion_id}/invitations/#{encode(username)}", payload, headers)
end

#update_discussion(discussion_id, properties = {}, headers = default_jwt_headers) ⇒ KineticSdk::Utils::KineticHttpResponse

Update a Discussion

Parameters:

  • discussion_id (String)

    id of the Discussion

  • properties (Hash) (defaults to: {})

    form properties to update

    • +title+ [String]
    • +description+ [String]
    • +isArchived+ [Boolean]
    • +joinPolicy+ [String] name of the security policy that defines who can join
    • +owningUsers+ [Array] array of user usernames
    • +owningTeams+ [Array] array of team names
  • headers (Hash) (defaults to: default_jwt_headers)

    hash of headers to send, default is bearer authentication and accept JSON content type

Returns:



62
63
64
65
# File 'lib/kinetic_sdk/discussions/lib/discussions.rb', line 62

def update_discussion(discussion_id, properties={}, headers=default_jwt_headers)
  @logger.info("Updating the \"#{discussion_id}\" Discussion.")
  put("#{@api_url}/discussions/#{discussion_id}", properties, headers)
end

#update_message(discussion_id, message_id, message, headers = default_jwt_headers) ⇒ KineticSdk::Utils::KineticHttpResponse

Update a Message without new attachments

If message parameter is a Hash, it assumes the message contains the content property set to an array of the expected tokens (type and value properties).

If message parameter is an Array, it assumes the message contains the array of expected tokens (type and value properties).

If message parameter is a string, it builds up the message content property as a single text token with the value of the message parameter.

Parameters:

  • discussion_id (String)

    id of the discussion

  • message_id (String)

    id of the message

  • message (String | Hash | Array)

    updated content of the message

  • headers (Hash) (defaults to: default_jwt_headers)

    hash of headers to send, default is bearer authentication and accept JSON content type

Returns:



94
95
96
97
98
# File 'lib/kinetic_sdk/discussions/lib/messages.rb', line 94

def update_message(discussion_id, message_id, message, headers=default_jwt_headers)
  payload = message_content(message)
  @logger.info("Updating the #{message_id} message in the #{discussion_id} Discussion")
  put("#{@api_url}/discussions/#{discussion_id}/messages/#{message_id}", payload, headers)
end

#update_message_with_attachments(discussion_id, message_id, message, attachments = [], headers = header_bearer_auth) ⇒ KineticSdk::Utils::KineticHttpResponse

Update a Message with new attachments

If message parameter is a Hash, it assumes the message contains the content property set to an array of the expected tokens (type and value properties).

If message parameter is an Array, it assumes the message contains the array of expected tokens (type and value properties).

If message parameter is a string, it builds up the message content property as a single text token with the value of the message parameter.

Parameters:

  • discussion_id (String)

    id of the discussion

  • message_id (String)

    id of the message

  • message (String | Hash | Array)

    updated content of the message

  • attachments (File[]) (defaults to: [])

    new attachments to add to the message

  • headers (Hash) (defaults to: header_bearer_auth)

    hash of headers to send, default is bearer authentication

Returns:



119
120
121
122
123
# File 'lib/kinetic_sdk/discussions/lib/messages.rb', line 119

def update_message_with_attachments(discussion_id, message_id, message, attachments=[], headers=header_bearer_auth)
  payload = { "message" => message_content(message).to_json, "attachments" => attachments }
  @logger.info("Updating the #{message_id} message in the #{discussion_id} Discussion")
  post_multipart("#{@api_url}/discussions/#{discussion_id}/messages/#{message_id}", payload, headers)
end

#update_participant(discussion_id, username, properties = {}, headers = default_jwt_headers) ⇒ KineticSdk::Utils::KineticHttpResponse

Update a participant in a discussion

Parameters:

  • discussion_id (String)

    id of the discussion

  • username (String)

    username of the participant

  • properties (Hash) (defaults to: {})

    participant properties to update

    • +isMuted+
  • headers (Hash) (defaults to: default_jwt_headers)

    hash of headers to send, default is bearer authentication and accept JSON content type

Returns:



58
59
60
61
# File 'lib/kinetic_sdk/discussions/lib/participants.rb', line 58

def update_participant(discussion_id, username, properties={}, headers=default_jwt_headers)
  @logger.info("Updating the #{username} Participant in the #{discussion_id} Discussion")
  put("#{@api_url}/discussions/#{discussion_id}/participants/#{encode(username)}", properties, headers)
end