Use a REST API: Difference between revisions
Content added Content deleted
m (Petelomax moved page Using the Meetup.com API to Use a REST API: A more generic task name) |
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
||
Line 24: | Line 24: | ||
<br> |
<br> |
||
Note that this version doesn't include code to submit events to Meetup. |
Note that this version doesn't include code to submit events to Meetup. |
||
< |
<syntaxhighlight lang="go">package main |
||
import ( |
import ( |
||
Line 147: | Line 147: | ||
fmt.Println("First event:\n", &evresp.Results[0]) |
fmt.Println("First event:\n", &evresp.Results[0]) |
||
} |
} |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 163: | Line 163: | ||
<br> |
<br> |
||
Note that this code is untested as you need a paid subscription to create events which I don't have. |
Note that this code is untested as you need a paid subscription to create events which I don't have. |
||
< |
<syntaxhighlight lang="go">package main |
||
import ( |
import ( |
||
Line 260: | Line 260: | ||
check(err) |
check(err) |
||
fmt.Printf("The %q event has been cancelled.\n", event.Name) |
fmt.Printf("The %q event has been cancelled.\n", event.Name) |
||
}</ |
}</syntaxhighlight> |
||
=={{header|Java}}== |
=={{header|Java}}== |
||
Line 268: | Line 268: | ||
EventGetter.java |
EventGetter.java |
||
< |
<syntaxhighlight lang="java">package src; |
||
import java.io.BufferedReader; |
import java.io.BufferedReader; |
||
Line 326: | Line 326: | ||
} |
} |
||
}</ |
}</syntaxhighlight> |
||
Main.java |
Main.java |
||
< |
<syntaxhighlight lang="java">/* |
||
* In this class, You can see the diferent |
* In this class, You can see the diferent |
||
* ways of asking for events. |
* ways of asking for events. |
||
Line 418: | Line 418: | ||
} |
} |
||
}</ |
}</syntaxhighlight> |
||
=={{header|JavaScript}}== |
=={{header|JavaScript}}== |
||
Line 424: | Line 424: | ||
Made on node js. Run using 'node filename.js' |
Made on node js. Run using 'node filename.js' |
||
< |
<syntaxhighlight lang="javascript">var fs = require('fs'); |
||
var request = require('request'); |
var request = require('request'); |
||
Line 567: | Line 567: | ||
}, function(result) { |
}, function(result) { |
||
console.log('Event: ', result); |
console.log('Event: ', result); |
||
})</ |
})</syntaxhighlight> |
||
=={{header|Phix}}== |
=={{header|Phix}}== |
||
Line 573: | Line 573: | ||
Unfortunately the API (V2) does not support creating events, so instead this shows how to use |
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). |
a post method to toggle sales (but see note below). |
||
<!--< |
<!--<syntaxhighlight lang="phix">(notonline)--> |
||
<span style="color: #000080;font-style:italic;">-- |
<span style="color: #000080;font-style:italic;">-- |
||
-- demo\rosetta\Using_a_REST_API.exw |
-- demo\rosetta\Using_a_REST_API.exw |
||
Line 681: | 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: #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> |
<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> |
||
<!--</ |
<!--</syntaxhighlight>--> |
||
Note that toggling sales off makes the (manually created) event invisible to the API, even without |
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 |
the {"status","live"} filter, hence I had to hard-code the event id to permit a second run to turn |
||
Line 746: | Line 746: | ||
eventGetter.py |
eventGetter.py |
||
< |
<syntaxhighlight lang="python">#http://docs.python-requests.org/en/latest/ |
||
import requests |
import requests |
||
import json |
import json |
||
Line 772: | Line 772: | ||
def submitEvent(url_path,params): |
def submitEvent(url_path,params): |
||
r = requests.post(url_path, data=json.dumps(params)) |
r = requests.post(url_path, data=json.dumps(params)) |
||
print(r.text+" : Event Submitted")</ |
print(r.text+" : Event Submitted")</syntaxhighlight> |
||
main.py |
main.py |
||
< |
<syntaxhighlight lang="python">import eventGetter as eg |
||
import json |
import json |
||
Line 890: | Line 890: | ||
main()</ |
main()</syntaxhighlight> |
||
=={{header|Wren}}== |
=={{header|Wren}}== |
||
Line 900: | 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. |
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. |
||
< |
<syntaxhighlight lang="ecmascript">/* meetup.wren */ |
||
import "./date" for Date |
import "./date" for Date |
||
Line 991: | Line 991: | ||
// delete the event just posted |
// delete the event just posted |
||
c.deleteEvent(event.eventId) |
c.deleteEvent(event.eventId) |
||
System.print("The %(event.eventName) event has been cancelled.\n")</ |
System.print("The %(event.eventName) event has been cancelled.\n")</syntaxhighlight> |
||
<br> |
<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. |
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. |
||
< |
<syntaxhighlight lang="go">/* go build meetup.go */ |
||
package main |
package main |
||
Line 1,241: | Line 1,241: | ||
vm.InterpretFile(fileName) |
vm.InterpretFile(fileName) |
||
vm.Free() |
vm.Free() |
||
}</ |
}</syntaxhighlight> |