/**
  * Creates and posts a service request
  *
  * @param string $serviceCode
  * @param float $lat
  * @param float $lng
  * @param string $addressString
  * @param string $addressId
  * @param string $email
  * @param string $deviceId
  * @param string $accountId
  * @param string $firstName
  * @param string $lastName
  * @param string $phone
  * @param string $description
  * @param string $mediaUrl
  * @param string $format
  * @return ServiceRequestResponse
  * @throws Open311Exception
  */
 public function createServiceRequest($serviceCode, $lat, $lng, $addressString, $addressId = '', $email = '', $deviceId = '', $accountId = '', $firstName = '', $lastName = '', $phone = '', $description = '', $mediaUrl = '', $format = self::FORMAT_JSON)
 {
     $data = array(ServiceRequest::FIELD_SERVICE_CODE => $serviceCode, ServiceRequest::FIELD_LATITUDE => !is_null($lat) && is_numeric($lat) ? (double) $lat : null, ServiceRequest::FIELD_LONGITUDE => !is_null($lng) && is_numeric($lng) ? (double) $lng : null, ServiceRequest::FIELD_ADDRESS_STRING => $addressString, ServiceRequest::FIELD_ADDRESS_ID => $addressId, ServiceRequest::FIELD_EMAIL => $email, ServiceRequest::FIELD_DEVICE_ID => $deviceId, ServiceRequest::FIELD_ACCOUNT_ID => $accountId, ServiceRequest::FIELD_FIRST_NAME => $firstName, ServiceRequest::FIELD_LAST_NAME => $lastName, ServiceRequest::FIELD_PHONE => $phone, ServiceRequest::FIELD_DESCRIPTION => $description, ServiceRequest::FIELD_MEDIA_URL => $mediaUrl);
     try {
         return $this->postServiceRequest(ServiceRequest::fromArray($data, $this->serviceRequestRequiredFields), $format);
     } catch (Open311Exception $e) {
         throw $e;
     }
 }
 /**
  * Posts a new service request to Open311
  *
  * @param ServiceRequest $serviceRequest
  * @param string $format
  * @return ServiceRequestResponse|null
  * @throws Open311Exception
  */
 public function postServiceRequest(ServiceRequest $serviceRequest, $format = self::FORMAT_JSON)
 {
     if ($serviceRequest instanceof ServiceRequest) {
         $response = $this->post(self::COMMAND_SERVICE_REQUESTS, $format, $serviceRequest->toArray());
         if (!is_null($response)) {
             $responseData = $response->json();
             if (is_array($responseData) && isset($responseData[0])) {
                 return ServiceRequestResponse::fromArray($responseData[0]);
             }
         }
     } else {
         throw new Open311Exception(self::ERROR_INVALID_SERVICE_REQUEST);
     }
     return null;
 }
 /**
  * @param mixed $serviceRequest
  * @param bool $expectSuccess
  *
  * @covers \GeoPal\Open311\BaseClient::postServiceRequest
  * @dataProvider providerTestPostServiceRequest
  */
 public function testPostServiceRequest($serviceRequest, $expectSuccess)
 {
     $stubResponse = array(array(array(ServiceRequest::FIELD_SERVICE_REQUEST_ID => 'stub_id')));
     /**
      * Create test client and do call
      */
     $stubClient = new StubClient($this->getStubGuzzleClient($stubResponse));
     if ($expectSuccess) {
         $response = $stubClient->postServiceRequest($serviceRequest);
         $this->assertInstanceOf('\\GeoPal\\Open311\\ServiceRequestResponse', $response);
     } else {
         $result = false;
         $exceptionThrown = false;
         try {
             // Throw an exception or change $result from false to null
             $result = $stubClient->postServiceRequest(ServiceRequest::fromArray($serviceRequest));
         } catch (Open311Exception $e) {
             $exceptionThrown = true;
         }
         $this->assertTrue($exceptionThrown || is_null($result));
     }
 }