Class: Hooky::Hook

Inherits:
Object
  • Object
show all
Defined in:
lib/hooky/hook.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(directory) ⇒ Hook

Returns a new instance of Hook.



8
9
10
# File 'lib/hooky/hook.rb', line 8

def initialize(directory)
  @directory = directory
end

Instance Attribute Details

#directoryObject

Returns the value of attribute directory.



6
7
8
# File 'lib/hooky/hook.rb', line 6

def directory
  @directory
end

Class Method Details

.allObject



12
13
14
# File 'lib/hooky/hook.rb', line 12

def self.all
  Dir.glob(".hooky/*").map{|d| d.gsub(".hooky/", "")}
end

Instance Method Details

#configObject



24
25
26
# File 'lib/hooky/hook.rb', line 24

def config
  JSON.parse(config_file)
end

#config_fileObject



16
17
18
# File 'lib/hooky/hook.rb', line 16

def config_file
  File.read(".hooky/#{directory}/config.json")
end

#dataObject



28
29
30
# File 'lib/hooky/hook.rb', line 28

def data
  JSON.parse(data_file)
end

#data_fileObject



20
21
22
# File 'lib/hooky/hook.rb', line 20

def data_file
  File.read(".hooky/#{directory}/data.json")
end

#headersObject



36
37
38
# File 'lib/hooky/hook.rb', line 36

def headers
  config["headers"]
end

#httpartyObject



40
41
42
43
44
45
46
# File 'lib/hooky/hook.rb', line 40

def httparty
  if config["method"] =~ /GET/
    HTTParty.get(url, body: data, headers: headers)
  elsif config["method"] =~ /POST/
    HTTParty.post(url, body: data, headers: headers)
  end
end

#send_requestObject



48
49
50
51
52
# File 'lib/hooky/hook.rb', line 48

def send_request
  resp = httparty

  resp.response
end

#urlObject



32
33
34
# File 'lib/hooky/hook.rb', line 32

def url
  config["url"]
end