Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed Importing users #61

Merged
merged 1 commit into from
Feb 3, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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