Class: CloudControl::API::Core
- Inherits:
-
Object
- Object
- CloudControl::API::Core
show all
- Defined in:
- lib/cloudcontrol/api/core.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(client) ⇒ Core
Returns a new instance of Core.
4
5
6
|
# File 'lib/cloudcontrol/api/core.rb', line 4
def initialize(client)
@client = client
end
|
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client.
3
4
5
|
# File 'lib/cloudcontrol/api/core.rb', line 3
def client
@client
end
|
Instance Method Details
#endpoint(e) ⇒ Object
22
23
24
|
# File 'lib/cloudcontrol/api/core.rb', line 22
def endpoint(e)
@endpoint = e
end
|
#get ⇒ Object
44
45
46
|
# File 'lib/cloudcontrol/api/core.rb', line 44
def get
perform :get
end
|
#get_simple ⇒ Object
52
53
54
|
# File 'lib/cloudcontrol/api/core.rb', line 52
def get_simple
perform :get, true
end
|
#log(*args) ⇒ Object
11
12
13
|
# File 'lib/cloudcontrol/api/core.rb', line 11
def log(*args)
@client.log(*args)
end
|
#org_endpoint(e) ⇒ Object
26
27
28
|
# File 'lib/cloudcontrol/api/core.rb', line 26
def org_endpoint(e)
endpoint("/#{org_id}" + e)
end
|
#org_id ⇒ Object
15
16
17
|
# File 'lib/cloudcontrol/api/core.rb', line 15
def org_id
@client.org_id
end
|
do not parse response if simple if simple, post body is also simple…
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
# File 'lib/cloudcontrol/api/core.rb', line 62
def perform(method, simple=false)
if simple
request = @client.build_request(method, @endpoint, request_query_string, request_simple_body, false)
else
request = @client.build_request(method, @endpoint, request_query_string, request_xml_body)
end
response = @client.perform_request(request)
@client.log_response(request, response)
if response.success?
if simple
result = response.body
else
result = @client.parse_response_xml_body(response.body)
if result['total_count']
log "#{result['total_count']} total", :yellow, :bold
result.delete('page_size')
result.delete('total_count')
result.delete('page_count')
result.delete('page_number')
end
result.values.count == 1 ? result.values.first : result
end
else
{}
end
end
|
#post ⇒ Object
48
49
50
|
# File 'lib/cloudcontrol/api/core.rb', line 48
def post
perform :post
end
|
#post_simple ⇒ Object
56
57
58
|
# File 'lib/cloudcontrol/api/core.rb', line 56
def post_simple
perform :post, true
end
|
#query_params(q) ⇒ Object
30
31
32
|
# File 'lib/cloudcontrol/api/core.rb', line 30
def query_params(q)
@query_params = q
end
|
#request_query_string ⇒ Object
104
105
106
107
108
109
|
# File 'lib/cloudcontrol/api/core.rb', line 104
def request_query_string
fparams = @client.filter_params || {}
qparams = @query_params || {}
params = fparams.merge(qparams)
@client.url_query(params) if params.present?
end
|
#request_simple_body ⇒ Object
120
121
122
123
124
125
|
# File 'lib/cloudcontrol/api/core.rb', line 120
def request_simple_body
return if @simple_params.blank?
body = @client.build_request_simple_body(@simple_params)
log(body, :green)
body
end
|
#request_xml_body ⇒ Object
111
112
113
114
115
116
117
118
119
|
# File 'lib/cloudcontrol/api/core.rb', line 111
def request_xml_body
return if @xml_params.blank?
schema = @xml_params.delete(:schema)
tag = @xml_params.delete(:tag)
body = @client.build_request_xml_body(schema, tag, @xml_params)
log(body, :green)
body
end
|
#simple_params(x) ⇒ Object
38
39
40
|
# File 'lib/cloudcontrol/api/core.rb', line 38
def simple_params(x)
@simple_params = x
end
|
#single(results) ⇒ Object
93
94
95
96
97
98
99
|
# File 'lib/cloudcontrol/api/core.rb', line 93
def single(results)
if results.is_a? Array
results.first
else
results
end
end
|
#xml_params(x) ⇒ Object
34
35
36
|
# File 'lib/cloudcontrol/api/core.rb', line 34
def xml_params(x)
@xml_params = x
end
|