Skip to content

Instantly share code, notes, and snippets.

@hasham2
hasham2 / devices_controller.rb
Created March 28, 2013 11:00
API sample for mobile app: Here the mobile app is sending a registration token to Rails app so that it can send it messages and push notifications and in events controller the mobile app is creating events on server so that it can be stored and analyzed
class DevicesController < ApplicationController
before_filter :authenticate_user!
def create
@device = current_user.app.devices.new(registration_id: params[:registration_id])
if params[:platform] && params[:platform].upcase == 'IOS'
@device.os = :ios
end
if @device.save
@hasham2
hasham2 / categories_controller.rb
Created March 28, 2013 11:00
Acts as API Example: I am using acts_as_api gem here to define this simple API this is part of overall much complex API, The Mongoid based model is part of tree structure for which we have used Mongoid-tree gem, This is why the model class inherits from Node class
class CategoriesController < ApplicationController
respond_to :html, :json
before_filter :find, :only => [:edit, :update, :destroy]
def index
parent = load_node_from_params
@nodes = parent.descendants.categories.sort
respond_with @nodes.to_a, :api_template => :basic
end
@hasham2
hasham2 / fog.rb
Last active September 16, 2018 14:17
Create s3 bucket and set CORS with Fog
# this goes into config/initializers/fog.rb
CONN = Fog::Storage.new({
:provider => 'AWS',
:aws_access_key_id => 'ACCESS_KEY',
:aws_secret_access_key => 'SECRET_KEY_HERE'
})
@hasham2
hasham2 / call_manager.rb
Created May 20, 2015 07:21
This is how call session is being initiated however the parameter has passed to method does not contain required values
# this is where call session is started from but the parameter hash does
# contain the required key / values
def startCallSession(data)
@current_call.callSessionId = data['sessionId']
updateCallStatus('call started')
callScreen = InCallScreen.new(nav_bar: false, modal: true)
callScreen.connectWith(data['sessionId'], andToken: data['token'])
callScreen.client_time_available = data['fromSecondsAvailable']
App.delegate.presentModal(callScreen)
end
// Object tracking annotations are returned as a objectAnnotations list.
{
"name": "projects/PROJECT_NUMBER/locations/LOCATION_ID/operations/OPERATION_ID",
"metadata": {
"@type": "type.googleapis.com/google.cloud.videointelligence.v1.AnnotateVideoProgress",
"annotationProgress": [
{
"inputUri": "/cloud-ml-sandbox/video/chicago.mp4",
"progressPercent": 100,
"startTime": "2019-12-21T16:56:46.755199Z",