Class: Netsol

Inherits:
Object
  • Object
show all
Defined in:
lib/netsol.rb

Constant Summary collapse

CONFIG =
{
  :host => {
    :test => 'partners.pte.networksolutions.com',
    :live => 'partners.networksolutions.com'
  },
  :api => {
    :availability => {
      :path => '/invoke/vpp/AvailabilityService',
      :port => 8010
    },
    :transaction  => {
      :path => '/invoke/vpp/TransactionService',
      :port => 8020
    }
  }
}

Instance Method Summary collapse

Constructor Details

#initialize(user, pass, mode = :live) ⇒ Netsol

Returns a new instance of Netsol.



24
25
26
27
28
29
30
31
32
# File 'lib/netsol.rb', line 24

def initialize(user, pass, mode = :live)
  environments = [:test, :live]
  unless environments.include? mode
    raise "mode is invalid, must be #{environments.map(&:inspect).join(' or ')}"
  end

  @user,@pass,@mode = user,pass,mode
  @host = CONFIG[:host][@mode]
end

Instance Method Details

#create_individual(individual) ⇒ Object



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/netsol.rb', line 87

def create_individual(individual)
  @individual = {
    :login_name  => nil,
    :password    => nil,
    :first_name  => nil,
    :middle_name => nil,
    :last_name   => nil,
    :address => {
      :line_1       => nil,
      :city         => nil,
      :state        => nil,
      :post_code    => nil,
      :country_code => nil
    },
    :phone => nil,
    :fax   => nil,
    :email => nil,
    :auth => {
      :question => nil,
      :answer   => nil
    }
  }.merge(individual)

  response = Nokogiri::XML(transmit(CONFIG[:api][:transaction], request_body).body, &:noblanks)

  status = response.xpath('/UserResponse/Body/Status')
  status_code = status.xpath('StatusCode/text()')[0].to_s.to_i
  status_desc = status.xpath('Description/text()')[0].to_s
  success_codes = [5700, 5703]

  raise "Unable to create individual: [#{status_code}] #{status_desc}" unless success_codes.include?(status_code)
  
  {
    :status => {
      :code => status_code,
      :message => status_desc
    },
    :user_id => response.xpath('/UserResponse/Body/UserID/text()')[0].to_s.to_i,
    :login_name => response.xpath('/UserResponse/Body/LoginName/text()')[0].to_s
  }
end

#find_all_customers_for_partnerObject



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
# File 'lib/netsol.rb', line 34

def find_all_customers_for_partner
  response = transmit(CONFIG[:api][:transaction], request_body)

  customers = Nokogiri::XML(response.body, &:noblanks).xpath('//Customer').map do |c|
    type = c.children.first.name
    data = {
      :type => type,
      :user_id => c.xpath("#{type}/UserID/text()")[0].to_s,
      :nic_handle => c.xpath("#{type}/NicHandle/text()")[0].to_s,
      :login_name => c.xpath("#{type}/LoginName/text()")[0].to_s
    }

    case data[:type]
    when 'Individual'
      data.merge!(
        :first_name => c.xpath("#{type}/FirstName/text()")[0].to_s,
        :last_name => c.xpath("#{type}/LastName/text()")[0].to_s
      )
    when 'Business'
      data.merge!(
        :company_name => c.xpath("#{type}/CompanyName/text()")[0].to_s,
        :legal_contact => {
          :first_name => c.xpath("#{type}/LegalContactFirstName/text()")[0].to_s,
          :last_name => c.xpath("#{type}/LegalContactLastName/text()")[0].to_s
        }
      )
    end

    data
  end
end

#find_all_domains_for_partnerObject



66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/netsol.rb', line 66

def find_all_domains_for_partner
  response = transmit(CONFIG[:api][:transaction], request_body)
  
  domains = Nokogiri::XML(response.body, &:noblanks).xpath('//Domain').map do |domain|
    {
      :product_id  => domain.xpath('ProductID/text()')[0].to_s,
      :domain_name => domain.xpath('DomainName/text()')[0].to_s,
      :customer_id => domain.xpath('CustomerID/text()')[0].to_s,
      :product_type => domain.xpath('ProductType/text()')[0].to_s,
      :auto_renew => (domain.xpath('AutoRenew/text()')[0].to_s == 'Y')
    }
  end
end

#modify_registrationObject



80
81
82
83
84
85
# File 'lib/netsol.rb', line 80

def modify_registration
  raise 'Not yet implemented'
  # @domain_name = nil
  # @customer_id = nil
  # @auto_renew  = nil
end