fastprowl 0.2 → 0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +2 -2
- data/README.markdown +7 -9
- data/fastprowl.gemspec +1 -1
- data/lib/fastprowl.rb +22 -17
- metadata +34 -13
data/LICENSE
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
Copyright (c)
|
1
|
+
Copyright (c) 2011 Matthew Riley MacPherson
|
2
2
|
|
3
3
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
4
|
of this software and associated documentation files (the "Software"), to deal
|
@@ -16,4 +16,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
16
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
17
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
18
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
-
THE SOFTWARE.
|
19
|
+
THE SOFTWARE.
|
data/README.markdown
CHANGED
@@ -1,21 +1,19 @@
|
|
1
1
|
# FastProwl
|
2
2
|
## Ruby Prowl library that uses libcurl-multi for parallel requests
|
3
3
|
|
4
|
-
*FastProwl* is a Ruby library for interacting with the Prowl API **using Typhoeus** (a libcurl-multi interface written in Ruby). It is inspired heavily by [August Lilleaas](http://august.lilleaas.net/)'s [ruby-prowl](http://github.com/augustl/ruby-prowl) library (the class method `FastProwl.add()` still works if you include this library instead).
|
4
|
+
*FastProwl* is a Ruby library for interacting with the [Prowl API](http://prowl.weks.net/api.php) **using Typhoeus** (a libcurl-multi interface written in Ruby). It is inspired heavily by [August Lilleaas](http://august.lilleaas.net/)'s [ruby-prowl](http://github.com/augustl/ruby-prowl) library (the class method `FastProwl.add()` still works if you include this library instead).
|
5
5
|
|
6
|
-
*FastProwl* lets you queue up many Prowl API requests then make them concurrently, which is handy if you make a bunch of requests in quick succession. It was developed for [Prey Fetcher](http://preyfetcher.com), which sends too many
|
6
|
+
*FastProwl* lets you queue up many Prowl API requests then make them concurrently, which is handy if you make a bunch of requests in quick succession. It was developed for [Prey Fetcher](http://preyfetcher.com), which sends too many notification requests to wait on blocking HTTP calls.
|
7
7
|
|
8
8
|
Please fork away and send me a pull request if you think you can make it better or whatnot.
|
9
9
|
|
10
10
|
## Installation
|
11
11
|
|
12
|
-
|
12
|
+
Install with RubyGems:
|
13
13
|
|
14
14
|
gem install fastprowl
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
gem install fastprowl --source http://gemcutter.org/
|
16
|
+
You'll need [Paul Dix](http://www.pauldix.net/)'s [Typhoeus](http://github.com/pauldix/typhoeus), which will automatically install as a dependency, but does require a reasonably current version of [libcurl](http://curl.haxx.se/libcurl/) installed. Check out the [Typhoeus README](http://github.com/pauldix/typhoeus/blob/master/README.textile) for more info. If you're having trouble getting that to work and just need a simple Prowl library with no dependancies/native extensions, check out [ruby-prowl](http://github.com/augustl/ruby-prowl).
|
19
17
|
|
20
18
|
## Usage
|
21
19
|
|
@@ -33,7 +31,7 @@ As mentioned, this is the same as using [ruby-prowl](http://github.com/augustl/r
|
|
33
31
|
If you want to send concurrent requests (presumably you do), create an instance object and use the `add()` method to queue up your requests. When all of your requests are ready, use the `run()` method to send all of your queued notifications:
|
34
32
|
|
35
33
|
# You can put any attributes you want in the constructor
|
36
|
-
# to save
|
34
|
+
# to save repeatedly supplying them when you call add()
|
37
35
|
prowl = FastProwl.new(
|
38
36
|
:application => 'Car Repair Shop',
|
39
37
|
:event => 'Your car has been ready for ages!',
|
@@ -52,8 +50,8 @@ You get the idea.
|
|
52
50
|
|
53
51
|
## License
|
54
52
|
|
55
|
-
This program is free software; it is distributed under an
|
53
|
+
This program is free software; it is distributed under an MIT-style License.
|
56
54
|
|
57
55
|
---
|
58
56
|
|
59
|
-
Copyright (c)
|
57
|
+
Copyright (c) 2011 [Matthew Riley MacPherson](http://lonelyvegan.com).
|
data/fastprowl.gemspec
CHANGED
data/lib/fastprowl.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'typhoeus'
|
3
3
|
|
4
|
+
# Create a FastProwl instance and iPhone-spam away via Prowl! ;-)
|
4
5
|
class FastProwl
|
5
6
|
|
6
7
|
class MissingAPIKey < Exception; end
|
@@ -10,7 +11,7 @@ class FastProwl
|
|
10
11
|
API_URL = 'https://prowl.weks.net/publicapi/'
|
11
12
|
PRIORITY_RANGE = -2..2
|
12
13
|
# You can change this using the user_agent() method
|
13
|
-
USER_AGENT = 'FastProwl 0.
|
14
|
+
USER_AGENT = 'FastProwl 0.3 (http://github.com/tofumatt/FastProwl)'
|
14
15
|
|
15
16
|
# Supply Prowl defaults in a hash (:apikey, :providerkey, etc.), along
|
16
17
|
# with optional Typhoeus Hydra options.
|
@@ -47,16 +48,15 @@ class FastProwl
|
|
47
48
|
@hydra.queue(request('verify'))
|
48
49
|
end
|
49
50
|
|
50
|
-
# Send a single Prowl notification _immediately_
|
51
|
-
# the Hydra). Returns the response code of the action
|
51
|
+
# Send a single Prowl notification _immediately_.
|
52
52
|
def self.add(params = {})
|
53
53
|
prowl = new
|
54
54
|
prowl.add(params)
|
55
55
|
prowl.run
|
56
56
|
end
|
57
57
|
|
58
|
-
#
|
59
|
-
#
|
58
|
+
# Verify a Prowl API key _immediately_. Returns true if the key is
|
59
|
+
# valid; false otherwise.
|
60
60
|
def self.verify(apikey)
|
61
61
|
prowl = new(:apikey => apikey)
|
62
62
|
prowl.valid?
|
@@ -86,21 +86,26 @@ class FastProwl
|
|
86
86
|
|
87
87
|
# If there are multiple API Keys in an array, merge them into a comma-delimited string
|
88
88
|
if params[:apikey].is_a?(Array)
|
89
|
-
params[:apikey] = params[:apikey].collect{|v| v + ','}.to_s.chop
|
89
|
+
params[:apikey] = params[:apikey].collect{|v| v + ',' }.to_s.chop
|
90
90
|
end
|
91
91
|
|
92
|
-
#
|
92
|
+
# Delete any empty key/value sets
|
93
|
+
params.delete_if {|key, value| value.nil? }
|
94
|
+
|
95
|
+
# Make the request
|
93
96
|
req = Typhoeus::Request.new(API_URL + action,
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
97
|
+
:user_agent => @user_agent,
|
98
|
+
:method => (action == 'add') ? :post : :get,
|
99
|
+
:params => (action == 'add') ? params : {:apikey => params[:apikey]}
|
100
|
+
)
|
101
|
+
|
102
|
+
# Typhoeus request on_complete method adds the HTTP code to an array
|
103
|
+
req.on_complete do |response|
|
104
|
+
@responses << response.code
|
105
|
+
end
|
106
|
+
|
107
|
+
# Return the request
|
108
|
+
req
|
104
109
|
end
|
105
110
|
|
106
111
|
# Check to see if any notifications succeeded. Like the Prowl API with multiple
|
metadata
CHANGED
@@ -1,7 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fastprowl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
hash: 13
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 3
|
9
|
+
version: "0.3"
|
5
10
|
platform: ruby
|
6
11
|
authors:
|
7
12
|
- Matthew Riley MacPherson
|
@@ -9,29 +14,39 @@ autorequire:
|
|
9
14
|
bindir: bin
|
10
15
|
cert_chain: []
|
11
16
|
|
12
|
-
date:
|
17
|
+
date: 2011-01-25 00:00:00 -04:00
|
13
18
|
default_executable:
|
14
19
|
dependencies:
|
15
20
|
- !ruby/object:Gem::Dependency
|
16
21
|
name: typhoeus
|
17
|
-
|
18
|
-
|
19
|
-
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
20
25
|
requirements:
|
21
26
|
- - ">="
|
22
27
|
- !ruby/object:Gem::Version
|
28
|
+
hash: 27
|
29
|
+
segments:
|
30
|
+
- 0
|
31
|
+
- 1
|
32
|
+
- 0
|
23
33
|
version: 0.1.0
|
24
|
-
|
34
|
+
type: :runtime
|
35
|
+
version_requirements: *id001
|
25
36
|
- !ruby/object:Gem::Dependency
|
26
37
|
name: mocha
|
27
|
-
|
28
|
-
|
29
|
-
|
38
|
+
prerelease: false
|
39
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
30
41
|
requirements:
|
31
42
|
- - ">="
|
32
43
|
- !ruby/object:Gem::Version
|
44
|
+
hash: 3
|
45
|
+
segments:
|
46
|
+
- 0
|
33
47
|
version: "0"
|
34
|
-
|
48
|
+
type: :development
|
49
|
+
version_requirements: *id002
|
35
50
|
description:
|
36
51
|
email: matt@lonelyvegan.com
|
37
52
|
executables: []
|
@@ -60,21 +75,27 @@ rdoc_options:
|
|
60
75
|
require_paths:
|
61
76
|
- lib
|
62
77
|
required_ruby_version: !ruby/object:Gem::Requirement
|
78
|
+
none: false
|
63
79
|
requirements:
|
64
80
|
- - ">="
|
65
81
|
- !ruby/object:Gem::Version
|
82
|
+
hash: 3
|
83
|
+
segments:
|
84
|
+
- 0
|
66
85
|
version: "0"
|
67
|
-
version:
|
68
86
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
|
+
none: false
|
69
88
|
requirements:
|
70
89
|
- - ">="
|
71
90
|
- !ruby/object:Gem::Version
|
91
|
+
hash: 3
|
92
|
+
segments:
|
93
|
+
- 0
|
72
94
|
version: "0"
|
73
|
-
version:
|
74
95
|
requirements: []
|
75
96
|
|
76
97
|
rubyforge_project:
|
77
|
-
rubygems_version: 1.
|
98
|
+
rubygems_version: 1.4.2
|
78
99
|
signing_key:
|
79
100
|
specification_version: 3
|
80
101
|
summary: Ruby Prowl library that uses libcurl-multi for parallel requests
|