Class: TextVeloper::Api

Inherits:
Object
  • Object
show all
Includes:
Singleton, TextVeloper
Defined in:
lib/text_veloper.rb

Constant Summary

Constants included from TextVeloper

URL_BASE, VERSION

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from TextVeloper

#url_base_for

Constructor Details

#initializeApi

Returns a new instance of Api.



14
15
16
17
18
19
# File 'lib/text_veloper.rb', line 14

def initialize
  @base_request_data = {
      cuenta_token: "",
      subcuenta_token: ""
  }
end

Instance Attribute Details

#sub_tokenObject

Returns the value of attribute sub_token.



12
13
14
# File 'lib/text_veloper.rb', line 12

def sub_token
  @sub_token
end

#token_accountObject

Returns the value of attribute token_account.



12
13
14
# File 'lib/text_veloper.rb', line 12

def 
  
end

Instance Method Details

#config_tokens_account(token_account, sub_token) ⇒ Object



21
22
23
24
25
# File 'lib/text_veloper.rb', line 21

def  , sub_token
  @base_request_data[:cuenta_token] = 
  @base_request_data[:subcuenta_token] = sub_token
  self
end

#messages_recordsObject



48
49
50
51
52
53
54
# File 'lib/text_veloper.rb', line 48

def messages_records
  response = RestClient.post url_base_for('historial-envios'), @base_request_data
rescue => e
  raise TextVeloperError.new "Problem with message records", e
ensure
  return response
end

#points_queryObject



40
41
42
43
44
45
46
# File 'lib/text_veloper.rb', line 40

def points_query
  response = RestClient.post url_base_for('historial-transferencias'), @base_request_data
rescue => e
  raise TextVeloperError.new "Problem with points query", e
ensure
  return response
end

#send_message(message, phones = []) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/text_veloper.rb', line 27

def send_message(message, phones = [])
  response = {}
  phones_arg = phones
  phones = phones_arg.is_a?(Array) ? phones_arg : [phones_arg]
  phones.each do |phone|
    response = RestClient.post url_base_for('enviar'), @base_request_data.merge({telefono: phone, mensaje: message})
  end
rescue => e
  raise TextVeloperError.new "Problem with send message", e
ensure
  return response
end

#setup {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:



56
57
58
59
60
61
# File 'lib/text_veloper.rb', line 56

def setup
  yield self
  @base_request_data = {cuenta_token: , subcuenta_token: @sub_token}
  TextVeloper::ApiSelector..token = 
  TextVeloper::ApiSelector..payload = {cuenta_token: }
end