Skip to content

Commit

Permalink
Add sandbox sample code (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
gitmai authored Dec 11, 2024
1 parent 716b2d7 commit 0031f2b
Show file tree
Hide file tree
Showing 4 changed files with 129 additions and 46 deletions.
45 changes: 45 additions & 0 deletions catalog/devicelocation/samplecode_devicelocation.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,18 @@ First step is to instantiate the DeviceLocation service class included in the co

Since Open Gateway authorization is 3-legged, meaning it identifies the application, the operator and the operator's subscriber, who is also the end-user holder of the mobile line, each check for a different phone number needs its own SDK class instantiation, or access token if not using an SDK.

```python Sandbox SDK for Python
from opengateway_sandbox_sdk import ClientCredentials, DeviceLocation

credentials = ClientCredentials(
client_id='yout_client_id',
client_secret='your_client_secret'
)

customer_phone_number = "+34666666666"

devicelocation_client = DeviceLocation(credentials=credentials, phone_number=customer_phone_number)
```
```python Sample SDK for Python
from aggregator_opengateway_sdk import ClientCredentials, DeviceLocation

Expand Down Expand Up @@ -255,6 +267,11 @@ access_token = response.json().get("access_token")
```

#### API usage
```python Sandbox SDK for Python
result = devicelocation_client.verify(40.5150, -3.6640, 10, customer_phone_number) # as set in the authorization step

print (f"Is the device in location? {result}")
```
```python Sample SDK for Python
result = devicelocation_client.verify(40.5150, -3.6640, 10, customer_phone_number) # as set in the authorization step

Expand Down Expand Up @@ -466,6 +483,27 @@ fetch(url, requestOptions);

Samples represent how to publish the callback URL in Python or Node.js, so the code from the Auth Code Flow can be received. The same can be achieved in any other language with capabilities to run an HTTP server and listen for the redirect from the authorization flow:

```python Sandbox SDK for Python
from flask import Flask, request, jsonify
from opengateway_sandbox_sdk import ClientCredentials, DeviceLocation

credentials = ClientCredentials(
clientid='my-app-id',
clientsecret='my-app-secret'
)

app = Flask(__name__)

@app.route('/device-location-callback', methods=['GET'])
def callback():
code = request.args.get('code', '')
state = request.args.get('state', '')

devicelocation_client = DeviceLocation(credentials=credentials, code=code)

if __name__ == '__main__':
app.run()
```
```python Sample SDK for Python
from flask import Flask, request, jsonify
from aggregator_opengateway_sdk import ClientCredentials, DeviceLocation
Expand Down Expand Up @@ -585,6 +623,13 @@ app.listen(port, () => {

Once your app is authenticated it only takes a single line of code to use the service API and effectively get a result.

```python Sandbox SDK for Python
data = json.loads(state)

result = await device_client.verify(data['latitude'], data['longitude'], data['accuracy'], data['phone_number'])

print(f"Is the device in location? {result}")
```
```python Sample SDK for Python
data = json.loads(state)

Expand Down
25 changes: 25 additions & 0 deletions catalog/numberverification/samplecode_numberverification.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,26 @@ As the opposite to the flow triggering, this API consumption flow will always co

Samples represent how to publish the callback URL in Python or Node.js, so the code from the Auth Code Flow can be received. The same can be achieved in any other language with capabilities to run an HTTP server and listen for the redirect from the authentication flow:

```python Sandbox SDK for Python
from flask import Flask, request, jsonify
from opengateway_sandbox_sdk import ClientCredentials, NumberVerification

credentials = ClientCredentials(
clientid='my-app-id',
clientsecret='my-app-secret'
)

app = Flask(__name__)

@app.route('/numberverification-callback', methods=['GET'])
def callback():
code = request.args.get('code', '')
phone_number = request.args.get('state', '')
api_client = NumberVerification(credentials, code)

if __name__ == '__main__':
app.run()
```
```python Sample SDK for Python
from flask import Flask, request, jsonify
from aggregator_opengateway_sdk import ClientCredentials, NumberVerification
Expand Down Expand Up @@ -230,6 +250,11 @@ app.listen(port, () => {

Once your app is authenticated it only takes a single line of code to use the service API and effectively get a result.

```python Sandbox SDK for Python
result = await api_client.verify(phone_number)

print(f"Phone number {'verified' if result else 'does not match mobile line'}")
```
```python Sample SDK for Python
result = await api_client.verify(phone_number)

Expand Down
62 changes: 18 additions & 44 deletions catalog/qod/samplecode_qod.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ First step is to instantiate the Quality on Demand service class included in the

Since Open Gateway authentication is 3-legged, meaning it identifies the application, the operator and the operator's mobile line providing the device with connectivity, each operation on a different device needs its own SDK class instantiation with its IP address, or access token if not using an SDK.

##### [TAB] SDK for Node.js
```Node
```node Sample SDK for Node.js
import { QoDMobile, ClientCredentials, QoSProfiles } from "aggregator/opengateway-sdk"

const credentials: ClientCredentials(
Expand All @@ -55,8 +54,7 @@ let deviceIpPortAddress = getDeviceIP() // e.g. '203.0.113.25:8080'
const qodClient = new QoDMobile(credentials, null, deviceIpPortAddress)
```

##### [TAB] SDK for Java
```Java
```java Sample SDK for Java
import aggregator.opengatewaysdk.ClientCredentials;
import aggregator.opengatewaysdk.QoDMobile;
import aggregator.opengatewaysdk.QoSProfiles;
Expand All @@ -71,8 +69,7 @@ String deviceIpPortAddress = this.getDeviceIP(); // e.g. "203.0.113.25:8080"
QoDMobile qodClient = new QoDMobile(credentials, null, deviceIpPortAddress);
```

##### [TAB] SDK for Python
```Python
```python Sample SDK for Python
from aggregator_opengateway_sdk import QoDMobile, ClientCredentials, QoSProfiles

credentials = ClientCredentials(
Expand All @@ -85,8 +82,7 @@ device_ip_address = self.get_device_ip() # e.g. '203.0.113.25:8080'
qod_client = QoDMobile(client=credentials, ip_address=device_ip_address)
```

##### [TAB] HTTP using JavaScript (ES6)
```JavaScript
```ecmascript HTTP using JavaScript (ES6)
// First step:
// Perform an authorization request
Expand Down Expand Up @@ -145,8 +141,7 @@ fetch("https://opengateway.aggregator.com/token", requestOptions)
})
```

##### [TAB] HTTP using Java
```Java
```java HTTP using Java
// First step:
// Perform an authorization request

Expand Down Expand Up @@ -214,8 +209,7 @@ JSONObject jsonResponse = new JSONObject(response.body());
String accessToken = jsonResponse.getString("access_token");
```

##### [TAB] HTTP using Python
```Python
```python Sample HTTP using Python
# First step:
# Perform an authorization request

Expand Down Expand Up @@ -272,29 +266,22 @@ access_token = response.json().get("access_token")
Once your app is authenticated it only takes a single line of code to use the service API and effectively optimize device connectivity.


##### [TAB] SDK for Node.js
```Node
```node Sample SDK for Node.js
const duration = 300 // Seconds

qodClient.setQualityOfService(duration, QoSProfiles.QOS_E)
```

##### [TAB] SDK for Java
```Java
```java Sample SDK for Java
int duration = 300; // Seconds

qodClient.setQualityOfService(duration, QoSProfiles.QOS_E);
```

##### [TAB] SDK for Python
```Python
```python Sample SDK for Python
duration = 300 # Seconds

qod_client.set_quality(duration, QoSProfiles.QOS_E)
```

##### [TAB] HTTP using JavaScript (ES6)
```JavaScript
```ecmascript HTTP using Javascript(ES6)
const myHeaders = new Headers();
myHeaders.append("Content-Type", "application/json");
myHeaders.append("Authorization", `Bearer ${accessToken}`);
Expand Down Expand Up @@ -325,9 +312,7 @@ fetch("https://opengateway.aggregator.com/qod/v0/sessions", requestOptions)
console.log(`Session created with id: ${result.sessionId}`)
})
```

##### [TAB] HTTP using Java
```Java
```java HTTP using Java
JSONObject requestBody = new JSONObject();
JSONObject device = new JSONObject();
JSONObject ipv4Address = new JSONObject();
Expand All @@ -354,9 +339,7 @@ String sessionId = jsonResponse.getString("sessionId");

System.out.println("Session created with id: " + sessionId);
```

##### [TAB] HTTP using Python
```Python
```python HTTP with Python
headers = {
"Content-Type": "application/json",
"Authorization": f"Bearer {access_token}"
Expand Down Expand Up @@ -399,8 +382,7 @@ You can check the CAMARA documentation on this flow [here](https://github.com/ca

The following samples show how your application can trigger the authentication flow from the frontend either from code or by submitting a simple HTML form. The same can be achieved from code in any other programming language with the ability to perform HTTP requests:

##### [TAB] HTTP using JavaScript (ES6)
```JavaScript
```ecmascript HTTP using JavaScript (ES6)
let clientId = "my-app-id";
let clientSecret = "my-app-secret";
let apiScope = "dpv:RequestedServiceProvision#qod";
Expand All @@ -426,9 +408,7 @@ const requestOptions = {
fetch(url, requestOptions);
```

##### [TAB] HTML form
```HTML
```html HTML form
<!--
In this example you need your auth callback URL to continue the flow calling the service API
and providing an HTML response to be shown in the web browser displaying the result.
Expand Down Expand Up @@ -461,8 +441,7 @@ fetch(url, requestOptions);

Samples represent how to publish the auth callback URL in Python or Node.js, so the code from the Auth Code Flow can be received. The same can be achieved in any other language with capabilities to run an HTTP server and listen for the redirect from the authentication flow:

##### [TAB] SDK for Python
```Python
```python Sample SDK for Python
from flask import Flask, request, jsonify
from aggregator_opengateway_sdk import ClientCredentials, QoDMobile, QoSProfiles

Expand All @@ -481,9 +460,7 @@ def auth_callback():
if __name__ == '__main__':
app.run()
```

##### [TAB] SDK for Node.js
```Node
```node Sample SDK for Node.js
import { ClientCredentials, QoDMobile } from "aggregator/opengateway-sdk"
import express from "express"

Expand Down Expand Up @@ -511,16 +488,13 @@ Once we have instantiated the SDK class with the authorization code received fro

For that, still in the code of the auth callback URL endpoint listener, following to the QoDMobile class instantiation, follow the samples below:

##### [TAB] SDK for Python
```Python
```python Sample SDK for Python
ip = request.remote_addr
port = request.environ.get('REMOTE_PORT')

qod_client.set_quality(300, QoSProfiles.QOS_E, client_ip=ip, client_port=port)
```

##### [TAB] SDK for Node.js
```Node
```node Sample SDK for Node.js
const ip = req.ip
const port = req.socket.remotePort

Expand Down
43 changes: 41 additions & 2 deletions catalog/simswap/samplecode_simswap.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@ First step is to instantiate the SIM Swap service class included in the correspo

Since Open Gateway authorization is 3-legged, meaning it identifies the application, the operator and the operator's subscriber, who is also the end-user holder of the mobile line, each check for a different phone number needs its own SDK class instantiation, or access token if not using an SDK.

```python Sandbox SDK for Python
from opengateway_sandbox_sdk import ClientCredentials, Simswap

client_id='my-app-id',
client_secret='my-app-secret'
customer_phone_number = '+34555555555'

simswap_client = Simswap(app_client_id, app_client_secret, customer_phone_number)
```
```python Sample SDK for Python
from aggregator_opengateway_sdk import ClientCredentials, SimSwap

Expand Down Expand Up @@ -258,6 +267,11 @@ access_token = response.json().get("access_token")

Once your app is authenticated it only takes a single line of code to use the service API and effectively get a result.

```python Sandbox SDK for Python
result = simswap_client.retrieve_date()

print(f"SIM was swapped: {result.strftime('%B %d, %Y, %I:%M:%S %p')}")
```
```python Sample SDK for Python
result = simswap_client.retrieve_date()

Expand Down Expand Up @@ -420,9 +434,29 @@ fetch(url, requestOptions);

Samples represent how to publish the callback URL in Python or Node.js, so the code from the Auth Code Flow can be received. The same can be achieved in any other language with capabilities to run an HTTP server and listen for the redirect from the authorization flow:

```python Sandbox SDK for Python
from flask import Flask, request, jsonify
from opengateway_sandbox_sdk import ClientCredentials, Simswap

credentials = ClientCredentials(
clientid='my-app-id',
clientsecret='my-app-secret'
)

app = Flask(__name__)

@app.route('/simswap-callback', methods=['GET'])
def callback():
code = request.args.get('code', '')
phone_number = request.args.get('state', '')
simswap_client = Simswap(client=credentials, auth_code=code)

if __name__ == '__main__':
app.run()
```
```python Sample SDK for Python
from flask import Flask, request, jsonify
from aggregator_opengateway_sdk import ClientCredentials, SIMSwap
from aggregator_opengateway_sdk import ClientCredentials, SimSwap

credentials = ClientCredentials(
clientid='my-app-id',
Expand All @@ -435,7 +469,7 @@ app = Flask(__name__)
def callback():
code = request.args.get('code', '')
phone_number = request.args.get('state', '')
simswap_client = SIMSwap(client=credentials, auth_code=code)
simswap_client = SimSwap(client=credentials, auth_code=code)

if __name__ == '__main__':
app.run()
Expand Down Expand Up @@ -540,6 +574,11 @@ app.listen(port, () => {

Once your app is authenticated it only takes a single line of code to use the service API and effectively get a result.

```python Sandbox SDK for Python
result = await simswap_client.retrieve_date(phone_number)

print(f"SIM was swapped: {result.strftime('%B %d, %Y, %I:%M:%S %p')}")
```
```python Sample SDK for Python
result = await simswap_client.retrieve_date(phone_number)

Expand Down

0 comments on commit 0031f2b

Please sign in to comment.