This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'pony' | |
require "openssl" | |
require "net/smtp" | |
Net::SMTP.class_eval do | |
private | |
def do_start(helodomain, user, secret, authtype) | |
raise IOError, 'SMTP session already started' if @started | |
if RUBY_VERSION > "1.8.6" | |
check_auth_args user, secret # for rails 1.8.7 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#perl script to automate git push | |
`git add . >/dev/null`; | |
print "add\n"; | |
print "Commit Message:"; | |
$cmsg = <>; | |
`git commit -m '$cmsg' >/dev/null`; | |
print "\npushing to github...\n"; | |
print "#################################\n"; | |
`git push > /dev/null`; | |
print "#################################\n"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Copy and paste this to the rails console to test your email settings | |
class MyMailer < ActionMailer::Base | |
def msg | |
mail( | |
# Option 2 | |
:from => "[email protected]", | |
:to => "[email protected]", | |
:subject => "hey dude" | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Set zone to the users time zone | |
Time.zone = user.time_zone | |
# convert time to UTC | |
user_time_to_utc = Time.zone.parse('2012-10-22 09:25:00').utc | |
puts "Scheduling for #{user.login} at #{user_time_to_utc}" | |
# Schedule the sidekiq job | |
SendPromoEmail.perform_at(user_time_to_utc,user.id) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This is how we grant access to the API. | |
# User logs in via the API. Access_token is granted and returned to them. | |
# On subsequent logins they use the access_token rather than their credentials. | |
class ApiKey < ActiveRecord::Base | |
attr_accessible :access_token, :expires_at, :user_id, :active, :application | |
before_create :generate_access_token | |
before_create :set_expiration | |
belongs_to :user |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CreateApiKeys < ActiveRecord::Migration | |
def change | |
create_table :api_keys do |t| | |
t.string :access_token, null: false | |
t.integer :user_id, null: false | |
t.boolean :active, null: false, default: true | |
t.datetime :expires_at | |
t.timestamps | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
helpers do | |
def authenticate! | |
error!('Unauthorized. Invalid or expired token.', 401) unless current_user | |
end | |
def current_user | |
# find token. Check if valid. | |
user_token = params[:token] | |
token = ApiKey.where(:access_token => user_token).first | |
if token && !token.expired? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# /api/auth | |
resource :auth do | |
desc "Creates and returns access_token if valid login" | |
params do | |
requires :login, :type => String, :desc => "Username or email address" | |
requires :password, :type => String, :desc => "Password" | |
end | |
post :login do |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module API | |
class Root < Grape::API | |
prefix "api" | |
version 'v1', :using => :header, :vendor => 'vendor' | |
format :json | |
error_format :json | |
# load the rest of the API | |
mount API::Auth | |
mount API::Tasks |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module API | |
class Auth < Grape::API | |
# /api/auth | |
resource :auth do | |
# | |
# auth code goes here! | |
# | |
desc "Returns pong if logged in correctly." |
OlderNewer