class Object
Constants
- ENDPOINT
Public Instance Methods
call(args)
click to toggle source
API call method
# File lib/requests.rb, line 19 def call(args) method = args[0] path = args[1] params = args[2] # construct api endpoint uri = URI("#{ENDPOINT}/#{path}") http = Net::HTTP.new(uri.host, uri.port) # use ssl http.use_ssl = true http.verify_mode = OpenSSL::SSL::VERIFY_NONE # construct request req = Net::HTTP.const_get(method).new(uri.request_uri) req['api_key'] = Graphenedb.configuration.api_key req['Accept'] = 'text/html' req['Content-Type'] = 'application/json' req.body = params.to_json # parse response res = http.request(req) if res.code == '401' "Unauthorized. Have you configured your GrapheneDB api key?" else res.body ? JSON.parse(res.body) : 'no content' end end
delete(*args)
click to toggle source
# File lib/requests.rb, line 14 def delete(*args) call(args.insert(0, 'Delete')) end
get(*args)
click to toggle source
HTTP Request Methods
# File lib/requests.rb, line 2 def get(*args) call(args.insert(0, 'Get')) end
post(*args)
click to toggle source
# File lib/requests.rb, line 6 def post(*args) call(args.insert(0, 'Post')) end
put(*args)
click to toggle source
# File lib/requests.rb, line 10 def put(*args) call(args.insert(0, 'Put')) end