Sha256: a59b16613e4705d737d0a85e66aee6dbafd225f4fe15dc8508adf6e6964c4c87

Contents?: true

Size: 1.57 KB

Versions: 6

Compression:

Stored size: 1.57 KB

Contents

require 'uservoice-ruby'

module QuickappsFeedback
  class SendFeedbackToUservoice
    def perform(feedback)
      send_options = {:email => feedback.user_email,
                      :subject => "[#{ENV['MXIT_APP_NAME']}] #{feedback.subject}",
                      :message => feedback.message,
                      :name => feedback.user_real_name || CGI::unescape(feedback.user_name.to_s).gsub(/[^a-zA-Z0-9\s]/, '')}
      if feedback.support_type == 'suggestion'
        send_suggestion(send_options)
      else
        send_support(send_options)
      end
    end

    def send_suggestion(options = {})
      client = UserVoice::Client.new(subdomain_name, api_key, api_secret)
      forum = client.get('/api/v1/forums.json')['forums'].first
      forum_id = forum['id']
      client.login_as(options[:email]) do |access_token|
        access_token.post("/api/v1/forums/#{forum_id}/suggestions.json", {
          :suggestion => {
            :title => options[:subject],
            :text => options[:message],
            :votes => 0
          }
        })
      end
    end

    def send_support(options = {})
      client = UserVoice::Client.new(subdomain_name, api_key, api_secret)
      client.post('/api/v1/tickets.json', {
        :email => options[:email],
        :name => options[:name],
        :ticket => {
          :subject => options[:subject],
          :message => options[:message]
        }
      })
    end

    def subdomain_name
      ENV['UV_SUBDOMAIN_NAME']
    end

    def api_key
      ENV['UV_API_KEY']
    end

    def api_secret
      ENV['UV_API_SECRET']
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
quickapps_feedback-0.1.5 lib/quickapps_feedback/send_feedback_to_uservoice.rb
quickapps_feedback-0.1.4 lib/quickapps_feedback/send_feedback_to_uservoice.rb
quickapps_feedback-0.1.3 lib/quickapps_feedback/send_feedback_to_uservoice.rb
quickapps_feedback-0.1.2 lib/quickapps_feedback/send_feedback_to_uservoice.rb
quickapps_feedback-0.1.1 lib/quickapps_feedback/send_feedback_to_uservoice.rb
quickapps_feedback-0.1.0 lib/quickapps_feedback/send_feedback_to_uservoice.rb