class ComteleSdk::ContactService

Public Class Methods

new(api_key) click to toggle source
# File lib/comtele_sdk.rb, line 249
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

Public Instance Methods

add_contact_to_group(group_name, contact_phone, contact_name) click to toggle source
# File lib/comtele_sdk.rb, line 291
def add_contact_to_group(group_name, contact_phone, contact_name)

    url = @base_address + 'contactgroup'
    payload = JSON.generate({'groupName': group_name, 'contactPhone': contact_phone, 'contactName': contact_name, 'action': 'add_number'})

    response = RestClient.put(url, payload, @headers)
    return JSON.parse(response)
end
create_group(group_name, group_description) click to toggle source
# File lib/comtele_sdk.rb, line 259
def create_group(group_name, group_description)
    url = @base_address + 'contactgroup'

    payload = JSON.generate({'name': group_name, 'description': group_description})
    response = RestClient.post(url, payload, @headers)

    return JSON.parse(response)
end
get_all_groups() click to toggle source
# File lib/comtele_sdk.rb, line 275
def get_all_groups()

    url = @base_address + 'contactgroup'
    response = RestClient.get(url, @headers)

    return JSON.parse(response)
end
get_group_by_name(group_name) click to toggle source
# File lib/comtele_sdk.rb, line 283
def get_group_by_name(group_name)

    url = @base_address + 'contactgroup?id=' + group_name
    response = RestClient.get(url, @headers)

    return JSON.parse(response)
end
remove_contact_from_group(group_name, contact_phone) click to toggle source
# File lib/comtele_sdk.rb, line 300
def remove_contact_from_group(group_name, contact_phone)
    url = @base_address + 'contactgroup'
    payload = JSON.generate({'groupName': group_name, 'contactPhone': contact_phone, 'action': 'remove_number'})

    response = RestClient.put(url, payload, @headers)
    return JSON.parse(response)
end
remove_group(group_name) click to toggle source
# File lib/comtele_sdk.rb, line 268
def remove_group(group_name)
    url = @base_address + 'contactgroup?id=' + group_name
    response = RestClient.delete(url, {}, @headers)

    return JSON.parse(response)
end