Class: ComteleSdk::CreditService

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

Instance Method Summary collapse

Constructor Details

#initialize(api_key) ⇒ CreditService

Returns a new instance of CreditService.



82
83
84
85
86
87
88
89
90
# File 'lib/comtele_sdk.rb', line 82

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

#add_credits(username, amount) ⇒ Object



113
114
115
116
117
118
# File 'lib/comtele_sdk.rb', line 113

def add_credits(username, amount)
    url = @base_address + '/credits/'+ username + '?amount=' + amount.to_s        
    response = RestClient.put(url, {}, @headers)
    
    return JSON.parse(response)
end

#get_credits(username) ⇒ Object



92
93
94
95
96
97
# File 'lib/comtele_sdk.rb', line 92

def get_credits(username)
    url = @base_address + '/credits/' + username
    response = RestClient.get(url, @headers)
    
    return JSON.parse(response)
end

#get_history(username) ⇒ Object



106
107
108
109
110
111
# File 'lib/comtele_sdk.rb', line 106

def get_history(username)
    url = @base_address + '/balancehistory/' + username
    response = RestClient.get(url, @headers)
    
    return JSON.parse(response)
end

#get_my_creditsObject



99
100
101
102
103
104
# File 'lib/comtele_sdk.rb', line 99

def get_my_credits
    url = @base_address + '/credits'
    response = RestClient.get(url, @headers)
    
    return JSON.parse(response)
end