class Ruboty::Kendama::Actions::Kendama
Constants
- YOUTUBE_API_URL
Public Class Methods
new()
click to toggle source
# File lib/ruboty/kendama/actions/kendama.rb, line 7 def initialize @trick = trick end
Public Instance Methods
get(message)
click to toggle source
# File lib/ruboty/kendama/actions/kendama.rb, line 11 def get(message) if url = parse(response) message.reply(@trick + "\n" + url) end end
Private Instance Methods
api_url()
click to toggle source
# File lib/ruboty/kendama/actions/kendama.rb, line 38 def api_url YOUTUBE_API_URL end
connection()
click to toggle source
# File lib/ruboty/kendama/actions/kendama.rb, line 26 def connection Faraday.new(url: api_url) do |builder| builder.request :url_encoded builder.adapter Faraday.default_adapter end end
parse(response)
click to toggle source
# File lib/ruboty/kendama/actions/kendama.rb, line 33 def parse(response) videos = JSON.parse(response)['feed']['entry'] videos.first['link'][0]['href'] end
response()
click to toggle source
# File lib/ruboty/kendama/actions/kendama.rb, line 19 def response connection.get do |req| req.params['alt'] = 'json' req.params['q'] = "けん玉 #{@trick}" end.body end
trick()
click to toggle source
# File lib/ruboty/kendama/actions/kendama.rb, line 42 def trick yaml = File.expand_path("../../../trick.yml", __FILE__) YAML.load_file(yaml).sample end