themockerpush 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +20 -0
- data/.rbenv-gemsets +1 -0
- data/.rbenv-version +1 -0
- data/Gemfile +13 -0
- data/LICENSE.txt +22 -0
- data/README.md +40 -0
- data/Rakefile +1 -0
- data/lib/themockerpush.rb +6 -0
- data/lib/themockerpush/notification.rb +12 -0
- data/lib/themockerpush/themockerpush_active_resource.rb +67 -0
- data/lib/themockerpush/version.rb +3 -0
- data/test/notification_test.rb +29 -0
- data/test/test_helper.rb +10 -0
- data/themockerpush.gemspec +19 -0
- metadata +61 -0
data/.gitignore
ADDED
data/.rbenv-gemsets
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
themockerpush-gem
|
data/.rbenv-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.9.3-p194
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Laurent Cobos
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
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:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
# Themockerpush - iPhone push notifications as a service
|
2
|
+
|
3
|
+
**TheMockerPush** aims to be easy iphone notifications pushing.
|
4
|
+
This gems is a wrapper of the [REST API provided](http://www.themockerpush.com/documentation) by themockerpush.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
gem 'themockerpush'
|
11
|
+
|
12
|
+
And then execute:
|
13
|
+
|
14
|
+
$ bundle
|
15
|
+
|
16
|
+
Or install it yourself as:
|
17
|
+
|
18
|
+
$ gem install themockerpush
|
19
|
+
|
20
|
+
## Usage
|
21
|
+
|
22
|
+
You have to set your **SECRET_KEY** and your **API_KEY** that you can get on www.themockerpush.com
|
23
|
+
And you are ready to push !
|
24
|
+
|
25
|
+
```rb
|
26
|
+
Themockerpush::SECRET_KEY = '00000000000000000'
|
27
|
+
Themockerpush::API_KEY = '12345'
|
28
|
+
|
29
|
+
notification = Themockerpush::Notification.new(
|
30
|
+
:message => "Welcome",
|
31
|
+
:badge => "12",
|
32
|
+
:recipients_list => 'new_subscribers',
|
33
|
+
:scheduled_at_date => '2012-12-31',
|
34
|
+
:scheduled_at_time => '20:35')
|
35
|
+
notification.push
|
36
|
+
```
|
37
|
+
|
38
|
+
## License
|
39
|
+
|
40
|
+
Copyright (c) 2012 Laurent Cobos, 11Factory. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'active_resource'
|
2
|
+
require 'cgi'
|
3
|
+
require 'openssl'
|
4
|
+
require 'net/http'
|
5
|
+
|
6
|
+
class ThemockerpushActiveResource < ActiveResource::Base
|
7
|
+
self.site = "http://themockerpush.com/api/:api_key"
|
8
|
+
self.format = :json
|
9
|
+
|
10
|
+
def initialize(params)
|
11
|
+
super(params.merge({:api_key => Themockerpush::API_KEY}))
|
12
|
+
end
|
13
|
+
|
14
|
+
class << self
|
15
|
+
def element_path(id, prefix_options = {}, query_options = nil)
|
16
|
+
prefix_options, query_options = split_options(prefix_options) if query_options.nil?
|
17
|
+
"#{prefix(prefix_options)}#{collection_name}/#{id}#{query_string(query_options)}"
|
18
|
+
end
|
19
|
+
|
20
|
+
def collection_path(prefix_options = {}, query_options = nil)
|
21
|
+
prefix_options, query_options = split_options(prefix_options) if query_options.nil?
|
22
|
+
"#{prefix(prefix_options)}#{collection_name}#{query_string(query_options)}"
|
23
|
+
end
|
24
|
+
|
25
|
+
def custom_method_collection_url(method_name, options = {})
|
26
|
+
prefix_options, query_options = split_options(options)
|
27
|
+
"#{prefix(prefix_options)}#{collection_name}/#{method_name}#{query_string(query_options)}"
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
module ActiveResource
|
35
|
+
class Connection
|
36
|
+
|
37
|
+
[:put, :post].each do |method_name|
|
38
|
+
alias_method "original_#{method_name}", method_name
|
39
|
+
define_method method_name.to_s do |path, body, headers|
|
40
|
+
with_hmac_authentication(path, body) do |authenticated_path, authenticated_body|
|
41
|
+
self.send("original_#{method_name}", authenticated_path, authenticated_body || '', headers || {})
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
def digest
|
49
|
+
@digest ||= OpenSSL::Digest::Digest.new('sha1')
|
50
|
+
end
|
51
|
+
|
52
|
+
def build_hmac_token_for_body(body = '')
|
53
|
+
OpenSSL::HMAC.hexdigest digest, Themockerpush::SECRET_KEY, body
|
54
|
+
end
|
55
|
+
|
56
|
+
def path_by_appending_parameters_hash(path, parameters_hash)
|
57
|
+
parameters_query = parameters_hash.to_query
|
58
|
+
path + (path.include?('?') ? "&#{parameters_query}" : "?#{parameters_query}")
|
59
|
+
end
|
60
|
+
|
61
|
+
def with_hmac_authentication(path, body = '')
|
62
|
+
path_with_hmac = path_by_appending_parameters_hash(path, {:hmac_token => build_hmac_token_for_body(body)})
|
63
|
+
yield path_with_hmac, body
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
#encoding: utf-8
|
2
|
+
require 'test_helper'
|
3
|
+
require 'openssl'
|
4
|
+
require 'net/http'
|
5
|
+
|
6
|
+
class NotificationTest < ActiveSupport::TestCase
|
7
|
+
|
8
|
+
Themockerpush::SECRET_KEY = '00000000000000000'
|
9
|
+
Themockerpush::API_KEY = '12345'
|
10
|
+
|
11
|
+
setup do
|
12
|
+
@digest = OpenSSL::Digest::Digest.new('sha1')
|
13
|
+
end
|
14
|
+
|
15
|
+
test "create a notification with valid hmac auth" do
|
16
|
+
notification = Themockerpush::Notification.new(
|
17
|
+
:message => "Hello world",
|
18
|
+
:badge => "12",
|
19
|
+
:tokens => ['t1', 't2'],
|
20
|
+
:scheduled_at_date => '2012-12-31',
|
21
|
+
:scheduled_at_time => '20:35')
|
22
|
+
hmac_token = OpenSSL::HMAC.hexdigest @digest, Themockerpush::SECRET_KEY, notification.to_json
|
23
|
+
ActiveResource::HttpMock.respond_to do |mock|
|
24
|
+
mock.post "/api/#{Themockerpush::API_KEY}/notifications?hmac_token=#{hmac_token}", {}, '', 201
|
25
|
+
end
|
26
|
+
assert notification.push
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'themockerpush/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "themockerpush"
|
8
|
+
gem.version = Themockerpush::VERSION
|
9
|
+
gem.authors = ["Laurent Cobos"]
|
10
|
+
gem.email = ["laurent@11factory.fr"]
|
11
|
+
gem.description = %q{iPhone push notifications as a service - client}
|
12
|
+
gem.summary = %q{iPhone push notifications as a service - client}
|
13
|
+
gem.homepage = "http://www.themockerpush.com"
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
end
|
metadata
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: themockerpush
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Laurent Cobos
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-12-17 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: iPhone push notifications as a service - client
|
15
|
+
email:
|
16
|
+
- laurent@11factory.fr
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- .gitignore
|
22
|
+
- .rbenv-gemsets
|
23
|
+
- .rbenv-version
|
24
|
+
- Gemfile
|
25
|
+
- LICENSE.txt
|
26
|
+
- README.md
|
27
|
+
- Rakefile
|
28
|
+
- lib/themockerpush.rb
|
29
|
+
- lib/themockerpush/notification.rb
|
30
|
+
- lib/themockerpush/themockerpush_active_resource.rb
|
31
|
+
- lib/themockerpush/version.rb
|
32
|
+
- test/notification_test.rb
|
33
|
+
- test/test_helper.rb
|
34
|
+
- themockerpush.gemspec
|
35
|
+
homepage: http://www.themockerpush.com
|
36
|
+
licenses: []
|
37
|
+
post_install_message:
|
38
|
+
rdoc_options: []
|
39
|
+
require_paths:
|
40
|
+
- lib
|
41
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ! '>='
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
48
|
+
none: false
|
49
|
+
requirements:
|
50
|
+
- - ! '>='
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '0'
|
53
|
+
requirements: []
|
54
|
+
rubyforge_project:
|
55
|
+
rubygems_version: 1.8.23
|
56
|
+
signing_key:
|
57
|
+
specification_version: 3
|
58
|
+
summary: iPhone push notifications as a service - client
|
59
|
+
test_files:
|
60
|
+
- test/notification_test.rb
|
61
|
+
- test/test_helper.rb
|