pushy-api 0.0.0 → 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +16 -0
- data/VERSION +1 -1
- data/lib/pushy.rb +9 -0
- data/lib/pushy/application.rb +59 -0
- metadata +6 -3
data/Rakefile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
begin
|
2
|
+
require 'jeweler'
|
3
|
+
Jeweler::Tasks.new do |gemspec|
|
4
|
+
gemspec.name = "pushy-api"
|
5
|
+
gemspec.summary = "Client library for the Pushy API"
|
6
|
+
gemspec.description = "Pushy makes the Apple push notification service easy. Just use our API and we handle everything else."
|
7
|
+
gemspec.email = "charlie@pushyapp.com"
|
8
|
+
gemspec.homepage = "http://github.com/pushy/pushy-ruby"
|
9
|
+
gemspec.authors = ["Charlie Melbye"]
|
10
|
+
|
11
|
+
gemspec.files = FileList["[A-Z]*", "{bin,generators,lib,test}/**/*"]
|
12
|
+
gemspec.add_dependency('httparty', '>= 0.5.2')
|
13
|
+
end
|
14
|
+
rescue LoadError
|
15
|
+
puts "Jeweler not available. Install it with: sudo gem install jeweler"
|
16
|
+
end
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.1
|
data/lib/pushy.rb
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
module Pushy
|
2
|
+
class Application
|
3
|
+
include HTTParty
|
4
|
+
base_uri 'pushyapp.com/api/v1'
|
5
|
+
format :json
|
6
|
+
|
7
|
+
def initialize(args)
|
8
|
+
# We are using the hash argument idea from Rails
|
9
|
+
raise TypeError, 'Argument must be a hash' unless args.is_a? Hash
|
10
|
+
|
11
|
+
# Converting all the args keys to symbols
|
12
|
+
args.each_pair do |k,v|
|
13
|
+
args.delete(k)
|
14
|
+
args[k.to_sym] = v if k.respond_to? :to_sym
|
15
|
+
end
|
16
|
+
|
17
|
+
@api_key = args[:api_key]
|
18
|
+
@api_secret = args[:api_secret]
|
19
|
+
|
20
|
+
raise ArgumentError, 'No API key specified' unless @api_key
|
21
|
+
raise ArgumentError, 'No API secret specified' unless @api_secret
|
22
|
+
raise TypeError, ":api_key must be a String" unless @api_key.is_a? String
|
23
|
+
raise TypeError, ":api_secret must be a String" unless @api_secret.is_a? String
|
24
|
+
|
25
|
+
self.class.basic_auth @api_key, @api_secret
|
26
|
+
end
|
27
|
+
|
28
|
+
def new_device(device_token, device_alias="")
|
29
|
+
params = {}
|
30
|
+
|
31
|
+
params[:token] = device_token
|
32
|
+
params[:alias] = device_alias unless device_alias.empty?
|
33
|
+
|
34
|
+
self.class.post('/devices.json', :body => params)
|
35
|
+
end
|
36
|
+
|
37
|
+
def send_notification(payload, options)
|
38
|
+
params = {}
|
39
|
+
|
40
|
+
params[:alert] = payload[:alert] if payload[:alert]
|
41
|
+
params[:badge] = payload[:badge] if payload[:badge]
|
42
|
+
params[:sound] = payload[:sound] if payload[:sound]
|
43
|
+
|
44
|
+
if options[:aliases].is_a? Array
|
45
|
+
options[:aliases].each do |the_alias|
|
46
|
+
params["aliases[]"] = the_alias
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
if options[:tokens].is_a? Array
|
51
|
+
options[:tokens].each do |the_token|
|
52
|
+
params["tokens[]"] = the_token
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
self.class.post('/notifications.json', :body => params)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 1
|
9
|
+
version: 0.0.1
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Charlie Melbye
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-03-
|
17
|
+
date: 2010-03-09 00:00:00 -06:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -40,7 +40,10 @@ extensions: []
|
|
40
40
|
extra_rdoc_files: []
|
41
41
|
|
42
42
|
files:
|
43
|
+
- Rakefile
|
43
44
|
- VERSION
|
45
|
+
- lib/pushy.rb
|
46
|
+
- lib/pushy/application.rb
|
44
47
|
has_rdoc: true
|
45
48
|
homepage: http://github.com/pushy/pushy-ruby
|
46
49
|
licenses: []
|