Skip to content

Instantly share code, notes, and snippets.

View evanjmg's full-sized avatar
👨‍💻
actively contributing

Evan Gillogley evanjmg

👨‍💻
actively contributing
View GitHub Profile
class Api::V1::UberController < Api::V1::BaseController
skip_authorization_check
skip_before_filter :check_api_auth!, only: [:webhook]
def webhook
digest = OpenSSL::Digest.new('sha256')
hmac_key = OpenSSL::HMAC.hexdigest(digest, ENV['UBER_CLIENT_SECRET'],request.body.read)
{
"event_id": "3a3f3da4-14ac-4056-bbf2-d0b9cdcb0777",
"event_time": 1427343990,
"event_type": "all_trips.status_changed",
"meta": {
"user_id": "d13dff8b",
"resource_id": "2a2f3da4",
"resource_type": "request",
"status": "accepted"
},
class UberService
def run(params)
@current_identity = get_user(params[:meta][:user_id]) # first get the current user in the ride
@current_identity.refresh_token_if_expired('https://login.uber.com')
return 'not accepted status' if params[:meta][:status] != 'accepted'
@ride = current_ride(params[:meta][:status], @current_identity)
# add pusher to your GemFile
gem 'pusher'
# then in create a config/initializers/pusher.rb
require 'pusher'
Pusher.logger = Rails.logger
Pusher.encrypted = true
Pusher.app_id = ENV['PUSHER_APP_ID']
Pusher.key = ENV['PUSHER_KEY']
# in routes.rb add your endpoint
post 'pusher/auth', to: "pusher#auth"
# create a pusher_controller.rb in your api
class Api::V1::PusherController < Api::V1::BaseController
skip_authorization_check
skip_before_filter :check_api_auth!, only: [:auth]
class UberService
def run
#... all the other stuff we did before
send_pusher(data, build_pusher_notification(data))
end
def send_pusher(response, text)
channel = 'private-' + @current_identity.user.id.to_s
Pusher.trigger(channel, 'notification', {
<script src="bower_components/pusher-websocket-iso/dist/web/pusher.js"></script>
<script src="bower_components/pusher-angular/lib/pusher-angular.min.js"></script>
<script>
// in app.js
angular.module("YourApp",['pusher-angular'])
// in pusherService.js
(function () {
@evanjmg
evanjmg / gulp-browserify-sample.js
Last active January 21, 2021 19:31
Browserify Sample
// Paths is a nodejs global object with path url string we're using to specify our bundle
const gulp = require('gulp');
const browserify = require('browserify');
const gutil = require('gulp-util');
const source = require('vinyl-source-stream'); // Convert our stream to an output vinyl
const sourcemaps = require('gulp-sourcemaps'); // We need to include the sourcemaps for our files
const ngAnnotate = require('browserify-ngannotate'); // e.g Browserify plugin to make sure Angular dependencies will work on minification
const buffer = require('vinyl-buffer'); // This finishes what source stream started
/* BROWSERIFY SETTINGS */
var webpack = require('webpack');
var HtmlWebpackPlugin = require('html-webpack-plugin');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var helpers = require('./helpers');
module.exports = {
entry: { // in this case we have three entry points in order to import three separate files for our build
'polyfills': './src/polyfills.ts',
'vendor': './src/vendor.ts',
'app': './src/main.ts'
@evanjmg
evanjmg / .block
Last active February 19, 2017 16:43
Drag, Pan, Snap To Grid example
license: gpl-3.0