Module: Imified

Defined in:
lib/imified.rb,
lib/imified/version.rb

Defined Under Namespace

Classes: Request, Userkey

Constant Summary collapse

URL =

Imified API url

'https://www.imified.com/api/bot/'
VERSION =
"0.0.4"

Class Method Summary collapse

Class Method Details

.get_all_usersObject

Fetch a list of all of the bots known users. Includes a total count of the users.

Example

Imified.get_all_users

Return

Successful Response:
  <rsp stat="ok">
    <users count="2">
      <user>
        <status>Online</status>
        <extendedstatus>Working on an IMified bot</extendedstatus>
        <userkey>123456789</userkey>
        <screenname>user_screenname</screenname> *deprecated
        <user>user_screenname</user>
        <network>AIM</network>
        <created>2007-09-26 13:30:25</created>
        <lastonline>2007-09-28 15:20:15</lastonline>
        <lastcall>2007-09-28 15:20:15</lastcall>
      </user>
      <user>
        <status>Offline</status>
        <extendedstatus></extendedstatus>
        <userkey>123456789</userkey>
        <screenname>user_screenname</screenname> *deprecated
        <user>user_screenname</user>
        <network>Jabber</network>
        <created>2007-09-26 13:30:25</created>
        <lastonline>2007-09-28 15:20:15</lastonline>
        <lastcall>2007-09-28 15:20:15</lastcall>
      </user>
    </users>
  </rsp>

Failed Response:
  <rsp stat="fail">
    <err msg="error message text"/>
  </rsp>


107
108
109
110
111
# File 'lib/imified.rb', line 107

def Imified.get_all_users
  request = Imified::Request.new
  response = request.submit
  self.user_list = Nokogiri::XML(response)
end

.get_user(userkey) ⇒ Object



113
114
115
116
117
# File 'lib/imified.rb', line 113

def Imified.get_user(userkey)
  request = Imified::Request.new('getuser')
  request.add_field 'userkey', userkey
  response = request.submit
end

.send_message(msg, options) ⇒ Object



119
120
121
122
123
124
# File 'lib/imified.rb', line 119

def Imified.send_message(msg, options)
  request = Imified::Request.new('send')
  request.add_field 'userkey', Imified::Userkey.find(options[:to])
  request.add_field 'msg', msg
  response = request.submit
end

.setup {|_self| ... } ⇒ Object

Default way to setup Imified. To be used during initialization.

Example:

Imified.setup do |config|
  config.botkey = 'the bot you would like to use'
  config.email_address = 'your imified email address'
  config.password = 'your imified password'
end

Yields:

  • (_self)

Yield Parameters:

  • _self (Imified)

    the object that the method was called on



37
38
39
# File 'lib/imified.rb', line 37

def self.setup
  yield self
end

.validate_configuration!Object

Validate that the Imified module has been configured with the users account information. Raise an error containing instructions to properly configure the module.



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/imified.rb', line 46

def Imified.validate_configuration!
  if Imified.botkey.nil? ||
     Imified.email_address.nil? ||
     Imified.password.nil?
    raise ArgumentError, "Invalid Configuration.
      In order to use the Imified API, you must
      first run the setup and provide your account
      information.

      This can be done using the following syntax:

      Imified.setup do |config|
        config.botkey = 'your botkey'
        config.email_address = 'your email address'
        config.password = 'your password'
      end"
  end
end