Skip to content

Commit

Permalink
[0.1.0-rc.1] - Initial Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
RikkertTheDeveloper committed May 15, 2023
0 parents commit cf984ae
Show file tree
Hide file tree
Showing 13 changed files with 190 additions and 0 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Rust

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

env:
CARGO_TERM_COLOR: always

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Rust Cache
uses: Swatinem/rust-cache@v2.2.1
- name: Build
run: cargo build --verbose
- name: Run tests
run: cargo test --verbose

3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/target
/.vscode
Cargo.lock
23 changes: 23 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[package]
name = "multisafepay-rust-sdk"
version = "0.1.0"
edition = "2021"
authors = ["Rick Arendsen"]
readme = "README.md"
repository = "https://github.com/rikkertthedeveloper/multisafepay-rust-sdk"
keywords = ["multisafepay", "ecommerce"]

[dependencies]
minreq = { version = "2.8.0", features = ["https"] }

[dev-dependencies]
pretty_assertions = "1"

[profile.release]
panic = "unwind"
opt-level = 3

[profile.production]
inherits = "release"
lto = true
codegen-units = 1
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<p align="center">
<img src="https://camo.githubusercontent.com/517483ae0eaba9884f397e9af1c4adc7bbc231575ac66cc54292e00400edcd10/68747470733a2f2f7777772e6d756c7469736166657061792e636f6d2f66696c6561646d696e2f74656d706c6174652f696d672f6d756c7469736166657061792d6c6f676f2d69636f6e2e737667" width="400px" position="center">
</p>

<h1 align="center">
<b>
<span style="color: #009fff">Rust Software</span>
<span style="color: #00005a">Development Kit</span>
</b>
</h1>

## Introduction to MultiSafePay
MultiSafepay is a Dutch payment services provider, which takes care of contracts, processing transactions, and collecting payment for a range of local and international payment methods. Start selling online today and manage all your transactions in one place!

## Installation
The MultiSafePay Rust SDK makes use of the "Cargo" toolchain included within rust itself, in order to locally build the library. Run the `cargo build --release` command in your terminal.

## Tests
The tests within this project can be ran with the `cargo test` command. This project has built-in tests for all classes associated with the libary.

### Offline testing
This library makes use of mockup data sites such as **DummyJSON** in order to test it's internal parsing tools. If you'd like to fully test offline, you can add the `--offline` flag to your `cargo test` command.
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
mod objects;
mod tests;
13 changes: 13 additions & 0 deletions src/objects/client.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
pub struct Client {
api_key: String,
}

impl Client {
pub fn new(api_key: String) -> Self {
Self { api_key }
}

pub fn verify(&self) -> bool {
!self.api_key.is_empty()
}
}
23 changes: 23 additions & 0 deletions src/objects/endpoint.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
pub struct Endpoint {
url: String,
api_key: String,
}

impl Endpoint {
pub fn new(url: String, api_key: String) -> Self {
Self { url, api_key }
}

pub fn format(&self) -> String {
assert!(self.verify(), "Failed to verify endpoint string.");
format!("{}?api-key={}", self.url, self.api_key)
}

fn verify_format(&self) -> bool {
self.url.is_empty() || !self.api_key.is_empty()
}

pub fn verify(&self) -> bool {
self.verify_format()
}
}
28 changes: 28 additions & 0 deletions src/objects/httpclient.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
use minreq::{self, Response, Error};

pub struct HttpClient {
url: String,
method: String,
}

impl HttpClient {
pub fn new(url: String, method: String) -> Self {
Self { url, method }
}

pub fn post(&self, payload: String) -> Result<String, Error> {
let response = minreq::post(self.url.to_owned())
.with_body(payload)
.send()?;

let parsed = response.as_str()?;
Ok(parsed.to_owned())
}

pub fn get(&self) -> Result<String, Error> {
let response: Response = minreq::get(self.url.to_owned()).send()?;
let parsed = response.as_str()?;

Ok(parsed.to_owned())
}
}
3 changes: 3 additions & 0 deletions src/objects/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pub(crate) mod endpoint;
pub(crate) mod client;
pub(crate) mod httpclient;
9 changes: 9 additions & 0 deletions src/tests/client_tests.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
use crate::objects::client::Client as Client;

#[test]
fn test_client_verification() {
let api_key = "my-api-key";
let my_client = Client::new(api_key.to_owned());

assert!(my_client.verify())
}
19 changes: 19 additions & 0 deletions src/tests/endpoint_tests.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
use crate::objects::endpoint::Endpoint as Endpoint;

#[test]
fn test_endpoint_formatting() {
let endpoint_url: &str = "https://my-url.com";
let endpoint_api_key: &str = "my-api-key";
let my_endpoint: Endpoint = Endpoint::new(endpoint_url.to_string(), endpoint_api_key.to_string());

assert_eq!(my_endpoint.format(), format!("{}?api-key={}", endpoint_url.clone(), endpoint_api_key.clone()));
}

#[test]
fn test_endpoint_verification() {
let endpoint_url: &str = "https://my-url.com";
let endpoint_api_key: &str = "my-api-key";
let my_endpoint: Endpoint = Endpoint::new(endpoint_url.to_string(), endpoint_api_key.to_string());

assert!(my_endpoint.verify())
}
12 changes: 12 additions & 0 deletions src/tests/http_client_tests.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
use crate::objects::httpclient::HttpClient as HttpClient;

#[test]
fn http_get_functionality() {
let endpoint_url = "https://dummyjson.com/test";
let endpoint_method = "GET";

let my_client = HttpClient::new(endpoint_url.to_owned(), endpoint_method.to_owned());
let http_result = my_client.get();

assert_ne!(http_result.unwrap(), "")
}
8 changes: 8 additions & 0 deletions src/tests/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#[cfg(test)]
mod client_tests;

#[cfg(test)]
mod endpoint_tests;

#[cfg(test)]
mod http_client_tests;

0 comments on commit cf984ae

Please sign in to comment.