class Lita::Handlers::MeetupFinder
Constants
- MeetupApiError
START:custom_error
Public Instance Methods
build_search(search_text)
click to toggle source
START:build_search
# File lib/lita/handlers/meetup_finder.rb, line 73 def build_search(search_text) { zip: config.meetup_zip, format: 'json', page: '5', text: search_text } end
client()
click to toggle source
START:build_api_client
# File lib/lita/handlers/meetup_finder.rb, line 42 def client MeetupClient.configure do |meetup_config| # sets meetup config using value from lita config meetup_config.api_key = config.meetup_api_key end # store client rather than rebuilding on each call @_client ||= MeetupApi.new end
find_matching_meetup(message)
click to toggle source
START:handle_user_input
# File lib/lita/handlers/meetup_finder.rb, line 26 def find_matching_meetup(message) # extract search term from user input search_term = message.matches.first # pass search term to meetup query method meetups = meetups_matching search_term # handle two basic outcomes: no results, 1+ results if meetups.none? message.reply "Sorry, no matching meetups found." else message.reply meetups.first&.tagline end end
meetups_matching(search_text)
click to toggle source
START:perform_lookup query Meetup API for local meetups and return a
list of matching MeetupResult objects
# File lib/lita/handlers/meetup_finder.rb, line 56 def meetups_matching(search_text) query = build_search(search_text) begin response = client.open_events(query) results = response.fetch('results') rescue StandardError raise MeetupApiError.new(response) end # coerce an array of JSON-ish results into richer # MeetupResult objects results.map { |r| MeetupResult.new(r) } end