moo_moo 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (107) hide show
  1. data/.travis.yml +9 -3
  2. data/LICENSE +1 -1
  3. data/README.md +16 -5
  4. data/Rakefile +21 -0
  5. data/lib/moo_moo/base.rb +93 -0
  6. data/lib/moo_moo/command.rb +36 -0
  7. data/lib/moo_moo/config.rb +26 -1
  8. data/lib/moo_moo/cookie.rb +28 -0
  9. data/lib/moo_moo/dns_zone.rb +45 -0
  10. data/lib/moo_moo/exceptions.rb +1 -1
  11. data/lib/moo_moo/lookup.rb +97 -0
  12. data/lib/moo_moo/middleware/open_srs_errors.rb +12 -0
  13. data/lib/moo_moo/middleware/open_srs_xml_builder.rb +101 -0
  14. data/lib/moo_moo/middleware/parse_open_srs.rb +58 -0
  15. data/lib/moo_moo/nameserver.rb +29 -0
  16. data/lib/moo_moo/provisioning.rb +62 -0
  17. data/lib/moo_moo/response.rb +39 -0
  18. data/lib/moo_moo/transfer.rb +60 -0
  19. data/lib/moo_moo/version.rb +1 -1
  20. data/lib/moo_moo.rb +18 -3
  21. data/moo_moo.gemspec +7 -5
  22. data/spec/fixtures/success_response.xml +14 -0
  23. data/spec/integration_spec.rb +15 -0
  24. data/spec/moo_moo/base_spec.rb +77 -0
  25. data/spec/moo_moo/command_spec.rb +42 -0
  26. data/spec/moo_moo/config_spec.rb +38 -0
  27. data/spec/moo_moo/cookie_spec.rb +8 -0
  28. data/spec/moo_moo/dns_zone_spec.rb +11 -0
  29. data/spec/moo_moo/lookup_spec.rb +18 -0
  30. data/spec/moo_moo/middleware/open_srs_xml_builder_spec.rb +53 -0
  31. data/spec/moo_moo/nameserver_spec.rb +8 -0
  32. data/spec/moo_moo/provisioning_spec.rb +14 -0
  33. data/spec/moo_moo/transfer_spec.rb +12 -0
  34. data/spec/moo_moo_spec.rb +1 -1
  35. data/spec/spec_helper.rb +35 -23
  36. data/spec/vcr_cassettes/integration/lookup.yml +44 -0
  37. metadata +117 -153
  38. data/lib/cacert.pem +0 -3910
  39. data/lib/moo_moo/opensrs/args.rb +0 -109
  40. data/lib/moo_moo/opensrs/base.rb +0 -73
  41. data/lib/moo_moo/opensrs/command.rb +0 -190
  42. data/lib/moo_moo/opensrs/cookie_commands.rb +0 -52
  43. data/lib/moo_moo/opensrs/lookup_commands.rb +0 -195
  44. data/lib/moo_moo/opensrs/nameserver_commands.rb +0 -70
  45. data/lib/moo_moo/opensrs/provisioning_commands.rb +0 -167
  46. data/lib/moo_moo/opensrs/response.rb +0 -41
  47. data/lib/moo_moo/opensrs/transfer_commands.rb +0 -83
  48. data/lib/moo_moo/opensrs.rb +0 -13
  49. data/spec/moo_moo/opensrs/args_spec.rb +0 -176
  50. data/spec/moo_moo/opensrs/base_spec.rb +0 -22
  51. data/spec/moo_moo/opensrs/cookie_spec.rb +0 -76
  52. data/spec/moo_moo/opensrs/lookup_spec.rb +0 -208
  53. data/spec/moo_moo/opensrs/nameserver_spec.rb +0 -136
  54. data/spec/moo_moo/opensrs/provisioning_spec.rb +0 -198
  55. data/spec/moo_moo/opensrs/transfer_spec.rb +0 -124
  56. data/spec/vcr_cassettes/cookie/delete_cookie.yml +0 -219
  57. data/spec/vcr_cassettes/cookie/quit_session.yml +0 -97
  58. data/spec/vcr_cassettes/cookie/set_cookie.yml +0 -123
  59. data/spec/vcr_cassettes/cookie/set_cookie_fail.yml +0 -54
  60. data/spec/vcr_cassettes/cookie/update_cookie.yml +0 -239
  61. data/spec/vcr_cassettes/lookup/belongs_to_rsp.yml +0 -54
  62. data/spec/vcr_cassettes/lookup/belongs_to_rsp_negative.yml +0 -55
  63. data/spec/vcr_cassettes/lookup/get_balance.yml +0 -55
  64. data/spec/vcr_cassettes/lookup/get_deleted_domains.yml +0 -80
  65. data/spec/vcr_cassettes/lookup/get_domain.yml +0 -211
  66. data/spec/vcr_cassettes/lookup/get_domain_fail.yml +0 -269
  67. data/spec/vcr_cassettes/lookup/get_domains_by_expiredate.yml +0 -76
  68. data/spec/vcr_cassettes/lookup/get_domains_contacts.yml +0 -129
  69. data/spec/vcr_cassettes/lookup/get_domains_contacts_fail.yml +0 -58
  70. data/spec/vcr_cassettes/lookup/get_notes_for_domain.yml +0 -85
  71. data/spec/vcr_cassettes/lookup/get_notes_for_order.yml +0 -61
  72. data/spec/vcr_cassettes/lookup/get_notes_for_transfer.yml +0 -61
  73. data/spec/vcr_cassettes/lookup/get_order_info.yml +0 -139
  74. data/spec/vcr_cassettes/lookup/get_orders_by_domain.yml +0 -76
  75. data/spec/vcr_cassettes/lookup/get_price.yml +0 -54
  76. data/spec/vcr_cassettes/lookup/get_product_info.yml +0 -49
  77. data/spec/vcr_cassettes/lookup/lookup_domain_available.yml +0 -55
  78. data/spec/vcr_cassettes/lookup/lookup_domain_registered.yml +0 -55
  79. data/spec/vcr_cassettes/lookup/name_suggest.yml +0 -396
  80. data/spec/vcr_cassettes/nameserver/create.yml +0 -49
  81. data/spec/vcr_cassettes/nameserver/delete.yml +0 -49
  82. data/spec/vcr_cassettes/nameserver/get.yml +0 -71
  83. data/spec/vcr_cassettes/nameserver/modify.yml +0 -49
  84. data/spec/vcr_cassettes/provisioning/cancel_order.yml +0 -56
  85. data/spec/vcr_cassettes/provisioning/cancel_order_invalid.yml +0 -49
  86. data/spec/vcr_cassettes/provisioning/cancel_pending_orders.yml +0 -58
  87. data/spec/vcr_cassettes/provisioning/modify_all_domains.yml +0 -49
  88. data/spec/vcr_cassettes/provisioning/modify_domain.yml +0 -49
  89. data/spec/vcr_cassettes/provisioning/process_pending.yml +0 -57
  90. data/spec/vcr_cassettes/provisioning/register_domain.yml +0 -57
  91. data/spec/vcr_cassettes/provisioning/register_pending_domain.yml +0 -55
  92. data/spec/vcr_cassettes/provisioning/register_taken_domain.yml +0 -55
  93. data/spec/vcr_cassettes/provisioning/renew_domain.yml +0 -58
  94. data/spec/vcr_cassettes/provisioning/revoke_domain.yml +0 -55
  95. data/spec/vcr_cassettes/provisioning/trust_service.yml +0 -60
  96. data/spec/vcr_cassettes/provisioning/update_contacts.yml +0 -66
  97. data/spec/vcr_cassettes/transfer/cancel_transfer.yml +0 -49
  98. data/spec/vcr_cassettes/transfer/cancel_trasnfer_order.yml +0 -49
  99. data/spec/vcr_cassettes/transfer/check_transfer.yml +0 -56
  100. data/spec/vcr_cassettes/transfer/check_transfer_exists.yml +0 -57
  101. data/spec/vcr_cassettes/transfer/get_transfers_away.yml +0 -60
  102. data/spec/vcr_cassettes/transfer/get_transfers_in.yml +0 -80
  103. data/spec/vcr_cassettes/transfer/process_transfer.yml +0 -49
  104. data/spec/vcr_cassettes/transfer/process_transfer_unsuccessful.yml +0 -49
  105. data/spec/vcr_cassettes/transfer/rsp2rsp_push_transfer.yml +0 -49
  106. data/spec/vcr_cassettes/transfer/send_password.yml +0 -49
  107. data/spec/vcr_cassettes/transfer/transfer.yml +0 -58
data/.travis.yml CHANGED
@@ -1,11 +1,17 @@
1
+ language: ruby
1
2
  script: "bundle exec rake spec"
2
3
  notifications:
3
- disabled: true
4
+ email:
5
+ recipients:
6
+ - engineering@internal.site5.com
7
+ on_success: never
8
+ on_failure: always
4
9
  rvm:
5
10
  - 1.8.7
6
11
  - 1.9.2
7
12
  - 1.9.3
8
13
  - ree
9
- - rbx
10
14
  - rbx-head
11
- - jruby
15
+ - rbx-18mode
16
+ - jruby-18mode
17
+ - jruby-19mode
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2011 Site5 LLC
1
+ Copyright (c) 2012 Site5.com <http://www.site5.com>
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person ob-
4
4
  taining a copy of this software and associated documentation
data/README.md CHANGED
@@ -23,9 +23,9 @@ documentation of the OpenSRS XML API see
23
23
  Usage
24
24
  -----
25
25
 
26
- First, create an opensrs object from which all commands are called:
26
+ First, create an opensrs object for the namespace you want to use:
27
27
 
28
- opensrs = MooMoo::OpenSRS::Base.new(
28
+ lookup = MooMoo::Lookup.new(
29
29
  "horizon.opensrs.net",
30
30
  "<YOUR_KEY>",
31
31
  "<YOUR_RESELLER_USER>",
@@ -43,12 +43,15 @@ Or configure MooMoo and you can initialize it without any arguments:
43
43
 
44
44
  ...
45
45
 
46
- opensrs = MooMoo::OpenSRS::Base.new
46
+ lookup = MooMoo::Lookup.new
47
+
48
+ As an alternative, you can create a .moomoo.yml file in your project root with a default
49
+ configuration for the library to use.
47
50
 
48
51
  Now you can call a variety of commands to deal with domains, nameservers, etc.
49
52
  Here's how to check the availability of a domain name:
50
53
 
51
- res = opensrs.lookup_domain('example.com')
54
+ res = lookup.lookup_domain('example.com')
52
55
  p res.success?
53
56
  p res.result['status']
54
57
 
@@ -60,6 +63,14 @@ if the call was successful and retrieve the response code and/or error
60
63
  message. The result variable is a hash that contains all of the relevant data
61
64
  returned by the call.
62
65
 
66
+ Currently, there is support for the following services:
67
+
68
+ * Cookie
69
+ * Lookup
70
+ * Nameserver
71
+ * Provisioning
72
+ * Transfer
73
+
63
74
  Note on Patches/Pull Requests
64
75
  -----------------------------
65
76
 
@@ -75,4 +86,4 @@ Note on Patches/Pull Requests
75
86
  Copyright
76
87
  ---------
77
88
 
78
- Copyright (c) 2011 Site5 LLC. See LICENSE for details.
89
+ Copyright (c) 2012 Site5.com. See LICENSE for details.
data/Rakefile CHANGED
@@ -16,6 +16,22 @@ rescue LoadError
16
16
  puts "Can't load metric_fu"
17
17
  end
18
18
 
19
+ begin
20
+ require 'rdoc/task'
21
+ Rake::RDocTask.new do |rdoc|
22
+ version = MooMoo::VERSION
23
+
24
+ rdoc.rdoc_dir = 'rdoc'
25
+ rdoc.title = "solusvm #{version}"
26
+ rdoc.rdoc_files.include('README*')
27
+ rdoc.rdoc_files.include('lib/**/*.rb')
28
+ end
29
+ rescue LoadError
30
+ task :rdoc do
31
+ abort "rdoc is not available. In order to run rdoc, you must: sudo gem install rdoc"
32
+ end
33
+ end
34
+
19
35
  desc "Sanitize sensitive info from cassettes"
20
36
  task :sanitize_cassettes do
21
37
  if ENV['OPENSRS_TEST_KEY'] && ENV['OPENSRS_TEST_URL'] && ENV['OPENSRS_TEST_USER'] && ENV['OPENSRS_TEST_PASS']
@@ -53,3 +69,8 @@ RSpec::Core::RakeTask.new(:rcov) do |t|
53
69
  end
54
70
 
55
71
  task :default => [:spec]
72
+
73
+ desc "Open an irb session preloaded with this library"
74
+ task :console do
75
+ sh "irb -rubygems -r ./lib/moo_moo.rb"
76
+ end
@@ -0,0 +1,93 @@
1
+ module MooMoo
2
+ class Base
3
+ attr_reader :host, :key, :user, :pass, :port
4
+
5
+ # Register an api service for the current class.
6
+ #
7
+ # register_service :action_one, :object_one
8
+ #
9
+ # That will generate the following method for this class:
10
+ #
11
+ # def action_one(params)
12
+ # run_command :action_one, :object_one, params, cookie
13
+ # end
14
+ #
15
+ # === Parameters
16
+ #
17
+ # * <tt>method_name</tt> - the method name
18
+ # * <tt>object</tt> - the object
19
+ # * <tt>action_name</tt> - the api action to be called; by default it is the same as method_name
20
+ def self.register_service(method_name, object, action_name = method_name, &block)
21
+ define_method(method_name) do |*args|
22
+ params = args.first || {}
23
+
24
+ params[:key] = 'attributes'
25
+ cookie = params.delete :cookie
26
+ instance_exec(params, &block) if block
27
+ run_command action_name, object, params, cookie
28
+ end
29
+ end
30
+
31
+ # Constructor
32
+ #
33
+ # === Required
34
+ # * <tt>:host</tt> - host of the OpenSRS server
35
+ # * <tt>:key</tt> - private key
36
+ # * <tt>:user</tt> - username of the reseller
37
+ # * <tt>:pass</tt> - password of the rseller
38
+ #
39
+ # === Optional
40
+ # * <tt>:port</tt> - port to connect on
41
+ def initialize(host = nil, key = nil, user = nil, pass = nil, port = 55443)
42
+ @host = host || MooMoo.config.host || raise(ArgumentError, "Host is required")
43
+ @key = key || MooMoo.config.key || raise(ArgumentError, "Key is required")
44
+ @user = user || MooMoo.config.user || raise(ArgumentError, "User is required")
45
+ @pass = pass || MooMoo.config.pass || raise(ArgumentError, "Password is required")
46
+ @port = port || MooMoo.config.port || raise(ArgumentError, "Port is required")
47
+ end
48
+
49
+ # Runs a command
50
+ #
51
+ # === Required
52
+ # * <tt>:command</tt> - command to run
53
+ # * <tt>:command</tt> - command to run
54
+ #
55
+ # === Optional
56
+ # * <tt>:params</tt> - parameters for the command
57
+ # * <tt>:cookie</tt> - cookie, if the command requires it
58
+ def run_command(action, object, params = {}, cookie = nil)
59
+ cmd = Command.new(action, object, params, cookie)
60
+
61
+ try_opensrs do
62
+ result = cmd.run(@host, @key, @user, @port)
63
+ Response.new(result, params[:key])
64
+ end
65
+ end
66
+
67
+ private
68
+
69
+ # Indexes an array by building a hash with numeric keys
70
+ #
71
+ # === Required
72
+ # * <tt>:arr</tt> - array to build an indexed hash of
73
+ def index_array(arr)
74
+ arr_indexed = {}
75
+
76
+ arr.each_with_index do |item, index|
77
+ arr_indexed[index] = item
78
+ end
79
+
80
+ arr_indexed
81
+ end
82
+
83
+ def try_opensrs
84
+ begin
85
+ yield
86
+ rescue Exception => e
87
+ exception = OpenSRSException.new(e.message)
88
+ exception.set_backtrace(e.backtrace)
89
+ raise exception
90
+ end
91
+ end
92
+ end
93
+ end
@@ -0,0 +1,36 @@
1
+ module MooMoo
2
+ class Command
3
+ # Constructor
4
+ #
5
+ # ==== Required
6
+ # * <tt>:action</tt> - action of the command
7
+ # * <tt>:object</tt> - object the command operates on
8
+ # * <tt>:params</tt> - additional parameters for the command
9
+ #
10
+ # ==== Optional
11
+ # * <tt>:cookie</tt> - a cookie for the domain if the command requires it
12
+ def initialize(action, object, params = {}, cookie = nil)
13
+ @action = action
14
+ @object = object
15
+ @params = params
16
+ @cookie = cookie
17
+ end
18
+
19
+ # Runs the command against OpenSRS server
20
+ #
21
+ # ==== Required
22
+ # * <tt>:host</tt> - host of the OpenSRS server
23
+ # * <tt>:key</tt> - private key for the account
24
+ # * <tt>:user</tt> - username for the account
25
+ # * <tt>:port</tt> - port to connect to
26
+ def run(host, key, user, port)
27
+ @returned_parameters = Faraday.new(:url => "https://#{host}:#{port}", :ssl => {:verify => true}) do |c|
28
+ c.request :open_srs_xml_builder, @action, @object, @cookie, @params, key, user
29
+ c.response :parse_open_srs
30
+ c.response :open_srs_errors
31
+ c.adapter :net_http
32
+ end.post.body
33
+ end
34
+
35
+ end
36
+ end
@@ -1,3 +1,5 @@
1
+ require 'yaml'
2
+
1
3
  module MooMoo
2
4
  class Config
3
5
  attr_accessor :host
@@ -7,7 +9,30 @@ module MooMoo
7
9
  attr_accessor :port
8
10
 
9
11
  def initialize
10
- @host = 'horizion.opensrs.net'
12
+ @host = default_option("host") || 'horizon.opensrs.net'
13
+ @key = default_option("key")
14
+ @user = default_option("user")
15
+ @pass = default_option("pass")
16
+ @port = default_option("port")
17
+ end
18
+
19
+ private
20
+
21
+ def options_file_name
22
+ ".moomoo.yml"
23
+ end
24
+
25
+ # Retrieves default options coming from a configuration file, if any.
26
+ def default_option(key)
27
+ @yaml ||= begin
28
+ if File.exists?(options_file_name)
29
+ YAML.load(File.open(options_file_name))
30
+ else
31
+ {}
32
+ end
33
+ end
34
+
35
+ @yaml[key.to_s]
11
36
  end
12
37
  end
13
38
  end
@@ -0,0 +1,28 @@
1
+ module MooMoo
2
+ class Cookie < Base
3
+
4
+ ##
5
+ # Creates a cookie for use in commands where a cookie is required to access OpenSRS.
6
+ #
7
+ # http://www.opensrs.com/docs/apidomains/set_cookie.htm
8
+ register_service :set, :cookie
9
+
10
+ ##
11
+ # Deletes a cookie.
12
+ #
13
+ # http://www.opensrs.com/docs/apidomains/delete_(cookie).htm
14
+ register_service :delete, :cookie
15
+
16
+ ##
17
+ # Allows the client to change the domain associated with the current cookie.
18
+ #
19
+ # http://www.opensrs.com/docs/apidomains/update_(cookie).htm
20
+ register_service :update, :cookie
21
+
22
+ ##
23
+ # Cleanly terminates the connection.
24
+ #
25
+ # http://www.opensrs.com/docs/apidomains/quit_session.htm
26
+ register_service :quit_session, :session, :quit
27
+ end
28
+ end
@@ -0,0 +1,45 @@
1
+ module MooMoo
2
+ class DnsZone < Base
3
+
4
+ ##
5
+ # Creates a custom DNS zone for managed DNS service.
6
+ #
7
+ # http://www.opensrs.com/docs/apidomains/create_dns_zone_request.htm
8
+ register_service :create_dns_zone, :domain
9
+
10
+ ##
11
+ # Deletes the DNS zones for the specified domain.
12
+ #
13
+ # http://www.opensrs.com/docs/apidomains/delete_dns_zone_request.htm
14
+ register_service :delete_dns_zone, :domain
15
+
16
+ ##
17
+ # Changes the nameservers on your domain to use the
18
+ # nameservers for managed DNS service.
19
+ #
20
+ # http://www.opensrs.com/docs/apidomains/Request_parameters_for_force_dns_nameservers.htm
21
+ register_service :force_dns_nameservers, :domain
22
+
23
+ ##
24
+ # View the DNS records for a specified domain.
25
+ #
26
+ # http://www.opensrs.com/docs/apidomains/get_dns_zone_request.htm
27
+ register_service :get_dns_zone, :domain
28
+
29
+ ##
30
+ # Sets the DNS zone to the values in the specified template.
31
+ # If a template is not specified in the command, the records
32
+ # are set to what was in the template that was used to enable
33
+ # the DNS service.
34
+ #
35
+ # http://www.opensrs.com/docs/apidomains/reset_dns_zone_request.htm
36
+ register_service :reset_dns_zone, :domain
37
+
38
+ ##
39
+ # Set the records for a domain's DNS zone.
40
+ #
41
+ # http://www.opensrs.com/docs/apidomains/set_dns_zone_request.htm
42
+ register_service :set_dns_zone, :domain
43
+
44
+ end
45
+ end
@@ -1,4 +1,4 @@
1
1
  module MooMoo
2
- class MooMooArgumentError < ArgumentError; end
2
+ class ArgumentError < ::ArgumentError; end
3
3
  class OpenSRSException < Exception; end
4
4
  end
@@ -0,0 +1,97 @@
1
+ module MooMoo
2
+ class Lookup < Base
3
+
4
+ ##
5
+ # Determines whether the domain belongs to the RSP who issued the command.
6
+ #
7
+ # http://www.opensrs.com/docs/apidomains/belongs_to_rsp.htm
8
+ register_service :belongs_to_rsp, :domain
9
+
10
+ ##
11
+ # Queries the requester's account, and returns the total amount of money in the account and
12
+ # the amount that is allocated to pending transactions.
13
+ #
14
+ # http://www.opensrs.com/docs/apidomains/get_balance.htm
15
+ register_service :get_balance, :balance
16
+
17
+ ##
18
+ # Lists domains that have been deleted due to expiration or deleted by request (revoked).
19
+ # This command applies to all domains in a Reseller's profile. Results include the domain,
20
+ # status, and deleted date.
21
+ #
22
+ # http://www.opensrs.com/docs/apidomains/get_deleted_domains.htm
23
+ register_service :get_deleted_domains, :domain
24
+
25
+ ##
26
+ # Queries various types of data regarding the user's domain. For example, the all_info type
27
+ # allows you to retrieve all data for the domain linked to the current cookie. The list type
28
+ # queries the list of domains associated with the user's profile. The list type can also be
29
+ # used to return a list of domains that expire within a specified range. The nameservers type
30
+ # returns the nameservers currently acting as DNS servers for the domain.
31
+ #
32
+ # http://www.opensrs.com/docs/apidomains/get_domain.htm
33
+ register_service :get_domain, :domain, :get
34
+
35
+ ##
36
+ # Queries contact information for a list of domains.
37
+ #
38
+ # http://www.opensrs.com/docs/apidomains/get_domains_contacts.htm
39
+ register_service :get_domains_contacts, :domain
40
+
41
+ ##
42
+ # Retrieves domains that expire within a specified date range.
43
+ #
44
+ # http://www.opensrs.com/docs/apidomains/get_domains_by_expiredate.htm
45
+ register_service :get_domains_by_expiredate, :domain
46
+
47
+ ##
48
+ # Retrieves the domain notes that detail the history of the domain, for example, renewals and
49
+ # transfers.
50
+ #
51
+ # http://www.opensrs.com/docs/apidomains/get_notes.htm
52
+ register_service :get_notes, :domain
53
+
54
+ ##
55
+ # Queries all the information for an order, but does not return sensitive information such as
56
+ # username, password, and Authcode.
57
+ #
58
+ # http://www.opensrs.com/docs/apidomains/get_order_info.htm
59
+ register_service :get_order_info, :domain
60
+
61
+ ##
62
+ # Retrieves information about orders placed for a specific domain.
63
+ #
64
+ # http://www.opensrs.com/docs/apidomains/get_orders_by_domain.htm
65
+ register_service :get_orders_by_domain, :domain
66
+
67
+ ##
68
+ # Queries the price of a domain, and can be used to determine the cost of a billable transaction
69
+ # for any TLD. A returned price for a given domain does not guarantee the availability of the
70
+ # domain, but indicates that the requested action is supported by the system and calculates the
71
+ # cost to register the domain (if available).
72
+ #
73
+ # http://www.opensrs.com/docs/apidomains/get_price.htm
74
+ register_service :get_price, :domain
75
+
76
+ ##
77
+ # Queries the properties of the specified Trust Service product
78
+ #
79
+ # ==== Required
80
+ # * <tt>:product_id</tt> - ID of the product
81
+ register_service :get_product_info, :trust_service
82
+
83
+ ##
84
+ # Determines the availability of a specified domain name.
85
+ #
86
+ # http://www.opensrs.com/docs/apidomains/lookup_domain.htm
87
+ register_service :lookup_domain, :domain, :lookup
88
+
89
+ ##
90
+ # Checks whether a specified name, word, or phrase is available for registration in gTLDs and
91
+ # ccTLDs, suggests other similar domain names for .COM, .NET, .ORG, .INFO, .BIZ, .US, and .MOBI
92
+ # domains, and checks whether they are available. Reseller must be enabled for the specified TLDs.
93
+ #
94
+ # http://www.opensrs.com/docs/apidomains/name_suggest_domain.htm
95
+ register_service :name_suggest, :domain
96
+ end
97
+ end
@@ -0,0 +1,12 @@
1
+ module MooMoo
2
+ class OpenSRSErrors < Faraday::Response::Middleware
3
+
4
+ def on_complete(env)
5
+ # Checks for invalid http status
6
+ unless (200..299).include?(env[:status])
7
+ raise OpenSRSException, "Bad HTTP Status: #{env[:status]}"
8
+ end
9
+ end
10
+
11
+ end
12
+ end
@@ -0,0 +1,101 @@
1
+ module MooMoo
2
+ class OpenSRSXMLBuilder < Faraday::Middleware
3
+ dependency 'rexml/document'
4
+ dependency 'digest/md5'
5
+
6
+ def initialize(app, *args)
7
+ @action = args[0]
8
+ @object = args[1]
9
+ @cookie = args[2]
10
+ @params = args[3]
11
+ @key = args[4]
12
+ @user = args[5]
13
+ super(app)
14
+ end
15
+
16
+ def call(env)
17
+ env[:body] = build_command.to_s
18
+ env[:request_headers] = {
19
+ 'Content-Type' => 'text/xml',
20
+ 'X-Username' => @user,
21
+ 'X-Signature' => signature(env[:body]),
22
+ 'Content-Length' => env[:body].size.to_s
23
+ }.merge(env[:request_headers])
24
+ @app.call(env)
25
+ end
26
+
27
+ private
28
+
29
+ # Builds an XML string of the command which can be sent to OpenSRS
30
+ def build_command
31
+ xml = <<-XML
32
+ <?xml version='1.0' encoding='UTF-8' standalone='no' ?>
33
+ <!DOCTYPE OPS_envelope SYSTEM 'ops.dtd'>
34
+ <OPS_envelope>
35
+ <header>
36
+ <version>0.9</version>
37
+ </header>
38
+ <body>
39
+ <data_block>
40
+ <dt_assoc>
41
+ <item key="protocol">XCP</item>
42
+ <item key="action">GET_BALANCE</item>
43
+ <item key="object">BALANCE</item>
44
+ <item key="registrant_ip"/>
45
+ </dt_assoc>
46
+ </data_block>
47
+ </body>
48
+ </OPS_envelope>
49
+ XML
50
+
51
+ doc = REXML::Document.new(xml)
52
+ doc.root.elements["body/data_block/dt_assoc/item[@key='action']"].text = @action
53
+ doc.root.elements["body/data_block/dt_assoc/item[@key='object']"].text = @object
54
+
55
+ unless @cookie.nil?
56
+ cookie_elem = doc.root.elements["body/data_block/dt_assoc"].add_element('item', {'key' => 'cookie'})
57
+ cookie_elem.text = @cookie
58
+ end
59
+
60
+ unless @params.nil?
61
+ elem = doc.root.elements["body/data_block/dt_assoc"].add_element('item', {'key' => 'attributes'})
62
+ build_child(elem, @params)
63
+ end
64
+
65
+ doc
66
+ end
67
+
68
+ # Adds XML child elements to the specified XML element for a given collection
69
+ #
70
+ # ==== Required
71
+ # * <tt>:elem</tt> - XML element to add the child nodes to
72
+ # * <tt>:coll</tt> - collection that will be added as XML child elements
73
+ def build_child(elem, coll)
74
+ if coll.is_a?(Hash)
75
+ elem = elem.add_element("dt_assoc")
76
+ coll.each do |key, val|
77
+ child = elem.add_element('item', {'key' => key})
78
+ build_child(child, val)
79
+ end
80
+ elsif coll.is_a?(Array)
81
+ elem = elem.add_element("dt_array")
82
+ coll.each_with_index do |val, key|
83
+ child = elem.add_element('item', {'key' => key})
84
+ build_child(child, val)
85
+ end
86
+ else
87
+ elem.text = coll
88
+ end
89
+ end
90
+
91
+
92
+ def signature(content)
93
+ Digest::MD5.hexdigest(
94
+ Digest::MD5.hexdigest(
95
+ content + @key
96
+ ) + @key
97
+ )
98
+ end
99
+
100
+ end
101
+ end
@@ -0,0 +1,58 @@
1
+ module MooMoo
2
+ class ParseOpenSRS < Faraday::Response::Middleware
3
+
4
+ def on_complete(env)
5
+ env[:body] = parse_response(env[:body])
6
+ end
7
+
8
+ def response_values(env)
9
+ {:status => env[:status], :headers => env[:response_headers], :body => env[:body]}
10
+ end
11
+
12
+ private
13
+
14
+ # Parses an XML response from the OpenSRS registry and generates a
15
+ # hash containing all of the data. Elements with child elements
16
+ # are converted into hashes themselves, with the :element_text entry
17
+ # containing any raw text
18
+ #
19
+ # ==== Required
20
+ # * <tt>data</tt> - data of the response
21
+ def parse_response(data)
22
+ doc = REXML::Document.new(data)
23
+
24
+ values = {}
25
+
26
+ elements = doc.elements["/OPS_envelope/body/data_block/dt_assoc"].select { |item|
27
+ item.is_a? REXML::Element
28
+ }
29
+
30
+ build_xml_hash(elements)
31
+ end
32
+
33
+ # Builds a hash from a collection of XML elements
34
+ #
35
+ # ==== Required
36
+ # * <tt>elements</tt> - collection of elemenents
37
+ def build_xml_hash(elements)
38
+ data_hash = {}
39
+
40
+ elements.each do |elem|
41
+ key = elem.attributes['key']
42
+
43
+ if elem.elements.size > 0
44
+ if key.nil?
45
+ data_hash.merge!(build_xml_hash(elem.elements))
46
+ else
47
+ data_hash[key] = build_xml_hash(elem.elements)
48
+ end
49
+ else
50
+ data_hash[key] = elem.text unless key.nil?
51
+ end
52
+ end
53
+
54
+ data_hash
55
+ end
56
+
57
+ end
58
+ end
@@ -0,0 +1,29 @@
1
+ module MooMoo
2
+ class Nameserver < Base
3
+
4
+ ##
5
+ # Creates a nameserver in the same domain space as the cookie's domain.
6
+ #
7
+ # http://www.opensrs.com/docs/apidomains/create_nameserver.htm
8
+ register_service :create, :nameserver
9
+
10
+ ##
11
+ # Deletes a nameserver.
12
+ #
13
+ # http://www.opensrs.com/docs/apidomains/Delete_Nameserver.htm
14
+ register_service :delete, :nameserver
15
+
16
+ ##
17
+ # Queries nameservers that exist in the current user profile (current cookie). These nameservers
18
+ # may or may not be currently assigned to a domain.
19
+ #
20
+ # http://www.opensrs.com/docs/apidomains/get_nameserver.htm
21
+ register_service :get, :nameserver
22
+
23
+ ##
24
+ # Renames a nameserver.
25
+ #
26
+ # http://www.opensrs.com/docs/apidomains/modify_nameserver.htm
27
+ register_service :modify, :nameserver
28
+ end
29
+ end