diff options
author | Stefan Wintermeyer <stefan.wintermeyer@amooma.de> | 2013-02-15 15:56:16 +0100 |
---|---|---|
committer | Stefan Wintermeyer <stefan.wintermeyer@amooma.de> | 2013-02-15 15:56:16 +0100 |
commit | b1cbfe7a7bd5e966be14b71be4e201cc9e2b1aa6 (patch) | |
tree | dc8dc01b5c4103516eb076121e47e7b5a3e70eb9 | |
parent | 14e8e9923666991703f747a4abfd6fbfb96d2dc1 (diff) |
Activate a new sim_card.
-rw-r--r-- | app/models/sim_card.rb | 27 | ||||
-rw-r--r-- | app/views/sim_cards/_index_core.html.haml | 2 | ||||
-rw-r--r-- | app/views/sim_cards/show.html.haml | 5 |
3 files changed, 34 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 diff --git a/app/views/sim_cards/_index_core.html.haml b/app/views/sim_cards/_index_core.html.haml index 460c8ba..16440ff 100644 --- a/app/views/sim_cards/_index_core.html.haml +++ b/app/views/sim_cards/_index_core.html.haml @@ -1,5 +1,6 @@ %table.table.table-striped %tr + %th= t('sim_cards.show.sim_number') %th= t('sim_cards.index.sip_account_id') %th= t('sip_accounts.index.phone_numbers') %th= t('sim_cards.index.auth_key') @@ -8,6 +9,7 @@ - for sim_card in sim_cards %tr + %td= sim_card.sim_number %td= sim_card.sip_account %td = render 'phone_numbers/listing', :phone_numbers => sim_card.sip_account.phone_numbers.order(:number) diff --git a/app/views/sim_cards/show.html.haml b/app/views/sim_cards/show.html.haml index 88822f1..4752aab 100644 --- a/app/views/sim_cards/show.html.haml +++ b/app/views/sim_cards/show.html.haml @@ -5,6 +5,11 @@ %table.table.table-striped %tr %td + %strong= t('sim_cards.show.sim_number') + ":" + %td + = @sim_card.sim_number + %tr + %td %strong= t('sim_cards.show.sip_account_id') + ":" %td = @sim_card.sip_account |