mattpuchlerz-rjab 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ coverage/*
2
+ pkg/*
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Matt Puchlerz
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.markdown ADDED
@@ -0,0 +1,51 @@
1
+ RJab: a Ruby library for Jabbify
2
+ ================================
3
+
4
+ [Jabbify][jabbify] is a simple messaging service that one can plug into their website with a few lines of Javascript. At the heart of Jabbify is a centralized, ready-to-use Comet server.
5
+
6
+ You can [utilize their Comet service][jabbify_comet] via the Javascript API, or by creating a simple GET or POST request along with the necessary parameters. This library attempts to simplify creation of that request.
7
+
8
+ Installing the Gem
9
+ ------------------
10
+
11
+ $ sudo gem install mattpuchlerz-rjab -s http://gems.github.com
12
+
13
+ Utilizing the Library
14
+ ---------------------
15
+
16
+ require 'rubygems'
17
+ require 'jabbify'
18
+
19
+ For one-off message deliveries, you might find it easiest to use the class method:
20
+
21
+ Jabbify::Comet.deliver(
22
+ :api_key => 'YourApiKeyGoesHere',
23
+ :type => :message,
24
+ :action => :create,
25
+ :name => 'John Doe',
26
+ :message => 'This is the message!',
27
+ :to => 'Jane Doe',
28
+ )
29
+
30
+ Or you could always instantiate an instance, and deliver when you're ready:
31
+
32
+ defaults = {
33
+ :api_key => 'YourApiKeyGoesHere',
34
+ :type => :message,
35
+ :action => :create,
36
+ :name => 'The Server'
37
+ }
38
+
39
+ @comet = Jabbify::Comet.new defaults
40
+ @comet.message = "The time is now #{ Time.now }"
41
+
42
+ if @comet.deliver
43
+ # do something
44
+ else
45
+ # do something else
46
+ end
47
+
48
+
49
+
50
+ [jabbify]: http://jabbify.com
51
+ [jabbify_comet]: https://jabbify.com/home/comet_service
data/Rakefile ADDED
@@ -0,0 +1,53 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'spec/rake/spectask'
4
+ require 'jeweler'
5
+
6
+
7
+
8
+ Jeweler::Tasks.new do |gem|
9
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
10
+
11
+ gem.name = 'rjab'
12
+ gem.summary = %Q{A Ruby library for interacting with Jabbify.}
13
+ gem.description = %Q{A Ruby library for interacting with Jabbify. Simplifies the process of delivering messages to Jabbify's Comet server.}
14
+ gem.email = 'matt@puchlerz.com'
15
+ gem.homepage = 'http://github.com/mattpuchlerz/rjab'
16
+ gem.authors = [ 'Matt Puchlerz' ]
17
+ gem.add_dependency 'adamwiggins-rest-client', '>= 0.9.2'
18
+ end
19
+
20
+
21
+
22
+ spec_files = FileList['spec/**/*_spec.rb']
23
+
24
+ desc 'Run all specs'
25
+ Spec::Rake::SpecTask.new(:spec) do |task|
26
+ task.spec_opts = ['--colour --format progress --loadby mtime --reverse']
27
+ task.spec_files = spec_files
28
+ end
29
+ task :default => :spec
30
+
31
+ desc 'Run all examples with RCov'
32
+ Spec::Rake::SpecTask.new(:rcov) do |task|
33
+ task.rcov = true
34
+ task.spec_opts = ['--colour --format progress --loadby mtime --reverse']
35
+ task.spec_files = spec_files
36
+ end
37
+
38
+
39
+
40
+ # require 'rake/rdoctask'
41
+ # Rake::RDocTask.new do |rdoc|
42
+ # if File.exist?('VERSION.yml')
43
+ # config = YAML.load(File.read('VERSION.yml'))
44
+ # version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
45
+ # else
46
+ # version = ""
47
+ # end
48
+ #
49
+ # rdoc.rdoc_dir = 'rdoc'
50
+ # rdoc.title = "rjab #{version}"
51
+ # rdoc.rdoc_files.include('README*')
52
+ # rdoc.rdoc_files.include('lib/**/*.rb')
53
+ # end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.1
@@ -0,0 +1,58 @@
1
+ require 'rubygems'
2
+ require 'restclient' # http://github.com/adamwiggins/rest-client
3
+
4
+ module Jabbify
5
+ class Comet
6
+
7
+ attr_accessor :action, :api_key, :message, :name, :to, :type
8
+
9
+ def initialize(options = {})
10
+ options.each_pair { |key, val| send("#{ key }=", val) }
11
+ end
12
+
13
+ def action=(action)
14
+ @action = action.to_sym
15
+ end
16
+
17
+ def deliver
18
+ return false unless valid?
19
+ begin
20
+ RestClient.post jabbify_uri, uri_params
21
+ true
22
+ rescue
23
+ false
24
+ end
25
+ end
26
+
27
+ def jabbify_uri
28
+ 'https://jabbify.com:8443/message_push'
29
+ end
30
+
31
+ def type=(type)
32
+ @type = type.to_sym
33
+ end
34
+
35
+ def uri_params
36
+ {
37
+ :action => action,
38
+ :key => api_key,
39
+ :message => message,
40
+ :name => name,
41
+ :to => to,
42
+ :type => type
43
+ }.reject { |key, val| val.nil? }
44
+ end
45
+
46
+ def valid?
47
+ %w[ api_key name message ].each do |attribute|
48
+ return false if send(attribute).nil?
49
+ end
50
+ true
51
+ end
52
+
53
+ def self.deliver(options)
54
+ new(options).deliver
55
+ end
56
+
57
+ end
58
+ end
data/lib/jabbify.rb ADDED
@@ -0,0 +1,3 @@
1
+ $LOAD_PATH << File.join( File.dirname(__FILE__), 'jabbify' )
2
+
3
+ require 'comet'
data/rjab.gemspec ADDED
@@ -0,0 +1,50 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{rjab}
5
+ s.version = "0.1.1"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Matt Puchlerz"]
9
+ s.date = %q{2009-05-22}
10
+ s.description = %q{A Ruby library for interacting with Jabbify. Simplifies the process of delivering messages to Jabbify's Comet server.}
11
+ s.email = %q{matt@puchlerz.com}
12
+ s.extra_rdoc_files = [
13
+ "LICENSE",
14
+ "README.markdown"
15
+ ]
16
+ s.files = [
17
+ ".gitignore",
18
+ "LICENSE",
19
+ "README.markdown",
20
+ "Rakefile",
21
+ "VERSION",
22
+ "lib/jabbify.rb",
23
+ "lib/jabbify/comet.rb",
24
+ "rjab.gemspec",
25
+ "spec/jabbify/comet_spec.rb",
26
+ "spec/spec_helper.rb"
27
+ ]
28
+ s.homepage = %q{http://github.com/mattpuchlerz/rjab}
29
+ s.rdoc_options = ["--charset=UTF-8"]
30
+ s.require_paths = ["lib"]
31
+ s.rubygems_version = %q{1.3.3}
32
+ s.summary = %q{A Ruby library for interacting with Jabbify.}
33
+ s.test_files = [
34
+ "spec/jabbify/comet_spec.rb",
35
+ "spec/spec_helper.rb"
36
+ ]
37
+
38
+ if s.respond_to? :specification_version then
39
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
40
+ s.specification_version = 3
41
+
42
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
43
+ s.add_runtime_dependency(%q<adamwiggins-rest-client>, [">= 0.9.2"])
44
+ else
45
+ s.add_dependency(%q<adamwiggins-rest-client>, [">= 0.9.2"])
46
+ end
47
+ else
48
+ s.add_dependency(%q<adamwiggins-rest-client>, [">= 0.9.2"])
49
+ end
50
+ end
@@ -0,0 +1,164 @@
1
+ require File.join( File.dirname(__FILE__), *%w[ .. spec_helper ] )
2
+
3
+ describe Jabbify::Comet do
4
+
5
+ def defaults(options = {})
6
+ {
7
+ :action => :i_am_the_action,
8
+ :api_key => 'qwer1234qwer1234',
9
+ :message => 'This is the message!',
10
+ :name => 'John Doe',
11
+ :to => 'Jane Doe',
12
+ :type => :i_am_the_type,
13
+ }.merge(options)
14
+ end
15
+
16
+ context "reading and writing attributes" do
17
+
18
+ before(:each) do
19
+ @comet = Jabbify::Comet.new
20
+ end
21
+
22
+ it "should be able to read/write an 'api_key' attribute" do
23
+ @comet.api_key = 'qwer1234qwer1234'
24
+ @comet.api_key.should == 'qwer1234qwer1234'
25
+ end
26
+
27
+ it "should be able to read/write a 'type' attribute as a symbol" do
28
+ @comet.type = :i_am_the_type
29
+ @comet.type.should == :i_am_the_type
30
+ @comet.type = 'i_am_the_type'
31
+ @comet.type.should == :i_am_the_type
32
+ end
33
+
34
+ it "should be able to read/write an 'action' attribute as a symbol" do
35
+ @comet.action = :i_am_the_action
36
+ @comet.action.should == :i_am_the_action
37
+ @comet.action = 'i_am_the_action'
38
+ @comet.action.should == :i_am_the_action
39
+ end
40
+
41
+ it "should be able to read/write a 'name' attribute" do
42
+ @comet.name = 'John Doe'
43
+ @comet.name.should == 'John Doe'
44
+ end
45
+
46
+ it "should be able to read/write a 'message' attribute" do
47
+ @comet.message = 'This is the message!'
48
+ @comet.message.should == 'This is the message!'
49
+ end
50
+
51
+ it "should be able to read/write a 'to' attribute" do
52
+ @comet.to = 'Jane Doe'
53
+ @comet.to.should == 'Jane Doe'
54
+ end
55
+
56
+ it "should be able to write any attribute via a hash passed in during initialization" do
57
+ @comet = Jabbify::Comet.new defaults
58
+ @comet.api_key.should == 'qwer1234qwer1234'
59
+ @comet.type.should == :i_am_the_type
60
+ @comet.action.should == :i_am_the_action
61
+ @comet.name.should == 'John Doe'
62
+ @comet.message.should == 'This is the message!'
63
+ @comet.to.should == 'Jane Doe'
64
+ end
65
+
66
+ end
67
+
68
+ context "determining the validity of the attributes" do
69
+
70
+ it "should be able to check the validity of the attributes" do
71
+ @comet = Jabbify::Comet.new
72
+ @comet.should respond_to(:valid?)
73
+ end
74
+
75
+ it "should not be valid if the 'api_key' attribute is blank" do
76
+ @comet = Jabbify::Comet.new defaults(:api_key => nil)
77
+ @comet.should_not be_valid
78
+ end
79
+
80
+ it "should not be valid if the 'name' attribute is blank" do
81
+ @comet = Jabbify::Comet.new defaults(:name => nil)
82
+ @comet.should_not be_valid
83
+ end
84
+
85
+ it "should not be valid if the 'message' attribute is blank" do
86
+ @comet = Jabbify::Comet.new defaults(:message => nil)
87
+ @comet.should_not be_valid
88
+ end
89
+
90
+ it "should be valid if all attributes are provided" do
91
+ @comet = Jabbify::Comet.new defaults
92
+ @comet.should be_valid
93
+ end
94
+
95
+ end
96
+
97
+ context "constructing the Jabbify URI" do
98
+
99
+ it "should be able to get the Jabbify URI" do
100
+ @comet = Jabbify::Comet.new
101
+ URI.parse(@comet.jabbify_uri).should_not raise_error(URI::InvalidURIError)
102
+ end
103
+
104
+ it "should be able to get a hash of all the needed URI parameters" do
105
+ @comet = Jabbify::Comet.new defaults
106
+ @comet.uri_params.should ==
107
+ {
108
+ :action => :i_am_the_action,
109
+ :key => 'qwer1234qwer1234',
110
+ :message => 'This is the message!',
111
+ :name => 'John Doe',
112
+ :to => 'Jane Doe',
113
+ :type => :i_am_the_type,
114
+ }
115
+ end
116
+
117
+ it "should not include any URI parameters that are blank" do
118
+ @comet = Jabbify::Comet.new defaults(:to => nil)
119
+ @comet.uri_params.should ==
120
+ {
121
+ :action => :i_am_the_action,
122
+ :key => 'qwer1234qwer1234',
123
+ :message => 'This is the message!',
124
+ :name => 'John Doe',
125
+ :type => :i_am_the_type,
126
+ }
127
+ end
128
+
129
+ end
130
+
131
+ context "delivering messages" do
132
+
133
+ it "should be able to deliver messages" do
134
+ @comet = Jabbify::Comet.new
135
+ @comet.should respond_to(:deliver)
136
+ end
137
+
138
+ it "should not deliver if any attributes are invalid" do
139
+ @comet = Jabbify::Comet.new defaults(:api_key => nil)
140
+ @comet.deliver.should == false
141
+ end
142
+
143
+ it "should not deliver if the request fails" do
144
+ RestClient.should_receive(:post).and_raise(RuntimeError)
145
+ @comet = Jabbify::Comet.new defaults
146
+ @comet.deliver.should == false
147
+ end
148
+
149
+ it "should deliver if the request succeeds" do
150
+ RestClient.should_receive(:post).and_return('body of response')
151
+ @comet = Jabbify::Comet.new defaults
152
+ @comet.deliver.should == true
153
+ end
154
+
155
+ it "should be able to handle one-off deliveries via a class method" do
156
+ comet = mock('Jabbify::Comet')
157
+ comet.should_receive(:deliver).and_return(true)
158
+ Jabbify::Comet.should_receive(:new).with(defaults).and_return(comet)
159
+ Jabbify::Comet.deliver(defaults).should == true
160
+ end
161
+
162
+ end
163
+
164
+ end
@@ -0,0 +1,4 @@
1
+ require 'rubygems'
2
+ require 'spec'
3
+
4
+ require File.join( File.dirname(__FILE__), *%w[ .. lib jabbify ] )
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mattpuchlerz-rjab
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Matt Puchlerz
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-05-22 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: adamwiggins-rest-client
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 0.9.2
24
+ version:
25
+ description: A Ruby library for interacting with Jabbify. Simplifies the process of delivering messages to Jabbify's Comet server.
26
+ email: matt@puchlerz.com
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - LICENSE
33
+ - README.markdown
34
+ files:
35
+ - .gitignore
36
+ - LICENSE
37
+ - README.markdown
38
+ - Rakefile
39
+ - VERSION
40
+ - lib/jabbify.rb
41
+ - lib/jabbify/comet.rb
42
+ - rjab.gemspec
43
+ - spec/jabbify/comet_spec.rb
44
+ - spec/spec_helper.rb
45
+ has_rdoc: false
46
+ homepage: http://github.com/mattpuchlerz/rjab
47
+ post_install_message:
48
+ rdoc_options:
49
+ - --charset=UTF-8
50
+ require_paths:
51
+ - lib
52
+ required_ruby_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: "0"
57
+ version:
58
+ required_rubygems_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: "0"
63
+ version:
64
+ requirements: []
65
+
66
+ rubyforge_project:
67
+ rubygems_version: 1.2.0
68
+ signing_key:
69
+ specification_version: 3
70
+ summary: A Ruby library for interacting with Jabbify.
71
+ test_files:
72
+ - spec/jabbify/comet_spec.rb
73
+ - spec/spec_helper.rb