class ZoomSlack::ProfileUpdater

Attributes

stderr[RW]
token[RW]

Public Class Methods

new(token:, stderr: STDERR) click to toggle source
# File lib/zoom_slack/profile_updater.rb, line 8
def initialize(token:, stderr: STDERR)
  self.token = token
  self.stderr = stderr
end

Public Instance Methods

status(status) click to toggle source
# File lib/zoom_slack/profile_updater.rb, line 13
def status(status)
  update_profile status
end

Private Instance Methods

connection() click to toggle source
# File lib/zoom_slack/profile_updater.rb, line 39
def connection
  Faraday.new(url: "https://slack.com") do |faraday|
    faraday.adapter Faraday.default_adapter
    faraday.authorization :Bearer, token
  end
end
human_readable_error(response) click to toggle source
# File lib/zoom_slack/profile_updater.rb, line 34
def human_readable_error(response)
  json = JSON.parse(response.body)
  stderr.print "Unable to update Slack profile. Did you pass in the right token?\n" unless json.fetch("ok")
end
update_profile(status) click to toggle source
# File lib/zoom_slack/profile_updater.rb, line 21
def update_profile(status)
  response = connection.post do |req|
    req.url "/api/users.profile.set"
    req.headers["Content-Type"] = "application/json;charset=utf-8"
    req.body = JSON.generate(profile: {
      status_text: status.text,
      status_emoji: status.emoji,
      status_expiration: status.expires
    })
  end
  human_readable_error response
end