Module: ExetelSms::ClassMethods

Included in:
Deleter, Receiver, Retriever, Sender
Defined in:
lib/class_methods.rb

Instance Method Summary collapse

Instance Method Details

#build_url(params_hash) ⇒ Object



12
13
14
15
16
17
# File 'lib/class_methods.rb', line 12

def build_url(params_hash)
  exetel_url + request_fields.map do |field|
    raise "Missing field: #{field}" unless params_hash.has_key?(field)
    encode(field.to_s) + '=' + encode(params_hash[field].to_s)
  end.join('&')
end

#encode(str) ⇒ Object



19
20
21
# File 'lib/class_methods.rb', line 19

def encode(str)
  URI.encode(URI.encode(str), /=|&|\?/)
end

#new_reference_number(ident = '') ⇒ Object



6
7
8
9
10
# File 'lib/class_methods.rb', line 6

def new_reference_number(ident='')
  @@counter ||= 0
  @@counter += 1
  ident + ('%04X%02X%04X' % [Time.now.to_i, $$, @@counter])
end

#response_to_hash(fields) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/class_methods.rb', line 23

def response_to_hash(fields)
  raise "Missing fields in response body?  Expected #{response_fields.map(&:to_s).join(',')}, got #{fields.inspect}" unless fields.length >= response_fields.length
  ret = {}
  response_fields.each {|field| ret[field] = fields.shift }
  ret[:other] = fields
  class << ret
    def success?
      self[:status] == '1'
    end
  end
  ret
end