Sha256: 0df863c25793c037eb5ec0caf5b2303a6f8767289320fd7ae04e63cef407b444

Contents?: true

Size: 538 Bytes

Versions: 1

Compression:

Stored size: 538 Bytes

Contents

require 'bgg-api'

module Lita
  module Handlers
    class Boardgamegeek < Handler
      route(/bgg(?: me)?\s+(.+)/, :search, command: true)

      def search(response)
        term = response.match_data[1]
        id = game_id(term)
        response.reply "#{term}: http://www.boardgamegeek.com/boardgame/#{id}"
      end

      def game_id(name)
        bgg = BggApi.new
        result = bgg.search(query: name, type: 'boardgame')
        result["item"].first["id"]
      end
    end

    Lita.register_handler(Boardgamegeek)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
lita-boardgamegeek-0.1.0 lib/lita/handlers/boardgamegeek.rb