Class: Pushpad::Notification
- Inherits:
-
Object
- Object
- Pushpad::Notification
- Defined in:
- lib/pushpad/notification.rb
Defined Under Namespace
Classes: CancelError, DeliveryError, FindError, ReadonlyError
Instance Attribute Summary collapse
-
#actions ⇒ Object
Returns the value of attribute actions.
-
#badge_url ⇒ Object
Returns the value of attribute badge_url.
-
#body ⇒ Object
Returns the value of attribute body.
-
#created_at ⇒ Object
readonly
Returns the value of attribute created_at.
-
#custom_data ⇒ Object
Returns the value of attribute custom_data.
-
#custom_metrics ⇒ Object
Returns the value of attribute custom_metrics.
-
#icon_url ⇒ Object
Returns the value of attribute icon_url.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#image_url ⇒ Object
Returns the value of attribute image_url.
-
#opened_count ⇒ Object
readonly
Returns the value of attribute opened_count.
-
#require_interaction ⇒ Object
Returns the value of attribute require_interaction.
-
#scheduled_count ⇒ Object
readonly
Returns the value of attribute scheduled_count.
-
#send_at ⇒ Object
Returns the value of attribute send_at.
-
#silent ⇒ Object
Returns the value of attribute silent.
-
#starred ⇒ Object
Returns the value of attribute starred.
-
#successfully_sent_count ⇒ Object
readonly
Returns the value of attribute successfully_sent_count.
-
#target_url ⇒ Object
Returns the value of attribute target_url.
-
#title ⇒ Object
Returns the value of attribute title.
-
#ttl ⇒ Object
Returns the value of attribute ttl.
-
#urgent ⇒ Object
Returns the value of attribute urgent.
Class Method Summary collapse
Instance Method Summary collapse
- #broadcast(options = {}) ⇒ Object
- #cancel ⇒ Object
- #deliver_to(users, options = {}) ⇒ Object
-
#initialize(options) ⇒ Notification
constructor
A new instance of Notification.
- #readonly! ⇒ Object
Constructor Details
#initialize(options) ⇒ Notification
Returns a new instance of Notification.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/pushpad/notification.rb', line 21 def initialize() @id = [:id] @created_at = [:created_at] && Time.parse([:created_at]) @scheduled_count = [:scheduled_count] @successfully_sent_count = [:successfully_sent_count] @opened_count = [:opened_count] @body = [:body] @title = [:title] @target_url = [:target_url] @icon_url = [:icon_url] @badge_url = [:badge_url] @image_url = [:image_url] @ttl = [:ttl] @require_interaction = [:require_interaction] @silent = [:silent] @urgent = [:urgent] @custom_data = [:custom_data] @custom_metrics = [:custom_metrics] @actions = [:actions] @starred = [:starred] @send_at = [:send_at] end |
Instance Attribute Details
#actions ⇒ Object
Returns the value of attribute actions.
18 19 20 |
# File 'lib/pushpad/notification.rb', line 18 def actions @actions end |
#badge_url ⇒ Object
Returns the value of attribute badge_url.
18 19 20 |
# File 'lib/pushpad/notification.rb', line 18 def badge_url @badge_url end |
#body ⇒ Object
Returns the value of attribute body.
18 19 20 |
# File 'lib/pushpad/notification.rb', line 18 def body @body end |
#created_at ⇒ Object (readonly)
Returns the value of attribute created_at.
19 20 21 |
# File 'lib/pushpad/notification.rb', line 19 def created_at @created_at end |
#custom_data ⇒ Object
Returns the value of attribute custom_data.
18 19 20 |
# File 'lib/pushpad/notification.rb', line 18 def custom_data @custom_data end |
#custom_metrics ⇒ Object
Returns the value of attribute custom_metrics.
18 19 20 |
# File 'lib/pushpad/notification.rb', line 18 def custom_metrics @custom_metrics end |
#icon_url ⇒ Object
Returns the value of attribute icon_url.
18 19 20 |
# File 'lib/pushpad/notification.rb', line 18 def icon_url @icon_url end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
19 20 21 |
# File 'lib/pushpad/notification.rb', line 19 def id @id end |
#image_url ⇒ Object
Returns the value of attribute image_url.
18 19 20 |
# File 'lib/pushpad/notification.rb', line 18 def image_url @image_url end |
#opened_count ⇒ Object (readonly)
Returns the value of attribute opened_count.
19 20 21 |
# File 'lib/pushpad/notification.rb', line 19 def opened_count @opened_count end |
#require_interaction ⇒ Object
Returns the value of attribute require_interaction.
18 19 20 |
# File 'lib/pushpad/notification.rb', line 18 def require_interaction @require_interaction end |
#scheduled_count ⇒ Object (readonly)
Returns the value of attribute scheduled_count.
19 20 21 |
# File 'lib/pushpad/notification.rb', line 19 def scheduled_count @scheduled_count end |
#send_at ⇒ Object
Returns the value of attribute send_at.
18 19 20 |
# File 'lib/pushpad/notification.rb', line 18 def send_at @send_at end |
#silent ⇒ Object
Returns the value of attribute silent.
18 19 20 |
# File 'lib/pushpad/notification.rb', line 18 def silent @silent end |
#starred ⇒ Object
Returns the value of attribute starred.
18 19 20 |
# File 'lib/pushpad/notification.rb', line 18 def starred @starred end |
#successfully_sent_count ⇒ Object (readonly)
Returns the value of attribute successfully_sent_count.
19 20 21 |
# File 'lib/pushpad/notification.rb', line 19 def successfully_sent_count @successfully_sent_count end |
#target_url ⇒ Object
Returns the value of attribute target_url.
18 19 20 |
# File 'lib/pushpad/notification.rb', line 18 def target_url @target_url end |
#title ⇒ Object
Returns the value of attribute title.
18 19 20 |
# File 'lib/pushpad/notification.rb', line 18 def title @title end |
#ttl ⇒ Object
Returns the value of attribute ttl.
18 19 20 |
# File 'lib/pushpad/notification.rb', line 18 def ttl @ttl end |
#urgent ⇒ Object
Returns the value of attribute urgent.
18 19 20 |
# File 'lib/pushpad/notification.rb', line 18 def urgent @urgent end |
Class Method Details
.find(id) ⇒ Object
45 46 47 48 49 50 51 52 53 |
# File 'lib/pushpad/notification.rb', line 45 def self.find(id) response = Request.get("https://pushpad.xyz/api/v1/notifications/#{id}") unless response.code == "200" raise FindError, "Response #{response.code} #{response.}: #{response.body}" end new(JSON.parse(response.body, symbolize_names: true)).readonly! end |
.find_all(options = {}) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/pushpad/notification.rb', line 55 def self.find_all( = {}) project_id = [:project_id] || Pushpad.project_id raise "You must set project_id" unless project_id query_parameters = {} query_parameters[:page] = [:page] if .key?(:page) response = Request.get("https://pushpad.xyz/api/v1/projects/#{project_id}/notifications", query_parameters: query_parameters) unless response.code == "200" raise FindError, "Response #{response.code} #{response.}: #{response.body}" end JSON.parse(response.body, symbolize_names: true).map do |attributes| new(attributes).readonly! end end |
Instance Method Details
#broadcast(options = {}) ⇒ Object
79 80 81 |
# File 'lib/pushpad/notification.rb', line 79 def broadcast( = {}) deliver req_body(nil, [:tags]), end |
#cancel ⇒ Object
94 95 96 97 98 99 100 |
# File 'lib/pushpad/notification.rb', line 94 def cancel response = Request.delete("https://pushpad.xyz/api/v1/notifications/#{id}/cancel") unless response.code == "204" raise CancelError, "Response #{response.code} #{response.}: #{response.body}" end end |
#deliver_to(users, options = {}) ⇒ Object
83 84 85 86 87 88 89 90 91 92 |
# File 'lib/pushpad/notification.rb', line 83 def deliver_to(users, = {}) uids = if users.respond_to?(:ids) users.ids elsif users.respond_to?(:collect) users.collect {|u| u.respond_to?(:id) ? u.id : u } else [users.respond_to?(:id) ? users.id : users] end deliver req_body(uids, [:tags]), end |
#readonly! ⇒ Object
74 75 76 77 |
# File 'lib/pushpad/notification.rb', line 74 def readonly! @readonly = true self end |