Module: ExetelSms::ClassMethods
- Included in:
- CreditCheck, Deleter, Receiver, Retriever, Sender
- Defined in:
- lib/class_methods.rb
Instance Method Summary collapse
- #build_url(params_hash) ⇒ Object
- #encode(str) ⇒ Object
- #exetel_url ⇒ Object
- #matchurl?(url) ⇒ Boolean
- #new_reference_number(ident = '') ⇒ Object
- #response_to_hash(fields) ⇒ Object
Instance Method Details
#build_url(params_hash) ⇒ Object
22 23 24 25 26 27 |
# File 'lib/class_methods.rb', line 22 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
29 30 31 |
# File 'lib/class_methods.rb', line 29 def encode(str) URI.encode(URI.encode(str), /=|&|\?/) end |
#exetel_url ⇒ Object
12 13 14 |
# File 'lib/class_methods.rb', line 12 def exetel_url "https://smsgw.exetel.com.au/sendsms/#{api_path}?" end |
#matchurl?(url) ⇒ Boolean
33 34 35 |
# File 'lib/class_methods.rb', line 33 def matchurl?(url) url.match(/\/#{api_path}\?/) end |
#new_reference_number(ident = '') ⇒ Object
16 17 18 19 20 |
# File 'lib/class_methods.rb', line 16 def new_reference_number(ident='') @@counter ||= 0 @@counter += 1 ident + ('%04X%02X%04X' % [Time.now.to_i, $$, @@counter]) end |
#response_to_hash(fields) ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/class_methods.rb', line 37 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 ret.extend ResultHashMethods end |