prowly 0.2.1 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.1
1
+ 0.2.2
data/bin/prowly CHANGED
@@ -38,6 +38,10 @@ EOF
38
38
  opts.on("-dDESCRIPTION", "--description DESCRIPTION", "Description") do |desc|
39
39
  options[:description] = desc
40
40
  end
41
+
42
+ opts.on("-aAPPLICATION", "--application APPLICATION", "Application") do |app|
43
+ options[:application] = app
44
+ end
41
45
 
42
46
  opts.on("-eEVENT", "--event EVENT", "Event") do |event|
43
47
  options[:event] = event
@@ -1,6 +1,46 @@
1
+ #--
2
+ # Copyright (c) 2010 Rafael Magaña Ávalos
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining
5
+ # a copy of this software and associated documentation files (the
6
+ # "Software"), to deal in the Software without restriction, including
7
+ # without limitation the rights to use, copy, modify, merge, publish,
8
+ # distribute, sublicense, and/or sell copies of the Software, and to
9
+ # permit persons to whom the Software is furnished to do so, subject to
10
+ # the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ #++
23
+
1
24
  require 'prowly/interface'
2
25
  require 'prowly/notification'
3
26
 
27
+ # This is the main Prowly module
28
+ #
29
+ # Usage:
30
+ #
31
+ # Prowly.notify do |n|
32
+ # n.apikey = "the apikey" or
33
+ # n.apikeys = ["apikey_1", "apikey_2", "apikey_n"]
34
+ # n.priority = Prowly::Notification::Priority::MODERATE
35
+ # n.application = "Prowly"
36
+ # n.event = "Notification"
37
+ # n.description = "put description here"
38
+ # end
39
+ #
40
+ # notification = Prowly::Notification.new(:apikey => "apikey", :application => "Prowly", :description => "Testing...")
41
+ # result = Prowly.notify(notification)
42
+ #
43
+ #
4
44
  module Prowly
5
45
 
6
46
  extend self
@@ -1,3 +1,26 @@
1
+ #--
2
+ # Copyright (c) 2010 Rafael Magaña Ávalos
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining
5
+ # a copy of this software and associated documentation files (the
6
+ # "Software"), to deal in the Software without restriction, including
7
+ # without limitation the rights to use, copy, modify, merge, publish,
8
+ # distribute, sublicense, and/or sell copies of the Software, and to
9
+ # permit persons to whom the Software is furnished to do so, subject to
10
+ # the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ #++
23
+
1
24
  require 'net/https'
2
25
  require 'prowly/response'
3
26
  require 'prowly/notification'
@@ -5,6 +28,14 @@ require 'singleton'
5
28
 
6
29
  module Prowly
7
30
 
31
+ # This is the actual Prowl API wrapper
32
+ #
33
+ # Usage:
34
+ #
35
+ # prowl_api = Prowly::Interface.instance
36
+ #
37
+ # prowl_api.call(Prowly::Command::ADD, params)
38
+
8
39
  class Interface
9
40
 
10
41
  include Singleton
@@ -28,8 +28,7 @@ module Prowly
28
28
  if params[:apikeys] and params[:apikey]
29
29
  raise DuplicatedAssignmentOfApiKey, "Use apikey or apikeys, not both"
30
30
  else
31
- @apikey = params[:apikeys] unless params[:apikeys].nil?
32
- @apikey = params[:apikey] unless params[:apikey].nil?
31
+ @apikey = params[:apikeys] || params[:apikey]
33
32
  end
34
33
  end
35
34
 
@@ -2,44 +2,45 @@ require 'rexml/document'
2
2
 
3
3
  module Prowly
4
4
 
5
+ #This is a Prowl API response wrapper
5
6
  class Response
6
7
 
7
8
  attr_writer :response
8
9
  attr_accessor :http_response
9
10
 
10
- def initialize(xml_response, full_http_response)
11
+ def initialize(xml_response, full_http_response)
11
12
  @response = xml_response
12
13
  @http_response = full_http_response
13
14
  Response.map_xml @response
14
15
  end
15
16
 
16
17
  def self.map_xml(response)
17
- #parse xml
18
- data = REXML::Document.new response
19
- response_info = data.root[1]
20
-
18
+ response_info = parse_xml(response)
19
+
21
20
  #define dynamic methods based on the prowl api response
22
21
  #posible methods on success: code, remaining, resetdate
23
22
  #posible methods on error: code
24
23
  response_info.attributes.each do |key, value|
25
24
  add_instance_method(key, value)
26
25
  end
27
-
26
+
27
+ response_info_name = response_info.name
28
28
  #define a method named status and it'll return "success" or "error"
29
- Response.add_instance_method(:status, response_info.name)
29
+ add_instance_method(:status, response_info_name)
30
30
 
31
- if response_info.name == "success"
32
- boolean_status = true
33
- elsif response_info.name == "error"
34
- boolean_status = false
35
- end
31
+ boolean_status = response_info_name == "success" ? true : false
36
32
 
37
33
  add_instance_method(:message, response_info.text) unless boolean_status
38
34
 
39
35
  add_instance_method(:succeeded?, boolean_status)
40
36
  true
41
37
  end
42
-
38
+
39
+ def self.parse_xml(response)
40
+ data = REXML::Document.new response
41
+ data.root[1]
42
+ end
43
+
43
44
  #define dynamic methods
44
45
  def self.add_instance_method(name, content)
45
46
  define_method(name) { content }
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{prowly}
8
- s.version = "0.2.1"
8
+ s.version = "0.2.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Rafael Maga\303\261a"]
12
- s.date = %q{2010-02-15}
12
+ s.date = %q{2010-07-11}
13
13
  s.default_executable = %q{prowly}
14
14
  s.description = %q{The Prowly gem is a simple wrapper to the Prowl API, you can use it to send messages to your iPhone in a Rails or pure Ruby application.}
15
15
  s.email = %q{raf.magana@gmail.com}
@@ -37,7 +37,7 @@ Gem::Specification.new do |s|
37
37
  s.homepage = %q{http://github.com/rafmagana/prowly}
38
38
  s.rdoc_options = ["--charset=UTF-8"]
39
39
  s.require_paths = ["lib"]
40
- s.rubygems_version = %q{1.3.5}
40
+ s.rubygems_version = %q{1.3.6}
41
41
  s.summary = %q{A Ruby interface to Prowl (http://prowl.weks.net/)}
42
42
  s.test_files = [
43
43
  "test/helper.rb",
metadata CHANGED
@@ -1,7 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: prowly
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 2
8
+ - 2
9
+ version: 0.2.2
5
10
  platform: ruby
6
11
  authors:
7
12
  - "Rafael Maga\xC3\xB1a"
@@ -9,19 +14,21 @@ autorequire:
9
14
  bindir: bin
10
15
  cert_chain: []
11
16
 
12
- date: 2010-02-15 00:00:00 -06:00
17
+ date: 2010-07-11 00:00:00 -05:00
13
18
  default_executable: prowly
14
19
  dependencies:
15
20
  - !ruby/object:Gem::Dependency
16
21
  name: thoughtbot-shoulda
17
- type: :development
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
20
24
  requirements:
21
25
  - - ">="
22
26
  - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
23
29
  version: "0"
24
- version:
30
+ type: :development
31
+ version_requirements: *id001
25
32
  description: The Prowly gem is a simple wrapper to the Prowl API, you can use it to send messages to your iPhone in a Rails or pure Ruby application.
26
33
  email: raf.magana@gmail.com
27
34
  executables:
@@ -59,18 +66,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
59
66
  requirements:
60
67
  - - ">="
61
68
  - !ruby/object:Gem::Version
69
+ segments:
70
+ - 0
62
71
  version: "0"
63
- version:
64
72
  required_rubygems_version: !ruby/object:Gem::Requirement
65
73
  requirements:
66
74
  - - ">="
67
75
  - !ruby/object:Gem::Version
76
+ segments:
77
+ - 0
68
78
  version: "0"
69
- version:
70
79
  requirements: []
71
80
 
72
81
  rubyforge_project:
73
- rubygems_version: 1.3.5
82
+ rubygems_version: 1.3.6
74
83
  signing_key:
75
84
  specification_version: 3
76
85
  summary: A Ruby interface to Prowl (http://prowl.weks.net/)