mm_json_client 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +9 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +5 -0
  5. data/Gemfile +4 -0
  6. data/Guardfile +22 -0
  7. data/LICENSE.txt +21 -0
  8. data/README.md +151 -0
  9. data/Rakefile +33 -0
  10. data/bin/console +14 -0
  11. data/bin/setup +7 -0
  12. data/examples/claim_next_free_ip.rb +73 -0
  13. data/examples/register_dns.rb +37 -0
  14. data/examples/release_ip.rb +59 -0
  15. data/examples/unregister_dns.rb +44 -0
  16. data/fixtures/vcr_cassettes/MmJsonClient_GenericType/basic_server_interaction/allows_a_user_to_log_in_and_out.yml +74 -0
  17. data/fixtures/vcr_cassettes/MmJsonClient_GenericType/basic_server_interaction/filters_a_list_of_users.yml +110 -0
  18. data/fixtures/vcr_cassettes/MmJsonClient_GenericType/basic_server_interaction/gets_a_list_of_users.yml +111 -0
  19. data/fixtures/vcr_cassettes/MmJsonClient_GenericType/basic_server_interaction/gets_a_user_by_reference.yml +110 -0
  20. data/fixtures/vcr_cassettes/MmJsonClient_GenericType/basic_server_interaction/responds_with_a_server_error_on_bad_auth.yml +39 -0
  21. data/fixtures/vcr_cassettes/MmJsonClient_GenericType/multiple_proxy_servers/connects_to_another_proxy_when_one_is_disabled.yml +72 -0
  22. data/fixtures/vcr_cassettes/MmJsonClient_GenericType/proxy_options/allows_a_separate_proxy_to_be_defined.yml +75 -0
  23. data/fixtures/vcr_cassettes/MmJsonClient_GenericType/ssl_options/allows_ignoring_bad_certificates.yml +74 -0
  24. data/generators/enum_def_generator.rb +22 -0
  25. data/generators/method_def_generator.rb +20 -0
  26. data/generators/type_def_generator.rb +50 -0
  27. data/generators/wasabi_extension.rb +45 -0
  28. data/lib/core_ext/hash_extension.rb +43 -0
  29. data/lib/core_ext/string_extension.rb +60 -0
  30. data/lib/core_ext/symbol_extension.rb +24 -0
  31. data/lib/mm_json_client.rb +64 -0
  32. data/lib/mm_json_client/api_definitions/enums.json +1 -0
  33. data/lib/mm_json_client/api_definitions/methods.json +1 -0
  34. data/lib/mm_json_client/api_definitions/types.json +1 -0
  35. data/lib/mm_json_client/client.rb +148 -0
  36. data/lib/mm_json_client/enums/enum_factory.rb +24 -0
  37. data/lib/mm_json_client/enums/generic_enum.rb +12 -0
  38. data/lib/mm_json_client/exceptions.rb +23 -0
  39. data/lib/mm_json_client/generic_type.rb +37 -0
  40. data/lib/mm_json_client/http_client/client.rb +54 -0
  41. data/lib/mm_json_client/json_rpc_http/client.rb +40 -0
  42. data/lib/mm_json_client/json_rpc_http/error.rb +18 -0
  43. data/lib/mm_json_client/json_rpc_http/exceptions.rb +10 -0
  44. data/lib/mm_json_client/json_rpc_http/response.rb +31 -0
  45. data/lib/mm_json_client/response_code.rb +6 -0
  46. data/lib/mm_json_client/type_factory.rb +83 -0
  47. data/lib/mm_json_client/version.rb +3 -0
  48. data/mm_json_client.gemspec +38 -0
  49. metadata +231 -0
@@ -0,0 +1,44 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'mm_json_client'
4
+
5
+ #######################################
6
+ # Configuration values from somewhere #
7
+ #######################################
8
+ server = 'my-ipam.example.com'
9
+ username = 'admin'
10
+ password = 'password'
11
+
12
+ ip_address = '10.20.30.2'
13
+ dns_zone_name = 'example.com.'
14
+ dns_name = 'gemdemo'
15
+
16
+ #######################################
17
+
18
+ client = MmJsonClient::Client.new(server: server,
19
+ username: username,
20
+ password: password)
21
+ client.login
22
+
23
+ #######################
24
+ # Get the DNS Zone
25
+ #######################
26
+ response = client.get_dns_zones(filter: "name:^#{dns_zone_name}$")
27
+ raise "DNS Zone #{dns_zone_name} not found" if response.total_results == 0
28
+ dns_zone = response.dns_zones.first
29
+
30
+ #######################
31
+ # Get the DNS Record
32
+ #######################
33
+ # must match name, ip, and record type
34
+ record_filter = "name:^#{dns_name}$ data:^#{ip_address}$ type:A"
35
+ response = client.get_dns_records(filter: record_filter,
36
+ dns_zone_ref: dns_zone.ref)
37
+ if response.total_results == 0
38
+ raise "DNS record #{dns_name}.#{dns_zone_name} not found"
39
+ end
40
+ dns_record = response.dns_records.first
41
+
42
+ client.remove_object(ref: dns_record.ref, obj_type: 'DNSRecord')
43
+
44
+ puts "DNS record #{dns_name}.#{dns_zone_name} removed"
@@ -0,0 +1,74 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: http://test-ipam.local/_mmwebext/mmwebext.dll?Soap
6
+ body:
7
+ encoding: UTF-8
8
+ string: '{"jsonrpc":"2.0","method":"Login","params":{"loginName":"testuser","password":"testpass","server":"test-ipam.local"}}'
9
+ headers:
10
+ Accept-Encoding:
11
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
12
+ Accept:
13
+ - application/json
14
+ User-Agent:
15
+ - Ruby
16
+ Content-Type:
17
+ - application/json
18
+ response:
19
+ status:
20
+ code: 200
21
+ message: OK
22
+ headers:
23
+ Content-Length:
24
+ - '76'
25
+ Content-Type:
26
+ - application/json; charset=utf-8
27
+ Server:
28
+ - Microsoft-IIS/8.5
29
+ X-Powered-By:
30
+ - ASP.NET
31
+ Date:
32
+ - Mon, 11 Jul 2016 17:56:32 GMT
33
+ body:
34
+ encoding: UTF-8
35
+ string: '{"jsonrpc": "2.0", "result": {"session":"bsvh5S2kLC5Q9gnPbfYM"}, "id":
36
+ null}'
37
+ http_version:
38
+ recorded_at: Mon, 11 Jul 2016 17:56:34 GMT
39
+ - request:
40
+ method: post
41
+ uri: http://test-ipam.local/_mmwebext/mmwebext.dll?Soap
42
+ body:
43
+ encoding: UTF-8
44
+ string: '{"jsonrpc":"2.0","method":"Logout","params":{"session":"bsvh5S2kLC5Q9gnPbfYM"}}'
45
+ headers:
46
+ Accept-Encoding:
47
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
48
+ Accept:
49
+ - application/json
50
+ User-Agent:
51
+ - Ruby
52
+ Content-Type:
53
+ - application/json
54
+ response:
55
+ status:
56
+ code: 200
57
+ message: OK
58
+ headers:
59
+ Content-Length:
60
+ - '44'
61
+ Content-Type:
62
+ - application/json; charset=utf-8
63
+ Server:
64
+ - Microsoft-IIS/8.5
65
+ X-Powered-By:
66
+ - ASP.NET
67
+ Date:
68
+ - Mon, 11 Jul 2016 17:56:37 GMT
69
+ body:
70
+ encoding: UTF-8
71
+ string: '{"jsonrpc": "2.0", "result": "", "id": null}'
72
+ http_version:
73
+ recorded_at: Mon, 11 Jul 2016 17:56:40 GMT
74
+ recorded_with: VCR 3.0.3
@@ -0,0 +1,110 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: http://test-ipam.local/_mmwebext/mmwebext.dll?Soap
6
+ body:
7
+ encoding: UTF-8
8
+ string: '{"jsonrpc":"2.0","method":"Login","params":{"loginName":"testuser","password":"testpass","server":"test-ipam.local"}}'
9
+ headers:
10
+ Accept-Encoding:
11
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
12
+ Accept:
13
+ - application/json
14
+ User-Agent:
15
+ - Ruby
16
+ Content-Type:
17
+ - application/json
18
+ response:
19
+ status:
20
+ code: 200
21
+ message: OK
22
+ headers:
23
+ Content-Length:
24
+ - '76'
25
+ Content-Type:
26
+ - application/json; charset=utf-8
27
+ Server:
28
+ - Microsoft-IIS/8.5
29
+ X-Powered-By:
30
+ - ASP.NET
31
+ Date:
32
+ - Mon, 11 Jul 2016 17:57:03 GMT
33
+ body:
34
+ encoding: UTF-8
35
+ string: '{"jsonrpc": "2.0", "result": {"session":"MA2ksoukrfVjhPBoCU82"}, "id":
36
+ null}'
37
+ http_version:
38
+ recorded_at: Mon, 11 Jul 2016 17:57:05 GMT
39
+ - request:
40
+ method: post
41
+ uri: http://test-ipam.local/_mmwebext/mmwebext.dll?Soap
42
+ body:
43
+ encoding: UTF-8
44
+ string: '{"jsonrpc":"2.0","method":"GetUsers","params":{"filter":"name:^testuser$","session":"MA2ksoukrfVjhPBoCU82"}}'
45
+ headers:
46
+ Accept-Encoding:
47
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
48
+ Accept:
49
+ - application/json
50
+ User-Agent:
51
+ - Ruby
52
+ Content-Type:
53
+ - application/json
54
+ response:
55
+ status:
56
+ code: 200
57
+ message: OK
58
+ headers:
59
+ Content-Length:
60
+ - '288'
61
+ Content-Type:
62
+ - application/json; charset=utf-8
63
+ Server:
64
+ - Microsoft-IIS/8.5
65
+ X-Powered-By:
66
+ - ASP.NET
67
+ Date:
68
+ - Mon, 11 Jul 2016 17:57:08 GMT
69
+ body:
70
+ encoding: UTF-8
71
+ string: '{"jsonrpc": "2.0", "result": {"users":[{"ref":"{#14-#2}","name":"testuser","password":"","fullName":"","description":"","email":"","authenticationType":"Internal","groups":[],"roles":[{"ref":"{#31-#1}","objType":"Role","name":"Administrators
72
+ (built-in)"}]}],"totalResults":1}, "id": null}'
73
+ http_version:
74
+ recorded_at: Mon, 11 Jul 2016 17:57:10 GMT
75
+ - request:
76
+ method: post
77
+ uri: http://test-ipam.local/_mmwebext/mmwebext.dll?Soap
78
+ body:
79
+ encoding: UTF-8
80
+ string: '{"jsonrpc":"2.0","method":"Logout","params":{"session":"MA2ksoukrfVjhPBoCU82"}}'
81
+ headers:
82
+ Accept-Encoding:
83
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
84
+ Accept:
85
+ - application/json
86
+ User-Agent:
87
+ - Ruby
88
+ Content-Type:
89
+ - application/json
90
+ response:
91
+ status:
92
+ code: 200
93
+ message: OK
94
+ headers:
95
+ Content-Length:
96
+ - '44'
97
+ Content-Type:
98
+ - application/json; charset=utf-8
99
+ Server:
100
+ - Microsoft-IIS/8.5
101
+ X-Powered-By:
102
+ - ASP.NET
103
+ Date:
104
+ - Mon, 11 Jul 2016 17:57:13 GMT
105
+ body:
106
+ encoding: UTF-8
107
+ string: '{"jsonrpc": "2.0", "result": "", "id": null}'
108
+ http_version:
109
+ recorded_at: Mon, 11 Jul 2016 17:57:15 GMT
110
+ recorded_with: VCR 3.0.3
@@ -0,0 +1,111 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: http://test-ipam.local/_mmwebext/mmwebext.dll?Soap
6
+ body:
7
+ encoding: UTF-8
8
+ string: '{"jsonrpc":"2.0","method":"Login","params":{"loginName":"testuser","password":"testpass","server":"test-ipam.local"}}'
9
+ headers:
10
+ Accept-Encoding:
11
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
12
+ Accept:
13
+ - application/json
14
+ User-Agent:
15
+ - Ruby
16
+ Content-Type:
17
+ - application/json
18
+ response:
19
+ status:
20
+ code: 200
21
+ message: OK
22
+ headers:
23
+ Content-Length:
24
+ - '76'
25
+ Content-Type:
26
+ - application/json; charset=utf-8
27
+ Server:
28
+ - Microsoft-IIS/8.5
29
+ X-Powered-By:
30
+ - ASP.NET
31
+ Date:
32
+ - Mon, 11 Jul 2016 17:56:47 GMT
33
+ body:
34
+ encoding: UTF-8
35
+ string: '{"jsonrpc": "2.0", "result": {"session":"U3ODMFlsapyc799G2s3x"}, "id":
36
+ null}'
37
+ http_version:
38
+ recorded_at: Mon, 11 Jul 2016 17:56:50 GMT
39
+ - request:
40
+ method: post
41
+ uri: http://test-ipam.local/_mmwebext/mmwebext.dll?Soap
42
+ body:
43
+ encoding: UTF-8
44
+ string: '{"jsonrpc":"2.0","method":"GetUsers","params":{"session":"U3ODMFlsapyc799G2s3x"}}'
45
+ headers:
46
+ Accept-Encoding:
47
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
48
+ Accept:
49
+ - application/json
50
+ User-Agent:
51
+ - Ruby
52
+ Content-Type:
53
+ - application/json
54
+ response:
55
+ status:
56
+ code: 200
57
+ message: OK
58
+ headers:
59
+ Content-Length:
60
+ - '461'
61
+ Content-Type:
62
+ - application/json; charset=utf-8
63
+ Server:
64
+ - Microsoft-IIS/8.5
65
+ X-Powered-By:
66
+ - ASP.NET
67
+ Date:
68
+ - Mon, 11 Jul 2016 17:56:53 GMT
69
+ body:
70
+ encoding: UTF-8
71
+ string: '{"jsonrpc": "2.0", "result": {"users":[{"ref":"{#14-#0}","name":"administrator","password":"","fullName":"System
72
+ Administrator","description":"","email":"","authenticationType":"Internal","groups":[],"roles":[]},{"ref":"{#14-#2}","name":"testuser","password":"","fullName":"","description":"","email":"","authenticationType":"Internal","groups":[],"roles":[{"ref":"{#31-#1}","objType":"Role","name":"Administrators
73
+ (built-in)"}]}],"totalResults":2}, "id": null}'
74
+ http_version:
75
+ recorded_at: Mon, 11 Jul 2016 17:56:55 GMT
76
+ - request:
77
+ method: post
78
+ uri: http://test-ipam.local/_mmwebext/mmwebext.dll?Soap
79
+ body:
80
+ encoding: UTF-8
81
+ string: '{"jsonrpc":"2.0","method":"Logout","params":{"session":"U3ODMFlsapyc799G2s3x"}}'
82
+ headers:
83
+ Accept-Encoding:
84
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
85
+ Accept:
86
+ - application/json
87
+ User-Agent:
88
+ - Ruby
89
+ Content-Type:
90
+ - application/json
91
+ response:
92
+ status:
93
+ code: 200
94
+ message: OK
95
+ headers:
96
+ Content-Length:
97
+ - '44'
98
+ Content-Type:
99
+ - application/json; charset=utf-8
100
+ Server:
101
+ - Microsoft-IIS/8.5
102
+ X-Powered-By:
103
+ - ASP.NET
104
+ Date:
105
+ - Mon, 11 Jul 2016 17:56:58 GMT
106
+ body:
107
+ encoding: UTF-8
108
+ string: '{"jsonrpc": "2.0", "result": "", "id": null}'
109
+ http_version:
110
+ recorded_at: Mon, 11 Jul 2016 17:57:00 GMT
111
+ recorded_with: VCR 3.0.3
@@ -0,0 +1,110 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: http://test-ipam.local/_mmwebext/mmwebext.dll?Soap
6
+ body:
7
+ encoding: UTF-8
8
+ string: '{"jsonrpc":"2.0","method":"Login","params":{"loginName":"testuser","password":"testpass","server":"test-ipam.local"}}'
9
+ headers:
10
+ Accept-Encoding:
11
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
12
+ Accept:
13
+ - application/json
14
+ User-Agent:
15
+ - Ruby
16
+ Content-Type:
17
+ - application/json
18
+ response:
19
+ status:
20
+ code: 200
21
+ message: OK
22
+ headers:
23
+ Content-Length:
24
+ - '76'
25
+ Content-Type:
26
+ - application/json; charset=utf-8
27
+ Server:
28
+ - Microsoft-IIS/8.5
29
+ X-Powered-By:
30
+ - ASP.NET
31
+ Date:
32
+ - Mon, 11 Jul 2016 17:57:18 GMT
33
+ body:
34
+ encoding: UTF-8
35
+ string: '{"jsonrpc": "2.0", "result": {"session":"geegefFtGFAxoquZr8A4"}, "id":
36
+ null}'
37
+ http_version:
38
+ recorded_at: Mon, 11 Jul 2016 17:57:20 GMT
39
+ - request:
40
+ method: post
41
+ uri: http://test-ipam.local/_mmwebext/mmwebext.dll?Soap
42
+ body:
43
+ encoding: UTF-8
44
+ string: '{"jsonrpc":"2.0","method":"GetUser","params":{"userRef":"{#14-#2}","session":"geegefFtGFAxoquZr8A4"}}'
45
+ headers:
46
+ Accept-Encoding:
47
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
48
+ Accept:
49
+ - application/json
50
+ User-Agent:
51
+ - Ruby
52
+ Content-Type:
53
+ - application/json
54
+ response:
55
+ status:
56
+ code: 200
57
+ message: OK
58
+ headers:
59
+ Content-Length:
60
+ - '268'
61
+ Content-Type:
62
+ - application/json; charset=utf-8
63
+ Server:
64
+ - Microsoft-IIS/8.5
65
+ X-Powered-By:
66
+ - ASP.NET
67
+ Date:
68
+ - Mon, 11 Jul 2016 17:57:23 GMT
69
+ body:
70
+ encoding: UTF-8
71
+ string: '{"jsonrpc": "2.0", "result": {"user":{"ref":"{#14-#2}","name":"testuser","password":"","fullName":"","description":"","email":"","authenticationType":"Internal","groups":[],"roles":[{"ref":"{#31-#1}","objType":"Role","name":"Administrators
72
+ (built-in)"}]}}, "id": null}'
73
+ http_version:
74
+ recorded_at: Mon, 11 Jul 2016 17:57:25 GMT
75
+ - request:
76
+ method: post
77
+ uri: http://test-ipam.local/_mmwebext/mmwebext.dll?Soap
78
+ body:
79
+ encoding: UTF-8
80
+ string: '{"jsonrpc":"2.0","method":"Logout","params":{"session":"geegefFtGFAxoquZr8A4"}}'
81
+ headers:
82
+ Accept-Encoding:
83
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
84
+ Accept:
85
+ - application/json
86
+ User-Agent:
87
+ - Ruby
88
+ Content-Type:
89
+ - application/json
90
+ response:
91
+ status:
92
+ code: 200
93
+ message: OK
94
+ headers:
95
+ Content-Length:
96
+ - '44'
97
+ Content-Type:
98
+ - application/json; charset=utf-8
99
+ Server:
100
+ - Microsoft-IIS/8.5
101
+ X-Powered-By:
102
+ - ASP.NET
103
+ Date:
104
+ - Mon, 11 Jul 2016 17:57:28 GMT
105
+ body:
106
+ encoding: UTF-8
107
+ string: '{"jsonrpc": "2.0", "result": "", "id": null}'
108
+ http_version:
109
+ recorded_at: Mon, 11 Jul 2016 17:57:30 GMT
110
+ recorded_with: VCR 3.0.3