Last active
August 29, 2015 14:17
-
-
Save yaotti/0eea19fc6637f82e30dc to your computer and use it in GitHub Desktop.
ruboty-startup_quote
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Gem::Specification.new do |spec| | |
spec.name = "ruboty-startup_quote" | |
spec.version = "0.0.1" | |
spec.authors = ["Hiroshige Umino"] | |
spec.email = ["[email protected]"] | |
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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