azure-push 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +22 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +30 -0
- data/Rakefile +2 -0
- data/azure-push.gemspec +24 -0
- data/lib/azure/push.rb +6 -0
- data/lib/azure/push/message.rb +48 -0
- data/lib/azure/push/sas.rb +17 -0
- data/lib/azure/push/version.rb +5 -0
- metadata +96 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 7e145e55bb48f4842b4f4784fc1780d2c7de1dde
|
4
|
+
data.tar.gz: d5f4742156e3612b7f91515f786bb1a4340b621c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: cccbfe66d20ae3c182716d574a1bf3cf5a2fee5f1555aa1432c64f2766285c00d859dec1fc0d073f2fca9a5ba42d088a6700c9f148a14f79d4257ea51ac94f1f
|
7
|
+
data.tar.gz: 777207f91370b7191231d064f27a4942de588eed9466d418b4abdc947c2d7ad226a1d90cf33b4faecbc876cc8c70df0f302b84f6cb4ce2309be4729910211eaf
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Christian Sädtler
|
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,30 @@
|
|
1
|
+
# Azure::Push
|
2
|
+
|
3
|
+
This is a very simple Azure notification-hub implementation for sending push notifications to Mobile Devices.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'azure-push'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install azure-push
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
ap = Azure::Push::Message.new(namespace, hub, access_key)
|
22
|
+
ap.send({aps: {alert: message, sound: true}, 'my_tag')
|
23
|
+
|
24
|
+
## Contributing
|
25
|
+
|
26
|
+
1. Fork it ( https://github.com/christian-s/azure-push/fork )
|
27
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
28
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
29
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
30
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/azure-push.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'azure/push/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "azure-push"
|
8
|
+
spec.version = Azure::Push::VERSION
|
9
|
+
spec.authors = ["Christian Sädtler"]
|
10
|
+
spec.email = ["christian@saedtler.net"]
|
11
|
+
spec.summary = %q{Gem for interacting with Azure notification hubs without using the azure-sdk}
|
12
|
+
spec.homepage = "https://github.com/christian-s/azure-push"
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0")
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_runtime_dependency('json', '~> 1.8')
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
23
|
+
spec.add_development_dependency "rake", "~> 0"
|
24
|
+
end
|
data/lib/azure/push.rb
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'azure/push/sas'
|
2
|
+
require 'uri'
|
3
|
+
require 'net/https'
|
4
|
+
require 'json'
|
5
|
+
|
6
|
+
module Azure
|
7
|
+
module Push
|
8
|
+
class Message
|
9
|
+
include Azure::Push::Sas
|
10
|
+
|
11
|
+
def initialize(namespace, hub, access_key,
|
12
|
+
key_name: 'DefaultFullSharedAccessSignature',
|
13
|
+
sig_lifetime: 10)
|
14
|
+
@access_key = access_key
|
15
|
+
@key_name = key_name
|
16
|
+
@namespace = namespace
|
17
|
+
@hub = hub
|
18
|
+
@sig_lifetime = sig_lifetime
|
19
|
+
end
|
20
|
+
|
21
|
+
def send(payload, tags, format: 'apple')
|
22
|
+
raise ArgumentError unless ['apple', 'gcm', 'template'].include? format
|
23
|
+
if tags.instance_of?(Array)
|
24
|
+
tags = tags.join(' || ')
|
25
|
+
end
|
26
|
+
uri = URI(url)
|
27
|
+
headers = {
|
28
|
+
'Content-Type' => 'application/json',
|
29
|
+
'Authorization' => sas_token(url, @key_name, @access_key, lifetime: @sig_lifetime),
|
30
|
+
'ServiceBusNotification-Format' => format,
|
31
|
+
'ServiceBusNotification-Tags' => tags
|
32
|
+
}
|
33
|
+
http = Net::HTTP.new(uri.host,uri.port)
|
34
|
+
http.use_ssl = true
|
35
|
+
req = Net::HTTP::Post.new(uri.path, initheader = headers)
|
36
|
+
req.body = payload.to_json
|
37
|
+
res = http.request(req)
|
38
|
+
res.is_a?(Net::HTTPSuccess) ? true : res
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def url
|
44
|
+
"https://#{@namespace}.servicebus.windows.net/#{@hub}/messages"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'cgi'
|
2
|
+
require 'base64'
|
3
|
+
require 'digest'
|
4
|
+
|
5
|
+
module Azure
|
6
|
+
module Push
|
7
|
+
module Sas
|
8
|
+
def sas_token(url, key_name, access_key, lifetime: 60)
|
9
|
+
target_uri = CGI.escape(url.downcase).gsub('+', '%20').downcase
|
10
|
+
expires = Time.now.to_i + lifetime
|
11
|
+
to_sign = "#{target_uri}\n#{expires}"
|
12
|
+
signature = CGI.escape(Base64.strict_encode64(Digest::HMAC.digest(to_sign, access_key, Digest::SHA256))).gsub('+', '%20')
|
13
|
+
token = "SharedAccessSignature sr=#{target_uri}&sig=#{signature}&se=#{expires}&skn=#{key_name}"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
metadata
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: azure-push
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Christian Sädtler
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-09-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: json
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.8'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.8'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.6'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.6'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description:
|
56
|
+
email:
|
57
|
+
- christian@saedtler.net
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- Gemfile
|
64
|
+
- LICENSE.txt
|
65
|
+
- README.md
|
66
|
+
- Rakefile
|
67
|
+
- azure-push.gemspec
|
68
|
+
- lib/azure/push.rb
|
69
|
+
- lib/azure/push/message.rb
|
70
|
+
- lib/azure/push/sas.rb
|
71
|
+
- lib/azure/push/version.rb
|
72
|
+
homepage: https://github.com/christian-s/azure-push
|
73
|
+
licenses:
|
74
|
+
- MIT
|
75
|
+
metadata: {}
|
76
|
+
post_install_message:
|
77
|
+
rdoc_options: []
|
78
|
+
require_paths:
|
79
|
+
- lib
|
80
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
requirements: []
|
91
|
+
rubyforge_project:
|
92
|
+
rubygems_version: 2.2.2
|
93
|
+
signing_key:
|
94
|
+
specification_version: 4
|
95
|
+
summary: Gem for interacting with Azure notification hubs without using the azure-sdk
|
96
|
+
test_files: []
|