Skip to content

Instantly share code, notes, and snippets.

@petedickson
Created March 9, 2011 15:21
Show Gist options
  • Save petedickson/862376 to your computer and use it in GitHub Desktop.
Save petedickson/862376 to your computer and use it in GitHub Desktop.
Authenticate users via Infusionsoft
class SessionsController < ApplicationController
include ApiInfusionsoft
def new
end
def numeric?(object)
true if Float(object) rescue false
end
def create
user = api_data_authenticate_user(params[:session][:username],
params[:session][:password])
if numeric?(user)
# Log the user in
flash.now[:message] = "User logged in successfully"
redirect_to "http://localhost:3000"
else
flash.now[:error] = "Please try again. The username/password combination is not correct."
# @title = "Sign in"
render 'new'
end
end
end
require 'spec_helper'
describe SessionsController do
render_views
describe "GET 'new'" do
it "should be successful" do
get :new
response.should be_success
end
end
describe "POST 'create'" do
describe "invalid login" do
before(:each) do
@attr = { :username => "petedickson", :password => "invalid" }
end
it "should re-render the 'new' page" do
post :create, :session => @attr
response.should render_template('new')
end
it "should have a flash.now message" do
post :create, :session => @attr
flash.now[:error].should =~ /please/i
end
end
end
end
@petedickson
Copy link
Author

NoMethodError in SessionsController#create

undefined method `api_perform' for nil:NilClass

@nateleavitt
Copy link

Can you post our initializer code too. Should work.

@petedickson
Copy link
Author

api_infusionsoft.rb (in initializers)...

ApiInfusionsoft.set_account_apiconn("nimacus.infusionsoft.com", "MY_API_KEY")

@nateleavitt
Copy link

what the heck.. try this. Create a test controller. Include the ApiInfusionsoft, and then in the index action add this:

user = api_data_query(:Contact, 1, 0, { :Id => 454 }, ["Id", "FirstName", "LastName"])
logger.info "****here is the user: #{user.inspect}"

obviously, change the Id to an Id you know exists.

Browse to it and check your logs to see if it worked.

@devdiva
Copy link

devdiva commented Jun 17, 2011

have you guys had any luck resolving this issue? i've also encountered it.

@nateleavitt
Copy link

Hey.. send me a message with a gist of your code, and I'll have a look. Should be working fine.

@devdiva
Copy link

devdiva commented Jun 22, 2011 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment