Skip to content

Commit

Permalink
Merge pull request #61 from polishdeveloper/fix_importer
Browse files Browse the repository at this point in the history
Fixed Importing users
  • Loading branch information
glena committed Feb 3, 2016
2 parents 14fd340 + 8236901 commit f98b0be
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 18 deletions.
39 changes: 25 additions & 14 deletions src/API/Helpers/RequestBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public function addPath($name, $argument = null) {

public function addPathVariable($variable) {
$this->path[] = $variable;
return $this;
}

public function getUrl() {
Expand Down Expand Up @@ -85,18 +86,18 @@ public function dump() {
return $this;
}

public function addFile($file_path) {
$this->files[] = $filePath;
public function addFile($field, $file_path) {
$this->files[$field] = $file_path;
return $this;
}

public function addFormParam($key, $value) {
$this->form_params[$key] = $value;
return $this;
}

public function call() {

$client = new Client();
$method = $this->method;

try {

Expand All @@ -106,15 +107,8 @@ public function call() {
];

if (!empty($this->files)) {
foreach($this->files as $file) {
$data['multipart'][] = [
'name' => basename($file),
'contents' => $file
];
}
}

if (!empty($this->form_params)) {
$data['multipart'] = $this->buildMultiPart();
} else if (!empty($this->form_params)) {
$data['form_params'] = $this->form_params;
}

Expand All @@ -126,7 +120,6 @@ public function call() {
} catch (RequestException $e) {
throw $e;
}

}

public function withHeaders($headers) {
Expand Down Expand Up @@ -170,4 +163,22 @@ public function withParams($params) {
return $this;
}

private function buildMultiPart() {
$multipart = array();

foreach($this->files as $field => $file) {
$multipart[] = [
'name' => $field,
'contents' => fopen($file, 'r')
];
}
foreach($this->form_params as $param => $value) {
$multipart[] = [
'name' => $param,
'contents' => $value
];
}
return $multipart;
}

}
8 changes: 4 additions & 4 deletions src/API/Jobs.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@ public function get($id) {
->call();
}

public function sendVerificationEmail($file_path, $connection_id) {
public function importUsers($file_path, $connection_id) {

return $this->apiClient->post()
->jobs()
->addPath('verification-email')
->addFile($file_path)
->addPath('users-imports')
->addFile('users', $file_path)
->addFormParam('connection_id', $connection_id)
->call();
}

public function importUsers($user_id) {
public function sendVerificationEmail($user_id) {

return $this->apiClient->post()
->jobs()
Expand Down

0 comments on commit f98b0be

Please sign in to comment.