Module: Skypager::Builder::WebhookHandler

Defined in:
lib/skypager/builder/webhook_handler.rb

Class Method Summary collapse

Class Method Details

.handle(service_identifier = :custom, request) ⇒ Object



2
3
4
5
6
7
8
9
# File 'lib/skypager/builder/webhook_handler.rb', line 2

def self.handle(service_identifier=:custom, request)
  unless respond_to?("handle_#{service_identifier}")
    return [404, {}, [""]]
  end

  puts "== Handling #{ service_identifier }: #{ request.path } #{ request.params }"
  send("handle_#{service_identifier}", request)
end

.handle_custom(request) ⇒ Object



71
72
# File 'lib/skypager/builder/webhook_handler.rb', line 71

def self.handle_custom(request)
end

.handle_dropbox(request) ⇒ Object

The Dropbox API requires us to support two different types of Webhook requests.

One will include the UID of the users who have changes. We will need to find all of the skypager sites which are registered against this UID in order to find the credentials needed to make a delta request to the API.

We will then use the paths we find in the delta, to find the specific site that we need to mark for building



21
22
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
# File 'lib/skypager/builder/webhook_handler.rb', line 21

def self.handle_dropbox(request)
  puts "== Dropbox handler initiated"
  body = request.body.read

  puts "== Request body: #{ body }"
  puts "== Params: #{ request.params.inspect }"

  begin
    if request.params['challenge']
      puts "== challenge request"
      response = "#{request.params['challenge']}"
    elsif body.length > 0
      data = JSON.parse(body) rescue nil
      data = data.to_mash if data.respond_to?(:to_mash)

      Array(data.delta.users).each do |uid|
        puts "== Attempting to find a site for #{ uid }"
        sites = Skypager::Site.find_sites_for_dropbox_uid(uid)

        if sites.length > 0
          sites.each do |site|
            puts "== Marking site for build: #{ site.name }"
            site.requires_build!
          end
        else
          puts "== Could not find site for uid: #{ uid }"
        end
      end

      response = data.delta.users.to_json
    end
  rescue => e
    response = "== Error: #{ e.message }"
    puts response
  end

  [200, {}, [response]]
end

.handle_github(request) ⇒ Object

TODO Presumably we will get commit notifications from Github, and will find the site that matches the notification



68
69
# File 'lib/skypager/builder/webhook_handler.rb', line 68

def self.handle_github(request)
end

.handle_google(request) ⇒ Object

TODO Investigate the makeup of google drive webhook request



62
63
# File 'lib/skypager/builder/webhook_handler.rb', line 62

def self.handle_google(request)
end