Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# This file is for unifying the coding style for different editors and IDEs
# editorconfig.org

root = true

[*]
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.{js,rb,less,yml,yaml,jsx,rake}]
indent_style = space
indent_size = 2

[{package.json,.travis.yml}]
indent_style = space
indent_size = 2

[*.{css,html}]
indent_style = tab
indent_size = 2

[*.py]
indent_style = space
indent_size = 4

[Makefile]
indent_style = tab

[*.md]
trim_trailing_whitespace = false

[*.{sh,markdown}]
indent_size = 4

[*.go]
indent_style = tab
indent_size = 4
2 changes: 2 additions & 0 deletions .env.development
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
NOTIFICATION_TITLE=

NOTIFICATION_URL=

REDIS_URL=

SLACK_WEBHOOK=
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ In order of precedence RTPush uses:
```
NOTIFICATION_TITLE=XX

NOTIFICATION_URL=XX

REDIS_URL=XX

SLACK_WEBHOOK=XX
Expand Down
3 changes: 3 additions & 0 deletions lib/rtpush.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module RTPush
def self.initialize(options, message)
raise ArgumentError, 'Missing Message param' if message.to_s.empty?
raise ArgumentError, 'Missing Arguments params' if options.empty?

push(strategies(options), message)
end

Expand All @@ -21,6 +22,8 @@ def self.strategies(options)
strategies = []
options.each do |option|
case option
when 'post'
strategies << RTPush::HttpAdapter
when 'sms'
strategies << RTPush::TwilioAdapter
when 'mobile'
Expand Down
2 changes: 2 additions & 0 deletions lib/rtpush/adapters/fcm_adapter.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require_relative './base_adapter'
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/FrozenStringLiteralComment: Missing magic comment # frozen_string_literal: true.


module RTPush
class FcmAdapter < RTPush::BaseAdapter
class << self
Expand Down
42 changes: 42 additions & 0 deletions lib/rtpush/adapters/http_adapter.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
require_relative './base_adapter'
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/FrozenStringLiteralComment: Missing magic comment # frozen_string_literal: true.


module RTPush
class HttpAdapter < RTPush::BaseAdapter
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/Documentation: Missing top-level class documentation comment.

class << self
def push(message)
payload = {
notification: {
title: ENV['NOTIFICATION_TITLE'],
body: message
}
}
http_request(ENV['NOTIFICATION_URL'], 'post', payload)
rescue StandardError => e
raise Errors::AdapterError, e.message
end

def http_request(url, http_method, payload)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Metrics/AbcSize: Assignment Branch Condition size for http_request is too high. [20.47/15]
Metrics/MethodLength: Method has too many lines. [19/10]

uri = URI.parse url.strip
http = Net::HTTP.new(uri.host, uri.port)
if uri.scheme == 'https'
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
end
http.open_timeout = 5
http.read_timeout = 30
# http.set_debug_output($stdout)
case http_method
when 'get'
request = Net::HTTP::Get.new(safe_url(uri.path, uri.query, payload))
else
request = Net::HTTP::Post.new(uri.request_uri)
request['Content-Type'] = 'application/json'
request.body = payload.to_json
end
http.request(request)
rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH, Net::ReadTimeout, Net::OpenTimeout => e
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Metrics/LineLength: Line is too long. [94/80]

OpenStruct.new(code: 0, body: e.message)
end
end
end
end
2 changes: 2 additions & 0 deletions lib/rtpush/adapters/instapush_adapter.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require_relative './base_adapter'
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/FrozenStringLiteralComment: Missing magic comment # frozen_string_literal: true.


module RTPush
class InstapushAdapter < RTPush::BaseAdapter
class << self
Expand Down
2 changes: 2 additions & 0 deletions lib/rtpush/adapters/rpush_adapter.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require_relative './base_adapter'
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/FrozenStringLiteralComment: Missing magic comment # frozen_string_literal: true.


module RTPush
class RpushAdapter < RTPush::BaseAdapter
class << self
Expand Down
2 changes: 2 additions & 0 deletions lib/rtpush/adapters/slack_adapter.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require_relative './base_adapter'
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/FrozenStringLiteralComment: Missing magic comment # frozen_string_literal: true.


module RTPush
class SlackAdapter < RTPush::BaseAdapter
class << self
Expand Down
2 changes: 2 additions & 0 deletions lib/rtpush/adapters/twilio_adapter.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require_relative './base_adapter'
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/FrozenStringLiteralComment: Missing magic comment # frozen_string_literal: true.


module RTPush
class TwilioAdapter < RTPush::BaseAdapter
class << self
Expand Down