Skip to content

Instantly share code, notes, and snippets.

@scashin133
Created September 14, 2011 18:29
Show Gist options
  • Save scashin133/1217355 to your computer and use it in GitHub Desktop.
Save scashin133/1217355 to your computer and use it in GitHub Desktop.
Socialcast API examples
require 'rubygems'
require 'rest_client'
require 'json'
require 'logger'
require 'pp'
class VhackDemo
def self.request(method, path, request_params)
RestClient.log = Logger.new(STDOUT)
url = ['https://', 'demo.socialcast.com', path].join
basic_auth_options = {:user => 'emily@socialcast.com', :password => 'demo'}
resource = RestClient::Resource.new url, basic_auth_options
response = resource.send(method.to_sym, request_params)
puts response.body
JSON.parse(response.body)
rescue => e
puts e.message
end
end
pp VhackDemo.request(:get, '/api/messages.json', {})
response = VhackDemo.request(:post, '/api/messages.json', {:message => {:body => 'From the api'}})
pp response
pp VhackDemo.request(:put, "/api/messages/#{response["message"]["id"]}.json", {:message => {:body => 'Changed from the api'}})
pp VhackDemo.request(:delete, "/api/messages/#{response["message"]["id"]}.json", {})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment