webhook_manager 0.1.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5d4e1224298a76102a03f6a14d343b0f37acc585c108b9cb8d2882615e5b5602
4
- data.tar.gz: 71daaa526b6d99dec5b1c2d1a4fe74fda605e033ce599bfdd8bebc71783ebd07
3
+ metadata.gz: ba06ee724e738a0db42ee39e9360d8d86b757de54a62822f0965b99b1de8181f
4
+ data.tar.gz: 29b1e905350368051adb56a0b19952063261944731feed5056d049c9f3afffdc
5
5
  SHA512:
6
- metadata.gz: 5d7d1c00928b1de5cb83b42e688d3380ec499bf798aa1be2d15fe597a7888521b3463f62e4e83ab13165bf25f8af131c7990bf74f27449e92c44d12798e361c8
7
- data.tar.gz: ad27917c3c258e90bc059a51cf7953ab93c3eb5ee341b614efc281f3292d5998eadddeb49979cde07b108e8f58d90d02a91b8c8715df25f291f6d92eabc561b7
6
+ metadata.gz: 22db9baa25354dd6ae030204874734c1fde9485c29752ee34cc4a7ebe3032503a3c34115e0703b01e587a23d7cf15568a13c8f7bc5e0a8b067ed52da6bc46025
7
+ data.tar.gz: 649f45f5337f95e479f4afc4d49d69785aa64de35ca648eb387e3c96360e2669594704f34a9de0de9f8345a2dae27e051b9309db7621bced8ae52e37a8b690eb
data/.gitignore CHANGED
@@ -10,4 +10,7 @@
10
10
  # rspec failure tracking
11
11
  .rspec_status
12
12
  .DS_Store
13
- /.vscode
13
+ /.vscode
14
+ Gemfile.lock
15
+ .ruby-version
16
+ .ruby-gemset
data/README.md CHANGED
@@ -1,8 +1,6 @@
1
1
  # WebhookManager
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/webhook_manager`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
- TODO: Delete this and the text above, and describe your gem
3
+ A gem that integrates the https://gethooky.com API for plain Ruby or Ruby on Rails applications.
6
4
 
7
5
  ## Installation
8
6
 
@@ -22,7 +20,19 @@ Or install it yourself as:
22
20
 
23
21
  ## Usage
24
22
 
25
- TODO: Write usage instructions here
23
+ 1. Initialize the class with your Hooky API key:
24
+
25
+ ```ruby
26
+ client = WebhookManager::Webhook.new(HOOKY_API_KEY)
27
+ ```
28
+
29
+ 2. Send your webhook
30
+
31
+ Note: Payload expect a Ruby Hash. It will be automatically converted to JSON
32
+
33
+ ```ruby
34
+ client.trigger!(event_name: "any.event.name", payload: {foo: "bar"})
35
+ ```
26
36
 
27
37
  ## Development
28
38
 
@@ -4,6 +4,7 @@ require "faraday"
4
4
  require "json"
5
5
 
6
6
  require_relative "webhook_manager/version"
7
+ require_relative "webhook_manager/globals"
7
8
 
8
9
  module WebhookManager
9
10
  class Error < StandardError; end
@@ -11,9 +12,9 @@ module WebhookManager
11
12
  class Webhook
12
13
  attr_accessor :conn
13
14
 
14
- def initialize(url, api_key)
15
+ def initialize(api_key)
15
16
  @conn = Faraday::Connection.new(
16
- url: url,
17
+ url: HOOKY_API,
17
18
  headers: {
18
19
  "Authorization" => "ApiKey #{api_key}",
19
20
  "Content-Type" => "application/json"
@@ -22,13 +23,25 @@ module WebhookManager
22
23
  end
23
24
 
24
25
  def trigger!(event_name:, payload:)
25
- res = @conn.post("webhook_events/trigger", { event_name: event_name, event_payload: payload }.to_json)
26
+ begin
27
+ res = @conn.post("webhook_events/trigger", {webhook_event: { event_name: event_name, event_payload: payload }}.to_json)
28
+ rescue Faraday::ConnectionFailed => e
29
+ raise Error.new("Could not connect to API")
30
+ rescue Faraday::TimeoutError => e
31
+ raise Error.new("Time out error")
32
+ end
26
33
 
27
34
  handle_reponse(res)
28
35
  end
29
36
 
30
37
  def update_status(event_id:, status:)
31
- res = @conn.post("webhook_events/update_status", { event_id: event_id, status: status }.to_json)
38
+ begin
39
+ res = @conn.post("webhook_events/update_status", { event_id: event_id, event_status: status }.to_json)
40
+ rescue Faraday::ConnectionFailed => e
41
+ raise Error.new("Could not connect to API")
42
+ rescue Faraday::TimeoutError => e
43
+ raise Error.new("Time out error")
44
+ end
32
45
 
33
46
  handle_reponse(res)
34
47
  end
@@ -39,13 +52,16 @@ module WebhookManager
39
52
  if res.status == 200
40
53
  data = JSON.parse(res.body)
41
54
 
42
- if data["status"] == "ERROR"
55
+ case data["status"]
56
+ when "ERROR"
43
57
  raise "Something went wrong: #{data["errors"].join(", ")}"
44
- elsif data["status"] == "OK"
58
+ when "OK"
45
59
  true
46
60
  end
61
+ elsif res.status == 401
62
+ raise Error.new("Unauthorized access to the API!")
47
63
  else
48
- raise Error.new("Something went wrong calling the hooky API!")
64
+ raise Error.new("Something went wrong calling the hooky API! #{res.body}")
49
65
  end
50
66
  end
51
67
  end
@@ -0,0 +1 @@
1
+ HOOKY_API = "https://app.gethooky.com/api/v1".freeze
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module WebhookManager
4
- VERSION = "0.1.0"
4
+ VERSION = "0.3.0"
5
5
  end
@@ -12,7 +12,6 @@ Gem::Specification.new do |spec|
12
12
  spec.description = "A gem to manage webhook triggers"
13
13
  spec.homepage = "https://github.com/buttercloud/webhook_manager"
14
14
  spec.license = "MIT"
15
- spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
16
15
 
17
16
  spec.metadata["allowed_push_host"] = 'https://rubygems.org/'
18
17
 
@@ -30,8 +29,10 @@ Gem::Specification.new do |spec|
30
29
  spec.require_paths = ["lib"]
31
30
 
32
31
  # Uncomment to register a new dependency of your gem
33
- spec.add_dependency "faraday", ">= 1.2.0"
32
+ spec.add_dependency "faraday", "~> 0.17.3"
34
33
  spec.add_development_dependency "pry"
34
+
35
+ spec.required_ruby_version = '>= 2.1'
35
36
 
36
37
  # For more information and examples about making a new gem, checkout our
37
38
  # guide at: https://bundler.io/guides/creating_gem.html
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: webhook_manager
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Luay Bseiso
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-12-29 00:00:00.000000000 Z
11
+ date: 2021-03-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 1.2.0
19
+ version: 0.17.3
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 1.2.0
26
+ version: 0.17.3
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: pry
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -48,16 +48,14 @@ files:
48
48
  - ".gitignore"
49
49
  - ".rspec"
50
50
  - ".rubocop.yml"
51
- - ".ruby-gemset"
52
- - ".ruby-version"
53
51
  - Gemfile
54
- - Gemfile.lock
55
52
  - LICENSE.txt
56
53
  - README.md
57
54
  - Rakefile
58
55
  - bin/console
59
56
  - bin/setup
60
57
  - lib/webhook_manager.rb
58
+ - lib/webhook_manager/globals.rb
61
59
  - lib/webhook_manager/version.rb
62
60
  - webhook_manager.gemspec
63
61
  homepage: https://github.com/buttercloud/webhook_manager
@@ -76,7 +74,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
76
74
  requirements:
77
75
  - - ">="
78
76
  - !ruby/object:Gem::Version
79
- version: 2.3.0
77
+ version: '2.1'
80
78
  required_rubygems_version: !ruby/object:Gem::Requirement
81
79
  requirements:
82
80
  - - ">="
data/.ruby-gemset DELETED
@@ -1 +0,0 @@
1
- webhook_manager
data/.ruby-version DELETED
@@ -1 +0,0 @@
1
- ruby-2.7.2
data/Gemfile.lock DELETED
@@ -1,67 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- webhook_manager (0.1.0)
5
- faraday (>= 1.2.0)
6
-
7
- GEM
8
- remote: https://rubygems.org/
9
- specs:
10
- ast (2.4.1)
11
- coderay (1.1.3)
12
- diff-lcs (1.4.4)
13
- faraday (1.2.0)
14
- multipart-post (>= 1.2, < 3)
15
- ruby2_keywords
16
- method_source (1.0.0)
17
- multipart-post (2.1.1)
18
- parallel (1.20.1)
19
- parser (3.0.0.0)
20
- ast (~> 2.4.1)
21
- pry (0.13.1)
22
- coderay (~> 1.1)
23
- method_source (~> 1.0)
24
- rainbow (3.0.0)
25
- rake (13.0.3)
26
- regexp_parser (2.0.2)
27
- rexml (3.2.4)
28
- rspec (3.10.0)
29
- rspec-core (~> 3.10.0)
30
- rspec-expectations (~> 3.10.0)
31
- rspec-mocks (~> 3.10.0)
32
- rspec-core (3.10.0)
33
- rspec-support (~> 3.10.0)
34
- rspec-expectations (3.10.0)
35
- diff-lcs (>= 1.2.0, < 2.0)
36
- rspec-support (~> 3.10.0)
37
- rspec-mocks (3.10.0)
38
- diff-lcs (>= 1.2.0, < 2.0)
39
- rspec-support (~> 3.10.0)
40
- rspec-support (3.10.0)
41
- rubocop (1.7.0)
42
- parallel (~> 1.10)
43
- parser (>= 2.7.1.5)
44
- rainbow (>= 2.2.2, < 4.0)
45
- regexp_parser (>= 1.8, < 3.0)
46
- rexml
47
- rubocop-ast (>= 1.2.0, < 2.0)
48
- ruby-progressbar (~> 1.7)
49
- unicode-display_width (>= 1.4.0, < 2.0)
50
- rubocop-ast (1.3.0)
51
- parser (>= 2.7.1.5)
52
- ruby-progressbar (1.10.1)
53
- ruby2_keywords (0.0.2)
54
- unicode-display_width (1.7.0)
55
-
56
- PLATFORMS
57
- x86_64-darwin-17
58
-
59
- DEPENDENCIES
60
- pry
61
- rake (~> 13.0)
62
- rspec (~> 3.0)
63
- rubocop (~> 1.7.0)
64
- webhook_manager!
65
-
66
- BUNDLED WITH
67
- 2.2.3