class SimpleFanout::Client

Attributes

channel[R]
id[R]
key[R]
token[R]

Public Class Methods

new(opts={}) click to toggle source
# File lib/simple_fanout/client.rb, line 5
def initialize(opts={})
  @key = opts[:key] || config["realm_key"]
  @id = opts[:id] || config["realm_id"]
  @channel = opts[:channel] || config["default_channel"]
end

Public Instance Methods

send(data) click to toggle source
# File lib/simple_fanout/client.rb, line 15
def send(data)
  RestClient.post(url, parse(data), 
    "Content-Type" => "application/json", 
    "Authorization" => "Bearer #{token}")
end

Private Instance Methods

claim() click to toggle source
# File lib/simple_fanout/client.rb, line 31
def claim
  @claim ||= {'iss' => id, 'exp' => Time.now.to_i + 3600}
end
config() click to toggle source
# File lib/simple_fanout/client.rb, line 27
def config
  @config ||= YAML.load_file('config/simple_fanout.yml')
end
decoded_key() click to toggle source
# File lib/simple_fanout/client.rb, line 35
def decoded_key
  Base64.decode64(key)
end
parse(data) click to toggle source
# File lib/simple_fanout/client.rb, line 39
def parse(data)
  "{ \"items\": [{ \"fpp\": #{data}}] }"
end
url() click to toggle source
# File lib/simple_fanout/client.rb, line 23
def url
  "https://api.fanout.io/realm/#{id}/publish/#{channel}/"
end