Class: ComteleSdk::ContextMessageService

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

Instance Method Summary collapse

Constructor Details

#initialize(api_key) ⇒ ContextMessageService

Returns a new instance of ContextMessageService.



34
35
36
37
38
39
40
41
42
# File 'lib/comtele_sdk.rb', line 34

def initialize(api_key)
    @api_key = api_key
    @base_address = 'https://sms.comtele.com.br/api/v2' 
    @headers = {
        'Accept': 'application/json',
        'Content-type': 'application/json',            
        'auth-key': @api_key
    }  
end

Instance Method Details

#get_report(start_date, end_date, sender = '', context_rule_name = '') ⇒ Object



73
74
75
76
77
78
# File 'lib/comtele_sdk.rb', line 73

def get_report(start_date, end_date, sender = '', context_rule_name = '')
    url = @base_address + '/contextreporting?startDate=' + start_date + '&endDate=' + end_date + '&sender=' + sender + '&contextRuleName=' + context_rule_name
    response = RestClient.get(url, @headers)
    
    return JSON.parse(response)
end

#schedule(sender, context_rule_name, schedule_date, receivers) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/comtele_sdk.rb', line 58

def schedule(sender, context_rule_name, schedule_date, receivers)
    url = @base_address + '/schedulecontextmessage'   
    
    payload = JSON.generate({
        'sender': sender,
        'contextRuleName': context_rule_name,
        'scheduleDate': schedule_date,
        'receivers': receivers.join(',')
    })
    
    response = RestClient.post(url, payload, @headers)
    
    return JSON.parse(response)
end

#send(sender, context_rule_name, receivers) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/comtele_sdk.rb', line 44

def send(sender, context_rule_name, receivers)
    url = @base_address + '/sendcontextmessage'   
    
    payload = JSON.generate({
        'sender': sender,
        'contextRuleName': context_rule_name,
        'receivers': receivers.join(',')
    })
    
    response = RestClient.post(url, payload, @headers)
    
    return JSON.parse(response)
end