notifiable-sender 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1802fb2355228528ec608651288ee1226a63a4f6
4
- data.tar.gz: 744a6e5283de23e1a9fac1ded1f755949a48cd10
3
+ metadata.gz: a249ebe19e8abf711ae1830ed30878b403a786a8
4
+ data.tar.gz: 2ec98a7335cee4311398278f650484804298bd7e
5
5
  SHA512:
6
- metadata.gz: e975605296b9ec6c001a46515392addc64c313fd8897683bb3b25b650dd0fe72f96ad8a914dd21c67f2f6c98cfc0ada85d4481546f5821836dc1759455f8e014
7
- data.tar.gz: 411776c2e0bb6a026e650a8fa0d24d137a107757028240f3eda8482b1d1bc6d5f78cc0daebbfa804962f3baeffe7bc42948cea9c9a7ef975972d5a03ff71c688
6
+ metadata.gz: affe2b40c14243ce23a772079fc055fff40754ba16d4fa9a1b07a2690b36bbb90753685bbb8962091113a43b3dafd3a9f2306f92ee8c084525872c5cc4953d8c
7
+ data.tar.gz: 5f3ee8e9d2af9980fffc648e435ad3a21c77811e3dd0e80a0bdcc0eee51a448ab32b07befee39d4473d40116a39f861dd346bf2ecbb99f695542063fbbfe48b8
data/bin/console CHANGED
@@ -12,7 +12,7 @@ require "notifiable/sender"
12
12
 
13
13
  # convenience method
14
14
  def send_notification(recipient_email_address, message, access_id = ENV['access_id'], secret_key = ENV['secret_key'])
15
- sender = Notifiable::Sender::V1.new 'https://notifiable-staging.herokuapp.com', access_id, secret_key: secret_key
15
+ sender = Notifiable::Sender.new 'https://notifiable-staging.herokuapp.com', access_id, secret_key: secret_key
16
16
  sender.send_notification_to_user(recipient_email_address, message: message)
17
17
  end
18
18
 
@@ -5,37 +5,34 @@ require 'json'
5
5
  require 'logger'
6
6
 
7
7
  module Notifiable
8
- module Sender
9
- class V1
10
- def initialize(base_uri, access_id, secret_key: nil, logger: Logger.new(STDOUT))
11
- raise 'base_uri cannot be nil' if base_uri.empty?
12
- raise 'access_id cannot be nil' if access_id.empty?
13
-
14
- @base_uri, @access_id, @secret_key, @logger = base_uri, access_id, secret_key, logger
15
- end
16
-
17
- def send_notification_to_user(user_alias, message: nil, parameters: nil, content_available: nil)
18
- filters = [{property: "user_alias", predicate: "eq", value: user_alias}]
19
- send_notification(message: message, parameters: parameters, content_available: content_available, filters: filters)
20
- end
8
+ class Sender
9
+ def initialize(base_uri, access_id, secret_key: nil, logger: Logger.new(STDOUT))
10
+ raise 'base_uri cannot be nil' if base_uri.empty?
11
+ raise 'access_id cannot be nil' if access_id.empty?
21
12
 
22
- def send_notification(message: nil, parameters: nil, filters: nil, content_available: nil)
23
- body = {}
24
- body[:message] = message unless message.nil?
25
- body[:parameters] = parameters.to_json unless parameters.nil?
26
- body[:filters] = filters.to_json unless filters.nil?
27
- body[:content_available] = content_available unless content_available.nil?
28
- headers = {}
29
- headers[:authorization] = @access_id unless @secret_key
30
- @request = RestClient::Request.new url: "#{@base_uri}/api/v1/notifications", payload: {notification: body}, method: :post, headers: headers
31
- @request = ApiAuth.sign!(@request, @access_id, @secret_key) if @secret_key
32
- begin
33
- @request.execute
34
- rescue RestClient::ExceptionWithResponse => e
35
- @logger.warn "Request failed with code: #{e.response.code} body: #{e.response.body}"
36
- end
13
+ @base_uri, @access_id, @secret_key, @logger = base_uri, access_id, secret_key, logger
14
+ end
15
+
16
+ def send_notification_to_user(user_alias, message: nil, parameters: nil, content_available: nil)
17
+ filters = [{property: "user_alias", predicate: "eq", value: user_alias}]
18
+ send_notification(message: message, parameters: parameters, content_available: content_available, filters: filters)
19
+ end
20
+
21
+ def send_notification(message: nil, parameters: nil, filters: nil, content_available: nil)
22
+ body = {}
23
+ body[:message] = message unless message.nil?
24
+ body[:parameters] = parameters.to_json unless parameters.nil?
25
+ body[:filters] = filters.to_json unless filters.nil?
26
+ body[:content_available] = content_available unless content_available.nil?
27
+ headers = {}
28
+ headers[:authorization] = @access_id unless @secret_key
29
+ @request = RestClient::Request.new url: "#{@base_uri}/api/v1/notifications", payload: {notification: body}, method: :post, headers: headers
30
+ @request = ApiAuth.sign!(@request, @access_id, @secret_key) if @secret_key
31
+ begin
32
+ @request.execute
33
+ rescue RestClient::ExceptionWithResponse => e
34
+ @logger.warn "Request failed with code: #{e.response.code} body: #{e.response.body}"
37
35
  end
38
-
39
36
  end
40
37
  end
41
38
  end
@@ -1,5 +1,5 @@
1
1
  module Notifiable
2
2
  module Sender
3
- VERSION = "0.1.0"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: notifiable-sender
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Brooke-Smith