Class: DCMClient::Client

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

Constant Summary collapse

UNSUBSCRIBE_URI =
'/api/account/%s/subscribers/%s'
SUBSCRIBE_URI =
'/api/account/%s/subscribers/add_subscriptions'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Client

Create and return a new client with an established connection to DCM.

:username
:password
:api_root - fully-qualified root URL to DCM, including protocol and (optional) port.


15
16
17
# File 'lib/dcm_client/client.rb', line 15

def initialize(opts={})
  @connection = Connection.new(opts)
end

Instance Attribute Details

#connectionObject (readonly)

Returns the value of attribute connection.



6
7
8
# File 'lib/dcm_client/client.rb', line 6

def connection
  @connection
end

Instance Method Details

#delete_wireless_subscriber(number, account) ⇒ Object

Completely remove a wireless subscriber from an account.

number - String - the wireless number (with country code), formatted as CC+NUMBER
         Ex: 1+4444444444
account - String - the account code


25
26
27
28
# File 'lib/dcm_client/client.rb', line 25

def delete_wireless_subscriber(number, )
  number = Base64.encode64(number).strip
  @connection.delete(UNSUBSCRIBE_URI % [, number])
end

#email_subscribe(email, account, topics, send_notifications = true) ⇒ Object

Add one or more subscriptions to a wireless subscriber. If the subscriber doesn’t exist it will be created.

email              - String  - the email address to subscribe
account            - String  - the account code
topics             - Array   - the topics to subscribe
send_notifications - Boolean - whether DCM should send the subscriber a notification (defaults to true)


58
59
60
61
62
63
64
65
66
67
# File 'lib/dcm_client/client.rb', line 58

def email_subscribe(email, , topics, send_notifications=true)
  sub = {
    :subscriber => {
      :email => email,
      :send_notifications => send_notifications,
      :topics => topics.map{|code| {:code => code} }
    }
  }
  @connection.post(SUBSCRIBE_URI % , sub)
end

#wireless_subscribe(number, account, topics, send_notifications = true) ⇒ Object

Add one or more subscriptions to a wireless subscriber. If the subscriber doesn’t exist it will be created.

number             - String  - the wireless number (with country code), formatted as CC+NUMBER
                               Ex: 1+4444444444
account            - String  - the account code
topics             - Array   - the topics to subscribe
send_notifications - Boolean - whether DCM should send the subscriber a notification (defaults to true)


38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/dcm_client/client.rb', line 38

def wireless_subscribe(number, , topics, send_notifications=true)
  country_code, rest = number.split('+')
  sub = {
    :subscriber => {
      :phone =>  rest,
      :country_code =>  country_code,
      :send_notifications => send_notifications,
      :topics => topics.map{|code| {:code => code} }
    }
  }
  @connection.post(SUBSCRIBE_URI % , sub)
end