Class: EPochtaService::EPochtaSMS

Inherits:
EPochtaBase show all
Defined in:
lib/e_pochta_sms.rb

Constant Summary collapse

URL =
'http://atompark.com/api/sms/3.0/'

Instance Attribute Summary

Attributes inherited from EPochtaBase

#parameters, #private_key, #public_key

Instance Method Summary collapse

Methods inherited from EPochtaBase

#calculate_md5, #exec_command, #form_request, #initialize

Constructor Details

This class inherits a constructor from EPochtaService::EPochtaBase

Instance Method Details

#add_phones(params) ⇒ Object



43
44
45
46
47
48
49
50
51
52
# File 'lib/e_pochta_sms.rb', line 43

def add_phones(params)
  params['action'] = 'addPhoneToAddressBook'
  result = exec_command(params)
  result = JSON.parse(result.body)   
  if result.has_key? 'error'     
    false
  else
    true
  end  
end

#campaign_delivery_statuses(params) ⇒ Object

params = => 12345 campaign_id



93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/e_pochta_sms.rb', line 93

def campaign_delivery_statuses(params)
  params['action']    = 'getCampaignDeliveryStats'
      
  response = exec_command(params)
  response = JSON.parse(response.body)

  if response.has_key? 'error'     
    false
  else
    # makes "phone->status" structure from returned response
    format_delivery_status_hash(response['result'])
  end
  
end

#create_address_book(params) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/e_pochta_sms.rb', line 5

def create_address_book(params)
  params['action'] = 'addAddressbook'
  
  result = exec_command(params)
  result = JSON.parse(result.body)

  if result.has_key? 'error'     
    false
  else
    result['result']['addressbook_id']
  end
end

#create_campaign(params) ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
# File 'lib/e_pochta_sms.rb', line 66

def create_campaign(params)
  params['action']    = 'createCampaign'
  result = exec_command(params)
  result = JSON.parse(result.body)

  if result.has_key? 'error'     
    false
  else
    result['result']['id']
  end
end

#delete_address_book(params) ⇒ Object



32
33
34
35
36
37
38
39
40
41
# File 'lib/e_pochta_sms.rb', line 32

def delete_address_book(params)
  params['action'] = 'delAddressbook'
  result = exec_command(params)
  result = JSON.parse(result.body)   
  if result.has_key? 'error'     
    false
  else
    true
  end    
end

#get_balanceObject



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

def get_balance()
  params = {}
  params['action']    = 'getUserBalance'
  params['currency'] = 'RUB'
  result = exec_command(params)
  result = JSON.parse(result.body)

  if result.has_key? 'error'     
    false
  else
    result['result']['balance_currency']
  end
end

#get_campaign_status(params) ⇒ Object

params = => 12345 campaign_id



79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/e_pochta_sms.rb', line 79

def get_campaign_status(params)
  params['action']    = 'getCampaignInfo'
  result = exec_command(params)
  result = JSON.parse(result.body)

  if result.has_key? 'error'     
    false
  else
    result['result']['status_text'] = get_status_text(result['result']['status'].to_i)
    result['result']
  end
end

#send_sms(params) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
# File 'lib/e_pochta_sms.rb', line 54

def send_sms(params)    
  params['action']    = 'sendSMS'
  result = exec_command(params)
  result = JSON.parse(result.body)

  if result.has_key? 'error'     
    false
  else
    result['result']['id']
  end
end