class YikYak

Constants

URL

Public Class Methods

new(user, app, secret) click to toggle source
# File lib/yikyak.rb, line 7
def initialize user, app, secret
  @user = user
  @app = app
  @secret = secret
end

Public Instance Methods

set_status(status) click to toggle source
# File lib/yikyak.rb, line 13
def set_status status
  endpoint = '/setstatus'
  payload = {
    UserToken: @user,
    ApplicationId: @app,
    Status: status,
    Latitude: 0,
    Longitude: 0,
    IgnoreLatLng: true,
    VelocityEsitmateMagnitude: 0,
    VelocityEsitmateTheta: 0,
    Checksum: ''
  }
 
  post endpoint, payload
end

Private Instance Methods

post(endpoint, payload) click to toggle source
# File lib/yikyak.rb, line 32
def post(endpoint, payload)
  options = {
    body: prepare(payload).to_json,
    headers: { 'Content-Type' => 'application/json' }
  }
  res = HTTParty.post(URL + endpoint, options)
  res.code/100 == 2 # Returns true if the request worked and false otherwise
end
prepare(payload) click to toggle source
# File lib/yikyak.rb, line 41
def prepare(payload)
  token = JWT.encode payload, Array(@secret).pack('H*'), 'HS512'
  payload[:Checksum] = token
  payload
end