-
Notifications
You must be signed in to change notification settings - Fork 5
Add Webhooks API + slim README to docs.mifiel.com #25
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,126 +1,39 @@ | ||
| # java-api-client | ||
|
|
||
| Mifiel API Client for Java | ||
| Java SDK for the [Mifiel](https://www.mifiel.com) API. | ||
|
|
||
| Java SDK for [Mifiel](https://www.mifiel.com) API. | ||
| Please read our [documentation](http://docs.mifiel.com/) for instructions on how to start using the API. | ||
| ## Documentation | ||
|
|
||
| ## Installation | ||
|
|
||
| TODO | ||
|
|
||
| ## Usage | ||
|
|
||
| For your convenience Mifiel offers a Sandbox environment where you can confidently test your code. | ||
|
|
||
| To start using the API in the Sandbox environment you need to first create an account at [app-sandbox.mifiel.com](https://app-sandbox.mifiel.com). | ||
|
|
||
| Once you have an account you will need an APP_ID and an APP_SECRET which you can generate in [app-sandbox.mifiel.com/settings/access-tokens](https://app-sandbox.mifiel.com/settings/access-tokens). | ||
|
|
||
| Then you can configure the library with: | ||
|
|
||
| ```java | ||
| import com.mifiel.api.ApiClient; | ||
|
|
||
| ApiClient apiClient = new ApiClient(appId, appSecret); | ||
| // if you want to use our sandbox environment use: | ||
| apiClient.setUrl("https://app-sandbox.mifiel.com"); | ||
| ``` | ||
|
|
||
| By default the client talks to production (`https://app.mifiel.com`). | ||
|
|
||
| Document methods: | ||
|
|
||
| - Find: | ||
|
|
||
| ```java | ||
| import com.mifiel.api.dao.Documents; | ||
| import com.mifiel.api.objects.Document; | ||
| API reference, guides, and examples: | ||
|
|
||
| Documents documents = new Documents(apiClient); | ||
| Document document = documents.find("id"); | ||
| document.getOriginalHash(); | ||
| document.getFile(); | ||
| document.getFileSigned(); | ||
| // ... | ||
| ``` | ||
| - English: https://docs.mifiel.com/en/ | ||
| - Español: https://docs.mifiel.com/es/ | ||
|
|
||
| - Find all: | ||
| This README covers installation and client setup only. | ||
|
|
||
| ```java | ||
| import java.util.List; | ||
| import com.mifiel.api.dao.Documents; | ||
| import com.mifiel.api.objects.Document; | ||
|
|
||
| Documents documents = new Documents(apiClient); | ||
| List<Document> allDocuments = documents.findAll(); | ||
| ``` | ||
|
|
||
| - Create: | ||
|
|
||
| > Use only **original_hash** if you dont want us to have the file.<br> | ||
| > Only **file** or **original_hash** must be provided. | ||
|
|
||
| ```java | ||
| import java.util.List; | ||
| import java.util.ArrayList; | ||
| import com.mifiel.api.dao.Documents; | ||
| import com.mifiel.api.objects.Document; | ||
| import com.mifiel.api.objects.Signature; | ||
| import com.mifiel.api.utils.MifielUtils; | ||
|
|
||
| Documents documents = new Documents(apiClient); | ||
| Document document = new Document(); | ||
| document.setFile("path/to/my-file.pdf"); | ||
|
|
||
| List<Signature> signatures = new ArrayList<Signature>(); | ||
| Signature signature1 = new Signature(); | ||
| Signature signature2 = new Signature(); | ||
|
|
||
| signature1.setSignature("Signer 1"); | ||
| signature1.setEmail("signer1@email.com"); | ||
| signature1.setTaxId("AAA010101AAA"); | ||
|
|
||
| signature2.setSignature("Signer 2"); | ||
| signature2.setEmail("signer2@email.com"); | ||
| signature2.setTaxId("AAA010102AAA"); | ||
|
|
||
| signatures.add(signature1); | ||
| signatures.add(signature2); | ||
|
|
||
| document.setSignatures(signatures); | ||
| documents.save(document); | ||
| ## Installation | ||
|
|
||
| // if you dont want us to have the PDF, you can just send us | ||
| // the original_hash and the name of the document. Both are required | ||
| Document document2 = new Document(); | ||
| document2.setOriginalHash(MifielUtils.getDocumentHash("path/to/my-file.pdf")); | ||
| document2.setSignatures(signatures); | ||
| TODO | ||
|
|
||
| documents.save(document2); | ||
| ``` | ||
| ## Setup | ||
|
|
||
| - Save signed files | ||
| 1. Create an account (production or [sandbox](https://app-sandbox.mifiel.com)). | ||
| 2. Generate an `APP_ID` and `APP_SECRET` in [Access Tokens](https://app-sandbox.mifiel.com/settings/access-tokens). | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win Use an environment-specific access-token link. Step 1 supports production and sandbox accounts, but this link always opens the sandbox access-token settings. Production users can create credentials for the wrong environment. Use separate production and sandbox links, or make this step explicitly sandbox-only. 🤖 Prompt for AI Agents |
||
| 3. Configure the client: | ||
|
|
||
| ```java | ||
| import com.mifiel.api.dao.Documents; | ||
| import com.mifiel.api.ApiClient; | ||
|
|
||
| Documents documents = new Documents(apiClient); | ||
|
|
||
| // download the signed pdf | ||
| documents.saveSignedFile("id", "path/to/save/file-signed.pdf"); | ||
| // download the signed xml file | ||
| documents.saveXml("id", "path/to/save/xml.xml"); | ||
| // download zip file containing the signed pdf and the xml | ||
| documents.saveZip("id", "path/to/save/xml.xml"); | ||
| ApiClient apiClient = new ApiClient(appId, appSecret); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win Declare the credentials used by the Java example. The snippet passes 🤖 Prompt for AI Agents |
||
| // Production is the default (https://app.mifiel.com). | ||
| // For sandbox: | ||
| apiClient.setUrl("https://app-sandbox.mifiel.com"); | ||
| ``` | ||
|
|
||
| - Delete | ||
|
|
||
| ```java | ||
| import com.mifiel.api.dao.Documents; | ||
| import com.mifiel.api.objects.Document; | ||
| ## Contributing | ||
|
|
||
| Documents documents = new Documents(apiClient); | ||
| documents.delete("id"); | ||
| ``` | ||
| 1. Fork it (https://github.com/Mifiel/java-api-client/fork) | ||
| 2. Create your feature branch (`git checkout -b my-new-feature`) | ||
| 3. Commit your changes (`git commit -am 'Add some feature'`) | ||
| 4. Push to the branch (`git push origin my-new-feature`) | ||
| 5. Create a new Pull Request | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| package com.mifiel.api.dao; | ||
|
|
||
| import java.util.HashMap; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
|
|
||
| import org.apache.http.HttpEntity; | ||
| import org.apache.http.entity.ContentType; | ||
| import org.apache.http.entity.StringEntity; | ||
|
|
||
| import com.mifiel.api.ApiClient; | ||
| import com.mifiel.api.exception.MifielException; | ||
| import com.mifiel.api.objects.Webhook; | ||
| import com.mifiel.api.utils.MifielUtils; | ||
|
|
||
| /** | ||
| * CRUD + trigger helpers for account-level webhooks. | ||
| * | ||
| * @see <a href="https://docs.mifiel.com/en/#tag/Webhooks">Webhooks API</a> | ||
| */ | ||
| public class Webhooks extends BaseObjectDAO<Webhook> { | ||
|
|
||
| private final String WEBHOOK_CANONICAL_NAME = Webhook.class.getCanonicalName(); | ||
| private final String WEBHOOKS_PATH = "webhooks"; | ||
|
|
||
| public Webhooks(final ApiClient apiClient) { | ||
| super(apiClient); | ||
| } | ||
|
|
||
| @Override | ||
| public Webhook find(final String id) throws MifielException { | ||
| final HttpEntity entityResponse = apiClient.get(WEBHOOKS_PATH + "/" + id); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win 🔎 Supported by static analysis🏁 Script executed: #!/bin/bash
set -e
printf '%s\n' '--- Webhooks.java ---'
sed -n '1,180p' src/main/java/com/mifiel/api/dao/Webhooks.java
printf '%s\n' '--- apiClient bindings ---'
rg -n -C 3 'class ApiClient|HttpEntity get\\(|WEBHOOKS_PATH|find\\(' src/main/java src/test || true
printf '%s\n' '--- webhook endpoint references ---'
rg -n -i -C 2 'webhooks|find\\(' README.md docs src/test .github 2>/dev/null | head -240 || trueRepository: Mifiel/java-api-client Length of output: 3568 🌐 Web query:
💡 Result: The available documentation for the Mifiel API [1] does not provide information regarding a GET /webhooks/{id} endpoint. While the documentation is accessible, specific endpoint details for retrieving individual webhooks by ID are not listed in the retrieved search results. Citations: 🌐 Web query:
💡 Result: The Mifiel docs do not show a
Citations: 🏁 Script executed: #!/bin/bash
set -e
printf '%s\n' '--- local API client GET contract ---'
fd -i 'ApiClient.java|BaseObjectDAO.java' src
for f in $(fd -i 'ApiClient.java|BaseObjectDAO.java' src); do
printf '\n--- %s ---\n' "$f"
sed -n '1,220p' "$f"
done
printf '%s\n' '--- official docs page references ---'
python3 - <<'PY'
from urllib.request import urlopen
url = "https://docs.mifiel.com/en/"
try:
text = urlopen(url, timeout=10).read().decode("utf-8", "replace")
print("bytes:", len(text))
for i, line in enumerate(text.splitlines(), 1):
if "webhook" in line.lower():
print(f"{i}:{line[:500]}")
except Exception as e:
print(type(e).__name__ + ":", e)
PYRepository: Mifiel/java-api-client Length of output: 11966 Verify or remove the single-webhook GET request.
🤖 Prompt for AI Agents |
||
| final String response = MifielUtils.entityToString(entityResponse); | ||
| return (Webhook) MifielUtils.convertJsonToObject(response, WEBHOOK_CANONICAL_NAME); | ||
| } | ||
|
|
||
| @Override | ||
| @SuppressWarnings("unchecked") | ||
| public List<Webhook> findAll() throws MifielException { | ||
| final HttpEntity entityResponse = apiClient.get(WEBHOOKS_PATH); | ||
| final String response = MifielUtils.entityToString(entityResponse); | ||
| return (List<Webhook>) (Object) MifielUtils.convertJsonToObjects(response, WEBHOOK_CANONICAL_NAME); | ||
| } | ||
|
|
||
| @Override | ||
| public void delete(final String id) throws MifielException { | ||
| apiClient.delete(WEBHOOKS_PATH + "/" + id); | ||
| } | ||
|
|
||
| @Override | ||
| public Webhook save(final Webhook webhook) throws MifielException { | ||
| final String json = MifielUtils.convertObjectToJson(webhook); | ||
| final StringEntity httpContent = new StringEntity(json, ContentType.APPLICATION_JSON); | ||
| final HttpEntity entityResponse = apiClient.post(WEBHOOKS_PATH, httpContent); | ||
| final String response = MifielUtils.entityToString(entityResponse); | ||
| return (Webhook) MifielUtils.convertJsonToObject(response, WEBHOOK_CANONICAL_NAME); | ||
| } | ||
|
|
||
| /** | ||
| * Trigger delivery for a webhook. | ||
| * | ||
| * @param id webhook id | ||
| * @param resource UUID of the related resource included in the callback payload | ||
| * @param instant when true, deliver immediately once instead of enqueueing retries | ||
| */ | ||
| public String trigger(final String id, final String resource, final boolean instant) throws MifielException { | ||
| final Map<String, Object> body = new HashMap<String, Object>(); | ||
| body.put("resource", resource); | ||
| body.put("instant", instant); | ||
| final String json = MifielUtils.convertObjectToJson(body); | ||
| final StringEntity httpContent = new StringEntity(json, ContentType.APPLICATION_JSON); | ||
| final HttpEntity entityResponse = apiClient.post(WEBHOOKS_PATH + "/" + id + "/trigger", httpContent); | ||
| return MifielUtils.entityToString(entityResponse); | ||
| } | ||
|
|
||
| public String trigger(final String id, final String resource) throws MifielException { | ||
| return trigger(id, resource, false); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| package com.mifiel.api.objects; | ||
|
|
||
| import org.codehaus.jackson.annotate.JsonIgnoreProperties; | ||
| import org.codehaus.jackson.annotate.JsonProperty; | ||
|
|
||
| /** | ||
| * Account-level webhook subscription. | ||
| * | ||
| * @see <a href="https://docs.mifiel.com/en/#tag/Webhooks">Webhooks API</a> | ||
| */ | ||
| @JsonIgnoreProperties(ignoreUnknown = true) | ||
| public class Webhook { | ||
|
|
||
| @JsonProperty("id") | ||
| private String id; | ||
|
|
||
| @JsonProperty("url") | ||
| private String url; | ||
|
|
||
| @JsonProperty("callback_type") | ||
| private String callbackType; | ||
|
|
||
| @JsonProperty("created_at") | ||
| private String createdAt; | ||
|
|
||
| public String getId() { | ||
| return id; | ||
| } | ||
|
|
||
| public void setId(String id) { | ||
| this.id = id; | ||
| } | ||
|
|
||
| public String getUrl() { | ||
| return url; | ||
| } | ||
|
|
||
| public void setUrl(String url) { | ||
| this.url = url; | ||
| } | ||
|
|
||
| public String getCallbackType() { | ||
| return callbackType; | ||
| } | ||
|
|
||
| public void setCallbackType(String callbackType) { | ||
| this.callbackType = callbackType; | ||
| } | ||
|
|
||
| public String getCreatedAt() { | ||
| return createdAt; | ||
| } | ||
|
|
||
| public void setCreatedAt(String createdAt) { | ||
| this.createdAt = createdAt; | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Replace the installation placeholder.
The new Installation section still contains only
TODO. Add the supported Maven or Gradle dependency and the required installation command so the README provides the installation guidance promised by this PR.🤖 Prompt for AI Agents