Skip to content

Instantly share code, notes, and snippets.

@rubydubee
Created June 30, 2011 19:48
Show Gist options
  • Save rubydubee/1057047 to your computer and use it in GitHub Desktop.
Save rubydubee/1057047 to your computer and use it in GitHub Desktop.
Twitter Client in shoes
#Main file
require "Twitter.rb"
require 'json'
require 'uri'
Shoes.app :width=>300, :height=>400, :title=>"Rubydubee" do
@twitter = Twitter.new "consumer_key",
"consumer_secret"
@main_stack = stack do
caption "Rubydubee : Update your status"
image "twitter.png", :click => "#{@twitter.get_request_token.authorize_url}"
inscription "Sign with Twitter first and then Authrize your PIN."
button "Authorize" do
pin = ask("Please allow access and enter the PIN : ")
@access_token = @twitter.get_access_token(pin.chomp)
data = @access_token.get("/account/verify_credentials.json").body
debug("getting some data ")
result = JSON.parse(data)
username = result['name']
@main_stack.append do
caption "Howdy #{username}!"
edit_box :width=> 250, :height=>100 do |e|
@count.text = e.text.size
@str = e.text
end
@count = strong("0")
para @count," characters"
button "Tweet" do
new_status = URI.escape(@str, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))
@access_token.post("/statuses/update.json?status=#{new_status}").body
alert("Status Updated!")
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment