Class: Octopush::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/octopush-ruby/client.rb

Instance Method Summary collapse

Constructor Details

#initializeClient

Returns a new instance of Client.



8
9
10
11
12
13
# File 'lib/octopush-ruby/client.rb', line 8

def initialize
  raise "Should set user configuration before use" if Octopush.configuration.nil?

  @constants = Octopush::Constants
  @domain = @constants::DOMAIN
end

Instance Method Details

#create_sub_account(first_name, last_name, raison_sociable, alert_bound, alert_sms_type) ⇒ Object

create sub account

first_name
last_name
raison_sociable
alert_bound
alert_sms_type - check Octopush::Constants::SMS_TYPES


72
73
74
75
76
77
78
79
80
81
82
# File 'lib/octopush-ruby/client.rb', line 72

def  first_name, last_name, raison_sociable, alert_bound,
                       alert_sms_type
  path = @constants::PATH_SUB_ACCOUNT
  data = user_hash.merge( first_name: first_name,
                          last_name: last_name,
                          raison_sociable: raison_sociable,
                          alert_bound: alert_bound,
                          alert_sms_type: alert_sms_type
                        )
  res = request @domain, path, data
end

#credit_sub_account(sub_account_email, sms_amount, sms_type) ⇒ Object

credit sub account

sub_account - sub account email
sms_amount - number of credits
sms_type - a sms type, check Octopush::Constants::SMS_TYPES


88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/octopush-ruby/client.rb', line 88

def  , sms_amount, sms_type
  path = @constants::PATH_CREDIT_SUB_ACCOUNT_TOKEN
  data = user_hash.merge(sub_account_email: )
  res = request @domain, path, data
  token_res = parse_response res.body

  token = token_res['token']
  path = @constants::PATH_CREDIT_SUB_ACCOUNT
  if sms_type != 'FR' and sms_type != 'XXX'
    sms_type = 'FR'
  end

  data = data.merge(sms_number: sms_amount,
                    sms_type: sms_type,
                    token: token)

  res = request @domain, path, data
end

#edit_options(*args) ⇒ Object

update user options args should be a hash with the options that you want to update could be answer_email, sms_alert_bound, sms_alert_type

Examples:

{answer_email: '[email protected]'}


20
21
22
23
24
# File 'lib/octopush-ruby/client.rb', line 20

def edit_options *args
  path = @constants::PATH_EDIT_OPTIONS
  data = user_hash.merge args[0]
  res = request @domain, path, data
end

#get_balanceObject

returns current user’s balance return a hash in the form: => balance



28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/octopush-ruby/client.rb', line 28

def get_balance
  path = @constants::PATH_BALANCE
  data = user_hash
  response = request @domain, path, data

  h = {}
  response["balance"].each do |balance|
    h = h.merge(balance.attributes["type"] => balance)
  end

  h
end

#send_sms(sms, sending_date = nil, request_keys = nil) ⇒ Object

send a sms

sms - a Octopush::SMS instance
sending_date - a date to send sms, required if sms_mode is DIFFERE,
               check Octopush::Constants::SMS_MODES for modes allowed
request_keys - Lists the key fields of the application you want to add
               in the sha1 hash. Check Octopush::Constants::REQUEST_KEYS


47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/octopush-ruby/client.rb', line 47

def send_sms sms, sending_date=nil, request_keys=nil
  raise 'require a sms object' if sms.class != Octopush::SMS

  path = @constants::PATH_SMS
  data = user_hash.merge(sms.variables_hash)

  if data[:sms_mode] == @constants::SMS_MODES['DIFFERE']
    raise 'Need specify sending_date for DIFFERE mode' if sending_date.nil?
    data = data.merge(sending_date: sending_date)
  end

  if !request_keys.nil?
    sha1 = get_request_sha1_string(request_keys)
    data = data.merge(request_keys: request_keys, request_sha1: sha1)
  end

  res = request @domain, path, data
end