Skip to content

Instantly share code, notes, and snippets.

@antoine-lizee
Created April 25, 2016 00:35
Show Gist options
  • Save antoine-lizee/741a6e492f4133179f1ee7ac123c519d to your computer and use it in GitHub Desktop.
Save antoine-lizee/741a6e492f4133179f1ee7ac123c519d to your computer and use it in GitHub Desktop.
## claim_queries.R
# Quick R-script to test the claim API built by
# Andrew.
# Setup -------------------------------------------------------------------
# Library
library(httr)
# Constants
base_url <- "https://glacial-ridge-73115.herokuapp.com/"
external_key <- "abc123"
internal_key <- "abc123internal"
# Test ------------------------------------------------------
# Get a couple of random claims
r <- httr::POST(url = sprintf("%s%s", base_url, "search"),
add_headers('X-Api-Key' = internal_key),
encode = "json",
body = list(query = list(provider_id = 77)), # result_types = "claim" fails, because not an array,
verbose())
str(claims <- httr::content(r))
# Get one claim (not possible to know the id! had to guess :-), but 1 work)
r <- httr::GET(url = sprintf("%s%s/%d", base_url, "claims", 1),
add_headers('X-Api-Key' = internal_key),
verbose())
httr::content(r)
# Try the same without the right permissions
r <- httr::GET(url = sprintf("%s%s/%d", base_url, "claims", 1),
add_headers('X-Api-Key' = external_key),
verbose())
r$status_code # 401 -> okay
# Submit a new submission
r <- httr::POST(url = sprintf("%s%s", base_url, "submissions"),
add_headers('X-Api-Key' = external_key),
encode = "json",
body = list(
submission = list(insured_id = 42,
provider_id = 101,
services =
list(list(code = "e34",
cost = 5.65,
date = Sys.time())))),
verbose())
httr::content(r)
# Update the claim status
httr::PATCH(url = sprintf("%s%s/%d", base_url, "claims", 7),
encode = "json",
add_headers('X-Api-Key' = internal_key),
body = list("claim" = list(status = "processed")),
verbose())
# See the result -> No service? failing silently again :-/
r <- httr::GET(url = sprintf("%s%s/%d", base_url, "claims", 7),
add_headers('X-Api-Key' = internal_key),
body = list("claim" = list(status = "in_process")),
verbose())
httr::content(r)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment