Kemel Zaidan @kemelzaidan | Lucas Uyezu @coralton
#CPBR8
Evangelista de Tecnologia na @Locaweb
Código do projeto BitcoinCalc do XDK ainda está no Github: https://github.com/kemelzaidan/BitcoinCalc
Twitter tem várias APIs, dentre elas a de streaming (diferente da REST)
The reactor design pattern is an event handling pattern for handling service requests delivered concurrently to a service handler by one or more inputs. The service handler then demultiplexes the incoming requests and dispatches them synchronously to the associated request handlers".
Professor Chatoff
Ruby tem Event Machine, Python tem Twisted.
# Setup $conversions = 0 # Conversion currency, amount = parse_tweet("0.5 in #USD") result = convert('USD', 0.5) reply("#{amount} in #{currency} is #{result}") $conversions += 1 # Checking later reply("We have made #{$conversions} conversions so far")
# Setup $redis = Redis.connect # Conversion currency, amount = parse_tweet("0.5 in #USD") result = convert('USD', 0.5) reply("#{amount} in #{currency} is #{result}") $redis.sadd("conversions", "#{amount} in #{currency} at #{Time.now}") # Checking later reply("We have made #{$redis.scard("conversions")} conversions so far")
puts "1) Fetching data" respose_body = HTTParty.get "https://api.bitcoinaverage.com/ticker/global/all" # 1 second later puts "2) Storing fetched data" $redis.set(response_body["data"]) puts "3) Done!"
puts "1) Fetching data" http = EventMachine::HttpRequest.new("https://api.bitcoinaverage.com/ticker/global/all").get http.errback { p '3) Not-done! Error!'; EM.stop } http.callback do # 1 second later $redis.set(response_body["data"]) puts "3) Storing fetched data" p http.response_header.status p http.response_header p http.response puts "4) Done!" EventMachine.stop end puts "2) Doing other things"
@kemelzaidan
kemel.zaidan@locaweb.com.br
@coralton
lucas.uyezu@locaweb.com.br