Sha256: d72463b2c53a111b799e9e7a39daff9b7e1fcc07cf13858d0ece436a55ff2929

Contents?: true

Size: 1.85 KB

Versions: 14

Compression:

Stored size: 1.85 KB

Contents

# Send a notice to a Twitter account (http://twitter.com/).
#
# consumer_token  - The String OAuth consumer token (defaults to God's
#                   existing consumer token).
# consumer_secret - The String OAuth consumer secret (defaults to God's
#                   existing consumer secret).
# access_token    - The String OAuth access token.
# access_secret   - The String OAuth access secret.

CONTACT_DEPS[:twitter] = ['twitter']
CONTACT_DEPS[:twitter].each do |d|
  require d
end

module God
  module Contacts
    class Twitter < Contact
      class << self
        attr_accessor :consumer_token, :consumer_secret,
                      :access_token, :access_secret
      end

      self.consumer_token = 'gOhjax6s0L3mLeaTtBWPw'
      self.consumer_secret = 'yz4gpAVXJHKxvsGK85tEyzQJ7o2FEy27H1KEWL75jfA'

      def valid?
        valid = true
        valid &= complain("Attribute 'consumer_token' must be specified", self) unless arg(:consumer_token)
        valid &= complain("Attribute 'consumer_secret' must be specified", self) unless arg(:consumer_secret)
        valid &= complain("Attribute 'access_token' must be specified", self) unless arg(:access_token)
        valid &= complain("Attribute 'access_secret' must be specified", self) unless arg(:access_secret)
        valid
      end

      attr_accessor :consumer_token, :consumer_secret,
                    :access_token, :access_secret

      def notify(message, time, priority, category, host)
        oauth = ::Twitter::OAuth.new(arg(:consumer_token), arg(:consumer_secret))
        oauth.authorize_from_access(arg(:access_token), arg(:access_secret))

        ::Twitter::Base.new(oauth).update(message)

        self.info = "sent twitter update"
      rescue => e
        applog(nil, :info, "failed to send twitter update: #{e.message}")
        applog(nil, :debug, e.backtrace.join("\n"))
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 4 rubygems

Version Path
resurrected_god-0.14.0 lib/god/contacts/twitter.rb
mcproc-2016.2.20 lib/god/contacts/twitter.rb
god-0.13.7 lib/god/contacts/twitter.rb
god-0.13.6 lib/god/contacts/twitter.rb
god-0.13.5 lib/god/contacts/twitter.rb
god-0.13.4 lib/god/contacts/twitter.rb
god-0.13.3 lib/god/contacts/twitter.rb
god-0.13.2 lib/god/contacts/twitter.rb
god-0.13.1 lib/god/contacts/twitter.rb
god-0.13.0 lib/god/contacts/twitter.rb
god-0.12.1 lib/god/contacts/twitter.rb
god-0.12.0 lib/god/contacts/twitter.rb
firenxis-god-0.11.0 lib/god/contacts/twitter.rb
god-0.11.0 lib/god/contacts/twitter.rb