Skip to content

Instantly share code, notes, and snippets.

@yaotti
Last active August 29, 2015 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yaotti/0eea19fc6637f82e30dc to your computer and use it in GitHub Desktop.
Save yaotti/0eea19fc6637f82e30dc to your computer and use it in GitHub Desktop.
ruboty-startup_quote
Gem::Specification.new do |spec|
spec.name = "ruboty-startup_quote"
spec.version = "0.0.1"
spec.authors = ["Hiroshige Umino"]
spec.email = ["hiroshige88@gmail.com"]
spec.summary = "A ruboty handler for Startup Quote"
spec.homepage = "https://github.com/yaotti"
spec.license = "MIT"
spec.files = ["ruboty-startup_quote.rb"]
spec.require_paths = ["."]
spec.add_dependency "ruboty"
spec.add_dependency "faraday"
spec.add_dependency "faraday_middleware"
end
require 'faraday'
require 'faraday_middleware'
module Ruboty
module Handlers
class StartupQuote < Base
on /startup( me)?/, name: "startup", description: "Show a Startup Quote"
def startup(message)
if picture_url = get
message.reply(picture_url)
end
end
private
def connection
Faraday.new do |conn|
conn.adapter :net_http
conn.response :json
end
end
def get
api_url = 'https://wisdomapi.herokuapp.com/v1/random'
response = connection.get(api_url)
if data = response.body
data['picture_url']
end
rescue => exception
Ruboty.logger.error("Error: #{self}##{__method__} - #{exception}")
nil
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment