Use a REST API: Difference between revisions

m
syntax highlighting fixup automation
m (Petelomax moved page Using the Meetup.com API to Use a REST API: A more generic task name)
m (syntax highlighting fixup automation)
Line 24:
<br>
Note that this version doesn't include code to submit events to Meetup.
<langsyntaxhighlight lang="go">package main
 
import (
Line 147:
fmt.Println("First event:\n", &evresp.Results[0])
}
}</langsyntaxhighlight>
{{out}}
<pre>
Line 163:
<br>
Note that this code is untested as you need a paid subscription to create events which I don't have.
<langsyntaxhighlight lang="go">package main
 
import (
Line 260:
check(err)
fmt.Printf("The %q event has been cancelled.\n", event.Name)
}</langsyntaxhighlight>
 
=={{header|Java}}==
Line 268:
EventGetter.java
 
<langsyntaxhighlight lang="java">package src;
 
import java.io.BufferedReader;
Line 326:
}
}</langsyntaxhighlight>
 
Main.java
<langsyntaxhighlight lang="java">/*
* In this class, You can see the diferent
* ways of asking for events.
Line 418:
}
 
}</langsyntaxhighlight>
 
=={{header|JavaScript}}==
Line 424:
Made on node js. Run using 'node filename.js'
 
<langsyntaxhighlight lang="javascript">var fs = require('fs');
var request = require('request');
 
Line 567:
}, function(result) {
console.log('Event: ', result);
})</langsyntaxhighlight>
 
=={{header|Phix}}==
Line 573:
Unfortunately the API (V2) does not support creating events, so instead this shows how to use
a post method to toggle sales (but see note below).
<!--<langsyntaxhighlight Phixlang="phix">(notonline)-->
<span style="color: #000080;font-style:italic;">--
-- demo\rosetta\Using_a_REST_API.exw
Line 681:
<span style="color: #000000;">res</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">toggle_sales</span><span style="color: #0000FF;">({</span><span style="color: #008000;">"eventid"</span><span style="color: #0000FF;">,</span><span style="color: #000000;">id</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"status"</span><span style="color: #0000FF;">,</span><span style="color: #000000;">status</span><span style="color: #0000FF;">},</span><span style="color: #008000;">"events/togglesales"</span><span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">puts</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #000000;">print_json</span><span style="color: #0000FF;">(</span><span style="color: #008000;">""</span><span style="color: #0000FF;">,</span><span style="color: #000000;">res</span><span style="color: #0000FF;">))</span>
<!--</langsyntaxhighlight>-->
Note that toggling sales off makes the (manually created) event invisible to the API, even without
the {"status","live"} filter, hence I had to hard-code the event id to permit a second run to turn
Line 746:
 
eventGetter.py
<langsyntaxhighlight lang="python">#http://docs.python-requests.org/en/latest/
import requests
import json
Line 772:
def submitEvent(url_path,params):
r = requests.post(url_path, data=json.dumps(params))
print(r.text+" : Event Submitted")</langsyntaxhighlight>
 
main.py
<langsyntaxhighlight lang="python">import eventGetter as eg
import json
 
Line 890:
 
main()</langsyntaxhighlight>
 
=={{header|Wren}}==
Line 900:
 
I did wonder whether it was worth the effort to do this task given that we're using a deprecated API and can't test creating events without a paid subscription which I don't have. However, from Wren's viewpoint, there are some points of interest relating to the use of WrenGo - notably passing Wren maps to Go - which may be a useful reference for the future.
<langsyntaxhighlight lang="ecmascript">/* meetup.wren */
 
import "./date" for Date
Line 991:
// delete the event just posted
c.deleteEvent(event.eventId)
System.print("The %(event.eventName) event has been cancelled.\n")</langsyntaxhighlight>
<br>
We now embed this in the following Go program and build it. To run it, you will need the necessary authorization, a paid subscription and, of course, non-fictitious data.
<langsyntaxhighlight lang="go">/* go build meetup.go */
 
package main
Line 1,241:
vm.InterpretFile(fileName)
vm.Free()
}</langsyntaxhighlight>
10,327

edits