Guest User

Untitled

a guest
Jun 25th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.36 KB | None | 0 0
  1. curl -X DELETE https://my.firebase.io/users/bob.json?auth=my-secret
  2.  
  3. def client = new RESTClient('https://my.firebase.io/users/bob.json?auth=my-secret')
  4. def response = client.delete(requestContentType: ContentType.ANY)
  5.  
  6. def client = new RESTClient('https://my.firebase.io')
  7.  
  8. def response = client.delete(
  9. requestContentType: ContentType.ANY,
  10. path: '/users/bob.json',
  11. query: [auth: 'my-secret']
  12. )
  13.  
  14. def http = new HTTPBuilder('https://my.firebase.io')
  15.  
  16. // perform a POST request, expecting TEXT response
  17. http.request(Method.DELETE, ContentType.ANY) {
  18. uri.path = '/users/bob.json'
  19. uri.query = [auth: 'my-secret']
  20.  
  21. // response handler for a success response code
  22. response.success = { resp, reader ->
  23. println "response status: ${resp.statusLine}"
  24. }
  25. }
  26.  
  27. def http = new HttpURLClient(url:'https://some/path/')
  28. resp = http.request(method:DELETE, contentType:JSON, path: "destroy/somewhere.json")
  29. def json = resp.data
  30. assert json.id != null
  31. assert resp.statusLine.statusCode == 200
  32.  
  33. def createClient() {
  34. HttpParams params = new BasicHttpParams()
  35. HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1)
  36. HttpProtocolParams.setContentCharset(params, "UTF-8")
  37. params.setBooleanParameter(ClientPNames.HANDLE_REDIRECTS, true)
  38.  
  39. SchemeRegistry registry = new SchemeRegistry()
  40. registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80))
  41.  
  42. ClientConnectionManager ccm = new PoolingClientConnectionManager(registry)
  43. HttpConnectionParams.setConnectionTimeout(params, 8000)
  44. HttpConnectionParams.setSoTimeout(params, 5400000)
  45. HttpClient client = new DefaultHttpClient(ccm, params)
  46.  
  47. return client
  48. }
  49.  
  50. HttpClient client = createClient()
  51. def url = new URL("http", host, Integer.parseInt(port), "/dyn/admin/nucleus$component/")
  52. HttpDelete delete = new HttpDelete(url.toURI())
  53. // if you have any basic auth, you can plug it in here
  54. def auth="USER:PASS"
  55. delete.setHeader("Authorization", "Basic ${auth.getBytes().encodeBase64().toString()}")
  56.  
  57. // convert a data map to NVPs
  58. def data = [:]
  59. List<NameValuePair> nvps = new ArrayList<NameValuePair>(data.size())
  60. data.each { name, value ->
  61. nvps.add(new BasicNameValuePair(name, value))
  62. }
  63.  
  64. delete.setEntity(new UrlEncodedFormEntity(nvps))
  65.  
  66. HttpResponse response = client.execute(delete)
  67. def status = response.statusLine.statusCode
  68. def content = response.entity.content
Add Comment
Please, Sign In to add comment