Class: Eztexting::Base

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

Direct Known Subclasses

Availability, Credits, Keywords, Lookup, Sms, Voice

Class Method Summary collapse

Class Method Details

.do_post(uri, options) ⇒ Object

This method never is really called by itself it is called from the classses do the work of the actual interaction with the api itself.



6
7
8
9
10
11
12
13
# File 'lib/eztexting/base.rb', line 6

def self.do_post(uri,options)
  options  = options || {}
  options  = options.merge!(Eztexting.credentials)
  location = uri
  
  response = Eztexting.post(location, :body => options)
  return response.body
end

.process(response) ⇒ Object

This is a default result mapping. The response from the API is usually a coded number (except for the balance call which returns the acutal number of credits). Here we map over those values to a response. This is sometimes overidden by the subclasses as thses mappings to not apply the same way to all commands



18
19
20
21
22
23
24
25
26
27
# File 'lib/eztexting/base.rb', line 18

def self.process(response)
  api_result = case response
  when "-1"
    "Invalid user and/or password or API is not allowed for your account"
  when "-10"
    "Unknown error (please contact our support dept.)"
  else
    "successful"
  end
end

.processed_reponse(response_result, response_body) ⇒ Object

This just assembles the data to be returned from do_post in a nice clean way



30
31
32
# File 'lib/eztexting/base.rb', line 30

def self.processed_reponse(response_result,response_body)
  [response_result,response_body]
end