Class: InternetBS::RenewDomain

Inherits:
Base
  • Object
show all
Defined in:
lib/internetbs/renew_domain.rb

Instance Method Summary collapse

Methods inherited from Base

#inspect

Instance Method Details

#purchase!Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/internetbs/renew_domain.rb', line 9

def purchase!
  ensure_attribute_has_value :domain
  return false if @errors.any?
  
  params = {'domain' => @domain}
  params.merge!({'period' => @period}) if @period
  params.merge!({'discountcode' => @discount_code}) if @discount_code
  
  response = Client.post('/domain/renew', params)
  code = response.code rescue ""
  
  case code
  when '200'
    hash = JSON.parse(response.body)

    @status = hash['status']
    @transaction_id = hash['transactid']
    
    if @status == 'SUCCESS'
      @currency    = hash['currency']
      @total_price = hash['price']
    else
      set_errors(response)
      return false
    end
            
    return true
  else
    set_errors(response)
    return false
  end
end