katello_api 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (111) hide show
  1. data/.gitignore +2 -0
  2. data/Gemfile +2 -0
  3. data/README.rdoc +0 -4
  4. data/doc/KatelloApi/Base.html +831 -0
  5. data/doc/KatelloApi/Generator/Base.html +671 -0
  6. data/doc/KatelloApi/Generator.html +115 -0
  7. data/doc/KatelloApi/Resources/ActivationKey.html +1757 -0
  8. data/doc/KatelloApi/Resources/Architecture.html +1007 -0
  9. data/doc/KatelloApi/Resources/Changeset.html +1413 -0
  10. data/doc/KatelloApi/Resources/ChangesetsContent.html +2674 -0
  11. data/doc/KatelloApi/Resources/ComputeResource.html +1067 -0
  12. data/doc/KatelloApi/Resources/ConfigTemplate.html +1361 -0
  13. data/doc/KatelloApi/Resources/ContentView.html +938 -0
  14. data/doc/KatelloApi/Resources/ContentViewDefinition.html +1629 -0
  15. data/doc/KatelloApi/Resources/Crl.html +367 -0
  16. data/doc/KatelloApi/Resources/Distribution.html +560 -0
  17. data/doc/KatelloApi/Resources/Distributor.html +1892 -0
  18. data/doc/KatelloApi/Resources/Domain.html +1066 -0
  19. data/doc/KatelloApi/Resources/Environment.html +1645 -0
  20. data/doc/KatelloApi/Resources/Erratum.html +632 -0
  21. data/doc/KatelloApi/Resources/GpgKey.html +1220 -0
  22. data/doc/KatelloApi/Resources/HardwareModel.html +1025 -0
  23. data/doc/KatelloApi/Resources/Organization.html +1062 -0
  24. data/doc/KatelloApi/Resources/Package.html +728 -0
  25. data/doc/KatelloApi/Resources/Permission.html +1021 -0
  26. data/doc/KatelloApi/Resources/Ping.html +625 -0
  27. data/doc/KatelloApi/Resources/Product.html +1845 -0
  28. data/doc/KatelloApi/Resources/Provider.html +2237 -0
  29. data/doc/KatelloApi/Resources/Repository.html +1976 -0
  30. data/doc/KatelloApi/Resources/RepositorySet.html +770 -0
  31. data/doc/KatelloApi/Resources/Role.html +1257 -0
  32. data/doc/KatelloApi/Resources/RoleLdapGroup.html +728 -0
  33. data/doc/KatelloApi/Resources/SmartProxy.html +1054 -0
  34. data/doc/KatelloApi/Resources/Statu.html +367 -0
  35. data/doc/KatelloApi/Resources/Subnet.html +1007 -0
  36. data/doc/KatelloApi/Resources/Subscription.html +1064 -0
  37. data/doc/KatelloApi/Resources/Sync.html +826 -0
  38. data/doc/KatelloApi/Resources/SyncPlan.html +1148 -0
  39. data/doc/KatelloApi/Resources/System.html +3576 -0
  40. data/doc/KatelloApi/Resources/SystemGroup.html +2006 -0
  41. data/doc/KatelloApi/Resources/SystemGroupErratum.html +602 -0
  42. data/doc/KatelloApi/Resources/SystemGroupPackage.html +826 -0
  43. data/doc/KatelloApi/Resources/SystemPackage.html +770 -0
  44. data/doc/KatelloApi/Resources/Task.html +546 -0
  45. data/doc/KatelloApi/Resources/Template.html +1573 -0
  46. data/doc/KatelloApi/Resources/TemplatesContent.html +2268 -0
  47. data/doc/KatelloApi/Resources/Uebercert.html +406 -0
  48. data/doc/KatelloApi/Resources/User.html +1846 -0
  49. data/doc/KatelloApi/Resources.html +117 -0
  50. data/doc/KatelloApi.html +365 -0
  51. data/doc/_index.html +539 -0
  52. data/doc/class_list.html +53 -0
  53. data/doc/css/common.css +1 -0
  54. data/doc/css/full_list.css +57 -0
  55. data/doc/css/style.css +338 -0
  56. data/doc/file.README.html +127 -0
  57. data/doc/file_list.html +55 -0
  58. data/doc/frames.html +28 -0
  59. data/doc/index.html +127 -0
  60. data/doc/js/app.js +214 -0
  61. data/doc/js/full_list.js +173 -0
  62. data/doc/js/jquery.js +4 -0
  63. data/doc/method_list.html +2548 -0
  64. data/doc/top-level-namespace.html +112 -0
  65. data/lib/katello_api/base.rb +61 -6
  66. data/lib/katello_api/documentation.json +1 -0
  67. data/lib/katello_api/resources/activation_key.rb +51 -48
  68. data/lib/katello_api/resources/architecture.rb +19 -24
  69. data/lib/katello_api/resources/changeset.rb +39 -37
  70. data/lib/katello_api/resources/changesets_content.rb +64 -57
  71. data/lib/katello_api/resources/compute_resource.rb +37 -42
  72. data/lib/katello_api/resources/config_template.rb +40 -44
  73. data/lib/katello_api/resources/content_view.rb +14 -17
  74. data/lib/katello_api/resources/content_view_definition.rb +34 -42
  75. data/lib/katello_api/resources/crl.rb +3 -4
  76. data/lib/katello_api/resources/distribution.rb +8 -8
  77. data/lib/katello_api/resources/distributor.rb +35 -37
  78. data/lib/katello_api/resources/domain.rb +28 -32
  79. data/lib/katello_api/resources/environment.rb +38 -44
  80. data/lib/katello_api/resources/erratum.rb +9 -8
  81. data/lib/katello_api/resources/gpg_key.rb +28 -33
  82. data/lib/katello_api/resources/hardware_model.rb +25 -30
  83. data/lib/katello_api/resources/organization.rb +24 -26
  84. data/lib/katello_api/resources/package.rb +9 -12
  85. data/lib/katello_api/resources/permission.rb +21 -19
  86. data/lib/katello_api/resources/ping.rb +9 -12
  87. data/lib/katello_api/resources/product.rb +34 -43
  88. data/lib/katello_api/resources/provider.rb +55 -66
  89. data/lib/katello_api/resources/repository.rb +44 -55
  90. data/lib/katello_api/resources/repository_set.rb +9 -12
  91. data/lib/katello_api/resources/role.rb +35 -33
  92. data/lib/katello_api/resources/role_ldap_group.rb +10 -12
  93. data/lib/katello_api/resources/smart_proxy.rb +24 -28
  94. data/lib/katello_api/resources/statu.rb +3 -4
  95. data/lib/katello_api/resources/subnet.rb +19 -24
  96. data/lib/katello_api/resources/subscription.rb +16 -21
  97. data/lib/katello_api/resources/sync.rb +9 -12
  98. data/lib/katello_api/resources/sync_plan.rb +28 -33
  99. data/lib/katello_api/resources/system.rb +81 -90
  100. data/lib/katello_api/resources/system_group.rb +47 -57
  101. data/lib/katello_api/resources/system_group_erratum.rb +6 -8
  102. data/lib/katello_api/resources/system_group_package.rb +15 -18
  103. data/lib/katello_api/resources/system_package.rb +12 -15
  104. data/lib/katello_api/resources/task.rb +6 -8
  105. data/lib/katello_api/resources/template.rb +39 -47
  106. data/lib/katello_api/resources/templates_content.rb +40 -52
  107. data/lib/katello_api/resources/uebercert.rb +4 -4
  108. data/lib/katello_api/resources/user.rb +47 -50
  109. data/lib/katello_api/version.rb +1 -1
  110. data/lib/katello_api.rb +0 -13
  111. metadata +68 -4
@@ -0,0 +1,112 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
4
+ <head>
5
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
6
+ <title>
7
+ Top Level Namespace
8
+
9
+ &mdash; Documentation by YARD 0.8.5.2
10
+
11
+ </title>
12
+
13
+ <link rel="stylesheet" href="css/style.css" type="text/css" media="screen" charset="utf-8" />
14
+
15
+ <link rel="stylesheet" href="css/common.css" type="text/css" media="screen" charset="utf-8" />
16
+
17
+ <script type="text/javascript" charset="utf-8">
18
+ hasFrames = window.top.frames.main ? true : false;
19
+ relpath = '';
20
+ framesUrl = "frames.html#!" + escape(window.location.href);
21
+ </script>
22
+
23
+
24
+ <script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
25
+
26
+ <script type="text/javascript" charset="utf-8" src="js/app.js"></script>
27
+
28
+
29
+ </head>
30
+ <body>
31
+ <div id="header">
32
+ <div id="menu">
33
+
34
+ <a href="_index.html">Index</a> &raquo;
35
+
36
+
37
+ <span class="title">Top Level Namespace</span>
38
+
39
+
40
+ <div class="noframes"><span class="title">(</span><a href="." target="_top">no frames</a><span class="title">)</span></div>
41
+ </div>
42
+
43
+ <div id="search">
44
+
45
+ <a class="full_list_link" id="class_list_link"
46
+ href="class_list.html">
47
+ Class List
48
+ </a>
49
+
50
+ <a class="full_list_link" id="method_list_link"
51
+ href="method_list.html">
52
+ Method List
53
+ </a>
54
+
55
+ <a class="full_list_link" id="file_list_link"
56
+ href="file_list.html">
57
+ File List
58
+ </a>
59
+
60
+ </div>
61
+ <div class="clear"></div>
62
+ </div>
63
+
64
+ <iframe id="search_frame"></iframe>
65
+
66
+ <div id="content"><h1>Top Level Namespace
67
+
68
+
69
+
70
+ </h1>
71
+
72
+ <dl class="box">
73
+
74
+
75
+
76
+
77
+
78
+
79
+
80
+
81
+ </dl>
82
+ <div class="clear"></div>
83
+
84
+ <h2>Defined Under Namespace</h2>
85
+ <p class="children">
86
+
87
+
88
+ <strong class="modules">Modules:</strong> <span class='object_link'><a href="KatelloApi.html" title="KatelloApi (module)">KatelloApi</a></span>
89
+
90
+
91
+
92
+
93
+ </p>
94
+
95
+
96
+
97
+
98
+
99
+
100
+
101
+
102
+
103
+ </div>
104
+
105
+ <div id="footer">
106
+ Generated on Mon Mar 18 14:17:40 2013 by
107
+ <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
108
+ 0.8.5.2 (ruby-1.8.7).
109
+ </div>
110
+
111
+ </body>
112
+ </html>
@@ -4,6 +4,25 @@ require 'json'
4
4
  require 'katello_api/rest_client_oauth'
5
5
 
6
6
  module KatelloApi
7
+
8
+ def self.client_config
9
+ @client_config ||= YAML.load_file("#{root}/katello_api/config.yml")
10
+ end
11
+
12
+ def self.root
13
+ @root ||= File.expand_path('../', File.dirname(__FILE__))
14
+ end
15
+
16
+ def self.doc_file
17
+ "#{root}/katello_api/documentation.json"
18
+ end
19
+
20
+ def self.doc
21
+ @doc ||= File.open(doc_file, 'r') do |f|
22
+ JSON.load(f.read)['docs']
23
+ end
24
+ end
25
+
7
26
  class Base
8
27
  API_VERSION = "1.0"
9
28
 
@@ -22,11 +41,20 @@ module KatelloApi
22
41
  @config = config
23
42
  end
24
43
 
25
- def call(method, path, params = { }, headers = { })
44
+ def perform_call(method_name, params, headers)
45
+ method_doc = self.class.method_doc(method_name)
46
+ check_params params, :allowed => method_doc['params'].any?, :method => method_name
47
+ method_apis = method_doc['apis']
48
+ api = find_suitable_api_call(method_apis, params)
49
+ url, params = fill_params_in_url api['api_url'], params
50
+ return http_call(api['http_method'].downcase, url, params, headers)
51
+ end
52
+
53
+ def http_call(http_method, path, params = { }, headers = { })
26
54
  headers ||= { }
27
55
 
28
- args = [method]
29
- if [:post, :put].include?(method)
56
+ args = [http_method]
57
+ if %w[post put].include?(http_method.to_s)
30
58
  args << params.to_json
31
59
  else
32
60
  headers[:params] = params if params
@@ -86,12 +114,39 @@ module KatelloApi
86
114
  end
87
115
  end
88
116
 
117
+ # @param possible_apis [Array] Array of hasahs in form of
118
+ # [{:api_url => '/path1', :http_method => 'GET'}, {...}]
119
+ # @param params [Hash] enterred params
120
+ # @return api that suits the enterred params mosts
121
+ #
122
+ # Given this paths:
123
+ # 1. +/comments+
124
+ # 2. +/users/:user_id/comments+
125
+ # 3. +/users/:user_id/posts/:post_id/comments+
126
+ #
127
+ # If +:user_id+ and +:post_id+ is pecified, the third path is
128
+ # used. If only +:user_id+ is specified, the second one is used.
129
+ # The selection defaults to the path with the least number of
130
+ # incuded params in alphanumeric order.
131
+ def find_suitable_api_call(possible_apis, params)
132
+ apis_with_params = possible_apis.map do |api|
133
+ [api, self.class.params_in_path(api['api_url'])]
134
+ end.sort_by { |api, url_params| [-1 * url_params.count, api['api_url']] }
135
+
136
+ suitable_api = apis_with_params.find do |api, url_params|
137
+ url_params.all? { |url_param| params.keys.map(&:to_s).include?(url_param) }
138
+ end
139
+
140
+ suitable_api ||= apis_with_params.last
141
+ return suitable_api.first
142
+ end
143
+
89
144
  # @return url and rest of the params
90
145
  def fill_params_in_url(url, params)
91
146
  params ||= { }
92
147
  # insert param values
93
- url_param_names = params_in_path(url)
94
- url = params_in_path(url).inject(url) do |url, param_name|
148
+ url_param_names = self.class.params_in_path(url)
149
+ url = url_param_names.inject(url) do |url, param_name|
95
150
  param_value = params[param_name] or
96
151
  raise ArgumentError, "missing param '#{param_name}' in parameters"
97
152
  url.sub(":#{param_name}", param_value.to_s)
@@ -127,7 +182,7 @@ module KatelloApi
127
182
  end
128
183
  end
129
184
 
130
- def params_in_path(url)
185
+ def self.params_in_path(url)
131
186
  url.scan(/:([^\/]*)/).map { |m| m.first }
132
187
  end
133
188
  end