Skip to content

Commit

Permalink
Merge pull request #36 from Local-Data-Exchange/feature/add_more_log_…
Browse files Browse the repository at this point in the history
…json_mapping

#1175984683988670 Add more logs
  • Loading branch information
munir131 authored May 20, 2020
2 parents c4f35fb + e4989ca commit c2757d0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# CHANGELOG
## 0.1.24
- Adding logs in json mapping, so we can figure out if something is wrong with data.

## 0.1.23
- Added form_params support.
- Update circle ci config to test with laravel 6.
Expand Down
31 changes: 19 additions & 12 deletions src/ApiBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,18 +139,17 @@ public function __call($name, $arguments)
case 'POST':
case 'PUT':
// JSON or Form_params mappings
if($requestType == 'form_data'){

if ($requestType == 'form_data') {

$json = $this->processFormParamsMappings($arguments, $api);

$object = $this->call($method,$uri,['form_params' => $json]);
}
else {
$object = $this->call($method, $uri, ['form_params' => $json]);
} else {

$json = $this->processJsonMappings($arguments, $api);
// Call the API
$object = $this->call($method, $uri, ['json' => $json]);
$json = $this->processJsonMappings($arguments, $api);
// Call the API
$object = $this->call($method, $uri, ['json' => $json]);
}

break;
Expand All @@ -160,7 +159,7 @@ public function __call($name, $arguments)
// Call the API
$object = $this->call($method, $uri);
}

// check for success
if ($object->success == true) {
// Decode JSON body
Expand All @@ -186,7 +185,7 @@ public function __call($name, $arguments)

}

break;
break;
case 'xml':

switch ($method) {
Expand Down Expand Up @@ -506,7 +505,15 @@ protected function processJsonMappings($arguments, $api): array
$json = str_ireplace('{' . $key . '}', array_get($arguments[0], $value, null), $json);
}
}
return json_decode($json, true);
$mapping = json_decode($json, true);
if ($mapping == null) {
Log::error("ApiBuilder->processJsonMappings() - Error while decoding string", [
'json' => $json,
'arguments' => $arguments,
'api' => $api,
]);
}
return $mapping;
}

/**
Expand Down Expand Up @@ -545,7 +552,7 @@ protected function processFormParamsMappings($arguments, $api): array
$json = str_ireplace('{' . $key . '}', array_get($arguments[0], $value, null), $json);
}
}
return json_decode($json,true);
return json_decode($json, true);
}

/**
Expand Down

0 comments on commit c2757d0

Please sign in to comment.