class AppBase
Constants
- BODY_F_JSON
- BODY_F_NONE
- BODY_F_QUERY_STR
- BODY_F_RAW
- BODY_F_XML
- GET
map protocols
- PATCH
- POST
- PUT
Attributes
debug[RW]
Public Class Methods
new(debug=false)
click to toggle source
# File lib/lime_light_platform/app_base.rb, line 19 def initialize debug=false @debug = debug end
Public Instance Methods
gen_http(uri)
click to toggle source
# File lib/lime_light_platform/app_base.rb, line 82 def gen_http uri http = Net::HTTP.new uri.host, uri.port http.use_ssl = true http.verify_mode = OpenSSL::SSL::VERIFY_NONE http end
perform_api_call(call_params)
click to toggle source
# File lib/lime_light_platform/app_base.rb, line 23 def perform_api_call call_params valid = true response_body = '' uri = URI.parse call_params[:url] http = gen_http uri # determine http protocol case call_params[:proto] when POST api_request = Net::HTTP::Post.new uri.request_uri when PATCH api_request = Net::HTTP::Patch.new uri.request_uri when GET api_request = Net::HTTP::Get.new uri.request_uri when PUT api_request = Net::HTTP::Put.new uri.request_uri else valid = false end if valid # determine headers if any if !call_params[:headers].nil? call_params[:headers].each do |field| api_request.add_field field[:name], field[:value] end end # add request body case call_params[:format] when BODY_F_JSON api_request.body = call_params[:body].to_json when BODY_F_XML api_request.body = call_params[:body].to_xml(:root => call_params[:xml_root]) when BODY_F_QUERY_STR api_request.body = call_params[:body].to_query when BODY_F_RAW api_request.body = call_params[:body] when BODY_F_NONE api_request.body = '' end if @debug ap "API Request =>" ap api_request.body end api_response = http.request api_request response_body = api_response.body if @debug ap "API Response =>" ap response_body end end response_body end