class Appbaseio::Client

Public Class Methods

new(options) click to toggle source
Calls superclass method
# File lib/appbaseio/client.rb, line 26
def initialize(options)
  super
end

Public Instance Methods

common_path() click to toggle source
# File lib/appbaseio/client.rb, line 30
def common_path
  "/#{app_name}/#{api_version}/#{namespace}"
end
method_missing(m, *args, &block) click to toggle source
Calls superclass method
# File lib/appbaseio/client.rb, line 50
def method_missing(m, *args, &block)
  operation, target = m.to_s.split('_')
  return super unless HTTP_METHOD_MAP.keys.include? operation
  return super unless TARGETS.include? target
  options = args[0] || {}
  vertex = options[:vertex] || nil
  data = {data: options[:data]}
  data = {all: true} if operation == 'read' and target == 'properties'
  data = {filters: {}} if operation == 'read' and target == 'edges'
  data = options[:data] if target == 'search'

  method = HTTP_METHOD_MAP[operation]
  if data
    resp = rest_client.send method, path(target, operation, vertex), data do |req|
      req.body = data.to_json if operation == 'delete'
    end
  else
    resp = rest_client.send method, path(target, operation, vertex) do |req|
    end
  end
  resp
end
path(target, operation, vertex) click to toggle source
# File lib/appbaseio/client.rb, line 46
def path(target, operation, vertex)
  [common_path, vertex, "~#{target}"].compact.join '/'
end
rest_client() click to toggle source
# File lib/appbaseio/client.rb, line 34
def rest_client
  Faraday.new(url: "https://"+server_host) do |faraday|
    #faraday.request :url_encoded
    #faraday.response :logger
    faraday.request :json
    faraday.response :json
    faraday.response :mashify
    faraday.request :api_header_auth, app_secret, auth_header: 'Appbase-Secret'
    faraday.adapter Faraday.default_adapter
  end
end