Uninitialized Constant

I am sure that there is going to be info I leave out that you will need,
so bear with me please. I have extremely little knowledge of ruby so I
am sure this will be something simple (at least I hope). I am running
ruby 1.8.6 on a FreeBSD 7.0 server. I am not the one who created the
script so I am not sure where to start. When I run the script convert.rb
I get:

/usr/home/admin/rails/nusers/config/../vendor/rails/activesupport/lib/active_support/dependencies.rb:205:in
`const_missing': uninitialized constant ProvisioningAPI (NameError)
  from convert.rb:33

I have read what I need to do but I still cannot figure it out. Thank
you in advanced for any help you can throw my way. I know there is
probably a hundred other forum topics like this one, but like I said I
have no idea what I am doing. Let me know if any further info is needed.
I can post the scripts if need be.

···

--
Posted via http://www.ruby-forum.com/.

Josh Stevenson wrote:

I am sure that there is going to be info I leave out that you will need,
so bear with me please. I have extremely little knowledge of ruby so I
am sure this will be something simple (at least I hope). I am running
ruby 1.8.6 on a FreeBSD 7.0 server. I am not the one who created the
script so I am not sure where to start. When I run the script convert.rb
I get:

/usr/home/admin/rails/nusers/config/../vendor/rails/activesupport/lib/active_support/dependencies.rb:205:in
`const_missing': uninitialized constant ProvisioningAPI (NameError)
  from convert.rb:33

I have read what I need to do but I still cannot figure it out. Thank
you in advanced for any help you can throw my way. I know there is
probably a hundred other forum topics like this one, but like I said I
have no idea what I am doing. Let me know if any further info is needed.
I can post the scripts if need be.

Looks like you're in a Rails application. Where does convert.rb live?
What's your working directory when you're trying to run it?

Are you familiar with Rails? If not, then check out the guides at
http://guide.rails.info , and post further questions to the Rails list
if they're applicable more to the Rails framework than to the Ruby
language.

Best,

···

--
Marnen Laibow-Koser
http://www.marnen.org
marnen@marnen.org
--
Posted via http://www.ruby-forum.com/\.

Looks like you're in a Rails application. Where does convert.rb live?
What's your working directory when you're trying to run it?

Are you familiar with Rails? If not, then check out the guides at
http://guide.rails.info , and post further questions to the Rails list
if they're applicable more to the Rails framework than to the Ruby
language.

Best,
--
Marnen Laibow-Koser
http://www.marnen.org
marnen@marnen.org

These are the scripts that a rails application calls on, yes. However, I
am running the scripts as they are on the server and not by using rails
if that makes sense. I would run it like so:
echo admin | ruby convert.rb
The convert.rb script lives in: /usr/home/admin/email_conversion/
The working directory is:
/usr/home/admin/rails/nuser/lib/gappsprovisioning
Further info:
We use gmail and these scripts convert users from our database to gmail
using the Google API.

If I am wrong and need to repost in rails section let me know and I
will. I have been wrong once before :slight_smile:

···

--
Posted via http://www.ruby-forum.com/\.

Josh Stevenson wrote:

Looks like you're in a Rails application. Where does convert.rb live?
What's your working directory when you're trying to run it?

Are you familiar with Rails? If not, then check out the guides at
http://guide.rails.info , and post further questions to the Rails list
if they're applicable more to the Rails framework than to the Ruby
language.

Best,
--
Marnen Laibow-Koser
http://www.marnen.org
marnen@marnen.org

These are the scripts that a rails application calls on, yes. However, I
am running the scripts as they are on the server and not by using rails
if that makes sense. I would run it like so:
echo admin | ruby convert.rb
The convert.rb script lives in: /usr/home/admin/email_conversion/
The working directory is:
/usr/home/admin/rails/nuser/lib/gappsprovisioning
Further info:
We use gmail and these scripts convert users from our database to gmail
using the Google API.

OK, so these scripts are not part of the Rails app, and the rails
directory I was seeing came from your working directory. So...the error
was reported at convert.rb:33. What's on that line? It probably says
something about ProvisioningAPI, and that is not getting declared.

If I am wrong and need to repost in rails section let me know and I
will. I have been wrong once before :slight_smile:

No, it looks like this isn't a Rails issue after all...but we'll see
when you post the code!

Best,

···

--
Marnen Laibow-Koser
http://www.marnen.org
marnen@marnen.org
--
Posted via http://www.ruby-forum.com/\.

OK, so these scripts are not part of the Rails app, and the rails
directory I was seeing came from your working directory. So...the error
was reported at convert.rb:33. What's on that line? It probably says
something about ProvisioningAPI, and that is not getting declared.

If I am wrong and need to repost in rails section let me know and I
will. I have been wrong once before :slight_smile:

No, it looks like this isn't a Rails issue after all...but we'll see
when you post the code!

Best,
--
Marnen Laibow-Koser
http://www.marnen.org
marnen@marnen.org

On that line is this:
proivisioner = GAppsProvisioning::ProvisioningAPI.new(p_domain,
p_username, p_password)

···

--
Posted via http://www.ruby-forum.com/\.

Josh Stevenson wrote:
[...]

On that line is this:
proivisioner = GAppsProvisioning::ProvisioningAPI.new(p_domain,
p_username, p_password)

And are those classes defined anywhere?

Best,

···

--
Marnen Laibow-Koser
http://www.marnen.org
marnen@marnen.org
--
Posted via http://www.ruby-forum.com/\.

Marnen Laibow-Koser wrote:

Josh Stevenson wrote:
[...]

On that line is this:
proivisioner = GAppsProvisioning::ProvisioningAPI.new(p_domain,
p_username, p_password)

And are those classes defined anywhere?

Best,
--
Marnen Laibow-Koser
http://www.marnen.org
marnen@marnen.org

Yes.
Here is the entire script.
ENV['RAILS_ENV'] = 'production'
require '/usr/home/admin/rails/nusers/config/environment'
require 'gappsprovisioning/provisioningapi'
include GAppsProvisioning

dual = ARGV.first == '--dual'

# don't waste time with syncing password changes
CONFIG["auth_plugins"]["enable"] = 'f'

# dup'd from auth_plugins.rb
p_domain = CONFIG['auth_plugins']['google']['domain']
p_username = CONFIG['auth_plugins']['google']['username']
p_password = CONFIG['auth_plugins']['google']['password']

proivisioner = GAppsProvisioning::ProvisioningAPI.new(p_domain,
p_username, p_password)

while username = $stdin.gets
  username.chomp!
  user = User.find_by_uname(username)

  unless user
    $stderr.puts "#{username} not found"
    next
  end

  # if their password doesn't meet requirements, gen a temp one
  # and use that to create the google account if necessary.
  # once the google account is created, the user can change their
  # password with the new reqs and their google account will update
  if user.pass.blank? || user.pass.length < 6
    $stderr.puts "#{username} needs to change their password"
    google_pass = Password.phonemic(8,Password::ONE_DIGIT)
  else
    # otherwise just use their normal password
    google_pass = user.pass
  end

  # where to send mail so it lands in the user's google account
  google_destination = "#{user.uname}@extmail.yumaed.org"

  # where to send mail so it lands in both the user's google account
  # and their IMAP account
  dual_destination = [google_destination, user.mail].join(',')

  # if user is already set up to have their mail sent to google,
  # skip them. this lets us run this script multiple times with
  # the same usernames.
  next if user.mail_destination == google_destination

  # create an account if necessary
  begin
    unless proivisioner.retrieve_user(user.uname)
      proivisioner.create_user(user.fname, user.lname, google_pass,
user.uname)
    end
  rescue => e
    $stderr.puts "#{username} trouble creating google account: #{e}"
    next
  end

  # unless the --dual argument was given, send the user's mail
  # just to google. otherwise, do dual delivery.
  unless dual
    destination = google_destination
  else
    destination = dual_destination
  end

  # set their destination to what we decided on
  user.mail_destination = destination

  if user.save
    puts "#{username} updated (#{user.mail_destination})"
  else
    $stderr.puts "#{username} problem saving:
#{user.errors.full_messages.join(' / ')}"
  end
end

···

--
Posted via http://www.ruby-forum.com/\.

Josh Stevenson wrote:

Here is the entire script.
ENV['RAILS_ENV'] = 'production'
require '/usr/home/admin/rails/nusers/config/environment'

Aside: another way to bootstrap the rails environment is

  script/runner -e production myscript.rb

(then your script doesn't need to contain any explicit code for this)

require 'gappsprovisioning/provisioningapi'
include GAppsProvisioning

...

proivisioner = GAppsProvisioning::ProvisioningAPI.new(p_domain,
p_username, p_password)

You need to look at the code in the file
gappsprovisioning/provisioningapi.rb, as it doesn't appear to define
that class. Maybe it's just a simple typo or a case issue, e.g. it
should be ProvisioningApi

Another aside: because of the "include GAppsProvisioning" line above,
you could just say

  proivisioner = ProvisioningAPI.new(...)

Alternatively, you could drop the "include" line if you're always fully
qualifying the module name like this.

···

--
Posted via http://www.ruby-forum.com/\.

Brian Candler wrote:

Josh Stevenson wrote:

Here is the entire script.
ENV['RAILS_ENV'] = 'production'
require '/usr/home/admin/rails/nusers/config/environment'

Aside: another way to bootstrap the rails environment is

  script/runner -e production myscript.rb

(then your script doesn't need to contain any explicit code for this)

require 'gappsprovisioning/provisioningapi'
include GAppsProvisioning

...

proivisioner = GAppsProvisioning::ProvisioningAPI.new(p_domain,
p_username, p_password)

You need to look at the code in the file
gappsprovisioning/provisioningapi.rb, as it doesn't appear to define
that class. Maybe it's just a simple typo or a case issue, e.g. it
should be ProvisioningApi

Another aside: because of the "include GAppsProvisioning" line above,
you could just say

  proivisioner = ProvisioningAPI.new(...)

Alternatively, you could drop the "include" line if you're always fully
qualifying the module name like this.

Brian,
You were exactly right, it was a typo of sorts. Instead of it being
ProvisioningAPI it was ProvisioningApi. I cannot believe I over looked
that. Funny thing is, is I thought that myself and looked at it probably
a good 20 times and never even realized that the p and i were not
capitalized. I did remove the include from the top. Thank you all for
your help. Changing that did reveal other errors I was able to fix. Nice
to know there is help out there. I am reading O'Reilly's "The Ruby
Programming Language" book so hopefully one day I will be here to help
someone else out. Thanks again Brian and Marnen.

···

--
Posted via http://www.ruby-forum.com/\.