Module: HipTail::Util
- Defined in:
- lib/hiptail/util.rb
Constant Summary collapse
- DEFAULT_VENDOR_NAME =
"HipTail"
- DEFAULT_VENDOR_URL =
"https://github.com/dayflower/hiptail"
Class Method Summary collapse
-
.create_capability(params) ⇒ Object
Build capability object.
Class Method Details
.create_capability(params) ⇒ Object
Build capability object.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/hiptail/util.rb', line 23 def create_capability(params) requireds = %w( key name base_url capability_url webhook_url installed_url ) missings = requireds.select { |k| ! params.include?(k.to_sym) } if missings.length > 0 raise "missing parameters: " + missings.join(%q{, }) end capability = { key: params[:key], name: params[:name], description: params[:description] || params[:name], vendor: { name: params[:vendor_name] || DEFAULT_VENDOR_NAME, url: (params[:vendor_url] || DEFAULT_VENDOR_URL).to_s, }, links: { self: params[:capability_url].to_s, homepage: (params[:homepage_url] || params[:base_url]).to_s, }, capabilities: { webhook: [], hipchatApiConsumer: { scopes: %w( send_notification send_message admin_room view_group ), fromName: params[:sender_name] || params[:name], }, installable: { allowGlobal: params.include?(:allow_global) ? params[:allow_global] : true, allowRoom: params.include?(:allow_room) ? params[:allow_room] : true, callbackUrl: params[:installed_url].to_s, } }, } event_names = %w( room_notification room_topic_change room_enter room_exit ) webhook_url = params[:webhook_url].to_s capability[:capabilities][:webhook] = event_names.map { |key| { name: key, event: key, url: webhook_url, } } = { name: 'room_message', event: 'room_message', url: webhook_url, } if params[:message_filter] [:pattern] = params[:message_filter].to_s end capability[:capabilities][:webhook] << if params[:avatar] capability[:capabilities][:hipchatApiConsumer][:avatar] = params[:avatar] end capability end |