Skip to content

Commit

Permalink
Replace all calls of AbstractApi::put() with HttpClient
Browse files Browse the repository at this point in the history
  • Loading branch information
Art4 committed Mar 11, 2024
1 parent e975190 commit 9ad1b6c
Show file tree
Hide file tree
Showing 9 changed files with 71 additions and 29 deletions.
7 changes: 5 additions & 2 deletions src/Redmine/Api/Group.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,13 @@ public function update(int $id, array $params = [])
];
$params = $this->sanitizeParams($defaults, $params);

return $this->put(
$this->lastResponse = $this->getHttpClient()->request(HttpFactory::makeXmlRequest(
'PUT',
'/groups/' . $id . '.xml',
XmlSerializer::createFromArray(['group' => $params])->getEncoded()
);
));

return $this->lastResponse->getContent();
}

/**
Expand Down
14 changes: 10 additions & 4 deletions src/Redmine/Api/Issue.php
Original file line number Diff line number Diff line change
Expand Up @@ -260,10 +260,13 @@ public function update($id, array $params)
$sanitizedParams['assigned_to_id'] = '';
}

return $this->put(
$this->lastResponse = $this->getHttpClient()->request(HttpFactory::makeXmlRequest(
'PUT',
'/issues/' . urlencode(strval($id)) . '.xml',
XmlSerializer::createFromArray(['issue' => $sanitizedParams])->getEncoded()
);
));

return $this->lastResponse->getContent();
}

/**
Expand Down Expand Up @@ -417,10 +420,13 @@ public function attachMany($id, array $attachments)
'uploads' => $attachments,
];

return $this->put(
$this->lastResponse = $this->getHttpClient()->request(HttpFactory::makeJsonRequest(
'PUT',
'/issues/' . urlencode(strval($id)) . '.json',
JsonSerializer::createFromArray(['issue' => $params])->getEncoded()
);
));

return $this->lastResponse->getContent();
}

/**
Expand Down
7 changes: 5 additions & 2 deletions src/Redmine/Api/IssueCategory.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,10 +211,13 @@ public function update($id, array $params)
];
$params = $this->sanitizeParams($defaults, $params);

return $this->put(
$this->lastResponse = $this->getHttpClient()->request(HttpFactory::makeXmlRequest(
'PUT',
'/issue_categories/' . urlencode(strval($id)) . '.xml',
XmlSerializer::createFromArray(['issue_category' => $params])->getEncoded()
);
));

return $this->lastResponse->getContent();
}

/**
Expand Down
7 changes: 5 additions & 2 deletions src/Redmine/Api/Membership.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,13 @@ public function update($id, array $params = [])
throw new MissingParameterException('Theses parameters are mandatory: `role_ids`');
}

return $this->put(
$this->lastResponse = $this->getHttpClient()->request(HttpFactory::makeXmlRequest(
'PUT',
'/memberships/' . $id . '.xml',
XmlSerializer::createFromArray(['membership' => $params])->getEncoded()
);
));

return $this->lastResponse->getContent();
}

/**
Expand Down
27 changes: 17 additions & 10 deletions src/Redmine/Api/Project.php
Original file line number Diff line number Diff line change
Expand Up @@ -215,10 +215,13 @@ public function update($id, array $params)
];
$params = $this->sanitizeParams($defaults, $params);

return $this->put(
$this->lastResponse = $this->getHttpClient()->request(HttpFactory::makeXmlRequest(
'PUT',
'/projects/' . urlencode(strval($id)) . '.xml',
XmlSerializer::createFromArray(['project' => $params])->getEncoded()
);
));

return $this->lastResponse->getContent();
}

/**
Expand All @@ -242,10 +245,11 @@ final public function close($projectIdentifier): bool
));
}

$this->put(
$this->lastResponse = $this->getHttpClient()->request(HttpFactory::makeXmlRequest(
'PUT',
'/projects/' . strval($projectIdentifier) . '/close.xml',
''
);
));

$lastResponse = $this->getLastResponse();

Expand Down Expand Up @@ -277,10 +281,11 @@ final public function reopen($projectIdentifier): bool
));
}

$this->put(
$this->lastResponse = $this->getHttpClient()->request(HttpFactory::makeXmlRequest(
'PUT',
'/projects/' . strval($projectIdentifier) . '/reopen.xml',
''
);
));

$lastResponse = $this->getLastResponse();

Expand Down Expand Up @@ -312,10 +317,11 @@ final public function archive($projectIdentifier): bool
));
}

$this->put(
$this->lastResponse = $this->getHttpClient()->request(HttpFactory::makeXmlRequest(
'PUT',
'/projects/' . strval($projectIdentifier) . '/archive.xml',
''
);
));

$lastResponse = $this->getLastResponse();

Expand Down Expand Up @@ -347,10 +353,11 @@ final public function unarchive($projectIdentifier): bool
));
}

$this->put(
$this->lastResponse = $this->getHttpClient()->request(HttpFactory::makeXmlRequest(
'PUT',
'/projects/' . strval($projectIdentifier) . '/unarchive.xml',
''
);
));

$lastResponse = $this->getLastResponse();

Expand Down
7 changes: 5 additions & 2 deletions src/Redmine/Api/TimeEntry.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,13 @@ public function update($id, array $params)
];
$params = $this->sanitizeParams($defaults, $params);

return $this->put(
$this->lastResponse = $this->getHttpClient()->request(HttpFactory::makeXmlRequest(
'PUT',
'/time_entries/' . $id . '.xml',
XmlSerializer::createFromArray(['time_entry' => $params])->getEncoded()
);
));

return $this->lastResponse->getContent();
}

/**
Expand Down
7 changes: 5 additions & 2 deletions src/Redmine/Api/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -247,10 +247,13 @@ public function update($id, array $params)
];
$params = $this->sanitizeParams($defaults, $params);

return $this->put(
$this->lastResponse = $this->getHttpClient()->request(HttpFactory::makeXmlRequest(
'PUT',
'/users/' . urlencode(strval($id)) . '.xml',
XmlSerializer::createFromArray(['user' => $params])->getEncoded()
);
));

return $this->lastResponse->getContent();
}

/**
Expand Down
7 changes: 5 additions & 2 deletions src/Redmine/Api/Version.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,10 +224,13 @@ public function update($id, array $params)
$this->validateStatus($params);
$this->validateSharing($params);

return $this->put(
$this->lastResponse = $this->getHttpClient()->request(HttpFactory::makeXmlRequest(
'PUT',
'/versions/' . $id . '.xml',
XmlSerializer::createFromArray(['version' => $params])->getEncoded()
);
));

return $this->lastResponse->getContent();
}

private function validateStatus(array $params = [])
Expand Down
17 changes: 14 additions & 3 deletions src/Redmine/Api/Wiki.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,19 @@ public function create($project, $page, array $params = [])
];
$params = $this->sanitizeParams($defaults, $params);

return $this->put(
$this->lastResponse = $this->getHttpClient()->request(HttpFactory::makeXmlRequest(
'PUT',
'/projects/' . $project . '/wiki/' . urlencode($page) . '.xml',
XmlSerializer::createFromArray(['wiki_page' => $params])->getEncoded()
);
));

$body = $this->lastResponse->getContent();

if ($body !== '') {
return new SimpleXMLElement($body);
}

return $body;

Check warning on line 160 in src/Redmine/Api/Wiki.php

View check run for this annotation

Codecov / codecov/patch

src/Redmine/Api/Wiki.php#L160

Added line #L160 was not covered by tests
}

/**
Expand All @@ -162,7 +171,9 @@ public function create($project, $page, array $params = [])
*/
public function update($project, $page, array $params = [])
{
return $this->create($project, $page, $params);
$this->create($project, $page, $params);

return $this->lastResponse->getContent();
}

/**
Expand Down

0 comments on commit 9ad1b6c

Please sign in to comment.