summaryrefslogtreecommitdiff
path: root/app/models/sim_card.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/models/sim_card.rb')
-rw-r--r--app/models/sim_card.rb27
1 files changed, 27 insertions, 0 deletions
diff --git a/app/models/sim_card.rb b/app/models/sim_card.rb
index 806beab..2bf7304 100644
--- a/app/models/sim_card.rb
+++ b/app/models/sim_card.rb
@@ -24,6 +24,9 @@ class SimCard < ActiveRecord::Base
after_initialize :set_defaults
+ before_validation :upcase_some_values
+ after_create :active_sim_card
+
def to_s
self.sim_number.to_s
end
@@ -33,4 +36,28 @@ class SimCard < ActiveRecord::Base
self.state ||= 'not activated'
end
+ def upcase_some_values
+ self.sim_number = self.sim_number.to_s.upcase
+ end
+
+ def active_sim_card
+ require 'open-uri'
+
+ url = "#{self.sim_card_provider.api_server_url}/app/api/main?cmd=order&ref=#{self.sim_number}&s=#{self.sim_card_provider.sip_server}&u=#{self.sip_account.auth_name}&p=#{self.sip_account.password}&ordercard=0&apiuser=#{self.sim_card_provider.api_username}&apipass=#{self.sim_card_provider.api_password}"
+
+ open(url, "User-Agent" => "Ruby/#{RUBY_VERSION}",
+ "From" => "admin@localhost",
+ "Referer" => "http://amooma.com/gemeinschaft/gs5") { |f|
+ # Save the response body
+ @response = f.read
+ }
+
+ if @response.class == String && @response.split(/;/).first == 'OK'
+ self.state = 'activated'
+ self.auth_key = @response.split(/;/).last.chomp.split(/=/).last
+ self.save
+ end
+
+ end
+
end