Class: Cindy::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/cindy/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(sendy_url, api_key = nil) ⇒ Client

Returns a new instance of Client.



8
9
10
11
# File 'lib/cindy/client.rb', line 8

def initialize(sendy_url, api_key = nil)
  @url = sendy_url
  @key = api_key || ENV['SENDY_API_KEY']
end

Instance Method Details

#active_subscriber_count(list_id) ⇒ Object



37
38
39
40
41
42
43
# File 'lib/cindy/client.rb', line 37

def active_subscriber_count(list_id)
  response = connection.post "api/subscribers/active-subscriber-count.php" do |req|
    req.body = {list_id: list_id, api_key: @key}
  end

  response.body.to_i
end

#subscribe(list_id, email, name = nil) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/cindy/client.rb', line 13

def subscribe(list_id, email, name = nil)
  response = connection.post "subscribe" do |req|
    params = {list: list_id, email: email, boolean: true}
    params[:name] = name if name
    req.body = params
  end

  !!(response.body =~ /^1$/)
end

#subscription_status(list_id, email) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/cindy/client.rb', line 29

def subscription_status(list_id, email)
  response = connection.post "api/subscribers/subscription-status.php" do |req|
    req.body = {list_id: list_id, email: email, api_key: @key}
  end

  response.body
end

#unsubscribe(list_id, email) ⇒ Object



23
24
25
26
27
# File 'lib/cindy/client.rb', line 23

def unsubscribe(list_id, email)
  response = connection.post "unsubscribe", {list: list_id, email: email, boolean: true}

  !!(response.body =~ /^1$/)
end