rushover 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -23,7 +23,8 @@ Or install it yourself as:
23
23
  require "rushover"
24
24
 
25
25
  client = Rushover::Client.new(your_app_token)
26
- client.notify(user_key, "some message", :priority => 1, :title => "a title!")
26
+ resp = client.notify(user_key, "some message", :priority => 1, :title => "a title!")
27
+ resp.ok? # => true
27
28
 
28
29
  # Also provides a User class for convenience. Just keeps the user key
29
30
  # around if you want to deal with a User object
@@ -33,8 +34,9 @@ user.notify("some user message", :title => "another title")
33
34
 
34
35
  Optional params to the Pushover like `priority` or `title` are passed through.
35
36
 
36
- Calls to `#notify` will return the parsed JSON response body. Pushover app uses
37
- :status => 1 for success, 0 for failures.
37
+ Calls to `#notify` will return a `Rushover::Response`. Pushover app uses
38
+ :status => 1 for success, 0 for failures. The response can be checked for
39
+ success with `#ok?`, or mined like a plain old hash.
38
40
 
39
41
  ## Contributing
40
42
 
@@ -15,12 +15,14 @@ module Rushover
15
15
  def notify(user_key, message, options = {})
16
16
  data = { :token => token, :user => user_key, :message => message }
17
17
  data.merge!(options)
18
- begin
18
+ data = begin
19
19
  resp = RestClient.post MESSAGES_ENDPOINT, data.to_json, :content_type => "application/json"
20
20
  JSON.parse(resp)
21
21
  rescue RestClient::Exception => e
22
22
  JSON.parse(e.response)
23
23
  end
24
+
25
+ Response.new(data)
24
26
  end
25
27
  end
26
28
 
@@ -36,4 +38,32 @@ module Rushover
36
38
  client.notify(key, message, options)
37
39
  end
38
40
  end
41
+
42
+ class Response
43
+ attr_accessor :data
44
+
45
+ def initialize(data)
46
+ @data = data
47
+ end
48
+
49
+ def [](key)
50
+ @data[key.to_s]
51
+ end
52
+
53
+ def ok?
54
+ self["status"].to_i == 1
55
+ end
56
+
57
+ def inspect
58
+ @data.inspect
59
+ end
60
+
61
+ def to_s
62
+ @data.to_s
63
+ end
64
+
65
+ def to_h
66
+ @data.dup
67
+ end
68
+ end
39
69
  end
@@ -1,3 +1,3 @@
1
1
  module Rushover
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -33,7 +33,7 @@ class RushoverClientTest < RushoverTest
33
33
 
34
34
  test "successful notify" do
35
35
  resp = client.notify("test_user", "test message")
36
- assert_equal({"status" => 1}, resp)
36
+ assert_equal 1, resp["status"]
37
37
  end
38
38
 
39
39
  test "failed notify" do
@@ -48,7 +48,8 @@ class RushoverClientTest < RushoverTest
48
48
 
49
49
  context "with optional params" do
50
50
  test "basic optional params" do
51
- client.notify("test_user", "test message", :device => "test device", :title => "test title", :priority => 1, :timestamp => 123123)
51
+ client.notify("test_user", "test message", :device => "test device",
52
+ :title => "test title", :priority => 1, :timestamp => 123123)
52
53
  assert_equal "test device", last_request_json["device"]
53
54
  assert_equal "test title", last_request_json["title"]
54
55
  assert_equal "1", last_request_json["priority"].to_s
@@ -0,0 +1,41 @@
1
+ require File.expand_path("../test_helper", __FILE__)
2
+
3
+ class RushoverResponseTest < RushoverTest
4
+ def data
5
+ @data ||= { "status" => 1 }
6
+ end
7
+
8
+ test "initializing with a response data" do
9
+ response = Rushover::Response.new(data)
10
+ assert_equal data, response.data
11
+ end
12
+
13
+ test "delegates [] lookups to the response hash" do
14
+ data = { "status" => 1, "foo" => "bar" }
15
+ response = Rushover::Response.new(data)
16
+ assert_equal 1, response["status"]
17
+ assert_equal "bar", response[:foo]
18
+ end
19
+
20
+ test "checking if ok?" do
21
+ response = Rushover::Response.new(data)
22
+ assert response.ok?
23
+ response.data = { "status" => 0 }
24
+ refute response.ok?
25
+ end
26
+
27
+ test "inspect delegates to the data" do
28
+ response = Rushover::Response.new(data)
29
+ assert_equal data.inspect, response.inspect
30
+ end
31
+
32
+ test "to_s delegates to the data" do
33
+ response = Rushover::Response.new(data)
34
+ assert_equal data.to_s, response.to_s
35
+ end
36
+
37
+ test "to_h returns the data" do
38
+ response = Rushover::Response.new(data)
39
+ assert_equal data, response.to_h
40
+ end
41
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rushover
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-08-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json
16
- requirement: &2164476560 !ruby/object:Gem::Requirement
16
+ requirement: &2160386140 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2164476560
24
+ version_requirements: *2160386140
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rest-client
27
- requirement: &2164476140 !ruby/object:Gem::Requirement
27
+ requirement: &2160385720 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *2164476140
35
+ version_requirements: *2160385720
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rake
38
- requirement: &2164475720 !ruby/object:Gem::Requirement
38
+ requirement: &2160385300 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *2164475720
46
+ version_requirements: *2160385300
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: contest
49
- requirement: &2164475300 !ruby/object:Gem::Requirement
49
+ requirement: &2160384880 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *2164475300
57
+ version_requirements: *2160384880
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: fakeweb
60
- requirement: &2164474880 !ruby/object:Gem::Requirement
60
+ requirement: &2160384460 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,7 +65,7 @@ dependencies:
65
65
  version: '0'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *2164474880
68
+ version_requirements: *2160384460
69
69
  description: A simple ruby Pushover client
70
70
  email:
71
71
  - xternal1+github@gmail.com
@@ -82,6 +82,7 @@ files:
82
82
  - lib/rushover/version.rb
83
83
  - rushover.gemspec
84
84
  - test/rushover_client_test.rb
85
+ - test/rushover_response_test.rb
85
86
  - test/rushover_user_test.rb
86
87
  - test/test_helper.rb
87
88
  homepage: ''
@@ -98,7 +99,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
98
99
  version: '0'
99
100
  segments:
100
101
  - 0
101
- hash: 2170637214120495203
102
+ hash: -3386476054685149572
102
103
  required_rubygems_version: !ruby/object:Gem::Requirement
103
104
  none: false
104
105
  requirements:
@@ -107,7 +108,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
107
108
  version: '0'
108
109
  segments:
109
110
  - 0
110
- hash: 2170637214120495203
111
+ hash: -3386476054685149572
111
112
  requirements: []
112
113
  rubyforge_project:
113
114
  rubygems_version: 1.8.15
@@ -116,5 +117,6 @@ specification_version: 3
116
117
  summary: A simple ruby Pushover client
117
118
  test_files:
118
119
  - test/rushover_client_test.rb
120
+ - test/rushover_response_test.rb
119
121
  - test/rushover_user_test.rb
120
122
  - test/test_helper.rb