Permalink
Browse files

Initial commit

  • Loading branch information...
0 parents commit 99d64c2b26101168e593c05237880663a48537fa Brandon Tilley committed Feb 22, 2011
@@ -0,0 +1,5 @@
+*.gem
+.bundle
+Gemfile.lock
+pkg/*
+.rvmrc
@@ -0,0 +1,4 @@
+source "http://rubygems.org"
+
+# Specify your gem's dependencies in rforce-wrapper.gemspec
+gemspec
@@ -0,0 +1,72 @@
+rforce-wrapper
+==============
+
+RForce-wrapper creates a wrapper around RForce to make it easier to use.
+
+[RForce](https://github.com/undees/rforce) is a great binding to the
+Salesforce Web Services API. RForce transparently turns method calls into
+SOAP method calls against the Salesforce API. RForce-wrapper creates objects
+and methods that wrap RForce, providing a more concrete API against
+Salesforce's own SOAP API, and provides error checking and basic result
+parsing.
+
+RForce-wrapper tries to match the Salesforce Web Services API as closely
+as possible, matching method names and arguments. Anywhere the Salesforce API
+allows an array for an argument, RForce-wrapper allows either an array or
+multiple arguments.
+
+Examples
+--------
+
+ require 'rforce-wrapper'
+
+ # Connect to our sandbox.
+ sf = RForce::Wrapper::Connection.new('email', 'password' + 'token', :test)
+
+ # Describe the sObject "Account" and get a list of fields.
+ account_description = sf.describeSObjects('Account').first
+ # Filter out any fields that are marked as deprecated and hidden.
+ fields = account_description[:fields].map do |field|
+ next if field[:deprecatedAndHidden] == "true"
+ field[:name]
+ end
+
+ # Fetch some accounts.
+ accounts = sf.retrieve fields.join(', '), 'Account', '001S000000MBfXAIA1', '001S000000QJAeZIAX'
+
+ accounts.each do |account|
+ puts account[:IsPersonAccount] == "true" ? " Person Account" : " Business Account"
+ puts " ID: #{account[:Id]}"
+ puts " View: #{account_description[:urlDetail].sub "{ID}", account[:Id]}"
+ puts
+
+ if account[:IsPersonAccount] == "true"
+ puts " First Name: #{account[:FirstName]}"
+ puts " First Name: #{account[:LastName]}"
+ puts " Phone: #{account[:PersonHomePhone]}"
+ puts " Email: #{account[:PersonEmail]}"
+ else
+ puts " ID: #{account[:Id]}"
+ puts " Name: #{account[:Name]}"
+ puts " Phone: #{account[:Phone]}"
+ end
+ puts
+ end
+
+Output:
+
+ - Person Account
+ ID: 001S000000MBfXAIA1
+ View: https://cs1.salesforce.com/001S000000MBfXAIA1
+
+ First Name: Sample
+ First Name: Person
+ Phone: (555) 555-1234
+ Email: sample.person@company.com
+
+ - Business Account
+ ID: 001S000000QJAeZIAX
+ View: https://cs1.salesforce.com/001S000000QJAeZIAX
+
+ Name: Sample Company
+ Phone: (555) 555-4321
@@ -0,0 +1,2 @@
+require 'bundler'
+Bundler::GemHelper.install_tasks
@@ -0,0 +1 @@
+require 'rforce-wrapper/connection'
@@ -0,0 +1,75 @@
+require 'rforce'
+require 'rforce-wrapper/salesforce_fault_exception'
+require 'rforce-wrapper/methods/core'
+require 'rforce-wrapper/methods/describe'
+require 'rforce-wrapper/methods/utility'
+
+module RForce
+ module Wrapper
+ class Connection
+ include RForce::Wrapper::CoreMethods
+ include RForce::Wrapper::DescribeMethods
+ include RForce::Wrapper::UtilityMethods
+
+ attr_reader :binding
+
+ # Create a connection to the database with the given email and password/token combo.
+ # Optional parameter type can be used to specify live or test accounts (defaults to live).
+ def initialize(email, pass, type = :live)
+ @binding = RForce::Binding.new url_for_environment(type)
+ @binding.login email, pass
+ end
+
+ # def sObject(type ,id = nil)
+ # sobject = SObject.new(type, id, self)
+ # end
+
+ protected
+
+ # Make the SOAP API call identified by method
+ # using the given params.
+ def make_api_call(method, params = nil)
+ if params
+ result = @binding.send method, params
+ else
+ result = @binding.send method
+ end
+
+ # Errors will result in result[:Fault] being set
+ if result[:Fault]
+ raise RForce::Wrapper::SalesforceFaultException.new result[:Fault][:faultcode], result[:Fault][:faultstring]
+ end
+
+ # If the result was successful, there will be a key: "#{method.to_s}Response".to_sym
+ # which will contain the key :result
+ result_field_name = method.to_s + "Response"
+ if result[result_field_name.to_sym]
+ return ensure_array result[result_field_name.to_sym][:result]
+ else
+ return nil
+ end
+ end
+
+ # Returns the URL for the given environment type.
+ # Valid types are :test and :live.
+ def url_for_environment(type)
+ case type
+ when :test
+ 'https://test.salesforce.com/services/Soap/u/21.0'
+ when :live
+ 'https://www.salesforce.com/services/Soap/u/21.0'
+ end
+ end
+
+ # Ensures that the parameter is wrapped in an array.
+ # Parameter is returned as-is if it is already an array.
+ def ensure_array(thing)
+ if thing.is_a? Array
+ thing
+ else
+ [thing]
+ end
+ end
+ end
+ end
+end
@@ -0,0 +1,66 @@
+module RForce
+ module Wrapper
+ module CoreMethods
+
+ def convertLead(*leadConverts)
+ end
+
+ def create(*sObjects)
+ end
+
+ def delete(*ids)
+ end
+
+ def emptyRecycleBin(*ids)
+ end
+
+ def getDeleted(sObjectType, startDate, endDate)
+ end
+
+ def getUpdated(sObjectType, startDate, endDate)
+ end
+
+ def invalidateSessions(*sessionIds)
+ end
+
+ def logout
+ make_api_call :logout
+ end
+
+ def merge(*mergeRequests)
+ end
+
+ def process(*processRequests)
+ end
+
+ def query(queryString)
+ end
+
+ def queryAll(queryString)
+ end
+
+ def queryMore(queryLocator)
+ end
+
+ # http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_calls_retrieve.htm
+ def retrieve(fieldList, sObjectType, *ids)
+ params = [ :fieldList, fieldList, :sObjectType, sObjectType ]
+ params += ids.flatten.map { |id| [:Id, id] }.flatten
+ make_api_call :retrieve, params
+ end
+
+ def search(searchString)
+ end
+
+ def undelete(*ids)
+ end
+
+ def update(*sObjects)
+ end
+
+ def upsert(externalIdFieldName, *sObjects)
+ end
+
+ end
+ end
+end
@@ -0,0 +1,34 @@
+module RForce
+ module Wrapper
+ module DescribeMethods
+
+ def describeDataCategoryGroups(*sObjectTypes)
+ end
+
+ def describeDataCategoryGroupStructures(*dataCategoryGroupSObjectTypePairs, topCategoriesOnly)
+ end
+
+ def describeGlobal
+ end
+
+ def describeLayout(sObjectType, *recordTypeIds)
+ end
+
+ def describeSObject(sObjectType)
+ describeSObjects(sObjectType)
+ end
+
+ def describeSObjects(*sObjectTypes)
+ params = sObjectTypes.flatten.map { |type| [:sObjectType, type] }.flatten
+ make_api_call :describeSObjects, params
+ end
+
+ def describeSoftphoneLayout
+ end
+
+ def describeTabs
+ end
+
+ end
+ end
+end
@@ -0,0 +1,22 @@
+module RForce
+ module Wrapper
+ module UtilityMethods
+
+ def getServerTimestamp
+ end
+
+ def getUserInfo
+ end
+
+ def resetPassword(userId)
+ end
+
+ def sendEmail(*emails)
+ end
+
+ def setPassword(userId, password)
+ end
+
+ end
+ end
+end
@@ -0,0 +1,16 @@
+module RForce
+ module Wrapper
+
+ class SalesforceFaultException < Exception
+ def initialize(code, string)
+ @code = code
+ @string = string
+ end
+
+ def to_s
+ "#{@code}: #{@string}"
+ end
+ end
+
+ end
+end
@@ -0,0 +1,5 @@
+module RForce
+ module Wrapper
+ VERSION = "0.0.1"
+ end
+end
@@ -0,0 +1,25 @@
+# -*- encoding: utf-8 -*-
+$:.push File.expand_path("../lib", __FILE__)
+require "rforce-wrapper/version"
+
+Gem::Specification.new do |s|
+ s.name = "rforce-wrapper"
+ s.version = RForce::Wrapper::VERSION
+ s.platform = Gem::Platform::RUBY
+ s.authors = ["Brandon Tilley"]
+ s.email = ["brandon@brandontilley.com"]
+ s.homepage = "https://github.com/BinaryMuse/rforce-wrapper"
+ s.summary = "RForce-wrapper creates a wrapper around rforce to make it easier to use."
+ s.description = s.summary
+
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
+ s.add_runtime_dependency 'rforce'
+ else
+ s.add_dependency 'rforce'
+ end
+
+ s.files = `git ls-files`.split("\n")
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
+ s.require_paths = ["lib"]
+end

0 comments on commit 99d64c2

Please sign in to comment.