Skip to content

Commit f98b0be

Browse files
committed
Merge pull request #61 from polishdeveloper/fix_importer
Fixed Importing users
2 parents 14fd340 + 8236901 commit f98b0be

File tree

2 files changed

+29
-18
lines changed

2 files changed

+29
-18
lines changed

Diff for: src/API/Helpers/RequestBuilder.php

+25-14
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ public function addPath($name, $argument = null) {
5353

5454
public function addPathVariable($variable) {
5555
$this->path[] = $variable;
56+
return $this;
5657
}
5758

5859
public function getUrl() {
@@ -85,18 +86,18 @@ public function dump() {
8586
return $this;
8687
}
8788

88-
public function addFile($file_path) {
89-
$this->files[] = $filePath;
89+
public function addFile($field, $file_path) {
90+
$this->files[$field] = $file_path;
91+
return $this;
9092
}
9193

9294
public function addFormParam($key, $value) {
9395
$this->form_params[$key] = $value;
96+
return $this;
9497
}
9598

9699
public function call() {
97-
98100
$client = new Client();
99-
$method = $this->method;
100101

101102
try {
102103

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

108109
if (!empty($this->files)) {
109-
foreach($this->files as $file) {
110-
$data['multipart'][] = [
111-
'name' => basename($file),
112-
'contents' => $file
113-
];
114-
}
115-
}
116-
117-
if (!empty($this->form_params)) {
110+
$data['multipart'] = $this->buildMultiPart();
111+
} else if (!empty($this->form_params)) {
118112
$data['form_params'] = $this->form_params;
119113
}
120114

@@ -126,7 +120,6 @@ public function call() {
126120
} catch (RequestException $e) {
127121
throw $e;
128122
}
129-
130123
}
131124

132125
public function withHeaders($headers) {
@@ -170,4 +163,22 @@ public function withParams($params) {
170163
return $this;
171164
}
172165

166+
private function buildMultiPart() {
167+
$multipart = array();
168+
169+
foreach($this->files as $field => $file) {
170+
$multipart[] = [
171+
'name' => $field,
172+
'contents' => fopen($file, 'r')
173+
];
174+
}
175+
foreach($this->form_params as $param => $value) {
176+
$multipart[] = [
177+
'name' => $param,
178+
'contents' => $value
179+
];
180+
}
181+
return $multipart;
182+
}
183+
173184
}

Diff for: src/API/Jobs.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,17 @@ public function get($id) {
2020
->call();
2121
}
2222

23-
public function sendVerificationEmail($file_path, $connection_id) {
23+
public function importUsers($file_path, $connection_id) {
2424

2525
return $this->apiClient->post()
2626
->jobs()
27-
->addPath('verification-email')
28-
->addFile($file_path)
27+
->addPath('users-imports')
28+
->addFile('users', $file_path)
2929
->addFormParam('connection_id', $connection_id)
3030
->call();
3131
}
3232

33-
public function importUsers($user_id) {
33+
public function sendVerificationEmail($user_id) {
3434

3535
return $this->apiClient->post()
3636
->jobs()

0 commit comments

Comments
 (0)