Class: KatelloApi::Base
- Inherits:
-
Object
show all
- Defined in:
- lib/katello_api/base.rb
Direct Known Subclasses
Resources::ActivationKey, Resources::Architecture, Resources::Changeset, Resources::ChangesetsContent, Resources::ComputeResource, Resources::ConfigTemplate, Resources::ContentView, Resources::ContentViewDefinition, Resources::Crl, Resources::Distribution, Resources::Distributor, Resources::Domain, Resources::Environment, Resources::Erratum, Resources::GpgKey, Resources::HardwareModel, Resources::Organization, Resources::Package, Resources::Permission, Resources::Ping, Resources::Product, Resources::Provider, Resources::Repository, Resources::RepositorySet, Resources::Role, Resources::RoleLdapGroup, Resources::SmartProxy, Resources::Statu, Resources::Subnet, Resources::Subscription, Resources::Sync, Resources::SyncPlan, Resources::System, Resources::SystemGroup, Resources::SystemGroupErratum, Resources::SystemGroupPackage, Resources::SystemPackage, Resources::Task, Resources::Template, Resources::TemplatesContent, Resources::Uebercert, Resources::User
Constant Summary
- API_VERSION =
"1.0"
Instance Attribute Summary (collapse)
Class Method Summary
(collapse)
Instance Method Summary
(collapse)
Constructor Details
- (Base) initialize(config, options = { })
31
32
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/katello_api/base.rb', line 31
def initialize(config, options = { })
@client = RestClient::Resource.new(
config[:base_url],
{ :user => config[:username],
:password => config[:password],
:oauth => config[:oauth],
:headers => { :content_type => 'application/json',
:accept => "application/json;version=#{API_VERSION}",
'HTTP_KATELLO_USER' => 'admin' }
}.merge(options))
@config = config
end
|
Instance Attribute Details
- (Object) client
Returns the value of attribute client
29
30
31
|
# File 'lib/katello_api/base.rb', line 29
def client
@client
end
|
- (Object) config
Returns the value of attribute config
29
30
31
|
# File 'lib/katello_api/base.rb', line 29
def config
@config
end
|
Class Method Details
+ (Object) doc
67
68
69
|
# File 'lib/katello_api/base.rb', line 67
def self.doc
raise NotImplementedError
end
|
+ (Object) method_doc(method)
75
76
77
|
# File 'lib/katello_api/base.rb', line 75
def self.method_doc(method)
method_docs[method.to_s]
end
|
+ (Object) validation_hash(method)
71
72
73
|
# File 'lib/katello_api/base.rb', line 71
def self.validation_hash(method)
validation_hashes[method.to_s]
end
|
Instance Method Details
- (Object) http_call(http_method, path, params = { }, headers = { })
53
54
55
56
57
58
59
60
61
62
63
64
65
|
# File 'lib/katello_api/base.rb', line 53
def http_call(http_method, path, params = { }, = { })
||= { }
args = [http_method]
if %w[post put].include?(http_method.to_s)
args << params.to_json
else
[:params] = params if params
end
args << if
process_data client[path].send(*args)
end
|
44
45
46
47
48
49
50
51
|
# File 'lib/katello_api/base.rb', line 44
def perform_call(method_name, params, )
method_doc = self.class.method_doc(method_name)
check_params params, :allowed => method_doc['params'].any?, :method => method_name
method_apis = method_doc['apis']
api = find_suitable_api_call(method_apis, params)
url, params = fill_params_in_url api['api_url'], params
return http_call(api['http_method'].downcase, url, params, )
end
|
- (Object) validate_params!(params, rules)
79
80
81
82
83
84
85
86
87
88
89
90
|
# File 'lib/katello_api/base.rb', line 79
def validate_params!(params, rules)
return unless params.is_a?(Hash)
invalid_keys = params.keys.map(&:to_s) - (rules.is_a?(Hash) ? rules.keys : rules)
raise ArgumentError, "Invalid keys: #{invalid_keys.join(", ")}" unless invalid_keys.empty?
if rules.is_a? Hash
rules.each do |key, sub_keys|
validate_params!(params[key], sub_keys) if params[key]
end
end
end
|