simplepush 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/Gemfile +9 -0
- data/Gemfile.lock +37 -0
- data/README.md +109 -0
- data/Rakefile +4 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/example/async.rb +28 -0
- data/example/config.rb +24 -0
- data/example/example.rb +18 -0
- data/lib/simplepush/version.rb +5 -0
- data/lib/simplepush.rb +61 -0
- data/simplepush.gemspec +34 -0
- metadata +73 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: c13cefedbd1151589a852fa4f91c1f43a2ad117d01b56752fad35959cc1c3a21
|
4
|
+
data.tar.gz: fde8e2a819e41a5de6c9d82142e045567f22fcf6b9a31b25b119a2ffdba8ddf8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 044447bdfd5f5c08b441e537dc2a5984c64a005a15d49b714714f21ce62f45d21ee4a23ab10dd96ad959139c03c3ae30d153d4629de7b92e8eb059036d351307
|
7
|
+
data.tar.gz: fd381bafb1e625c9a64308f7becf9c29623ddbb896c9a906fd4aa9f50e68d9f8a0937f6d66f81b0ad84f19ecb5ad1b4e9755aff7148318f11debeb5a17191ec4
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
simplepush (0.6.0)
|
5
|
+
httparty
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
async (1.30.1)
|
11
|
+
console (~> 1.10)
|
12
|
+
nio4r (~> 2.3)
|
13
|
+
timers (~> 4.1)
|
14
|
+
console (1.13.1)
|
15
|
+
fiber-local
|
16
|
+
fiber-local (1.0.0)
|
17
|
+
httparty (0.20.0)
|
18
|
+
mime-types (~> 3.0)
|
19
|
+
multi_xml (>= 0.5.2)
|
20
|
+
mime-types (3.3.1)
|
21
|
+
mime-types-data (~> 3.2015)
|
22
|
+
mime-types-data (3.2021.0901)
|
23
|
+
multi_xml (0.6.0)
|
24
|
+
nio4r (2.5.8)
|
25
|
+
rake (13.0.6)
|
26
|
+
timers (4.3.3)
|
27
|
+
|
28
|
+
PLATFORMS
|
29
|
+
x86_64-linux
|
30
|
+
|
31
|
+
DEPENDENCIES
|
32
|
+
async
|
33
|
+
rake (~> 13.0)
|
34
|
+
simplepush!
|
35
|
+
|
36
|
+
BUNDLED WITH
|
37
|
+
2.2.5
|
data/README.md
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
# Simplepush Gem for Ruby
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/simplepush`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'simplepush'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
```
|
16
|
+
$ bundle install
|
17
|
+
```
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
```
|
22
|
+
$ gem install simplepush
|
23
|
+
```
|
24
|
+
|
25
|
+
Add as a dependency:
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
require 'simplepush'
|
29
|
+
```
|
30
|
+
|
31
|
+
## Usage
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
# From example/example.rb
|
35
|
+
require 'simplepush'
|
36
|
+
|
37
|
+
Simplepush.new('<your key>').send("Title", "Message") # Unenrypted
|
38
|
+
|
39
|
+
Simplepush.new('<your key>', "<pass>", "<salt>").send("Title", "Message") # Enrypted
|
40
|
+
|
41
|
+
```
|
42
|
+
|
43
|
+
## Asynchronous send
|
44
|
+
|
45
|
+
The following does not work... `#TODO`
|
46
|
+
|
47
|
+
```ruby
|
48
|
+
require 'async' # gem 'async'
|
49
|
+
|
50
|
+
s = Simplepush.new('<your key>')
|
51
|
+
|
52
|
+
Sync do
|
53
|
+
100.times do |i|
|
54
|
+
Async do
|
55
|
+
s.send("Title", i.to_s) # Unenrypted
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
```
|
60
|
+
|
61
|
+
## Example of query
|
62
|
+
|
63
|
+
The following is a sample of the query as it is produced:
|
64
|
+
|
65
|
+
```json
|
66
|
+
{
|
67
|
+
"args": {},
|
68
|
+
"data": "",
|
69
|
+
"files": {},
|
70
|
+
"form": {
|
71
|
+
"encrypted": "true",
|
72
|
+
"iv": "CEEFFBE72CC70DF45480DDAC775743B6",
|
73
|
+
"key": "<the key, the key>",
|
74
|
+
"msg": "szR70wqD9g8T2nX0FRZwoQ=="
|
75
|
+
},
|
76
|
+
"headers": {
|
77
|
+
"Accept": "*/*",
|
78
|
+
"Accept-Encoding": "gzip;q=1.0,deflate;q=0.6,identity;q=0.3",
|
79
|
+
"Content-Length": "94",
|
80
|
+
"Content-Type": "application/x-www-form-urlencoded",
|
81
|
+
"Host": "httpbin.org",
|
82
|
+
"User-Agent": "Ruby",
|
83
|
+
"X-Amzn-Trace-Id": "Root=1-617714e4-08fc2a3f349df4203121ce0e"
|
84
|
+
},
|
85
|
+
"json": null,
|
86
|
+
"origin": "91.32.103.70",
|
87
|
+
"url": "https://httpbin.org/post"
|
88
|
+
}
|
89
|
+
```
|
90
|
+
|
91
|
+
## Todos
|
92
|
+
|
93
|
+
- [x] Encrypted Messages
|
94
|
+
- [x] Processing responses
|
95
|
+
- [x] Async calls
|
96
|
+
- [ ] Example how to integrate into rails to notify of failures
|
97
|
+
|
98
|
+
## Changelog
|
99
|
+
|
100
|
+
- 0.5.0 Initial Commits
|
101
|
+
- 0.6.0 Changing API to cache keys, better examples
|
102
|
+
|
103
|
+
## Contributing
|
104
|
+
|
105
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/coezbek/simplepush
|
106
|
+
|
107
|
+
## License
|
108
|
+
|
109
|
+
MIT
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require "bundler/setup"
|
5
|
+
require "simplepush"
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require "irb"
|
15
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/example/async.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
|
2
|
+
require_relative 'config.rb'
|
3
|
+
|
4
|
+
config = load_config
|
5
|
+
simplepush = Simplepush.new(config[:key])
|
6
|
+
|
7
|
+
n = 10
|
8
|
+
if 3 >= RUBY_VERSION.split(".").first.to_i
|
9
|
+
|
10
|
+
require 'async'
|
11
|
+
Sync do
|
12
|
+
n.times do |i|
|
13
|
+
Async do
|
14
|
+
simplepush.send("Asynchronous sending with Async", i.to_s)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end # join here
|
18
|
+
|
19
|
+
else
|
20
|
+
|
21
|
+
threads = Array.new(n) { |i|
|
22
|
+
Thread.new {
|
23
|
+
simplepush.send("Asynchronous sending with Threads", i.to_s)
|
24
|
+
}
|
25
|
+
}
|
26
|
+
threads.each(&:join)
|
27
|
+
|
28
|
+
end
|
data/example/config.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require_relative '../lib/simplepush'
|
2
|
+
|
3
|
+
def load_config
|
4
|
+
if !File.exists?('config.yml')
|
5
|
+
|
6
|
+
config = {}
|
7
|
+
|
8
|
+
puts "Enter your key"
|
9
|
+
config[:key] = gets[/.+/] # Strip newline and return nil if ""
|
10
|
+
|
11
|
+
puts "Enter your password or leave empty to send unencrypted"
|
12
|
+
config[:pass] = gets[/.+/]
|
13
|
+
|
14
|
+
if config[:pass]
|
15
|
+
puts "Enter the salt"
|
16
|
+
config[:salt] = gets[/.+/]
|
17
|
+
end
|
18
|
+
|
19
|
+
puts "Configuration stored (as plaintext) in config.yml"
|
20
|
+
File.write('config.yml', config.to_yaml)
|
21
|
+
end
|
22
|
+
|
23
|
+
YAML.load_file('config.yml')
|
24
|
+
end
|
data/example/example.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
|
2
|
+
require_relative 'config.rb'
|
3
|
+
|
4
|
+
config = load_config
|
5
|
+
|
6
|
+
puts "Please enter your message"
|
7
|
+
message = gets.strip
|
8
|
+
|
9
|
+
puts "Should this message be encrypted? (y or n)"
|
10
|
+
|
11
|
+
simplepush = if gets =~ /n/i
|
12
|
+
Simplepush.new(config[:key])
|
13
|
+
else
|
14
|
+
Simplepush.new(config[:key], config[:pass], config[:salt])
|
15
|
+
end
|
16
|
+
|
17
|
+
simplepush.send('Message from Example.rb', message)
|
18
|
+
|
data/lib/simplepush.rb
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "simplepush/version"
|
4
|
+
require 'httparty'
|
5
|
+
|
6
|
+
class Simplepush
|
7
|
+
|
8
|
+
include HTTParty
|
9
|
+
|
10
|
+
base_uri 'https://api.simplepush.io'.freeze
|
11
|
+
# For testing:
|
12
|
+
# base_uri 'https://httpbin.org'.freeze
|
13
|
+
format :json
|
14
|
+
default_timeout 5 # 5 seconds
|
15
|
+
# debug_output $stdout # Uncomment to get detailled httparty log output to stdout
|
16
|
+
|
17
|
+
# If password and salt are provided, then message and title will be encrypted.
|
18
|
+
def initialize(key, password = nil, salt = '1789F0B8C4A051E5')
|
19
|
+
raise "Key must be set" unless key
|
20
|
+
@key = key
|
21
|
+
@cipher_key = [Digest::SHA1.hexdigest(password + salt)[0,32]].pack "H*" if password
|
22
|
+
end
|
23
|
+
|
24
|
+
#
|
25
|
+
# Send the given title/message.
|
26
|
+
#
|
27
|
+
# This method is blocking.
|
28
|
+
#
|
29
|
+
def send(title, message, event = nil)
|
30
|
+
raise "Key and message argument must be set" unless message
|
31
|
+
|
32
|
+
payload = {}
|
33
|
+
payload[:key] = @key
|
34
|
+
payload[:msg] = message.to_s
|
35
|
+
payload[:event] = event.to_s if event
|
36
|
+
payload[:title] = title.to_s if title
|
37
|
+
|
38
|
+
if @cipher_key
|
39
|
+
require 'openssl'
|
40
|
+
payload[:encrypted] = true
|
41
|
+
|
42
|
+
cipher = OpenSSL::Cipher::AES.new(128, :CBC)
|
43
|
+
cipher.encrypt
|
44
|
+
cipher.key = @cipher_key
|
45
|
+
|
46
|
+
# Set random_iv and store as payload
|
47
|
+
payload[:iv] = cipher.random_iv.unpack("H*").first.upcase
|
48
|
+
|
49
|
+
# Automatically uses PKCS7
|
50
|
+
payload[:msg] = Base64.urlsafe_encode64(cipher.update(payload[:msg]) + cipher.final)
|
51
|
+
|
52
|
+
if title
|
53
|
+
cipher.encrypt # Restart cipher
|
54
|
+
payload[:title] = Base64.urlsafe_encode64(cipher.update(payload[:title]) + cipher.final)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
return self.class.post('/send', body: payload)
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
data/simplepush.gemspec
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/simplepush/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "simplepush"
|
7
|
+
spec.version = Simplepush::VERSION
|
8
|
+
spec.authors = ["Christopher Oezbek"]
|
9
|
+
spec.email = ["c.oezbek@gmail.com"]
|
10
|
+
|
11
|
+
spec.summary = "Ruby SimplePush.io API client (unofficial)"
|
12
|
+
spec.description = "Httpary wrapper for SimplePush.io"
|
13
|
+
spec.homepage = "https://github.com/coezbek/simplepush"
|
14
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.4.0")
|
15
|
+
|
16
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
17
|
+
|
18
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
19
|
+
spec.metadata["source_code_uri"] = spec.homepage
|
20
|
+
spec.metadata["changelog_uri"] = "https://github.com/coezbek/simplepush/README.md#Changelog"
|
21
|
+
|
22
|
+
# Specify which files should be added to the gem when it is released.
|
23
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
24
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
25
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
|
26
|
+
end
|
27
|
+
spec.bindir = "exe"
|
28
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
29
|
+
spec.require_paths = ["lib"]
|
30
|
+
|
31
|
+
# Runtime dependencies
|
32
|
+
spec.add_dependency "httparty"
|
33
|
+
|
34
|
+
end
|
metadata
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: simplepush
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.6.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Christopher Oezbek
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-10-31 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: httparty
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
description: Httpary wrapper for SimplePush.io
|
28
|
+
email:
|
29
|
+
- c.oezbek@gmail.com
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- ".gitignore"
|
35
|
+
- Gemfile
|
36
|
+
- Gemfile.lock
|
37
|
+
- README.md
|
38
|
+
- Rakefile
|
39
|
+
- bin/console
|
40
|
+
- bin/setup
|
41
|
+
- example/async.rb
|
42
|
+
- example/config.rb
|
43
|
+
- example/example.rb
|
44
|
+
- lib/simplepush.rb
|
45
|
+
- lib/simplepush/version.rb
|
46
|
+
- simplepush.gemspec
|
47
|
+
homepage: https://github.com/coezbek/simplepush
|
48
|
+
licenses: []
|
49
|
+
metadata:
|
50
|
+
allowed_push_host: https://rubygems.org
|
51
|
+
homepage_uri: https://github.com/coezbek/simplepush
|
52
|
+
source_code_uri: https://github.com/coezbek/simplepush
|
53
|
+
changelog_uri: https://github.com/coezbek/simplepush/README.md#Changelog
|
54
|
+
post_install_message:
|
55
|
+
rdoc_options: []
|
56
|
+
require_paths:
|
57
|
+
- lib
|
58
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: 2.4.0
|
63
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
requirements: []
|
69
|
+
rubygems_version: 3.2.3
|
70
|
+
signing_key:
|
71
|
+
specification_version: 4
|
72
|
+
summary: Ruby SimplePush.io API client (unofficial)
|
73
|
+
test_files: []
|