Class: Pushpad::Subscription::CountQuery

Inherits:
Object
  • Object
show all
Defined in:
lib/pushpad/subscription.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ CountQuery

Returns a new instance of CountQuery.



13
14
15
# File 'lib/pushpad/subscription.rb', line 13

def initialize(options)
  @options = options
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



11
12
13
# File 'lib/pushpad/subscription.rb', line 11

def options
  @options
end

Instance Method Details

#performObject



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/pushpad/subscription.rb', line 17

def perform
  project_id = options[: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