Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
A ruby based REST Client for SugarCRM
Ruby

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib
test
.document
.gitignore
LICENSE
README.rdoc
Rakefile
VERSION

README.rdoc

SugarCRM

REST Bindings for SugarCRM!

SUMMARY:

RubyGem for interacting with SugarCRM via REST.

Description:

A less clunky way to interact with SugarCRM via REST.

I've built an abstraction layer on top of the SugarCRM REST API, instead of get_entry(“Users”, “1”) you can call SugarCRM::User.find(1). There is also support for collections à la SugarCRM::User.find(1).email_addresses. ActiveRecord style finders are in place, with limited support for conditions and joins e.g. SugarCRM::Contacts.find_by_title(“VP of Sales”) will work, but SugarCRM::Contacts.find_by_title(“VP of Sales”, {:conditions => {:deleted => 0}}) will not.

FEATURES/PROBLEMS:

  • Supports all v2 API calls

  • Supports saving of Module specific objects.

  • Auto-generation of Module specific objects. When a connection is established, get_available_modules is called and the resultant modules are turned into SugarCRM::Module classes.

  • If you just want to use the vanilla API, you can access the methods directly on the SugarCRM.connection object.

SYNOPSIS:

require 'sugarcrm'

# Establish a connection
SugarCRM.connect("http://localhost/sugarcrm", 'user', 'password')

# Enable debugging on the current connection
SugarCRM.connection.debug = true

# Get the logged in user
SugarCRM.current_user

# Show a list of available modules
SugarCRM.modules

# Retrieve a User by user_name
SugarCRM::User.find_by_user_name("admin")

# Update a User's title
u = SugarCRM::User.find_by_first_name_and_last_name("Will", "Westin")
u.title = "Sales Manager Central"
u.save

# Check if an object is valid (i.e. if it has the required fields to save)
u.valid?

# Access the errors collection
u.errors

# Delete an Account
a = SugarCRM::Account.find_by_name("JAB Funds Ltd.")
a.delete

# Retrieve all Email Addresses assigned to a particular user.
SugarCRM::User.find_by_user_name('sarah').email_addresses

# Retrieve all email addresses on an Account
SugarCRM::Account.find_by_name("JAB Funds Ltd.").contacts.each do |contact|
  contact.email_addresses.each do |email|
    puts "#{email.email_address}" unless email.opt_out == "1"
  end
end

# Look up the fields for a given module
SugarCRM::Module.find("Accounts").fields

# Look up the relationships for a given module
SugarCRM::Module.find("Accounts").link_fields

# Use the HTTP Connection and SugarCRM API to load the Admin user
SugarCRM.connection.get_entry("Users", 1)

# Retrieve the first 10 Accounts with a zip code between 10000 and 10500
SugarCRM::Account.all({
  :conditions => { :billing_address_postalcode => ["> '10000'", "<= '10500'" ] },
  :limit => '10',
  :order_by => 'billing_address_postalcode'
})

# Retrieve all Accounts by user name (direct API method)
SugarCRM.connection.get_entry_list(
  "Users",
  "users.user_name = \'sarah\'",
  {
    :link_fields => [
      {
        "name"  => "accounts",
        "value" => ["id", "name"]
      }
    ]          
  } 
)

REQUIREMENTS:

  • >= activesupport 3.0.0 gem

  • json gem

INSTALL:

  • sudo gem install sugarcrm

Note on Patches/Pull Requests

  • Fork the project.

  • Make your feature addition or bug fix.

  • Add tests for it. This is important so I don't break it in a future version unintentionally.

  • Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)

  • Send me a pull request. Bonus points for topic branches.

Copyright

Copyright © 2010 Carl Hicks. See LICENSE for details.

Something went wrong with that request. Please try again.