Class: CfRubyClient::Base
- Inherits:
-
Object
- Object
- CfRubyClient::Base
show all
- Defined in:
- lib/cf_ruby_client/base.rb
Instance Method Summary
collapse
Instance Method Details
#api_endpoint ⇒ Object
4
5
6
|
# File 'lib/cf_ruby_client/base.rb', line 4
def api_endpoint
cloud_foundry_config.api_endpoint
end
|
#authorization_string ⇒ Object
12
13
14
|
# File 'lib/cf_ruby_client/base.rb', line 12
def authorization_string
@authorization_string ||= Login.new.authorization_string
end
|
#cloud_foundry_config ⇒ Object
#delete_entity(url) ⇒ Object
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
# File 'lib/cf_ruby_client/base.rb', line 40
def delete_entity(url)
logger.info "cf_ruby_client: DELETEing: #{url.inspect}"
resource(url).delete(:Authorization => authorization_string) do |response, request, result, &block|
case response.code
when 204
true
when 404
logger.warn "cf_ruby_client: not found"
false
else
logger.error "cf_ruby_client: Received: #{response}"
response.return!(&block)
end
end
end
|
#fetch_entities(url) ⇒ Object
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/cf_ruby_client/base.rb', line 24
def fetch_entities(url)
logger.info "cf_ruby_client: GETting: #{url.inspect}"
resource(url).get(:Authorization => authorization_string) do |response, request, result, &block|
case response.code
when 200
response
when 404
logger.warn "cf_ruby_client: not found"
"{}"
else
logger.error "cf_ruby_client: Received: #{response}"
response.return!(&block)
end
end
end
|
#logger ⇒ Object
104
105
106
|
# File 'lib/cf_ruby_client/base.rb', line 104
def logger
::CfRubyClient.logger
end
|
#patch_entity(url, body = nil) ⇒ Object
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
# File 'lib/cf_ruby_client/base.rb', line 72
def patch_entity(url, body = nil)
logger.info "cf_ruby_client: PATCHing: #{url}, body: #{body.inspect}"
resource(url).patch(body.to_json, :Authorization => authorization_string) do |response, request, result, &block|
case response.code
when 200
true
when 404
logger.warn "cf_ruby_client: not found"
false
else
logger.error "cf_ruby_client: Received: #{response}"
response.return!(&block)
end
end
end
|
#post_entity(url, body = nil) ⇒ Object
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
# File 'lib/cf_ruby_client/base.rb', line 56
def post_entity(url, body = nil)
logger.info "cf_ruby_client: POSTing: #{url}, body: #{body.inspect}"
resource(url).post(body.to_json, :Authorization => authorization_string) do |response, request, result, &block|
case response.code
when 200
true
when 404
logger.warn "cf_ruby_client: not found"
false
else
logger.error "cf_ruby_client: Received: #{response}"
response.return!(&block)
end
end
end
|
#put_entity(url, body = nil) ⇒ Object
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
# File 'lib/cf_ruby_client/base.rb', line 88
def put_entity(url, body = nil)
logger.info "cf_ruby_client: PUTting: #{url}, body: #{body.inspect}"
resource(url).put(body.to_json, :Authorization => authorization_string) do |response, request, result, &block|
case response.code
when 201
true
when 404
logger.warn "cf_ruby_client: not found"
false
else
logger.error "cf_ruby_client: Received: #{response}"
response.return!(&block)
end
end
end
|
#resource(url) ⇒ Object
16
17
18
19
20
21
22
|
# File 'lib/cf_ruby_client/base.rb', line 16
def resource(url)
RestClient::Resource.new(
api_endpoint + url,
headers: ,
verify_ssl: cloud_foundry_config.skip_ssl_validation ? OpenSSL::SSL::VERIFY_NONE : OpenSSL::SSL::VERIFY_PEER
)
end
|
#uaa_endpoint ⇒ Object
8
9
10
|
# File 'lib/cf_ruby_client/base.rb', line 8
def uaa_endpoint
cloud_foundry_config.uaa_endpoint
end
|