imified 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,7 @@
1
+ *.gem
2
+ *.swp
3
+ .bundle
4
+ Gemfile.lock
5
+ pkg/*
6
+ vendor/*
7
+ lib/imified.yml
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format documentation
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in imified.gemspec
4
+ gemspec
data/README.rdoc ADDED
@@ -0,0 +1,61 @@
1
+ == Imified
2
+
3
+ Easily IM enable your Ruby or Rails applications with one simple API.
4
+
5
+ The Imified gem aims to be as flexible as possible while helping you
6
+ easily integrate instant messaging into your application.
7
+
8
+ Imified was designed to be as simple as possible. For the first implementation
9
+ it will simply contain the public API methods specified on the Imified website.
10
+ (http://www.imified.com/developers/api)
11
+
12
+ == Create an Imified account
13
+
14
+ 1. Create your FREE accout at http://www.imified.com/account/sign_up.
15
+
16
+ 2. Create your bot.
17
+ Imified will ask you to provide the following information:
18
+
19
+ - Name
20
+ - Screen Name
21
+ - URL (Note: Leave this blank until you need it.)
22
+
23
+ 3. Create a screenname for your bot.
24
+ Choose one of the following services:
25
+
26
+ - Jabber (www.jabber.org)
27
+ - AIM (www.aim.com)
28
+ - MSN (signup.live.com)
29
+ - YAHOO (http://edit.yahoo.com/registration?.intl=us&new=1&.done=http%3A//mail.yahoo.com&.src=ym)
30
+ - Google Talk (www.google.com/talk)
31
+ - Twitter (www.twitter.com)
32
+
33
+ 4. Login to your imified bot and connect the bot to the newly created account.
34
+
35
+ == Installation
36
+
37
+ Install the gem:
38
+
39
+ gem install imified
40
+
41
+ Setup IMified when your application initializes:
42
+
43
+ Imified.setup do |config|
44
+ config.botkey = 'botkey of the bot you want to use'
45
+ config.email_address = 'your imified account email address'
46
+ config.password = 'your imified account password'
47
+ end
48
+
49
+ == Usage
50
+
51
+ # Send a message to a user or list of users.
52
+ Imified.send_message("Welcome to Imified", :to => 'userkey')
53
+
54
+ # Fetch the user details for a specific user.
55
+ Imified.get_user(userkey)
56
+
57
+ # Fetch a list of all of the users known to the bot.
58
+ Imified.get_all_users
59
+
60
+ # Update the status of your bot
61
+ Imified.update_status
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
data/imified.gemspec ADDED
@@ -0,0 +1,28 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "imified/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "imified"
7
+ s.version = Imified::VERSION
8
+ s.authors = ["Joe Karayusuf"]
9
+ s.email = ["jkarayusuf@gmail.com"]
10
+ s.homepage = "https://github.com/karayusuf/imified"
11
+ s.summary = %q{ API for sending Text/Instant Messages using IMified.com }
12
+ s.description = %q{ The IMified API exposes methods for sending messages,
13
+ fetching user details, and updating status. To get started,
14
+ you'll need to sign up for a free developer account at:
15
+ http://imified.com/account/signup }
16
+
17
+ s.rubyforge_project = "imified"
18
+
19
+ s.files = `git ls-files`.split("\n")
20
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
21
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
22
+ s.require_paths = ["lib"]
23
+
24
+ s.add_dependency 'activesupport', '2.3.11'
25
+
26
+ s.add_development_dependency 'rspec'
27
+
28
+ end
@@ -0,0 +1,39 @@
1
+ # request.rb
2
+ #
3
+ # Net::HTTP::Post wrapper
4
+ #
5
+ # All API calls for requesting user details and sending messages
6
+ # should be sent via HTTP POST to the following URL:
7
+ # https://www.imified.com/api/bot/.
8
+ #
9
+ # Authentication is managed using Basic HTTP authentication.
10
+ # Every request must include the Authorization HTTP header
11
+ # with your IMified username and password.
12
+ #
13
+ class Imified::Request < Net::HTTP::Post
14
+ URL = URI.parse(Imified::URL)
15
+
16
+ # Construct a Net::HTTP::Post object.
17
+ # Prepare basic authentication using the username and
18
+ # password specified in the configuration.
19
+ #
20
+ # == Usage
21
+ # Imified::Request.new
22
+ #
23
+ # @return[Net::HTTP::Post]
24
+ def initialize(api_method = 'getallusers')
25
+ Imified.validate_configuration!
26
+ super(URL.path)
27
+
28
+ self.basic_auth Imified.email_address, Imified.password
29
+ self.add_field 'apimethod', api_method
30
+ self.add_field 'botkey', Imified.botkey
31
+ end
32
+
33
+ # Submit the request to Imified.
34
+ def submit
35
+ http = Net::HTTP.new(URL.host, URL.port)
36
+ http.use_ssl = true
37
+ http.start { |send| send.request(self) }.body
38
+ end
39
+ end
@@ -0,0 +1,3 @@
1
+ module Imified
2
+ VERSION = "0.0.2"
3
+ end
data/lib/imified.rb ADDED
@@ -0,0 +1,120 @@
1
+ require 'active_support'
2
+ require 'net/https'
3
+ require 'uri'
4
+
5
+ module Imified
6
+ autoload :Request, 'imified/request'
7
+ autoload :User, 'imified/user'
8
+ autoload :Version, 'imified/version'
9
+
10
+ # Imified API url
11
+ URL = 'https://www.imified.com/api/bot/'
12
+
13
+ # User's unique botkey
14
+ mattr_accessor :botkey
15
+
16
+ # User's Imified account name
17
+ mattr_accessor :email_address
18
+
19
+ # User's Imified account password
20
+ mattr_accessor :password
21
+
22
+ # Default way to setup Imified.
23
+ # To be used during initialization.
24
+ #
25
+ # == Example:
26
+ #
27
+ # Imified.setup do |config|
28
+ # config.botkey = 'the bot you would like to use'
29
+ # config.email_address = 'your imified email address'
30
+ # config.password = 'your imified password'
31
+ # end
32
+ #
33
+ def self.setup
34
+ yield self
35
+ end
36
+
37
+ # Validate that the Imified module has been configured
38
+ # with the users account information. Raise an error
39
+ # containing instructions to properly configure the
40
+ # module.
41
+ #
42
+ def Imified.validate_configuration!
43
+ if Imified.botkey.nil? ||
44
+ Imified.email_address.nil? ||
45
+ Imified.password.nil?
46
+ raise ArgumentError, "Invalid Configuration.
47
+ In order to use the Imified API, you must
48
+ first run the setup and provide your account
49
+ information.
50
+
51
+ This can be done using the following syntax:
52
+
53
+ Imified.setup do |config|
54
+ config.botkey = 'your botkey'
55
+ config.email_address = 'your email address'
56
+ config.password = 'your password'
57
+ end"
58
+ end
59
+ end
60
+
61
+ # Fetch a list of all of the bots known users.
62
+ # Includes a total count of the users.
63
+ #
64
+ # == Example
65
+ #
66
+ # Imified.get_all_users
67
+ #
68
+ # == Return
69
+ #
70
+ # Successful Response:
71
+ # <rsp stat="ok">
72
+ # <users count="2">
73
+ # <user>
74
+ # <status>Online</status>
75
+ # <extendedstatus>Working on an IMified bot</extendedstatus>
76
+ # <userkey>123456789</userkey>
77
+ # <screenname>user_screenname</screenname> *deprecated
78
+ # <user>user_screenname</user>
79
+ # <network>AIM</network>
80
+ # <created>2007-09-26 13:30:25</created>
81
+ # <lastonline>2007-09-28 15:20:15</lastonline>
82
+ # <lastcall>2007-09-28 15:20:15</lastcall>
83
+ # </user>
84
+ # <user>
85
+ # <status>Offline</status>
86
+ # <extendedstatus></extendedstatus>
87
+ # <userkey>123456789</userkey>
88
+ # <screenname>user_screenname</screenname> *deprecated
89
+ # <user>user_screenname</user>
90
+ # <network>Jabber</network>
91
+ # <created>2007-09-26 13:30:25</created>
92
+ # <lastonline>2007-09-28 15:20:15</lastonline>
93
+ # <lastcall>2007-09-28 15:20:15</lastcall>
94
+ # </user>
95
+ # </users>
96
+ # </rsp>
97
+ #
98
+ # Failed Response:
99
+ # <rsp stat="fail">
100
+ # <err msg="error message text"/>
101
+ # </rsp>
102
+ #
103
+ def Imified.get_all_users
104
+ request = Imified::Request.new
105
+ response = request.submit
106
+ end
107
+
108
+ def Imified.get_user(userkey)
109
+ request = Imified::Request.new('getuser')
110
+ request.add_field 'userkey', userkey
111
+ response = request.submit
112
+ end
113
+
114
+ def Imified.send_message(msg, options)
115
+ request = Imified::Request.new('send')
116
+ request.add_field 'userkey', options[:to]
117
+ request.add_field 'msg', msg
118
+ response = request.submit
119
+ end
120
+ end
@@ -0,0 +1,144 @@
1
+ require 'spec_helper'
2
+
3
+ describe Imified do
4
+
5
+ it "should know the Imified URL" do
6
+ Imified::URL.should eql('https://www.imified.com/api/bot/')
7
+ end
8
+
9
+ context "when the user is specifying their accout information" do
10
+ before(:each) do
11
+ Imified.setup do |config|
12
+ config.botkey = 'my botkey'
13
+ config.email_address = 'my email address'
14
+ config.password = 'my super secret password'
15
+ end
16
+ end
17
+
18
+ it "should set the botkey to the specified value" do
19
+ Imified.botkey.should eql('my botkey')
20
+ end
21
+
22
+ it "should set the email address to the specified value" do
23
+ Imified.email_address.should eql('my email address')
24
+ end
25
+
26
+ it "should set the password to the specified value" do
27
+ Imified.password.should eql('my super secret password')
28
+ end
29
+
30
+ end
31
+
32
+ context "when sending a message to a user" do
33
+ let(:mock_request) { double('imified_request').as_null_object }
34
+ let(:mock_response) { double('imfiied_response').as_null_object }
35
+
36
+ before(:each) do
37
+ Imified::Request.stub(:new).and_return(mock_request)
38
+ mock_request.stub(:submit).and_return(mock_response)
39
+ end
40
+
41
+ it "should prepare a new request to 'send'" do
42
+ Imified::Request.
43
+ should_receive(:new).
44
+ with('send').
45
+ and_return(mock_request)
46
+ Imified.send_message('Rspec message', :to => 'userkey')
47
+ end
48
+
49
+ it "should add the specified message to the request" do
50
+ mock_request.
51
+ should_receive(:add_field).
52
+ with('msg', 'a message to send')
53
+ Imified.send_message('a message to send', :to => 'a user')
54
+ end
55
+
56
+ it "should add the specified userkey to the request" do
57
+ mock_request.
58
+ should_receive(:add_field).
59
+ with('userkey', 'someones userkey')
60
+ Imified.send_message('A Message', :to => 'someones userkey')
61
+ end
62
+
63
+ it "should submit the request" do
64
+ mock_request.should_receive(:submit)
65
+ Imified.send_message('A Message', :to => 'someones userkey')
66
+ end
67
+ end
68
+
69
+ context "when fetching a list of the bot's users" do
70
+ let(:mock_request) { double('imified_request').as_null_object }
71
+ let(:mock_response) { double('imfiied_response').as_null_object }
72
+
73
+ before(:each) do
74
+ Imified::Request.stub(:new).and_return(mock_request)
75
+ mock_request.stub(:submit).and_return(mock_response)
76
+ end
77
+
78
+ it "should prepare a new request" do
79
+ Imified::Request.should_receive(:new)
80
+ Imified.get_all_users
81
+ end
82
+
83
+ it "should submit the request" do
84
+ mock_request.should_receive(:submit)
85
+ Imified.get_all_users
86
+ end
87
+ end
88
+
89
+ context "when fetching details for a specified user" do
90
+ let(:mock_request) { double('imified_request').as_null_object }
91
+ let(:mock_response) { double('imified_response').as_null_object }
92
+
93
+ before(:each) do
94
+ Imified::Request.stub(:new).and_return(mock_request)
95
+ mock_request.stub(:submit).and_return(mock_response)
96
+ end
97
+
98
+ it "should prepare a new request to 'getuser'" do
99
+ Imified::Request.
100
+ should_receive(:new).
101
+ with('getuser')
102
+ Imified.get_user('someones userkey')
103
+ end
104
+
105
+ it "should add the specified userkey to the request" do
106
+ mock_request.
107
+ should_receive(:add_field).
108
+ with('userkey', 'someones userkey')
109
+ Imified.get_user('someones userkey')
110
+ end
111
+
112
+ it "should submit the request" do
113
+ mock_request.should_receive(:submit)
114
+ Imified.get_user('userkey')
115
+ end
116
+ end
117
+
118
+ context "when validating the configuration" do
119
+ it "should not raise an error if all of the values are set" do
120
+ Imified.setup do |config|
121
+ config.botkey = 'botkey'
122
+ config.email_address = 'test email'
123
+ config.password = 'super secret'
124
+ end
125
+
126
+ expect { Imified.validate_configuration! }.to_not raise_error(ArgumentError)
127
+ end
128
+
129
+ it "should raise an error if the botkey has not been specified" do
130
+ Imified.stub(:botkey).and_return(nil)
131
+ expect { Imified.validate_configuration! }.to raise_error(ArgumentError)
132
+ end
133
+
134
+ it "should raise an error if the email address has not been specified" do
135
+ Imified.stub(:email_address).and_return(nil)
136
+ expect { Imified.validate_configuration! }.to raise_error(ArgumentError)
137
+ end
138
+
139
+ it "should raise an error if the password has not been specified" do
140
+ Imified.stub(:password).and_return(nil)
141
+ expect { Imified.validate_configuration! }.to raise_error(ArgumentError)
142
+ end
143
+ end
144
+ end
@@ -0,0 +1,58 @@
1
+ require 'spec_helper'
2
+
3
+ describe Imified::Request do
4
+
5
+ it "should validate the user's imified configuration" do
6
+ Imified.
7
+ should_receive(:validate_configuration!).
8
+ and_return(nil)
9
+ Imified::Request.new
10
+ end
11
+
12
+ it "should use the imified url" do
13
+ Imified::Request::URL.should == URI.parse('https://www.imified.com/api/bot/')
14
+ end
15
+
16
+ it "should use basic authentication" do
17
+ Imified::Request.any_instance.
18
+ should_receive(:basic_auth).
19
+ with('rspec_email_address', 'rspec_password')
20
+ Imified::Request.new
21
+ end
22
+
23
+ it "should default to the 'getallusers' api method" do
24
+ request = Imified::Request.new
25
+ request.get_fields('apimethod').should eql(['getallusers'])
26
+ end
27
+
28
+ it "should allow the 'getuser' method to be used" do
29
+ request = Imified::Request.new('getuser')
30
+ request.get_fields('apimethod').should eql(['getuser'])
31
+ end
32
+
33
+ context "when being submitted with valid account information" do
34
+ let(:mock_net_http) { double('net_http').as_null_object }
35
+ let(:mock_net_http_response) { double('net_http_response').as_null_object }
36
+
37
+ before(:each) { Net::HTTP.stub!(:new).and_return(mock_net_http) }
38
+
39
+ it "should build an HTTP request" do
40
+ Net::HTTP.should_receive(:new).
41
+ with(Imified::Request::URL.host, Imified::Request::URL.port)
42
+ Imified::Request.new.submit
43
+ end
44
+
45
+ it "should use ssl" do
46
+ mock_net_http.should_receive(:use_ssl=).with(true)
47
+ Imified::Request.new.submit
48
+ end
49
+
50
+ it "should send the request" do
51
+ mock_net_http.should_receive(:start).and_return(mock_net_http_response)
52
+ mock_net_http_response.should_receive(:body)
53
+ Imified::Request.new.submit
54
+ end
55
+ end
56
+
57
+
58
+ end
@@ -0,0 +1,15 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+
4
+ require 'imified'
5
+
6
+ RSpec.configure do |config|
7
+ config.mock_framework = :rspec
8
+
9
+ # Default configuration for tests.
10
+ config.before(:each) do
11
+ Imified.email_address = 'rspec_email_address'
12
+ Imified.password = 'rspec_password'
13
+ Imified.botkey = 'rspec_botkey'
14
+ end
15
+ end
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: imified
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Joe Karayusuf
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-08-07 00:00:00.000000000 -04:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: activesupport
17
+ requirement: &70288113780800 !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - =
21
+ - !ruby/object:Gem::Version
22
+ version: 2.3.11
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: *70288113780800
26
+ - !ruby/object:Gem::Dependency
27
+ name: rspec
28
+ requirement: &70288113780260 !ruby/object:Gem::Requirement
29
+ none: false
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: *70288113780260
37
+ description: ! " The IMified API exposes methods for sending messages,\n fetching
38
+ user details, and updating status. To get started,\n you'll
39
+ need to sign up for a free developer account at:\n http://imified.com/account/signup "
40
+ email:
41
+ - jkarayusuf@gmail.com
42
+ executables: []
43
+ extensions: []
44
+ extra_rdoc_files: []
45
+ files:
46
+ - .gitignore
47
+ - .rspec
48
+ - Gemfile
49
+ - README.rdoc
50
+ - Rakefile
51
+ - imified.gemspec
52
+ - lib/imified.rb
53
+ - lib/imified/request.rb
54
+ - lib/imified/version.rb
55
+ - spec/imified_spec.rb
56
+ - spec/request_spec.rb
57
+ - spec/spec_helper.rb
58
+ has_rdoc: true
59
+ homepage: https://github.com/karayusuf/imified
60
+ licenses: []
61
+ post_install_message:
62
+ rdoc_options: []
63
+ require_paths:
64
+ - lib
65
+ required_ruby_version: !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ! '>='
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ requirements: []
78
+ rubyforge_project: imified
79
+ rubygems_version: 1.6.2
80
+ signing_key:
81
+ specification_version: 3
82
+ summary: API for sending Text/Instant Messages using IMified.com
83
+ test_files:
84
+ - spec/imified_spec.rb
85
+ - spec/request_spec.rb
86
+ - spec/spec_helper.rb