-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit d349687
Showing
11 changed files
with
261 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/.bundle/ | ||
/.yardoc | ||
/_yardoc/ | ||
/coverage/ | ||
/doc/ | ||
/pkg/ | ||
/spec/reports/ | ||
/tmp/ | ||
/example/push.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# frozen_string_literal: true | ||
|
||
source "https://rubygems.org" | ||
|
||
# Specify your gem's dependencies in simplepush.gemspec | ||
gemspec | ||
|
||
gem "rake", "~> 13.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
PATH | ||
remote: . | ||
specs: | ||
simplepush (0.1.0) | ||
|
||
GEM | ||
remote: https://rubygems.org/ | ||
specs: | ||
httparty (0.20.0) | ||
mime-types (~> 3.0) | ||
multi_xml (>= 0.5.2) | ||
mime-types (3.3.1) | ||
mime-types-data (~> 3.2015) | ||
mime-types-data (3.2021.0901) | ||
multi_xml (0.6.0) | ||
rake (13.0.6) | ||
|
||
PLATFORMS | ||
x86_64-linux | ||
|
||
DEPENDENCIES | ||
httparty | ||
rake (~> 13.0) | ||
simplepush! | ||
|
||
BUNDLED WITH | ||
2.2.5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
# Simplepush Gem for Ruby | ||
|
||
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. | ||
|
||
## Installation | ||
|
||
Add this line to your application's Gemfile: | ||
|
||
```ruby | ||
gem 'simplepush' | ||
``` | ||
|
||
And then execute: | ||
|
||
``` | ||
$ bundle install | ||
``` | ||
|
||
Or install it yourself as: | ||
|
||
``` | ||
$ gem install simplepush | ||
``` | ||
|
||
Add as a dependency: | ||
|
||
```ruby | ||
require 'simplepush' | ||
``` | ||
|
||
## Usage | ||
|
||
```ruby | ||
# From example/example.rb | ||
require 'simplepush' | ||
|
||
Simplepush.send('<your key>', "Title", "Message") # Unenrypted | ||
|
||
Simplepush.send('<your key>', "Title", "Message", "<pass>", "<salt>") # Enrypted | ||
|
||
``` | ||
|
||
## Example of query | ||
|
||
The following is a sample of the query as it is produced: | ||
|
||
```json | ||
{ | ||
"args": {}, | ||
"data": "", | ||
"files": {}, | ||
"form": { | ||
"encrypted": "true", | ||
"iv": "CEEFFBE72CC70DF45480DDAC775743B6", | ||
"key": "<the key, the key>", | ||
"msg": "szR70wqD9g8T2nX0FRZwoQ==" | ||
}, | ||
"headers": { | ||
"Accept": "*/*", | ||
"Accept-Encoding": "gzip;q=1.0,deflate;q=0.6,identity;q=0.3", | ||
"Content-Length": "94", | ||
"Content-Type": "application/x-www-form-urlencoded", | ||
"Host": "httpbin.org", | ||
"User-Agent": "Ruby", | ||
"X-Amzn-Trace-Id": "Root=1-617714e4-08fc2a3f349df4203121ce0e" | ||
}, | ||
"json": null, | ||
"origin": "91.32.103.70", | ||
"url": "https://httpbin.org/post" | ||
} | ||
``` | ||
|
||
## Todos | ||
|
||
- [x] Encrypted Messages | ||
- [x] Processing responses | ||
- [ ] Async calls | ||
|
||
## Changelog | ||
|
||
- 0.5.0 Initial Release | ||
|
||
## Contributing | ||
|
||
Bug reports and pull requests are welcome on GitHub at https://github.com/coezbek/simplepush | ||
|
||
## License | ||
|
||
MIT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# frozen_string_literal: true | ||
|
||
require "bundler/gem_tasks" | ||
task default: %i[] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#!/usr/bin/env ruby | ||
# frozen_string_literal: true | ||
|
||
require "bundler/setup" | ||
require "simplepush" | ||
|
||
# You can add fixtures and/or initialization code here to make experimenting | ||
# with your gem easier. You can also use a different console, if you like. | ||
|
||
# (If you use this, don't forget to add pry to your Gemfile!) | ||
# require "pry" | ||
# Pry.start | ||
|
||
require "irb" | ||
IRB.start(__FILE__) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/usr/bin/env bash | ||
set -euo pipefail | ||
IFS=$'\n\t' | ||
set -vx | ||
|
||
bundle install | ||
|
||
# Do any other automated setup that you need to do here |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
require_relative '../lib/simplepush' | ||
|
||
puts Simplepush.send('<key>', "Title", "Message", "<pass>", "<salt>") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative "simplepush/version" | ||
require 'httparty' | ||
|
||
class Simplepush | ||
|
||
include HTTParty | ||
|
||
base_uri 'https://api.simplepush.io'.freeze | ||
# For testing: | ||
# base_uri 'https://httpbin.org'.freeze | ||
format :json | ||
default_timeout 5 # 5 seconds | ||
debug_output $stdout | ||
|
||
# Send a plain-text message. | ||
# | ||
# This method is blocking. | ||
# | ||
# If password and salt are provided, then message and title will be encrypted. | ||
def send(key, title, message, password = nil, salt = '1789F0B8C4A051E5', event = nil) | ||
raise "Key and message argument must be set" unless key && message | ||
|
||
payload = {} | ||
payload[:key] = key | ||
payload[:msg] = message | ||
payload[:event] = event if event | ||
payload[:title] = title if title | ||
|
||
if password | ||
require 'openssl' | ||
payload[:encrypted] = true | ||
|
||
cipher = OpenSSL::Cipher::AES.new(128, :CBC) | ||
cipher.encrypt | ||
cipher.key = [Digest::SHA1.hexdigest(password + salt)[0,32]].pack "H*" | ||
|
||
# Set random_iv and store as payload | ||
payload[:iv] = cipher.random_iv.unpack("H*").first.upcase | ||
|
||
# Automatically uses PKCS7 | ||
payload[:msg] = Base64.urlsafe_encode64(cipher.update(payload[:msg]) + cipher.final) | ||
|
||
if title | ||
cipher.encrypt | ||
payload[:title] = Base64.urlsafe_encode64(cipher.update(payload[:title]) + cipher.final) | ||
end | ||
end | ||
|
||
return self.class.post('/send', body: payload) | ||
end | ||
|
||
def self.send(...) | ||
Simplepush.new.send(...) | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# frozen_string_literal: true | ||
|
||
class Simplepush | ||
VERSION = "0.5.0" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative "lib/simplepush/version" | ||
|
||
Gem::Specification.new do |spec| | ||
spec.name = "simplepush" | ||
spec.version = Simplepush::VERSION | ||
spec.authors = ["Christopher Oezbek"] | ||
spec.email = ["[email protected]"] | ||
|
||
spec.summary = "Ruby SimplePush.io API client (unofficial)" | ||
spec.description = "Httpary wrapper for SimplePush.io" | ||
spec.homepage = "https://github.com/coezbek/simplepush" | ||
spec.required_ruby_version = Gem::Requirement.new(">= 2.4.0") | ||
|
||
spec.metadata["allowed_push_host"] = "https://rubygems.org" | ||
|
||
spec.metadata["homepage_uri"] = spec.homepage | ||
spec.metadata["source_code_uri"] = spec.homepage | ||
spec.metadata["changelog_uri"] = "https://github.com/coezbek/simplepush/README.md#Changelog" | ||
|
||
# Specify which files should be added to the gem when it is released. | ||
# The `git ls-files -z` loads the files in the RubyGem that have been added into git. | ||
spec.files = Dir.chdir(File.expand_path(__dir__)) do | ||
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) } | ||
end | ||
spec.bindir = "exe" | ||
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) } | ||
spec.require_paths = ["lib"] | ||
|
||
# Uncomment to register a new dependency of your gem | ||
spec.add_dependency "httparty" | ||
|
||
end |