Skip to content

Commit 56ddc45

Browse files
author
Ilya Nevolin
committed
initial code
0 parents  commit 56ddc45

File tree

8 files changed

+674
-0
lines changed

8 files changed

+674
-0
lines changed

.gitignore

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Ignore Gradle project-specific cache directory
2+
.gradle/
3+
4+
# Ignore Gradle build output directory
5+
build/
6+
7+
lib/
8+
9+
.properties
10+
11+
12+
gradle*

README.md

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# Spurwing API Java Library
2+
3+
Lightweight Java library for Spurwing's API.
4+
5+
Spurwing's API makes it easy to add robust scheduling and booking to your application. We power millions of appointment bookings for thousands of companies, from marketplaces to SaaS & healthcare.
6+
7+
## Account
8+
To use this API you need to obtain API credentials by signin up here: https://spurwing.io/
9+
10+
On your dashboard you will have the "API Info" page with your **API key** and **Provider ID**.
11+
12+
- **API Key:** This is your private API Key used for private and authorized operations.
13+
14+
- **Provider ID:** This is your public calendar identifier.
15+
16+
**Security Warning:** Never expose your **API Key** in front-end javascript code. All implementations that require your API Key should be handled by your back-end in a secure environment.
17+
18+
## Usage
19+
20+
You need to provide the Provider ID and API key in the project.
21+
22+
You can use `Client` Class Object for Calling Available Methods. For every method, You need to pass some arguments. You can use it as such:
23+
```java
24+
import spurwing.util.Client;
25+
import spurwing.util.settings.Credentials; // if you use the properties file
26+
27+
String types = Client.get_appointment_types(PID);
28+
...
29+
String days = Client.get_days_available(PID, appointment_type_id, date, null, null);
30+
...
31+
```
32+
33+
Please above details should be written in Credentials.java file for reusability purpose.
34+
35+
## Documentation
36+
37+
The currently implemented API functions and features are:
38+
39+
- get_appointment_types
40+
- get_days_available
41+
- get_slots_available
42+
- complete_booking
43+
- list_appointments
44+
- delete_appointment
45+
46+
For additional demos and use cases have a look under `test/Test.java`
47+
48+
Spurwing's REST API Reference and Docs: https://docs.spurwing.io/
49+
50+
## Testing
51+
To run our predefined unit tests use the `test/Test.java` script. But you do need to provide the API tokens (using Environment Variables or the properties file):
52+
53+
Environment variables:
54+
- `SPURWING_KEY` your secret API key
55+
- `SPURWING_PID` your provider ID
56+
57+
`.properties` file in the root the project:
58+
```
59+
KEY=change_me
60+
PID=change_me
61+
```
62+
63+
## Support
64+
- For public issues and bugs please use the GitHub Issues Page.
65+
- For enquiries and private issues reach out to us at support@spurwing.io
66+
- Join our Discord Community Server: https://discord.gg/j3gd5Qk5uW

build.gradle

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
apply plugin:'java'
2+
apply plugin:'application'
3+
4+
5+
repositories {
6+
mavenCentral()
7+
}
8+
9+
dependencies {
10+
// https://mvnrepository.com/artifact/org.json/json
11+
implementation group: 'org.json', name: 'json', version: '20210307'
12+
13+
}
14+
15+
mainClassName = 'test.Test'

settings.gradle

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/*
2+
* This file was generated by the Gradle 'init' task.
3+
*
4+
* The settings file is used to specify which projects to include in your build.
5+
*
6+
* Detailed information about configuring a multi-project build in Gradle can be found
7+
* in the user manual at https://docs.gradle.org/6.8.3/userguide/multi_project_builds.html
8+
*/
9+
10+
rootProject.name = 'Spurwing-API-Java-Library'
11+
include('lib')
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
package spurwing.util;
2+
import java.io.IOException;
3+
import java.util.HashMap;
4+
import java.util.Map;
5+
import org.json.*;
6+
7+
public class Client {
8+
static String API_URL = "https://api.spurwing.io/api/v2/";
9+
10+
// List all Appointment Type Categories
11+
static public String get_appointment_types(String provider_id) throws IOException {
12+
String url = API_URL + "appointment_types.json";
13+
Map<String, String> params = new HashMap<String, String>();
14+
if (provider_id != null) params.put("provider_id", provider_id);
15+
url = HttpUtil.appendQueryParams(url, params);
16+
return HttpUtil.get(url);
17+
}
18+
19+
// List all days, in a given month, that have availability in them.
20+
static public String get_days_available(String provider_id,
21+
String appointment_type_id,
22+
String date_from_month,
23+
String timezone,
24+
String org_level) throws IOException {
25+
String url = API_URL + "bookings/days_available.json";
26+
Map<String, String> params = new HashMap<String, String>();
27+
if (provider_id != null) params.put("provider_id", provider_id);
28+
if (appointment_type_id != null) params.put("appointment_type_id", appointment_type_id);
29+
if (date_from_month != null) params.put("date_from_month", date_from_month);
30+
if (timezone != null) params.put("timezone", timezone);
31+
if (org_level != null) params.put("org_level", org_level);
32+
url = HttpUtil.appendQueryParams(url, params);
33+
return HttpUtil.get(url);
34+
}
35+
36+
static public String get_slots_available(String provider_id,
37+
String appointment_type_id,
38+
String start_date,
39+
String end_date,
40+
String org_level) throws IOException {
41+
String url = API_URL + "bookings/slots_available.json";
42+
Map<String, String> params = new HashMap<String, String>();
43+
if (provider_id != null) params.put("provider_id", provider_id);
44+
if (appointment_type_id != null) params.put("appointment_type_id", appointment_type_id);
45+
if (start_date != null) params.put("start_date", start_date);
46+
if (end_date != null) params.put("end_date", end_date);
47+
if (org_level != null) params.put("org_level", org_level);
48+
url = HttpUtil.appendQueryParams(url, params);
49+
return HttpUtil.get(url);
50+
}
51+
52+
53+
54+
static public String complete_booking(String provider_id,
55+
String appointment_type_id,
56+
String date,
57+
String timezone,
58+
String first_name,
59+
String last_name,
60+
String email,
61+
String phone_number,
62+
String contact_type) throws IOException, JSONException {
63+
String url = API_URL + "bookings/complete_booking.json";
64+
JSONObject params = new JSONObject();
65+
Map<String, String> headers = new HashMap<String, String>();
66+
67+
if (provider_id != null) params.put("provider_id", provider_id);
68+
if (appointment_type_id != null) params.put("appointment_type_id", appointment_type_id);
69+
if (date != null) params.put("date", date);
70+
if (timezone != null) params.put("timezone", timezone);
71+
if (first_name != null) params.put("first_name", first_name);
72+
if (last_name != null) params.put("last_name", last_name);
73+
if (email != null) params.put("email", email);
74+
if (phone_number != null) params.put("phone_number", phone_number);
75+
if (contact_type != null) params.put("contact_type", contact_type);
76+
return HttpUtil.postJson(url, params.toString(), headers);
77+
}
78+
79+
public static String list_appointments(String authorization, String page_size, String offset, String provider_id) throws IOException {
80+
String url = API_URL + "appointments/";
81+
Map<String, String> params = new HashMap<String, String>();
82+
Map<String, String> params_1 = new HashMap<String, String>();
83+
if (provider_id != null) params.put("provider_id", provider_id);
84+
params_1.put("authorization", "Bearer " + authorization);
85+
if (page_size != null) params.put("page_size", page_size);
86+
if (offset != null) params.put("offset", offset);
87+
url = HttpUtil.appendQueryParams(url, params);
88+
return HttpUtil.get(url, params_1);
89+
}
90+
91+
public static String delete_appointment(String authorization, String appointment_id) throws IOException{
92+
String url = API_URL + "appointments/" + appointment_id;
93+
Map<String, String> params_1 = new HashMap<String, String>();
94+
params_1.put("authorization", "Bearer " + authorization);
95+
return HttpUtil.delete(url, params_1);
96+
}
97+
}

0 commit comments

Comments
 (0)