Class: Pushpad::Subscription
- Inherits:
-
Object
- Object
- Pushpad::Subscription
- Defined in:
- lib/pushpad/subscription.rb
Defined Under Namespace
Classes: CountError, FindError
Instance Attribute Summary collapse
-
#auth ⇒ Object
readonly
Returns the value of attribute auth.
-
#created_at ⇒ Object
readonly
Returns the value of attribute created_at.
-
#endpoint ⇒ Object
readonly
Returns the value of attribute endpoint.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#last_click_at ⇒ Object
readonly
Returns the value of attribute last_click_at.
-
#p256dh ⇒ Object
readonly
Returns the value of attribute p256dh.
-
#tags ⇒ Object
readonly
Returns the value of attribute tags.
-
#uid ⇒ Object
readonly
Returns the value of attribute uid.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(options) ⇒ Subscription
constructor
A new instance of Subscription.
Constructor Details
#initialize(options) ⇒ Subscription
Returns a new instance of Subscription.
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/pushpad/subscription.rb', line 11 def initialize() @id = [:id] @endpoint = [:endpoint] @p256dh = [:p256dh] @auth = [:auth] @uid = [:uid] = [:tags] @last_click_at = [:last_click_at] && Time.parse([:last_click_at]) @created_at = [:created_at] && Time.parse([:created_at]) end |
Instance Attribute Details
#auth ⇒ Object (readonly)
Returns the value of attribute auth.
9 10 11 |
# File 'lib/pushpad/subscription.rb', line 9 def auth @auth end |
#created_at ⇒ Object (readonly)
Returns the value of attribute created_at.
9 10 11 |
# File 'lib/pushpad/subscription.rb', line 9 def created_at @created_at end |
#endpoint ⇒ Object (readonly)
Returns the value of attribute endpoint.
9 10 11 |
# File 'lib/pushpad/subscription.rb', line 9 def endpoint @endpoint end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
9 10 11 |
# File 'lib/pushpad/subscription.rb', line 9 def id @id end |
#last_click_at ⇒ Object (readonly)
Returns the value of attribute last_click_at.
9 10 11 |
# File 'lib/pushpad/subscription.rb', line 9 def last_click_at @last_click_at end |
#p256dh ⇒ Object (readonly)
Returns the value of attribute p256dh.
9 10 11 |
# File 'lib/pushpad/subscription.rb', line 9 def p256dh @p256dh end |
#tags ⇒ Object (readonly)
Returns the value of attribute tags.
9 10 11 |
# File 'lib/pushpad/subscription.rb', line 9 def end |
#uid ⇒ Object (readonly)
Returns the value of attribute uid.
9 10 11 |
# File 'lib/pushpad/subscription.rb', line 9 def uid @uid end |
Class Method Details
.count(options = {}) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/pushpad/subscription.rb', line 22 def self.count( = {}) project_id = [:project_id] || Pushpad.project_id raise "You must set project_id" unless project_id endpoint = "https://pushpad.xyz/api/v1/projects/#{project_id}/subscriptions" response = Request.head(endpoint, query_parameters: query_parameters()) unless response.code == "200" raise CountError, "Response #{response.code} #{response.message}: #{response.body}" end response["X-Total-Count"].to_i end |
.find_all(options = {}) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/pushpad/subscription.rb', line 36 def self.find_all( = {}) project_id = [:project_id] || Pushpad.project_id raise "You must set project_id" unless project_id query_parameters_with_pagination = query_parameters() query_parameters_with_pagination << ["page", [:page]] if .key?(:page) response = Request.get("https://pushpad.xyz/api/v1/projects/#{project_id}/subscriptions", query_parameters: query_parameters_with_pagination) unless response.code == "200" raise FindError, "Response #{response.code} #{response.message}: #{response.body}" end JSON.parse(response.body, symbolize_names: true).map do |attributes| new(attributes) end end |