Module: ExetelSms::ClassMethods
Instance Method Summary collapse
- #build_url(params_hash) ⇒ Object
- #encode(str) ⇒ Object
- #new_reference_number(ident = '') ⇒ Object
- #response_to_hash(fields) ⇒ Object
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 |
# File 'lib/class_methods.rb', line 23 def response_to_hash(fields) raise 'Missing fields in response body' unless fields.length >= response_fields.length ret = {} response_fields.each {|field| ret[field] = fields.shift } ret[:other] = fields ret end |