Skip to content

Instantly share code, notes, and snippets.

@stursby
Last active August 29, 2015 14:09
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stursby/0e6bb16dce440c8c3052 to your computer and use it in GitHub Desktop.
Save stursby/0e6bb16dce440c8c3052 to your computer and use it in GitHub Desktop.
↩️ Hooks (http://hooks.events)
// by @itskathuria
NSURL *url = [NSURL URLWithString:@"http://hooks.events/hooks/post.php"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[request setHTTPMethod:@"POST"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
NSString *apiKey = @"yourAPIKeyShouldGoHere";
NSString *title = @"yourTitleShouldGoHere";
NSString *message = @"yourMessageShouldGoHere";
NSString *query = [NSString stringWithFormat:@"hooksTitle=%@&hooksMessage=%@&hooksApi=%@", title, message, apiKey];
NSData *data = [query dataUsingEncoding:NSUTF8StringEncoding];
[request setHTTPBody:data];
[NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
NSLog(@"responseData: %@, error: %@: responseItself: %@", data, connectionError, response);
}];
<?php
$data = [
'hooksTitle' => 'Hello world',
'hooksMessage' => 'I happen to exist as a PHP message',
'hooksApi' => 'YOUR API KEY' // http://hooks.events/
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://hooks.events/hooks/post.php');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_exec($ch);
curl_close ($ch);
#!/usr/bin/python
import urllib
import urllib2
data = {
'hooksTitle' : 'Hello world',
'hooksMessage' : 'I happen to exist as a Python message',
'hooksApi' : 'YOUR API KEY' # http://hooks.events/
}
url = 'http://hooks.events/hooks/post.php'
req = urllib2.Request(url, urllib.urlencode(data))
urllib2.urlopen(req)
require 'net/http'
require 'uri'
data = {
'hooksTitle' => 'Hello World',
'hooksMessage' => 'I happen to exist as a Ruby message',
'hooksApi' => 'YOUR API KEY' # http://hooks.events/
}
uri = URI.parse('http://hooks.events/hooks/post.php')
http = Net::HTTP.new(uri.host, uri.port)
request = Net::HTTP::Post.new(uri.request_uri)
request.set_form_data(data)
http.request(request)
// Uncomment if running in a Playground
// import XCPlayground
// XCPSetExecutionShouldContinueIndefinitely()
let url = NSURL(string: "http://hooks.events/hooks/post.php")
let request = NSMutableURLRequest(URL: url)
request.HTTPMethod = "POST"
request.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")
let title = "Hello World"
let message = "I happen to exist as a Swift message"
let api = "YOUR API KEY" // http://hooks.events/
let raw = "hooksTitle=\(title)&hooksMessage=\(message)&hooksApi=\(api)"
let data = (raw as NSString).dataUsingEncoding(NSUTF8StringEncoding)
request.HTTPBody = data
NSURLConnection.sendAsynchronousRequest(request, queue: NSOperationQueue.mainQueue()) {(response, data, error) in
println(NSString(data: data, encoding: NSUTF8StringEncoding))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment