Created
April 24, 2012 17:09
-
-
Save mlc/2481575 to your computer and use it in GitHub Desktop.
Accessing the Meetup API, setting the Accept-Charset header
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Meetup { | |
public HttpResponse get(String url, List<? extends NameValuePair> params) throws IOException { | |
DefaultHttpClient cli = new DefaultHttpClient(); | |
cli.addRequestInterceptor(new HttpRequestInterceptor() { | |
@Override | |
public void process(HttpRequest httpRequest, HttpContext httpContext) throws HttpException, IOException { | |
httpRequest.addHeader(HttpHeaders.ACCEPT_CHARSET, "utf-8"); | |
} | |
}); | |
String query = URLEncodedUtils.format(params, "UTF-8"); | |
// oauth-sign the request using your favorite library, or ensure that there's an API key in the params list | |
return cli.execute(new HttpGet(url + "?" + query)); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Meetup | |
def get(url, params = {}) | |
client = make_client | |
response = client.get(url, :params => params.merge({access_token: @token}), :headers => {"Accept-Charset" => "utf-8"}) | |
raise "boo. #{response.status} getting #{url}" unless (200..206).include?(response.status) | |
MultiJson.decode(response.body) | |
end | |
private | |
def make_client | |
cli = OAuth2::Client.new(@consumer_key, @consumer_secret, :site => "https://api.meetup.com") | |
OAuth2::AccessToken.new(cli, @token) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment