lib/bubbles/config.rb in bubbles-rest-client-0.6.0 vs lib/bubbles/config.rb in bubbles-rest-client-0.7.0
- old
+ new
@@ -169,16 +169,39 @@
if endpoint.method == :get
if endpoint.authenticated?
Bubbles::RestEnvironment.class_exec do
if endpoint.has_uri_params?
- define_method(endpoint_name_as_sym) do |auth_token, uri_params|
- RestClientResources.execute_get_authenticated self, endpoint, auth_token, uri_params, endpoint.additional_headers, self.get_api_key_if_needed(endpoint), self.api_key_name
+ if endpoint.encode_authorization_header?
+ define_method(endpoint_name_as_sym) do |username, password, uri_params|
+ login_data = {
+ :login => username,
+ :password => password
+ }
+ auth_value = RestClientResources.get_encoded_authorization(endpoint, login_data)
+ RestClientResources.execute_get_authenticated self, endpoint, :basic, auth_value, uri_params, endpoint.additional_headers, self.get_api_key_if_needed(endpoint), self.api_key_name
+ end
+ else
+ define_method(endpoint_name_as_sym) do |auth_token, uri_params|
+ RestClientResources.execute_get_authenticated self, endpoint, :bearer, auth_token, uri_params, endpoint.additional_headers, self.get_api_key_if_needed(endpoint), self.api_key_name
+ end
end
else
- define_method(endpoint_name_as_sym) do |auth_token|
- RestClientResources.execute_get_authenticated self, endpoint, auth_token, {}, endpoint.additional_headers, self.get_api_key_if_needed(endpoint), self.api_key_name
+ if endpoint.encode_authorization_header?
+ define_method(endpoint_name_as_sym) do |username, password|
+ login_data = {
+ :username => username,
+ :password => password
+ }
+ auth_value = RestClientResources.get_encoded_authorization(endpoint, login_data)
+
+ RestClientResources.execute_get_authenticated self, endpoint, :basic, auth_value, {}, endpoint.additional_headers, self.get_api_key_if_needed(endpoint), self.api_key_name
+ end
+ else
+ define_method(endpoint_name_as_sym) do |auth_token|
+ RestClientResources.execute_get_authenticated self, endpoint, :bearer, auth_token, {}, endpoint.additional_headers, self.get_api_key_if_needed(endpoint), self.api_key_name
+ end
end
end
end
else
Bubbles::RestEnvironment.class_exec do
@@ -192,26 +215,34 @@
end
end
end
end
elsif endpoint.method == :post
- if endpoint.authenticated?
+ if endpoint.authenticated? and !endpoint.encode_authorization_header?
Bubbles::RestEnvironment.class_exec do
define_method(endpoint_name_as_sym) do |auth_token, data|
- RestClientResources.execute_post_authenticated self, endpoint, auth_token, data, endpoint.additional_headers, self.get_api_key_if_needed(endpoint), self.api_key_name
+ RestClientResources.execute_post_authenticated self, endpoint, :bearer, auth_token, data, endpoint.additional_headers, self.get_api_key_if_needed(endpoint), self.api_key_name
end
end
+ elsif endpoint.encode_authorization_header?
+ Bubbles::RestEnvironment.class_exec do
+ define_method(endpoint_name_as_sym) do |username, password, data = {}|
+ login_data = {
+ :username => username,
+ :password => password
+ }
+
+ auth_value = RestClientResources.get_encoded_authorization(endpoint, login_data)
+ # composite_headers = RestClientResources.build_composite_headers(endpoint.additional_headers, {
+ # Authorization: 'Basic ' + Base64.strict_encode64(auth_value)
+ # })
+ RestClientResources.execute_post_authenticated self, endpoint, :basic, auth_value, data, endpoint.additional_headers, self.get_api_key_if_needed(endpoint), self.api_key_name
+ end
+ end
else
Bubbles::RestEnvironment.class_exec do
define_method(endpoint_name_as_sym) do |data|
composite_headers = endpoint.additional_headers
- if endpoint.encode_authorization_header?
- auth_value = RestClientResources.get_encoded_authorization(endpoint, data)
- composite_headers = RestClientResources.build_composite_headers(endpoint.additional_headers, {
- Authorization: 'Basic ' + Base64.strict_encode64(auth_value)
- })
- end
-
RestClientResources.execute_post_unauthenticated self, endpoint, data, composite_headers, self.get_api_key_if_needed(endpoint), self.api_key_name
end
end
end
elsif endpoint.method == :delete