Skip to content

Commit

Permalink
Merge pull request #164 from sachinira/slalpha5
Browse files Browse the repository at this point in the history
Add Cloudmersive connectors to alpha5 branch
  • Loading branch information
indikasampath2000 authored Aug 3, 2021
2 parents 814502a + bf9636b commit 322d345
Show file tree
Hide file tree
Showing 40 changed files with 9,090 additions and 0 deletions.
1 change: 1 addition & 0 deletions openapi/cloudmersive.barcode/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
target
10 changes: 10 additions & 0 deletions openapi/cloudmersive.barcode/Ballerina.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[package]
license = ["Apache-2.0"]
keywords = ["Cloudmersive", "barcode"]
org = "ballerinax"
name = "cloudmersive.barcode"
repository = "https://github.com/ballerina-platform/ballerinax-openapi-connectors"
version = "0.1.0-SNAPSHOT"
authors = ["Ballerina"]
[build-options]
observabilityIncluded = true
11 changes: 11 additions & 0 deletions openapi/cloudmersive.barcode/Dependencies.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[[dependency]]
org = "ballerina"
name = "http"
version = "1.1.0-alpha8"

[[dependency]]
org = "ballerina"
name = "url"
version = "1.1.0-alpha8"


46 changes: 46 additions & 0 deletions openapi/cloudmersive.barcode/Module.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
## Overview
Cloudmersive Barcode API provide capabilities to generate and recognize 1D and 2D barcodes.

Ballerina connector for Cloudmersive Barcode allows easy integration with Cloudmersive Barcode REST API via Ballerina language.
It allows scanning photos of barcodes to text, generate 1D barcodes and generate 2D barcodes

This module supports Cloudmersive Barcode REST API `v1` version.

### Prerequisites
* Create a Cloudmersive Account
* Obtaining tokens
1. [Login to the Cloudmersive account](https://account.cloudmersive.com/login)
2. [Obtain API keys](https://account.cloudmersive.com/keys)

## Quickstart

To use the Cloudmersive Barcode connector in your Ballerina application, update the .bal file as follows:
### Step 1: Import cloudmersive.barcode module
First, import the ballerinax/cloudmersive.barcode module into the Ballerina project.
```ballerina
import ballerinax/cloudmersive.barcode;
```
### Step 2: Configure the connection credentials.
You can now make the connection configuration using the access token.
```ballerina
barcode:ApiKeysConfig config = {
apiKeys : {
hapikey : "<your apiKey>"
}
};
barcode:Client baseClient = check new Client(clientConfig);
```
### Step 3: Lookup EAN barcode

```ballerina
barcode:BarcodeLookupResponse|error bEvent = baseClient->barcodeEanLookup("4 605664 00005");
if (bEvent is barcode:BarcodeLookupResponse) {
log:printInfo("Product data: " + bEvent.toString());
} else {
log:printError(msg = bEvent.toString());
}
```
18 changes: 18 additions & 0 deletions openapi/cloudmersive.barcode/Package.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Connects to Cloudmersive Barcode API from Ballerina

## Package overview

The `ballerinax/cloudmersive.barcode` is a [Ballerina](https://ballerina.io/) connector for connecting to Cloudmersive Barcode API.

### Compatibility
| | Version |
|:------------------------:|:--------------------------:|
| Ballerina Language | Ballerina Swan Lake Beta2 |
| Cloudmersive API | v1 |

## Report issues
To report bugs, request new features, start new discussions, view project boards, etc., go to the [Ballerina connector repository](https://github.com/ballerina-platform/ballerinax-openapi-connectors)
## Useful links
- Discuss code changes of the Ballerina project in [[email protected]](mailto:[email protected]).
- Chat live with us via our [Slack channel](https://ballerina.io/community/slack/).
- Post all technical questions on Stack Overflow with the [#ballerina](https://stackoverflow.com/questions/tagged/ballerina) tag
153 changes: 153 additions & 0 deletions openapi/cloudmersive.barcode/client.bal
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
// Copyright (c) 2021 WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
//
// WSO2 Inc. licenses this file to you under the Apache License,
// Version 2.0 (the "License"); you may not use this file except
// in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

import ballerina/http;

# Please visit [here](https://account.cloudmersive.com/keys) to get more information on obtaining API key
#
# + apiKeys - Provide your API Key as `Apikey`. Eg: `{"Apikey" : "<API Key>}`"
public type ApiKeysConfig record {
map<string> apiKeys;
};

# Barcode APIs let you generate barcode images, and recognize values from images of barcodes.
#
# + clientEp - Connector http endpoint
public client class Client {
http:Client clientEp;
map<string> apiKeys;
# Client initialization.
#
# + apiKeyConfig - API key configuration detail
# + clientConfig - Client configuration details
# + serviceUrl - Connector server URL
# + return - Error at failure of client initialization
public isolated function init(ApiKeysConfig apiKeyConfig, http:ClientConfiguration clientConfig = {}, string serviceUrl = "https://testapi.cloudmersive.com/") returns error? {
http:Client httpEp = check new (serviceUrl, clientConfig);
self.clientEp = httpEp;
self.apiKeys = apiKeyConfig.apiKeys;
}
# Lookup EAN barcode value, return product data
#
# + payload - Barcode value
# + return - OK
remote isolated function barcodeEanLookup(string payload) returns BarcodeLookupResponse|error {
string path = string `/barcode/lookup/ean`;
map<any> headerValues = {Apikey: self.apiKeys["Apikey"]};
map<string|string[]> accHeaders = getMapForHeaders(headerValues);
http:Request request = new;
json jsonBody = check payload.cloneWithType(json);
request.setPayload(jsonBody);
BarcodeLookupResponse response = check self.clientEp->post(path, request, headers = accHeaders, targetType=BarcodeLookupResponse);
return response;
}
# Scan and recognize an image of a barcode
#
# + payload - The image file to scan
# + return - OK
remote isolated function barcodeScanImage(Body payload) returns BarcodeScanResult|error {
string path = string `/barcode/scan/image`;
map<any> headerValues = {Apikey: self.apiKeys["Apikey"]};
map<string|string[]> accHeaders = getMapForHeaders(headerValues);
http:Request request = new;
BarcodeScanResult response = check self.clientEp->post(path, request, headers = accHeaders, targetType=BarcodeScanResult);
return response;
}
# Generate a QR code barcode as PNG file
#
# + payload - QR code text to convert into the QR code barcode
# + return - OK
remote isolated function generateBarcodeQrcode(string payload) returns string|error {
string path = string `/barcode/generate/qrcode`;
map<any> headerValues = {Apikey: self.apiKeys["Apikey"]};
map<string|string[]> accHeaders = getMapForHeaders(headerValues);
http:Request request = new;
json jsonBody = check payload.cloneWithType(json);
request.setPayload(jsonBody);
string response = check self.clientEp->post(path, request, headers = accHeaders, targetType=string);
return response;
}
# Generate a UPC-A code barcode as PNG file
#
# + payload - UPC-A barcode value to generate from
# + return - OK
remote isolated function generateBarcodeUpca(string payload) returns string|error {
string path = string `/barcode/generate/upc-a`;
map<any> headerValues = {Apikey: self.apiKeys["Apikey"]};
map<string|string[]> accHeaders = getMapForHeaders(headerValues);
http:Request request = new;
json jsonBody = check payload.cloneWithType(json);
request.setPayload(jsonBody);
string response = check self.clientEp->post(path, request, headers = accHeaders, targetType=string);
return response;
}
# Generate a UPC-E code barcode as PNG file
#
# + payload - UPC-E barcode value to generate from
# + return - OK
remote isolated function generateBarcodeUpce(string payload) returns string|error {
string path = string `/barcode/generate/upc-e`;
map<any> headerValues = {Apikey: self.apiKeys["Apikey"]};
map<string|string[]> accHeaders = getMapForHeaders(headerValues);
http:Request request = new;
json jsonBody = check payload.cloneWithType(json);
request.setPayload(jsonBody);
string response = check self.clientEp->post(path, request, headers = accHeaders, targetType=string);
return response;
}
# Generate a EAN-13 code barcode as PNG file
#
# + payload - Barcode value to generate from
# + return - OK
remote isolated function generateBarcodeEan13(string payload) returns string|error {
string path = string `/barcode/generate/ean-13`;
map<any> headerValues = {Apikey: self.apiKeys["Apikey"]};
map<string|string[]> accHeaders = getMapForHeaders(headerValues);
http:Request request = new;
json jsonBody = check payload.cloneWithType(json);
request.setPayload(jsonBody);
string response = check self.clientEp->post(path, request, headers = accHeaders, targetType=string);
return response;
}
# Generate a EAN-8 code barcode as PNG file
#
# + payload - Barcode value to generate from
# + return - OK
remote isolated function generateBarcodeEan8(string payload) returns string|error {
string path = string `/barcode/generate/ean-8`;
map<any> headerValues = {Apikey: self.apiKeys["Apikey"]};
map<string|string[]> accHeaders = getMapForHeaders(headerValues);
http:Request request = new;
json jsonBody = check payload.cloneWithType(json);
request.setPayload(jsonBody);
string response = check self.clientEp->post(path, request, headers = accHeaders, targetType=string);
return response;
}
}

# Generate header map for given header values.
#
# + headerParam - Headers map
# + return - Returns generated map or error at failure of client initialization
isolated function getMapForHeaders(map<any> headerParam) returns map<string|string[]> {
map<string|string[]> headerMap = {};
foreach var [key, value] in headerParam.entries() {
if value is string || value is string[] {
headerMap[key] = value;
}
}
return headerMap;
}
Loading

0 comments on commit 322d345

Please sign in to comment.