class SocialSnippet::Registry::RegistryResources::Base
Attributes
core[R]
default_headers[R]
end_point[R]
rest_client[R]
Public Class Methods
new(new_core)
click to toggle source
# File lib/social_snippet/registry/registry_resources/base.rb, line 11 def initialize(new_core) @core = new_core @end_point = core.config.sspm_url @rest_client = ::RestClient::Resource.new(end_point) @cookies = {} @default_headers = { :accept => :json, } core.logger.debug "registry: end-point = #{end_point}" end
Public Instance Methods
get(req_path, headers = {})
click to toggle source
# File lib/social_snippet/registry/registry_resources/base.rb, line 41 def get(req_path, headers = {}) core.logger.debug "registry: get #{req_path}" headers.merge! default_headers core.logger.debug "registry: headers:" core.logger.debug headers parse_response rest_client[req_path].get(headers) end
post(req_path, params, headers = {})
click to toggle source
# File lib/social_snippet/registry/registry_resources/base.rb, line 23 def post(req_path, params, headers = {}) core.logger.debug "registry: post: #{req_path}" core.logger.debug params csrf_token = fetch_csrf_token # set headers headers.merge! default_headers headers["Content-Type"] = "application/json" headers["X-CSRF-Token"] = csrf_token # debug output core.logger.debug "registry: post: csrf_token = #{csrf_token}" core.logger.debug "registry: post: headers:" core.logger.debug headers parse_response rest_client[req_path].post(params.to_json, headers) end
Private Instance Methods
fetch_csrf_token()
click to toggle source
# File lib/social_snippet/registry/registry_resources/base.rb, line 51 def fetch_csrf_token unless @csrf_token @csrf_token = get("token") default_headers.merge! :cookies => cookies end @csrf_token end
parse_response(res)
click to toggle source
# File lib/social_snippet/registry/registry_resources/base.rb, line 59 def parse_response(res) cookies.merge! res.cookies s = res.to_s begin ::JSON.parse s rescue ::JSON::ParserError s end end