How To Upload A Documen To Field Nation
Nosotros exercise not support Soap API for new developement, This code is for reference only
Field Nation PHP SDK
- Build Status
- Installation
- PHP Support
- PHP Requirements
- Installation with Composer
- Usage
- Authentication
- Environs
- Create a Work Society
- Work Order Actions and Metadata
- Publish
- Road to Provider
- Route to Group
- Approve
- Cancel
- Adhere Documents
- Detach Documents
- Add a Bulletin
- Add together a Custom Field
- Add a Label
- Remove a Label
- Resolving a Closeout Requirements
- Add together a Shipment
- Delete a Shipment
- Update Schedule
- Go the Entire Work Order
- Get the Status
- Get the Assigned Provider
- Go Progress
- Get Payment
- Get Messages
- Get Attached Documents
- Get Shipments
- Get Your Work Orders
- Get Your Projects
- Get Your Documents
- Convert a Tracking Number to a Shipping ID
- Using Your Classes
- Contributing
- Tests
- Coding Standards
- Changelog
- License
Build Condition
Installation
PHP Support
- PHP 5.half-dozen+
- PHP 7+
- HHVM
PHP Requirements
Your php runtime needs to accept Soap enabled. Follow the installation instructions for enabling the Soap module.
Installation with Composer
Crave the fieldnation/fieldnation-sdk
package in your project.
$ composer crave fieldnation/fieldnation-sdk
Usage
The central concept to successfully integrating with Field Nation is describing how your business objects become Field Nation objects. We provide interfaces for describing how your data can be created on Field Nation.
Authentication
To use the SDK yous demand to generate an API cardinal for your visitor. You lot tin can create an API key at https://app.fieldnation.com/api
. In one case you have a key y'all can create a connection.
<?php $fnCompanyId = $ _ENV ['FIELD_NATION_COMPANY_ID']; $fnApiKey = $ _ENV ['FIELD_NATION_API_KEY']; $fnEffectiveUser = $ _ENV ['FIELD_NATION_EFFECTIVE_USER']; // optional - Get-go admin user will be used if not provided. $credentials = new \FieldNation\LoginCredentials( $fnCompanyId, $fnApiKey, $fnEffectiveUser); $fn = new \FieldNation\SDK( $credentials);
Environs
The default environment for the SDK is prepare to production. If you would similar to use another environment for testing you can do so by setting the value on the credentials object.
<?php $fnCompanyId = $ _ENV ['FIELD_NATION_COMPANY_ID']; $fnApiKey = $ _ENV ['FIELD_NATION_API_KEY']; $credentials = new \FieldNation\LoginCredentials( $fnCompanyId, $fnApiKey, $fnEffectiveUser); $credentials->setEnvironment("https://stable.fieldnation.com"); $fn = new \FieldNation\SDK( $credentials);
Create a Work Order
Beginning, let's create a simple example of what your data model might look similar.
<?php class MyBusinessTicket { private $id; individual $title; individual $description; private $startDateTime; // ... setters and getters for the properties }
Now that we have our business organisation logic in our MyBusinessTicket
, how tin we commencement creating work orders on Field Nation? Uncomplicated -- nosotros update MyBusinessTicket
to implement FieldNation\WorkOrderSerializerInterface
(or better even so, create a new class MyFieldNationBusinessTicket
that extends MyBusinessTicket
and implements FieldNation\WorkOrderSerializerInterface
).
<?php use FieldNation\WorkOrderSerializerInterface; grade MyBusinessTicket implements WorkOrderSerializerInterface { private $id; individual $title; individual $description; private $startDateTime; private $fieldNationId; // ... setters and getters for the properties // WorkOrderSerializerInterface methods /** * Go the proper noun of the project the work order should be a member of. * * If not present, the piece of work order will not belong to a project (default behavior). * If the project does non already be, it volition exist created automatically and your effectiveUser * (Encounter Login structure) volition be the default manager for all newly-created projects. * * @return string */ public function getGroup() { return NULL; } /** * Become the full general descriptive data relevant to the job. * * @return FieldNation\ServiceDescriptionInterface */ public function getDescription() { $clarification = new \FieldNation\ServiceDescription(); $clarification->setCategoryId(ane); // Meet docs for category IDs $description->setTitle( $ this ->championship); $description->setDescription( $ this ->description); return $clarification; } /** * Become where the job site is located. * * @return FieldNation\ServiceLocationInterface */ public role getLocation() { // My business only has i service location $locationType = \FieldNation\LocationTypes::COMMERCIAL; $location = new \FieldNation\ServiceLocation(); $location->setType( $locationType); $location->setName('Foo Co'); $location->setAddress1('123 Main Street'); $location->setCity('Minneapolis'); $location->setState('MN'); $location->setPostalCode('55402'); $location->setCountry('U.s.a.'); $location->setContactName('Bob'); $location->setContactEmail('bob@mybusiness.com'); $location->setContactPhone('612-555-3485'); return $location; } /** * Get scheduling information for the Piece of work Order, including any applicable end time. * * @return FieldNation\TimeRangeInterface */ public role getStartTime() { $time = new \FieldNation\TimeRange(); $time->setTimeBegin( $ this ->startDateTime); return $fourth dimension; } /** * Become payment details to be advertised on the Work Order. * @return FieldNation\PayInfoInterface */ public function getPayInfo() { // All of our tickets are a flat $twenty charge per unit with a five hr max $info = new \FieldNation\PayInfo(); $rate = new \FieldNation\RatePay(); $charge per unit->setRate(20.0); $rate->setMaxUnits(5.0); $info->setPerHour( $rate); return $info; } /** * Get whether to let the technician to upload files to the Work Gild. * If enabled, this Work Guild will inherit required items from the project * it belongs to or settings your company has configured for all Work Orders. * * @return boolean */ public office getAllowTechUploads() { // We always allow return true; } /** * Get whether to e-mail whatsoever providers about the Work Order. * Typical usage is true and should only be disabled in sure circumstances. * * @return boolean */ public role getWillAlertWhenPublished() { // Always alert providers return true; } /** * Get whether to grant technician admission to a impress-friendly version of work lodge details. * It is strongly recommended this is prepare to true. This should only be set false * if y'all volition be attaching a printable version as a certificate. * * @render boolean */ public office getIsPrintable() { // Always allow to print return true; } /** * Get additional fields (custom fields) and values provided by your company for the Work Order. * * @return FieldNation\AdditionalFieldInterface[] */ public office getAdditionalFields() { // Add my 'TicketId' custom field to all work orders $ticketId = new \FieldNation\AdditionalField(); $ticketId->setName('Ticket ID'); $ticketId->setValue( $ this ->id); render array( $ticketId); } /** * Get labels that are set on the work gild. * * @return string[] */ public office getLabels() { return array(); } /** * Get a list of requirements to be met before the Work Order is able to be marked Piece of work Done. * Currently only configured and satisfied via the API. Should be Nil if non configured. * * @return array|NULL */ public office getCloseoutRequirements() { render Goose egg; } }
Let's take a second to intermission downwardly what we added.
These methods are a requirement of the WorkOrderSerializerInterface
. This interface describes how your information translates to Field Nation data, and is a requirement of the SDK for creating piece of work orders. Each method is documented with what it does, and what the return type should exist. For more than information about the types encounter the interfaces section.
At that place are a number of methods that require you lot to map your data to a type that is provided by the SDK. Let'due south utilise getPayInfo
as an example. Field Nation requires a specific schema for describing the pay info for a work order. Because we don't know how you pay technicians, we provide an interface, PayInfoInterface
, for translating your pay construction into a pay structure that we empathise. The PayInfoInterface
acts as container for the potential pay types -- FixedPayInterface
, RatePayInterface
, and BlendedPayInterface
. Each of these pay interfaces also has a concrete class provided with the SDK (FixedPay
, RatePay
, BlendedPay
). Y'all can apply the classes that we've implemented to translate your pay structure into a Field Nation pay structure, or you could create your own physical classes that implement the provided interfaces.
Now that we understand how our business organization objects translate to Field Nation business objects nosotros can create a work order.
<?php $fnCompanyId = $ _ENV ['FIELD_NATION_COMPANY_ID']; $fnApiKey = $ _ENV ['FIELD_NATION_API_KEY']; $fnEffectiveUser = $ _ENV ['FIELD_NATION_EFFECTIVE_USER']; $credentials = new \FieldNation\LoginCredentials( $fnCompanyId, $fnApiKey, $fnEffectiveUser); $fn = new \FieldNation\SDK( $credentials); $myTicket = new MyBusinessTicket(); $myTicket->setId(uniqid()); $myTicket->setTitle('Ready something at this place'); $myTicket->setDescription('Something went wrong. Gear up it.'); $myTicket->setStartDateTime(new \DateTime()); // Returns a \FieldNation\WorkOrderInterface object $fnWorkOrder = $fn->createWorkOrder( $myTicket); $myTicket->setFieldNationId( $fnWorkOrder->getId());
Piece of work Order Actions and Metadata
Updating a piece of work gild is similar to creating a work lodge, but in that location are granular actions that you can make on a piece of work order instance.
At that place are 2 ways of getting a Field Nation work order object.
- If you but created one through the SDK::createWorkOrder method
- If you called the SDK::getExistingWorkOrder method.
<?php // Only created a piece of work order $fnCompanyId = $ _ENV ['FIELD_NATION_COMPANY_ID']; $fnApiKey = $ _ENV ['FIELD_NATION_API_KEY']; $fnEffectiveUser = $ _ENV ['FIELD_NATION_EFFECTIVE_USER']; $credentials = new \FieldNation\LoginCredentials( $fnCompanyId, $fnApiKey, $fnEffectiveUser); $fn = new \FieldNation\SDK( $credentials); $myTicket = new MyBusinessTicket(); $myTicket->setId(uniqid()); $myTicket->setTitle('Fix something at this identify'); $myTicket->setDescription('Something went wrong. Fix it.'); $myTicket->setStartDateTime(new \DateTime()); // Returns a \FieldNation\WorkOrderInterface object $fnWorkOrder = $fn->createWorkOrder( $myTicket); $myTicket->setFieldNationId( $fnWorkOrder->getId()); // Fetching a work club later on information technology was created $ticket = $db->getTicket(1234); // pseudo code for fetching your ticket $fnWorkOrder = $fn->getExistingWorkOrder( $ticket->fnId);
Now that you lot have a Field Nation work guild instance you tin execute deportment or get metadata about it.
Publish
Publish your work club on Field Nation
/** * @returns ResultInterface */ $result = $fnWorkOrder->publish();
Route to Provider
Route your work social club to a Provider. When creating a Provider object yous need to set the Provider ID so information technology will be properly routed.
/** * Create a provider object to route to */ $provider = new \FieldNation\Technician(); $provider->setId('1'); /** * @returns ResultInterface */ $outcome = $fnWorkOrder->routeTo( $provider);
Route to Group
Route your piece of work order to a Group. When creating a Group object yous need to set the Grouping ID and so it will exist properly routed.
/** * Create a group to route to */ $grouping = new \FieldNation\Grouping(); $grouping->setId('100'); /** * @returns ResultInterface */ $result = $fnWorkOrder->routeTo( $group);
Approve
Approve your work gild.
/** * @returns ResultInterface */ $result = $fnWorkOrder->corroborate();
Abolish
Sometimes you need to cancel your work club and start over.
/** * @returns ResultInterface */ $event = $fnWorkOrder->cancel();
Attach Documents
Attach a document to your work lodge.
/** * Create your document. */ $certificate = new \FieldNation\Certificate(); $certificate->setTitle('Instructions'); $certificate->setType('application/pdf'); $document->setUpdateTime(new \DateTime('now', new \DateTimeZone('UTC'))); /** * @returns ResultInterface */ $upshot = $fnWorkOrder->attach( $document);
Detach Documents
Remove a document from your work order.
/** * Create the document object */ $document = new \FieldNation\Document(); $document->setTitle('Instructions'); /** * @returns ResultInterface */ $effect = $fnWorkOrder->detach( $document);
Add a Custom Field
Your work orders are yours. Brand them yours past adding a custom field.
/** * 1 of your custom fields */ $field = new \FieldNation\CustomField(); $field->setName('My Business Ticket ID'); /** * @returns ResultInterface */ $result = $fnWorkOrder->addAdditionalField( $field);
Add a Characterization
Add together labels to your piece of work order.
/** * Create a label */ $label = new \FieldNation\Label(); $label->setName('New Piece of work'); $label->setHideFromTech(truthful); /** * @returns ResultInterface */ $issue = $fnWorkOrder->addLabel( $label);
Remove a Characterization
Remove a label from your work order.
/** * Create a label */ $label = new \FieldNation\Label(); $characterization->setName('New Work'); /** * @returns ResultInterface */ $result = $fnWorkOrder->removeLabel( $label);
Resolving a Closeout Requirement
Mark a closeout requirement equally resolved.
/** * Closeout Requirement */ $requirement = new \FieldNation\CloseoutRequirement(); $requirement->setName('Provider upload moving-picture show'); /** * @returns ResultInterface */ $issue = $fnWorkOrder->resolveCloseoutRequirement( $requirement);
Add a Shipment
Add a shipment for Field Nation to rail to your piece of work order.
/** * Shipment */ $shipment = new \FieldNation\Shipment(); $shipment->setVendor('USPS'); $shipment->setTrackingId('my-tracking-number'); /** * @returns ResultInterface */ $result = $fnWorkOrder->addShipment( $shipment);
Delete a Shipment
If a shipment no longer needs to be tracked delete it from your work society.
// If you lot don't have the Field Nation shipment id, yous can become information technology with your tracking number $event = $fn->getShippingIdFrom('my-tracking-number'); $shipment = new \FieldNation\Shipment(); $shipment->setId( $event->getShipmentId()); /** * @returns ResultInterface */ $issue = $fnWorkOrder->deleteShipment( $shipment);
Update Schedule
Things change -- update the schedule for your piece of work club.
/** * Create a TimRange object */ $schedule = new TimeRange(); $schedule->setTimeBegin(new \DateTime('now')); $schedule->setTimeEnd(new \DateTime('at present')); /** * @returns ResultInterface */ $result = $fnWorkOrder->updateSchedule( $schedule);
Get the Unabridged Piece of work Social club
Occasionally it makes sense to go the entire piece of work order. Here'south how!
If you demand something specific you should be calling that getter directly. This action is expensive so use it when you really demand it.
/** * @returns WorkOrderInterface */ $fnWorkOrder = $fnWorkOrder->get(); // go all metadata and reassign the existing variable
Get the Status
Get the status of your work lodge
/** * @returns string from \FieldNation\WorkOrderStatuses */ $condition = $fnWorkOrder->getStatus();
Get the Assigned Provider
Go the data about the Provider that is assigned to your work order.
/** * @returns \FieldNation\TechnicianInterface */ $provider = $fnWorkOrder->getAssignedProvider();
Get Progress
Become the progress of your work order.
/** * @returns \FieldNation\ProgressInterface */ $progress = $fnWorkOrder->getProgress();
Get Payment
Go the payment information about your work order.
/** * @returns \FieldNation\PaymentInterface */ $payment = $fnWorkOrder->getPayment();
Get Messages
Get the messages on your work order
/** * @returns \FieldNation\MessageInterface[] */ $messages = $fnWorkOrder->getMessages();
Get Attached Documents
Become the attached documents on your work order.
/** * @returns from \FieldNation\Document[] */ $documents = $fnWorkOrder->getAttachedDocuments();
Get Shipments
Get the tracked shipments for your work order.
/** * @returns \FieldNation\Shipment[] */ $shipments = $fnWorkOrder->getShipments();
Get Your Work Orders
Sometimes you need to get all of your work orders. Here'southward how!
/** * Optionally you can filter your query by the status of the work guild. * If the status is NULL we'll return all work orders. * Yous tin get statuses from the \FieldNation\WorkOrderStatuses class */ $status = \FieldNation\WorkOrderStatuses::PUBLISHED /** * @returns \FieldNation\WorkOrderInterface[] */ $workOrders = $fn->getWorkOrders( $condition);
Go Your Projects
Use to get all of the projects for your visitor.
/** * @returns \FieldNation\ProjectInterface[] */ $projects = $fn->getProjects();
Get Your Documents
Get all of the documents for your company.
/** * @returns \FieldNation\DocumentInterface[] */ $documents = $fn->getDocuments();
Catechumen a Tracking Number to a Aircraft ID
If you accept a tracking number for a shipment you created, just didn't save the Field Nation aircraft ID you can get it here.
/** * @returns string */ $shippingId = $fn->getShippingIdFrom('my-tracking-number');
Using Your Classes
You may exist wondering if you lot have to employ our PHP classes. The proficient news is that you lot don't! We implement all of our own interfaces with plain ol' php objects as a prepare of defaults, merely if your classes implement our interfaces you can configure the SDK to use your classes. The only hard dominion nosotros accept is that your course must implement the interface for the type you're trying to inject. If your form doesn't implement the interface we will throw a TypeError
.
Example replacing our WorkOrder
with your class that implements our WorkOrderInterface
.
use \FieldNation\SDK; use \FieldNation\ClassMapFactoryInterface; SDK::configure(function (ClassMapFactoryInterface $classMap) { $classMap->setWorkOrder(\MyBusinessNamespace\MyClass::class); });
Hither is a list of all of the classes that are considered injectable.
// Default configuration SDK::configure(function (ClassMapFactoryInterface $classMap) { $classMap->setAdditionalExpense(\FieldNation\AdditionalExpense::grade); $classMap->setAdditionalField(\FieldNation\AdditionalField::class); $classMap->setBlendedPay(\FieldNation\BlendedPay::class); $classMap->setCheckInOut(\FieldNation\CheckInOut::class); $classMap->setCloseoutRequirement(\FieldNation\CloseoutRequirement::class); $classMap->setCustomField(\FieldNation\CustomField::class); $classMap->setDocument(\FieldNation\Certificate::course); $classMap->setFixedPay(\FieldNation\FixedPay::class); $classMap->setGroup(\FieldNation\Group::class); $classMap->setHistory(\FieldNation\History::class); $classMap->setLabel(\FieldNation\Characterization::class); $classMap->setMessage(\FieldNation\Message::grade); $classMap->setPayInfo(\FieldNation\PayInfo::class); $classMap->setPaymentDeduction(\FieldNation\PaymentDeduction::course); $classMap->setPayment(\FieldNation\Payment::grade); $classMap->setProblem(\FieldNation\Problem::class); $classMap->setProgress(\FieldNation\Progress::course); $classMap->setProject(\FieldNation\Project::class); $classMap->setRatePay(\FieldNation\RatePay::class); $classMap->setServiceDescription(\FieldNation\ServiceDescription::grade); $classMap->setServiceLocation(\FieldNation\ServiceLocation::class); $classMap->setShipmentHistory(\FieldNation\ShipmentHistory::class); $classMap->setShipment(\FieldNation\Shipment::class); $classMap->setTechnician(\FieldNation\Technician::class); $classMap->setTemplate(\FieldNation\Template::class); $classMap->setTimeRange(\FieldNation\TimeRange::course); $classMap->setWorkLog(\FieldNation\WorkLog::class); $classMap->setWorkOrder(\FieldNation\WorkOrder::form); });
Contributing
Tests
All merge requests require tests passing tests. Merge requests volition not be approved if the tests do not pass, and if at that place are no new tests for the changes.
Coding Standards
We follow the PSR-2 coding style. Nosotros will lint the code and merge requests volition not exist canonical if they do not pass linting. You tin lint using PHP_CodeSniffer.
If you lot have lint errors or warnings you tin can try to auto make clean them with composer lint:fix
. If the errors/warnings tin't exist fixed on their ain you lot will have to manually fix them. composer lint:check
should always get out with a 0.
Changelog
Delight run across the CHANGELOG
or view the releases.
License
Copyright © 2017 Field Nation
Licensed under the Apache License, Version 2.0 (the "License"); you may not utilise this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-ii.0
Unless required by applicable constabulary or agreed to in writing, software distributed under the License is distributed on an "AS IS" Footing, WITHOUT WARRANTIES OR Weather condition OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations nether the License.
Source: https://github.com/fieldnation/fieldnation-sdk-php
Posted by: martelyestrion.blogspot.com
0 Response to "How To Upload A Documen To Field Nation"
Post a Comment