urbanairship 2.0.0 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +25 -18
- data/README.markdown +31 -0
- data/lib/urbanairship.rb +7 -2
- data/spec/urbanairship_spec.rb +19 -0
- metadata +61 -76
data/LICENSE
CHANGED
@@ -1,22 +1,29 @@
|
|
1
|
-
(
|
1
|
+
Copyright (c) 2012, Groupon, Inc.
|
2
|
+
All rights reserved.
|
2
3
|
|
3
|
-
|
4
|
+
Redistribution and use in source and binary forms, with or without
|
5
|
+
modification, are permitted provided that the following conditions
|
6
|
+
are met:
|
4
7
|
|
5
|
-
|
6
|
-
|
7
|
-
'Software'), to deal in the Software without restriction, including
|
8
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
-
permit persons to whom the Software is furnished to do so, subject to
|
11
|
-
the following conditions:
|
8
|
+
Redistributions of source code must retain the above copyright notice,
|
9
|
+
this list of conditions and the following disclaimer.
|
12
10
|
|
13
|
-
|
14
|
-
|
11
|
+
Redistributions in binary form must reproduce the above copyright
|
12
|
+
notice, this list of conditions and the following disclaimer in the
|
13
|
+
documentation and/or other materials provided with the distribution.
|
15
14
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
15
|
+
Neither the name of GROUPON nor the names of its contributors may be
|
16
|
+
used to endorse or promote products derived from this software without
|
17
|
+
specific prior written permission.
|
18
|
+
|
19
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
20
|
+
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
21
|
+
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
22
|
+
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
23
|
+
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
24
|
+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
|
25
|
+
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
26
|
+
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
27
|
+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
28
|
+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
29
|
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
data/README.markdown
CHANGED
@@ -111,6 +111,37 @@ Urbanairship.delete_scheduled_push(123456789)
|
|
111
111
|
Urbanairship.delete_scheduled_push(:alias => "deadbeef")
|
112
112
|
```
|
113
113
|
|
114
|
+
Using Urbanairship with Android
|
115
|
+
-------------------------------
|
116
|
+
|
117
|
+
The Urban Airship API extends a subset of their push API to Android devices. You can read more about what is currently supported [here](https://docs.urbanairship.com/display/DOCS/Server%3A+Android+Push+API), but as of this writing, only registration, aliases, tags, broadcast, individual push, and batch push are supported.
|
118
|
+
|
119
|
+
To use this library with Android devices, you can set the `provider` configuration option to `:android`:
|
120
|
+
|
121
|
+
```ruby
|
122
|
+
Urbanairship.provider = :android
|
123
|
+
```
|
124
|
+
|
125
|
+
Alternatively, you can pass the `:provider => :android` option to device registration calls if your app uses Urbanairship to send notifications to both Android and iOS devices.
|
126
|
+
|
127
|
+
```ruby
|
128
|
+
Urbanairship.register_device("DEVICE-TOKEN", :provider => :android)
|
129
|
+
```
|
130
|
+
|
131
|
+
Note: all other supported actions use the same API endpoints as iOS, so it is not necessary to specify the provider as `:android` when calling them.
|
132
|
+
|
133
|
+
When sending notifications to Android devices, the Urban Airship API expects the following basic structure:
|
134
|
+
|
135
|
+
```ruby
|
136
|
+
notification = {
|
137
|
+
:schedule_for => [1.hour.from_now],
|
138
|
+
:apids => ['DEVICE-TOKEN-ONE', 'DEVICE-TOKEN-TWO'],
|
139
|
+
:android => {:alert => 'You have a new message!', :extra => {:foo => 'bar'}}
|
140
|
+
}
|
141
|
+
|
142
|
+
Urbanairship.push(notification)
|
143
|
+
```
|
144
|
+
|
114
145
|
-----------------------------
|
115
146
|
|
116
147
|
Note: all public library methods will return either an array or a hash, depending on the response from the Urban Airship API. In addition, you can inspect these objects to find out if they were successful or not, and what the http response code from Urban Airship was.
|
data/lib/urbanairship.rb
CHANGED
@@ -14,11 +14,16 @@ module Urbanairship
|
|
14
14
|
end
|
15
15
|
|
16
16
|
class << self
|
17
|
-
attr_accessor :application_key, :application_secret, :master_secret, :logger, :request_timeout
|
17
|
+
attr_accessor :application_key, :application_secret, :master_secret, :logger, :request_timeout, :provider
|
18
18
|
|
19
19
|
def register_device(device_token, options = {})
|
20
20
|
body = parse_register_options(options).to_json
|
21
|
-
|
21
|
+
|
22
|
+
if (options[:provider] || @provider) == :android
|
23
|
+
do_request(:put, "/api/apids/#{device_token}", :body => body, :authenticate_with => :application_secret)
|
24
|
+
else
|
25
|
+
do_request(:put, "/api/device_tokens/#{device_token}", :body => body, :authenticate_with => :application_secret)
|
26
|
+
end
|
22
27
|
end
|
23
28
|
|
24
29
|
def unregister_device(device_token)
|
data/spec/urbanairship_spec.rb
CHANGED
@@ -3,12 +3,14 @@ describe Urbanairship do
|
|
3
3
|
FakeWeb.allow_net_connect = false
|
4
4
|
|
5
5
|
# register_device
|
6
|
+
FakeWeb.register_uri(:put, "https://my_app_key:my_app_secret@go.urbanairship.com/api/apids/new_device_token", :status => ["201", "Created"])
|
6
7
|
FakeWeb.register_uri(:put, "https://my_app_key:my_app_secret@go.urbanairship.com/api/device_tokens/new_device_token", :status => ["201", "Created"])
|
7
8
|
FakeWeb.register_uri(:put, "https://my_app_key:my_app_secret@go.urbanairship.com/api/device_tokens/existing_device_token", :status => ["200", "OK"])
|
8
9
|
FakeWeb.register_uri(:put, "https://my_app_key:my_app_secret@go.urbanairship.com/api/device_tokens/device_token_one", :status => ["201", "Created"])
|
9
10
|
FakeWeb.register_uri(:put, /bad_key\:my_app_secret\@go\.urbanairship\.com/, :status => ["401", "Unauthorized"])
|
10
11
|
|
11
12
|
# unregister_device
|
13
|
+
FakeWeb.register_uri(:delete, /my_app_key\:my_app_secret\@go\.urbanairship.com\/api\/apids\/.+/, :status => ["204", "No Content"])
|
12
14
|
FakeWeb.register_uri(:delete, /my_app_key\:my_app_secret\@go\.urbanairship.com\/api\/device_tokens\/.+/, :status => ["204", "No Content"])
|
13
15
|
FakeWeb.register_uri(:delete, /bad_key\:my_app_secret\@go\.urbanairship.com\/api\/device_tokens\/.+/, :status => ["401", "Unauthorized"])
|
14
16
|
|
@@ -107,6 +109,23 @@ describe Urbanairship do
|
|
107
109
|
Urbanairship.register_device("device_token_one", :alias => 11)
|
108
110
|
request_json['alias'].should be_a_kind_of String
|
109
111
|
end
|
112
|
+
|
113
|
+
it "uses the iOS interface by default" do
|
114
|
+
Urbanairship.register_device("new_device_token")
|
115
|
+
FakeWeb.last_request.path.should == "/api/device_tokens/new_device_token"
|
116
|
+
end
|
117
|
+
|
118
|
+
it "uses the android interface if 'provider' configuration option is set to :android" do
|
119
|
+
Urbanairship.provider = :android
|
120
|
+
Urbanairship.register_device("new_device_token")
|
121
|
+
FakeWeb.last_request.path.should == "/api/apids/new_device_token"
|
122
|
+
Urbanairship.provider = nil
|
123
|
+
end
|
124
|
+
|
125
|
+
it "uses the android interface if 'provider' option is passed as :android" do
|
126
|
+
Urbanairship.register_device("new_device_token", :provider => :android)
|
127
|
+
FakeWeb.last_request.path.should == "/api/apids/new_device_token"
|
128
|
+
end
|
110
129
|
end
|
111
130
|
|
112
131
|
describe "::unregister_device" do
|
metadata
CHANGED
@@ -1,75 +1,72 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: urbanairship
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 2.1.0
|
5
5
|
prerelease:
|
6
|
-
segments:
|
7
|
-
- 2
|
8
|
-
- 0
|
9
|
-
- 0
|
10
|
-
version: 2.0.0
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Groupon, Inc.
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
dependencies:
|
21
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2012-06-24 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
22
15
|
name: json
|
23
|
-
|
24
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
25
17
|
none: false
|
26
|
-
requirements:
|
27
|
-
- -
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
|
30
|
-
segments:
|
31
|
-
- 0
|
32
|
-
version: "0"
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
33
22
|
type: :runtime
|
34
|
-
version_requirements: *id001
|
35
|
-
- !ruby/object:Gem::Dependency
|
36
|
-
name: rspec
|
37
23
|
prerelease: false
|
38
|
-
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
39
25
|
none: false
|
40
|
-
requirements:
|
41
|
-
- -
|
42
|
-
- !ruby/object:Gem::Version
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rspec
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
47
38
|
type: :development
|
48
|
-
version_requirements: *id002
|
49
|
-
- !ruby/object:Gem::Dependency
|
50
|
-
name: fakeweb
|
51
39
|
prerelease: false
|
52
|
-
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
53
41
|
none: false
|
54
|
-
requirements:
|
55
|
-
- -
|
56
|
-
- !ruby/object:Gem::Version
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: fakeweb
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
61
54
|
type: :development
|
62
|
-
|
63
|
-
|
64
|
-
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
description: Urbanairship is a Ruby library for interacting with the Urban Airship
|
63
|
+
(http://urbanairship.com) API.
|
64
|
+
email:
|
65
65
|
- rubygems@groupon.com
|
66
66
|
executables: []
|
67
|
-
|
68
67
|
extensions: []
|
69
|
-
|
70
68
|
extra_rdoc_files: []
|
71
|
-
|
72
|
-
files:
|
69
|
+
files:
|
73
70
|
- README.markdown
|
74
71
|
- LICENSE
|
75
72
|
- Rakefile
|
@@ -78,43 +75,31 @@ files:
|
|
78
75
|
- spec/response_spec.rb
|
79
76
|
- spec/spec_helper.rb
|
80
77
|
- spec/urbanairship_spec.rb
|
81
|
-
has_rdoc: true
|
82
78
|
homepage: http://github.com/groupon/urbanairship
|
83
79
|
licenses: []
|
84
|
-
|
85
80
|
post_install_message:
|
86
81
|
rdoc_options: []
|
87
|
-
|
88
|
-
require_paths:
|
82
|
+
require_paths:
|
89
83
|
- lib
|
90
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
84
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
91
85
|
none: false
|
92
|
-
requirements:
|
93
|
-
- -
|
94
|
-
- !ruby/object:Gem::Version
|
95
|
-
hash: 59
|
96
|
-
segments:
|
97
|
-
- 1
|
98
|
-
- 8
|
99
|
-
- 6
|
86
|
+
requirements:
|
87
|
+
- - ! '>='
|
88
|
+
- !ruby/object:Gem::Version
|
100
89
|
version: 1.8.6
|
101
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
90
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
102
91
|
none: false
|
103
|
-
requirements:
|
104
|
-
- -
|
105
|
-
- !ruby/object:Gem::Version
|
106
|
-
|
107
|
-
segments:
|
108
|
-
- 0
|
109
|
-
version: "0"
|
92
|
+
requirements:
|
93
|
+
- - ! '>='
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
110
96
|
requirements: []
|
111
|
-
|
112
97
|
rubyforge_project:
|
113
|
-
rubygems_version: 1.
|
98
|
+
rubygems_version: 1.8.24
|
114
99
|
signing_key:
|
115
100
|
specification_version: 3
|
116
101
|
summary: A Ruby wrapper for the Urban Airship API
|
117
|
-
test_files:
|
102
|
+
test_files:
|
118
103
|
- spec/response_spec.rb
|
119
104
|
- spec/spec_helper.rb
|
120
105
|
- spec/urbanairship_spec.rb
|