class Grenache::Link

Implement Grape connection helpers

Public Class Methods

new(config) click to toggle source

Initialize passing configuration

# File lib/grenache/link.rb, line 6
def initialize(config)
  @config = config
end

Public Instance Methods

send(type, payload, opts = {}, &block) click to toggle source

Send a message to grape

# File lib/grenache/link.rb, line 11
def send(type, payload, opts = {}, &block)
  res = http_send type, Oj.dump({"rid" => uuid, "data" => payload})
  block.call(res) if block
  res
end

Private Instance Methods

grape_url() click to toggle source
# File lib/grenache/link.rb, line 19
def grape_url
  @grape_url ||= @config.grape_address
end
http_send(type, payload) click to toggle source
# File lib/grenache/link.rb, line 23
def http_send(type, payload)
  url = grape_url + type
  options = {
    body: payload,
    timeout: Base.config.timeout
  }
  res = HTTParty.post(url, options).body
  Oj.load(res)
rescue => err
  if type != 'announce'
    raise err
  end
end
uuid() click to toggle source
# File lib/grenache/link.rb, line 37
def uuid
  SecureRandom.uuid
end