messenger 0.5.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -10,7 +10,7 @@ end
10
10
 
11
11
  task :default => :test
12
12
 
13
- require 'rake/rdoctask'
13
+ require 'rdoc/task'
14
14
 
15
15
  Rake::RDocTask.new do |rdoc|
16
16
  version = File.exist?('VERSION') ? File.read('VERSION') : ""
data/bin/messenger CHANGED
@@ -60,12 +60,6 @@ EOS
60
60
  opt :jabber_id, "The jabber ID to connect as (user@example.com)", :type => String
61
61
  opt :jabber_password, "The password for your jabber id", :type => String
62
62
 
63
- # Notifo options
64
- opt :notifo_api_username, "The service's API username", :type => String
65
- opt :notifo_api_secret, "The service's API secret", :type => String
66
- opt :notifo_title, "The notificaiton title", :type => String
67
- opt :notifo_url, "Open this URL", :type => String
68
-
69
63
  # CLI options
70
64
  # opt :silent, "Don't print anything to stdout", :default => false
71
65
  # opt :verbose, "Print verbose output on success", :default => false
data/lib/messenger.rb CHANGED
@@ -5,5 +5,4 @@ require 'messenger/email'
5
5
  require 'messenger/web'
6
6
  require 'messenger/campfire'
7
7
  require 'messenger/jabber'
8
- require 'messenger/notifo'
9
8
  require 'messenger/version'
@@ -34,7 +34,7 @@ class Messenger::Campfire
34
34
  private
35
35
 
36
36
  def self.matcher(url)
37
- url.match(/^campfire(-ssl)?:\/\/([^:]+):([^@]+)@([^\.]+).campfirenow.com/)[1,4]
37
+ url.match(/\Acampfire(-ssl)?:\/\/([^:]+):([^@]+)@([^\.]+).campfirenow.com/)[1,4]
38
38
  end
39
39
 
40
40
  def self.success?(response)
@@ -3,7 +3,7 @@ require 'mail'
3
3
  class Messenger::Email
4
4
 
5
5
  def self.valid_url?(url)
6
- !!url.match(/^(mailto:)?[^@]+@.*$/)
6
+ !!url.match(/\A(mailto:)?[^@]+@.*\Z/)
7
7
  end
8
8
 
9
9
  # URL format:
@@ -16,7 +16,7 @@ class Messenger::Email
16
16
  raise Messenger::URLError, "The URL provided is invalid" unless valid_url?(url)
17
17
  mail = Mail.new do
18
18
  from options[:email_from]
19
- to url.sub(/mailto:/, '')
19
+ to url.sub(/\Amailto:/, '')
20
20
  subject options[:email_subject]
21
21
  body message
22
22
  end
@@ -34,11 +34,10 @@ module Messenger
34
34
  # twitter://username
35
35
  # aim://username
36
36
  case url
37
- when /^http/ then :http
38
- when /^campfire/ then :campfire
39
- when /^jabber/ then :jabber
40
- when /^notifo/ then :notifo
41
- when /^mailto|@+/ then :email
37
+ when /\Ahttp/ then :http
38
+ when /\Acampfire/ then :campfire
39
+ when /\Ajabber/ then :jabber
40
+ when /\Amailto|@+/ then :email
42
41
  end
43
42
  end
44
43
 
@@ -48,7 +47,6 @@ module Messenger
48
47
  when :http then Messenger::Web
49
48
  when :campfire then Messenger::Campfire
50
49
  when :jabber then Messenger::Jabber
51
- when :notifo then Messenger::Notifo
52
50
  else
53
51
  raise Messenger::ProtocolError, "Malformed service URL: #{url}. Either this syntax is wrong or this service type is not yet implemented."
54
52
  end
@@ -1,3 +1,3 @@
1
1
  module Messenger
2
- VERSION = '0.5.0'
2
+ VERSION = '0.6.0'
3
3
  end
data/lib/messenger/web.rb CHANGED
@@ -1,11 +1,12 @@
1
+ require 'addressable/uri'
1
2
  require 'httparty'
2
3
  require 'cgi'
3
4
 
4
5
  class Messenger::Web
5
6
 
6
7
  def self.valid_url?(url)
7
- !!URI.parse(url)
8
- rescue URI::InvalidURIError
8
+ !!Addressable::URI.parse(url)
9
+ rescue Addressable::URI::InvalidURIError
9
10
  false
10
11
  end
11
12
 
@@ -18,21 +19,20 @@ class Messenger::Web
18
19
  raise Messenger::URLError, "The URL provided is invalid" unless valid_url?(url)
19
20
  options = options.dup
20
21
  method = options.delete(:method) || :post
21
- uri = URI.parse(url)
22
+ uri = Addressable::URI.parse(url)
22
23
  user = CGI.unescape(uri.user) if uri.user
23
24
  password = CGI.unescape(uri.password) if uri.password
24
25
  options = options.merge(:basic_auth => {:username => user, :password => password}) if user || password
25
- uri.user = nil if user
26
- uri.password = nil if password
26
+ uri.userinfo = nil if user || password
27
27
  response = HTTParty.send(method, uri.to_s, options.merge(:body => body))
28
28
  Messenger::Result.new(success?(response), response)
29
29
  end
30
30
 
31
31
  def self.obfuscate(url)
32
32
  raise Messenger::URLError, "The URL provided is invalid" unless valid_url?(url)
33
- path = URI.parse(url)
33
+ path = Addressable::URI.parse(url)
34
34
  if path.password
35
- url.sub(/#{path.password}/, 'xxxx')
35
+ url.sub(/#{Regexp.escape(path.password)}/, 'xxxx')
36
36
  else
37
37
  url
38
38
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: messenger
3
3
  version: !ruby/object:Gem::Version
4
- hash: 11
4
+ hash: 7
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 5
8
+ - 6
9
9
  - 0
10
- version: 0.5.0
10
+ version: 0.6.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Brandon Arbini
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2012-04-17 00:00:00 Z
19
+ date: 2013-01-11 00:00:00 Z
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
22
  name: scashin133-xmpp4r-simple
@@ -75,7 +75,7 @@ dependencies:
75
75
  type: :runtime
76
76
  version_requirements: *id004
77
77
  - !ruby/object:Gem::Dependency
78
- name: shoulda
78
+ name: addressable
79
79
  prerelease: false
80
80
  requirement: &id005 !ruby/object:Gem::Requirement
81
81
  none: false
@@ -86,10 +86,10 @@ dependencies:
86
86
  segments:
87
87
  - 0
88
88
  version: "0"
89
- type: :development
89
+ type: :runtime
90
90
  version_requirements: *id005
91
91
  - !ruby/object:Gem::Dependency
92
- name: mocha
92
+ name: shoulda
93
93
  prerelease: false
94
94
  requirement: &id006 !ruby/object:Gem::Requirement
95
95
  none: false
@@ -103,7 +103,7 @@ dependencies:
103
103
  type: :development
104
104
  version_requirements: *id006
105
105
  - !ruby/object:Gem::Dependency
106
- name: webmock
106
+ name: mocha
107
107
  prerelease: false
108
108
  requirement: &id007 !ruby/object:Gem::Requirement
109
109
  none: false
@@ -116,6 +116,48 @@ dependencies:
116
116
  version: "0"
117
117
  type: :development
118
118
  version_requirements: *id007
119
+ - !ruby/object:Gem::Dependency
120
+ name: webmock
121
+ prerelease: false
122
+ requirement: &id008 !ruby/object:Gem::Requirement
123
+ none: false
124
+ requirements:
125
+ - - ">="
126
+ - !ruby/object:Gem::Version
127
+ hash: 3
128
+ segments:
129
+ - 0
130
+ version: "0"
131
+ type: :development
132
+ version_requirements: *id008
133
+ - !ruby/object:Gem::Dependency
134
+ name: rake
135
+ prerelease: false
136
+ requirement: &id009 !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ">="
140
+ - !ruby/object:Gem::Version
141
+ hash: 3
142
+ segments:
143
+ - 0
144
+ version: "0"
145
+ type: :development
146
+ version_requirements: *id009
147
+ - !ruby/object:Gem::Dependency
148
+ name: rdoc
149
+ prerelease: false
150
+ requirement: &id010 !ruby/object:Gem::Requirement
151
+ none: false
152
+ requirements:
153
+ - - ">="
154
+ - !ruby/object:Gem::Version
155
+ hash: 3
156
+ segments:
157
+ - 0
158
+ version: "0"
159
+ type: :development
160
+ version_requirements: *id010
119
161
  description: "Messenger: easy message sending for various protocols."
120
162
  email: brandon@zencoder.com
121
163
  executables:
@@ -131,7 +173,6 @@ files:
131
173
  - lib/messenger/errors.rb
132
174
  - lib/messenger/jabber.rb
133
175
  - lib/messenger/messenger.rb
134
- - lib/messenger/notifo.rb
135
176
  - lib/messenger/result.rb
136
177
  - lib/messenger/version.rb
137
178
  - lib/messenger/web.rb
@@ -169,9 +210,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
169
210
  requirements: []
170
211
 
171
212
  rubyforge_project: messenger
172
- rubygems_version: 1.8.17
213
+ rubygems_version: 1.8.24
173
214
  signing_key:
174
215
  specification_version: 3
175
216
  summary: "Messenger: easy message sending"
176
217
  test_files: []
177
218
 
219
+ has_rdoc:
@@ -1,43 +0,0 @@
1
- require 'httparty'
2
- require 'json'
3
-
4
- class Messenger::Notifo
5
-
6
- def self.valid_url?(url)
7
- !!url.match(/^notifo:\/\/.+$/)
8
- end
9
-
10
- # URL format:
11
- # notifo://username
12
- #
13
- # Options:
14
- # :notifo_api_username => The service's API username
15
- # :notifo_api_secret => The service's API secret
16
- # :notifo_title => The notificaiton title
17
- # :notifo_url => Open this URL
18
- def self.deliver(url, message, options={})
19
- raise Messenger::URLError, "The URL provided is invalid" unless valid_url?(url)
20
- username = matcher(url)
21
- response = HTTParty.post("https://api.notifo.com/v1/send_notification",
22
- :body => { :to => username, :msg => message, :title => options[:notifo_title], :uri => options[:notifo_url] },
23
- :basic_auth => {:username => options[:notifo_api_username], :password => options[:notifo_api_secret]})
24
- Messenger::Result.new(success?(response), response)
25
- end
26
-
27
- def self.obfuscate(url)
28
- raise Messenger::URLError, "The URL provided is invalid" unless valid_url?(url)
29
- url
30
- end
31
-
32
-
33
- private
34
-
35
- def self.matcher(url)
36
- url.match(/^notifo:\/\/(.+)/)[1]
37
- end
38
-
39
- def self.success?(response)
40
- response.code == 200
41
- end
42
-
43
- end