Skip to content

Instantly share code, notes, and snippets.

@jeremyd
Created October 30, 2012 07:38
Show Gist options
  • Save jeremyd/3978816 to your computer and use it in GitHub Desktop.
Save jeremyd/3978816 to your computer and use it in GitHub Desktop.
example http android jruby
# REST METHODS
# takes a block of HttpGet/Put/Post/Delete
def self.get(&block)
options = self.load_preferences
client = DefaultHttpClient.new
params = BasicHttpParams.new
HttpProtocolParams.setVersion(params, HttpVersion::HTTP_1_1);
HttpProtocolParams.setContentCharset(params, "UTF_8");
HttpProtocolParams.setUseExpectContinue(params, false);
client.setParams(params)
creds = "#{options[:email]}:#{options[:pass]}"
base_64_creds = Base64.b64encode(creds).chomp
request = yield(options)
request.addHeader("Authorization", "Basic " + base_64_creds)
response_handler = BasicResponseHandler.new
response = client.execute(request, response_handler)
end
def self.get_deployments
response = get { |options| HttpGet.new("https://my.rightscale.com/api/acct/#{options[:account_id]}/deployments.js?api_version=1.0") }
result = parse_deployments_json(response)
# if we got this far, save them off to the cache
save_deployments(response)
result
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment