Class: Pushpad::Subscription
- Inherits:
-
Object
- Object
- Pushpad::Subscription
- Defined in:
- lib/pushpad/subscription.rb
Defined Under Namespace
Classes: CountError, CreateError, DeleteError, FindError, UpdateError
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
- .count(options = {}) ⇒ Object
- .create(attributes, options = {}) ⇒ Object
- .find(id, options = {}) ⇒ Object
- .find_all(options = {}) ⇒ Object
Instance Method Summary collapse
- #delete(options = {}) ⇒ Object
-
#initialize(options) ⇒ Subscription
constructor
A new instance of Subscription.
- #update(attributes, options = {}) ⇒ Object
Constructor Details
#initialize(options) ⇒ Subscription
Returns a new instance of Subscription.
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/pushpad/subscription.rb', line 20 def initialize() @id = [:id] @endpoint = [:endpoint] @p256dh = [:p256dh] @auth = [:auth] @uid = [:uid] @tags = [: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.
18 19 20 |
# File 'lib/pushpad/subscription.rb', line 18 def auth @auth end |
#created_at ⇒ Object (readonly)
Returns the value of attribute created_at.
18 19 20 |
# File 'lib/pushpad/subscription.rb', line 18 def created_at @created_at end |
#endpoint ⇒ Object (readonly)
Returns the value of attribute endpoint.
18 19 20 |
# File 'lib/pushpad/subscription.rb', line 18 def endpoint @endpoint end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
18 19 20 |
# File 'lib/pushpad/subscription.rb', line 18 def id @id end |
#last_click_at ⇒ Object (readonly)
Returns the value of attribute last_click_at.
18 19 20 |
# File 'lib/pushpad/subscription.rb', line 18 def last_click_at @last_click_at end |
#p256dh ⇒ Object (readonly)
Returns the value of attribute p256dh.
18 19 20 |
# File 'lib/pushpad/subscription.rb', line 18 def p256dh @p256dh end |
#tags ⇒ Object (readonly)
Returns the value of attribute tags.
18 19 20 |
# File 'lib/pushpad/subscription.rb', line 18 def @tags end |
#uid ⇒ Object (readonly)
Returns the value of attribute uid.
18 19 20 |
# File 'lib/pushpad/subscription.rb', line 18 def uid @uid end |
Class Method Details
.count(options = {}) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/pushpad/subscription.rb', line 45 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.}: #{response.body}" end response["X-Total-Count"].to_i end |
.create(attributes, options = {}) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/pushpad/subscription.rb', line 31 def self.create(attributes, = {}) 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.post(endpoint, attributes.to_json) unless response.code == "201" raise CreateError, "Response #{response.code} #{response.}: #{response.body}" end new(JSON.parse(response.body, symbolize_names: true)) end |
.find(id, options = {}) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/pushpad/subscription.rb', line 59 def self.find(id, = {}) project_id = [:project_id] || Pushpad.project_id raise "You must set project_id" unless project_id response = Request.get("https://pushpad.xyz/api/v1/projects/#{project_id}/subscriptions/#{id}") unless response.code == "200" raise FindError, "Response #{response.code} #{response.}: #{response.body}" end new(JSON.parse(response.body, symbolize_names: true)) end |
.find_all(options = {}) ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/pushpad/subscription.rb', line 72 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.}: #{response.body}" end JSON.parse(response.body, symbolize_names: true).map do |attributes| new(attributes) end end |
Instance Method Details
#delete(options = {}) ⇒ Object
111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/pushpad/subscription.rb', line 111 def delete( = {}) project_id = [:project_id] || Pushpad.project_id raise "You must set project_id" unless project_id raise "You must set id" unless id response = Request.delete("https://pushpad.xyz/api/v1/projects/#{project_id}/subscriptions/#{id}") unless response.code == "204" raise DeleteError, "Response #{response.code} #{response.}: #{response.body}" end end |
#update(attributes, options = {}) ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/pushpad/subscription.rb', line 91 def update(attributes, = {}) project_id = [:project_id] || Pushpad.project_id raise "You must set project_id" unless project_id raise "You must set id" unless id endpoint = "https://pushpad.xyz/api/v1/projects/#{project_id}/subscriptions/#{id}" response = Request.patch(endpoint, attributes.to_json) unless response.code == "200" raise UpdateError, "Response #{response.code} #{response.}: #{response.body}" end attributes = JSON.parse(response.body, symbolize_names: true) @uid = attributes[:uid] @tags = attributes[:tags] self end |