pithstudio/forrest
Composer 安装命令:
composer require pithstudio/forrest
包简介
Working version of - A Laravel 4 client for Salesforce REST API
关键字:
README 文档
README
Forrest is a Force.com REST API client for Laravel 4. It provides access to restricted Salesforce information via Oauth 2.0. REST is a lightweight alternative to the SOAP API and is useful for mobile users.
While this package is built for Laravel, it has been decoupled so that it can be extended into any framework or vanilla PHP application.
Installation
If you are upgrading to Version 1.0, be sure to re-publish your config file.
Forrest can be installed through composer. Open your composer.json file and add the following to the require key:
"omniphx/forrest": "1.*"
Next run composer update from the command line to install the package.
If you are using Laravel, add the service provider to your app/config/app.php file:
'Omniphx\Forrest\Providers\Laravel\ForrestServiceProvider'
Followed by the alias:
'Forrest' => 'Omniphx\Forrest\Providers\Laravel\Facades\Forrest'
Configuration
You will need a configuation file to add your creditials. Publish a config file using the artisan command:
php artisan config:publish omniphx/forrest
You can find the config file in: app/config/omniphx/forrest/config.php
After you have set up am connected app (see below), update your config file with a consumerKey, consumerSecret, loginURL and callbackURI.
Getting Started
Setting up a Connected App
- Log into to your Salesforce org
- Click on Setup in the upper right-hand menu
- Under Build click
Create > Apps - Scroll to the bottom and click
Newunder Connected Apps. - Enter the following details for the remote application:
- Connected App Name
- API Name
- Contact Email
- Enable OAuth Settings under the API dropdown
- Callback URL
- Select access scope (If you need a refresh token, specify it here)
- Click
Save
After saving, you will now be given a Consumer Key and Consumer Secret. Add those to your config file.
Setup
Forrest will come with the following routes included in it's package:
Web Server authentication flow
Route::get('/authenticate', function() { return Forrest::authenticate(); }); Route::get('/callback', function() { Forrest::callback(); $url = Config::get('forrest::authRedirect'); return Redirect::to($url); });
Username-Password authentication flow
Route::get('/authenticate', function() { Forrest::authenticate(); $url = Config::get('forrest::authRedirect'); return Redirect::to($url); });
Note: If you would like to customize the authentication process, these routes can be overwritten in your
route.phpfile. Feel free to call the routes anything you like, but the callback must match what is configured in your Connected App settings and config file.
Custom login urls
Sometimes users will need to connect to a sandbox or custom url. To do this, simply pass the url as an argument for the authenticatation method:
Route::get('/authenticate', function() { $loginURL = 'https://test.salesforce.com'; return Forrest::authenticate($loginURL); });
Usage
Query a record
The callback function will store an encrypted authentication token in the user's session which can now be used to make API requests such as:
Forrest::query('SELECT Id FROM Account');
Result:
{ "totalSize": 2, "done": true, "records": [ { "attributes": { "type": "Account", "url": "\/services\/data\/v30.0\/sobjects\/Account\/001i000000xxx" }, "Id": "001i000000xxx" }, { "attributes": { "type": "Account", "url": "\/services\/data\/v30.0\/sobjects\/Account\/001i000000xxx" }, "Id": "001i000000xxx" } ] }
The default format is JSON, but it can be changed to XML
Create a new record
Records can be created using the following format.
$body = ['Name' => 'New Account']; Forrest::sobjects('Account',[ 'method' => 'post', 'body' => $body]);
Update a record
Update a record with the PUT method.
$body = [ 'Name' => 'Acme' 'Phone' => '555-555-5555']; Forrest::sobjects('Account/001i000000xxx',[ 'method' => 'put', 'body' => $body]);
Upsert a record
Update a record with the PATCH method and if the external Id doesn't exist, it will insert a new record.
$body = [ 'Phone' => '555-555-5555', 'External_Id__c' => 'XYZ1234']; Forrest::sobjects('Account',[ 'method' => 'patch', 'body' => $body]);
Delete a record
Delete a record with the DELETE method.
Forrest::sobjects('Account/001i000000xxx', ['method' => 'delete']);
XML format
Change the request/response format to XML with the format key or make it default in your config file.
Forrest::describe('Account',['format'=>'xml']);
API Requests
With the exception of the search and query resources, all requests are made dynamically using method overloading. The available resources are stored in the user's session when they are authenticated.
First, determine which resources you have access to by calling:
Session::get('resources');
or
Forrest::resources();
Either will return the following array:
Array ( [sobjects] => /services/data/v30.0/sobjects [connect] => /services/data/v30.0/connect [query] => /services/data/v30.0/query [theme] => /services/data/v30.0/theme [queryAll] => /services/data/v30.0/queryAll [tooling] => /services/data/v30.0/tooling [chatter] => /services/data/v30.0/chatter [analytics] => /services/data/v30.0/analytics [recent] => /services/data/v30.0/recent [process] => /services/data/v30.0/process [identity] => https://login.salesforce.com/id/00Di0000000XXXXXX/005i0000000aaaaAAA [flexiPage] => /services/data/v30.0/flexiPage [search] => /services/data/v30.0/search [quickActions] => /services/data/v30.0/quickActions [appMenu] => /services/data/v30.0/appMenu )
Next, you can call resources by referring to the specified key. For instance:
Forrest::theme();
or
Forrest::appMenu();
Resource urls can be extended by passing additional parameters into the first argument:
Forrest::sobjects('Account/describe/approvalLayouts/');
You can also add optional parameters to requests:
Forrest::theme(['format'=>'xml']);
Additional API Requests
Refresh
If a refresh token is set, the server can refresh the access token on the user's behalf. Refresh tokens are only provided if you use the Web Server flow.
Forrest::refresh();
If you need a refresh token, be sure to specify this under
access scopein your Connected App. You can also specify this in your configuration file by adding'scope' => 'full refresh_token'. Setting scope access in the config file is optional, the default scope access is determined by your Salesforce org.
Revoke
This will revoke the authorization token. The session will continue to store a token, but it will become invalid.
Forrest::revoke();
Versions
Returns all currently supported versions. Includes the verison, label and link to each version's root:
Forrest::versions();
Resources
Returns list of available resources for a specific API.
Forrest::resources();
Identity
Returns information about the logged-in user.
Forrest::identity();
Limits
Lists information about organizational limits. Available for API version 29.0 and later.
Note: this call is part of a pilot program and may not be availabe to all orgs without a request to Salesforce.
Forrest::limits();
Describe
Describes all global objects availabe in the organization.
Forrest::describe();
Query
Returns results for a specified SOQL query.
Forrest::query('SELECT Id FROM Account');
Query Explain
Returns details of how Salesforce will process your query. Available for API verison 30.0 or later.
Forrest::queryExplain('SELECT Id FROM Account');
Query All
Returns results for a specified SOQL query, but will also inlcude deleted records.
Forrest::queryAll('SELECT Id FROM Account');
Search
Returns the specified SOSL query
Forrest::search('Find {foo}');
Scope Order
Global search keeps track of which objects the user interacts with and arranges them when the user performs a global search. This call will return this ordered list of objects.
Forrest::scopeOrder();
Search Layouts
Returns the search results layout for the objects in the query string. List should be formatted as a string, but delimited by a comma.
Forrest::searchLayouts('Account,Contact,Lead');
Suggested Articles
Returns a list of Salesforce Knowledge articles based on the a search query. Pass additional parameters into the second argument. Available for API verison 30.0 or later.
Salesforce Knowledge must be enabled for this to work.
Forrest::suggestedArticles('foo', [ 'parameters' => [ 'channel' => 'App', 'publishStatus' => 'Draft']]);
Suggested Queries
Returns a list of suggested searches based on a search text query. Matches search queries that other users have performed in Salesforce Knowledge. Like Suggest Articles, additional parameters can be passed into the second argument with the parameters key. Available for API version 30.0 or later.
Forrest::suggestedQueries('app, [ 'parameters' => ['foo' => 'bar']]);
For a complete listing of API resources, refer to the Force.com REST API Developer's Guide
Custom Apex endpoints
If you create a custom API using Apex, you can use the custom() method for consuming them.
Forrest::custom('/myEndpoint');
Additional options and parameters can be passed in like this:
Forrest::custom('/myEndpoint', [ 'method' => 'post', 'body' => ['foo' => 'bar'], 'parameters' => ['flim' => 'flam']]);
Read Creating REST APIs using Apex REST for more information.
pithstudio/forrest 适用场景与选型建议
pithstudio/forrest 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 35 次下载、GitHub Stars 达 1, 最近一次更新时间为 2014 年 12 月 02 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「salesforce」 「laravel」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 pithstudio/forrest 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 pithstudio/forrest 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 pithstudio/forrest 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A PHP client for the Salesforce SOAP API
WakeOnWeb Salesforce client
FormRelay route for SFDC Web-To-Lead API.
WakeOnWeb Salesforce bundle
An ORM solution for Salesforce Object Query Language (SOQL)
Alfabank REST API integration
统计信息
- 总下载量: 35
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 20
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2014-12-02