Class: InternetBS::AccountDomains

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

Instance Method Summary collapse

Methods inherited from Base

#inspect

Instance Method Details

#fetchObject



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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/internetbs/account_domains.rb', line 15

def fetch
  @errors.clear
  @list.clear
  @total_domains = 0
  @total_domains_by_tld = 0
  
  params = {'compactlist' => @compact_list ? 'YES' : 'NO', 'sortby' => @sort_by}
  params.merge!({'expiringonly' => @expiring_only}) if @expiring_only
  params.merge!({'extensionfilter' => @extension_filter}) if @extension_filter
  params.merge!({'pendingtransferonly' => 'YES'}) if @pending_transfer_only
  params.merge!({'rangefrom' => @range_from, 'rangeto' => @range_to}) if @range_from && @range_to
  params.merge!({'searchtermfilter' => @search_term_filter}) if @search_term_filter

  response = Client.get('/domain/list', params)
  code = response.code rescue ""
  
  case code
  when '200'
    hash = JSON.parse(response.body)
    
    @status = hash.delete('status')
    @transaction_id = hash.delete('transactid')

    if @status == 'SUCCESS'
      @total_domains = hash['domaincount']
      
      if @compact_list
        hash['domain'].each do |domain|
          @list << AccountDomain.new(:name => domain)
        end
      else
        hash['domain'].each do |domain|
          @list << AccountDomain.new(
            :name => domain['name'],
            :expiration_date => domain['expiration'],
            :registrar_lock => domain['registrarlock'],
            :status => domain['status'],
            :transfer_auth_info => domain['transferauthinfo']
          )
        end
      end
    else
      set_errors(response)
      return false
    end
    
    return true
  else
    set_errors(response)
    return false
  end
end

#fetch_totalsObject



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/internetbs/account_domains.rb', line 68

def fetch_totals
  @errors.clear
  
  response = Client.get('/domain/count')
  code = response.code rescue ""
  
  case code
  when '200'
    hash = JSON.parse(response.body)
    
    @status = hash.delete('status')
    @transaction_id = hash.delete('transactid')

    if @status == 'SUCCESS'
      @total_domains = hash.delete('totaldomains')
      @total_domains_by_tld.clear
      
      hash.each do |tld, total| 
        @total_domains_by_tld << DomainTotal.new(:tld => tld, :total => total)
      end
    else
      set_errors(response)
      return false
    end
    
    return true
  else
    set_errors(response)
    return false
  end
end