Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.wellsmith;
- import io.restassured.response.Response;
- import org.json.JSONObject;
- import java.io.File;
- import static io.restassured.RestAssured.given;
- //import org.junit.Test;
- //import org.testng.annotations.BeforeTest;
- public class WellSmithApiCall {
- private static String BASE_URL = "https://staging.wellsmith.com";
- private String token;
- public WellSmithApiCall() {
- token = getAccessToken();
- }
- //Get the access token for API call
- private String getAccessToken() {
- JSONObject jsonObj = new JSONObject().put("password", "temp123!")
- //.put("Authorization","Basic R29saWF0aGFwcDpteVNlY3JldE9BdXRoU2VjcmV0")
- .put("grant_tye", "password")
- .put("scope", "read write")
- .put("username", "coachbridgit")
- .put("client_id", "Goliathapp")
- .put("client_secret", "mySecretOAuthSecret");
- Response resp =
- given()
- .accept("application/json")
- .header("Authorization", "Basic R29saWF0aGFwcDpteVNlY3JldE9BdXRoU2VjcmV0")
- .contentType("application/x-www-form-urlencoded")
- // .body(jsonObj.toString())
- .body("username=coachbridgit&password=temp123!&grant_type=password&scope=read%20write&client_secret=mySecretOAuthSecret&client_id=Goliathapp")
- .log().all()
- .when()
- .post("https://staging.wellsmith.com/oauth/token")
- .then()
- .log().all()
- .extract().response();
- String auth_token = resp.path("access_token").toString();
- System.out.println(auth_token);
- return auth_token;
- }
- //Get the current users account info
- public Response getAccounts() {
- return
- given()
- .accept("application/json")
- .header("Authorization", "Bearer" + getAccessToken())
- .log().all()
- .when()
- .get("https://staging.wellsmith.com/api/account")
- .then()
- .log().all()
- .extract().response();
- }
- //verify a new patient is created
- public Response getGetResponse(String path) {
- Response resp =
- given()
- .accept("application/json")
- .header("Authorization", "Bearer " + token)
- .contentType("application/json")
- .log().all()
- .when()
- .get(BASE_URL + path)
- .then()
- .log().all()
- .extract().response();
- return resp;
- }
- //Return the new patients
- public Response getPostResponse(String path, File file) {
- Response resp =
- given()
- .accept("application/json")
- .header("Authorization", "Bearer " + token)
- .contentType("application/json")
- .body(file)
- .log().all()
- .when()
- .post(BASE_URL + path)
- .then()
- .log().all()
- .extract().response();
- return resp;
- }
- //Get the playbook info
- public Response getGetPlaybook(String path) {
- Response resp =
- given()
- .accept("application/json")
- .header("Authorization", "Bearer " + token)
- .contentType("application/json")
- .log().all()
- .when()
- .get(BASE_URL + path)
- .then()
- .log().all()
- .extract().response();
- return resp;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement