hostedhooks 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 589ce3bf7f35913ded48306ae3d4ec7a9424c9c351b773e189e0cc5fb0fae4ec
4
+ data.tar.gz: f746e4e7f92460b9b087a2fdaddbaa9baf96f9648736326f17440525c89f6642
5
+ SHA512:
6
+ metadata.gz: 38a3988a0930be8cf7a1e17828e393a20086e13e5b90b57663dccd8a350909c6e70570664f9b58cf540c6ec18a7ddeb2f9909a4f8b57a306dd8fd81646f769af
7
+ data.tar.gz: 9a4270c7d3a75b704e5681e61bc3258d7105a49d037d2b3a4e35e4474bf6492d876b4683f13ff643f89e42cb1f202806a6c261565ebab0fed878a3134f3cfbc7
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at ian.grabill@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [https://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: https://contributor-covenant.org
74
+ [version]: https://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in hostedhooks-ruby.gemspec
4
+ gemspec
5
+
6
+ gem "rake", "~> 12.0"
data/Gemfile.lock ADDED
@@ -0,0 +1,27 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ hostedhooks (0.1.0)
5
+ httparty
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ httparty (0.18.1)
11
+ mime-types (~> 3.0)
12
+ multi_xml (>= 0.5.2)
13
+ mime-types (3.3.1)
14
+ mime-types-data (~> 3.2015)
15
+ mime-types-data (3.2021.0225)
16
+ multi_xml (0.6.0)
17
+ rake (12.3.2)
18
+
19
+ PLATFORMS
20
+ ruby
21
+
22
+ DEPENDENCIES
23
+ hostedhooks!
24
+ rake (~> 12.0)
25
+
26
+ BUNDLED WITH
27
+ 2.1.4
data/README.md ADDED
@@ -0,0 +1,64 @@
1
+ # HostedHooks Ruby Gem
2
+
3
+ A Ruby library for [HostedHooks](https://www.hostedhooks.com) - a Webhooks as a Service Platform
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'hostedhooks'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle install
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install hostedhooks
20
+
21
+ ## How it works
22
+
23
+ ### Authentication
24
+
25
+ Initialize the gem with your API key [found here](https://www.hostedhooks.com/settings/account).
26
+
27
+ client = HostedHooks::Client.new('API_KEY')
28
+
29
+ ### Get one record
30
+
31
+ client.get_endpoint("endpoint_uuid")
32
+
33
+
34
+ ### Get a collection of records
35
+
36
+
37
+ client.list_subscriptions("app_uuid")
38
+
39
+ ### Create a record
40
+
41
+ client.create_app(name: "Test App Name")
42
+
43
+ ### Update a record
44
+
45
+ client.update_app("app_uuid", name: "Test App Name")
46
+
47
+
48
+ ## Resources
49
+
50
+ * Apps
51
+ * Subscriptions
52
+ * Endpoints
53
+ * Webhook Events
54
+ * Messages
55
+
56
+
57
+ ## Contributing
58
+
59
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/hostedhooks-ruby. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/HostedHooks/hostedhooks-ruby/blob/master/CODE_OF_CONDUCT.md).
60
+
61
+
62
+ ## Code of Conduct
63
+
64
+ Everyone interacting in the Hostedhooks::Ruby project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/HostedHooks/hostedhooks-ruby/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "hostedhooks"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,26 @@
1
+ require_relative 'lib/hostedhooks/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "hostedhooks"
5
+ spec.version = HostedHooks::VERSION
6
+ spec.authors = ["Ian Grabill"]
7
+ spec.email = ["ian@hostedhooks.com"]
8
+
9
+ spec.summary = %q{A ruby library for the HostedHooks API}
10
+ spec.homepage = "https://github.com/HostedHooks/hostedhooks-ruby"
11
+ spec.license = "MIT"
12
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
13
+ spec.metadata["homepage_uri"] = spec.homepage
14
+
15
+ # Specify which files should be added to the gem when it is released.
16
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
17
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
18
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
19
+ end
20
+ spec.bindir = "exe"
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+
25
+ spec.add_dependency "httparty"
26
+ end
@@ -0,0 +1,116 @@
1
+ module HostedHooks
2
+
3
+ class Client
4
+
5
+ def initialize(api_key = nil)
6
+ @api_key = api_key || ENV["HOSTEDHOOKS_API_KEY"]
7
+ end
8
+
9
+ # Apps
10
+
11
+ def list_apps
12
+ get_response("/apps")
13
+ end
14
+
15
+ def create_app(payload = {})
16
+ post_response "/apps", payload.slice(:name)
17
+ end
18
+
19
+ def update_app(uuid, payload = {})
20
+ patch_response "/apps/#{uuid}", payload.slice(:name)
21
+ end
22
+
23
+ # Subscriptions
24
+
25
+ def get_subscription(uuid)
26
+ get_response "/subscriptions/#{uuid}"
27
+ end
28
+
29
+ def list_subscriptions(app_uuid)
30
+ get_response("/apps/#{app_uuid}/subscriptions")
31
+ end
32
+
33
+ def create_subscription(app_uuid, payload = {})
34
+ post_response "/apps/#{app_uuid}/subscriptions", payload.slice(:name)
35
+ end
36
+
37
+ # Endpoints
38
+
39
+ def get_endpoint(app_uuid, endpoint_uuid)
40
+ get_response "/apps/#{app_uuid}/endpoints/#{endpoint_uuid}"
41
+ end
42
+
43
+ def list_endpoints(app_uuid)
44
+ get_response("/apps/#{app_uuid}/endpoints")
45
+ end
46
+
47
+ def create_subscription(subscription_uuid, payload = {})
48
+ post_response "/subscriptions/#{subscription_uuid}/endpoints", payload.slice(:url, :enabled_events, :version, :status, :description)
49
+ end
50
+
51
+ def update_app(subscription_uuid, endpoint_uuid, payload = {})
52
+ patch_response "/subscriptions/#{subscription_uuid}/endpoints/#{endpoint_uuid}", payload.slice(:url, :enabled_events, :version, :status, :description)
53
+ end
54
+
55
+ # Webhook Events
56
+
57
+ def list_webhook_events(app_uuid)
58
+ get_response("/apps/#{app_uuid}/webhook_events")
59
+ end
60
+
61
+ # Messages
62
+
63
+ def create_app_message(app_uuid, payload = {})
64
+ post_response "/apps/#{app_uuid}/messages", payload.slice(:event_type, :data, :version, :event_id)
65
+ end
66
+
67
+ def create_subscription_message(subscription_uuid, payload = {})
68
+ post_response "/subscriptions/#{subscription_uuid}/messages", payload.slice(:event_type, :data, :version, :event_id)
69
+ end
70
+
71
+ def create_endpoint_message(subscription_uuid, endpoint_uuid, payload = {})
72
+ post_response "/subscriptions/#{subscription_uuid}/endpoints/#{endpoint_uuid}/messages", payload.slice(:event_type, :data, :version, :event_id)
73
+ end
74
+
75
+ private
76
+
77
+ HOSTEDHOOKS_API_ENDPOINT = "https://hostedhooks.com/api/v1"
78
+
79
+ def get_response(url)
80
+ response = HTTParty.get("#{HOSTEDHOOKS_API_ENDPOINT}#{url}", timeout: 3, headers: { 'Authorization' => "Bearer #{@api_key}" })
81
+ body = JSON.parse(response.body)
82
+ return {"error" => body['message'], "code" => response.code} if response.code >= 400
83
+ return body
84
+ end
85
+
86
+ def post_response(url, payload)
87
+ response = HTTParty.post("#{HOSTEDHOOKS_API_ENDPOINT}#{url}",
88
+ body: payload.to_json,
89
+ timeout: 3,
90
+ headers: {
91
+ 'Authorization' => "Bearer #{@api_key}",
92
+ 'Content-Type' => 'application/json'
93
+ }
94
+ )
95
+ body = JSON.parse(response.body)
96
+ return {"error" => body['message'], "code" => response.code} if response.code >= 400
97
+ return body
98
+ end
99
+
100
+ def patch_response(url, payload)
101
+ response = HTTParty.patch("#{HOSTEDHOOKS_API_ENDPOINT}#{url}",
102
+ body: payload.to_json,
103
+ timeout: 3,
104
+ headers: {
105
+ 'Authorization' => "Bearer #{@api_key}",
106
+ 'Content-Type' => 'application/json'
107
+ }
108
+ )
109
+ body = JSON.parse(response.body)
110
+ return {"error" => body['message'], "code" => response.code} if response.code >= 400
111
+ return body
112
+ end
113
+
114
+ end
115
+
116
+ end
@@ -0,0 +1,3 @@
1
+ module HostedHooks
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,10 @@
1
+ require "httparty"
2
+ require "openssl"
3
+ require "base64"
4
+ require "hostedhooks/version"
5
+ require "hostedhooks/client"
6
+
7
+ module HostedHooks
8
+ class Error < StandardError; end
9
+
10
+ end
metadata ADDED
@@ -0,0 +1,70 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hostedhooks
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Ian Grabill
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-08-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: httparty
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description:
28
+ email:
29
+ - ian@hostedhooks.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".gitignore"
35
+ - CODE_OF_CONDUCT.md
36
+ - Gemfile
37
+ - Gemfile.lock
38
+ - README.md
39
+ - Rakefile
40
+ - bin/console
41
+ - bin/setup
42
+ - hostedhooks.gemspec
43
+ - lib/hostedhooks.rb
44
+ - lib/hostedhooks/client.rb
45
+ - lib/hostedhooks/version.rb
46
+ homepage: https://github.com/HostedHooks/hostedhooks-ruby
47
+ licenses:
48
+ - MIT
49
+ metadata:
50
+ homepage_uri: https://github.com/HostedHooks/hostedhooks-ruby
51
+ post_install_message:
52
+ rdoc_options: []
53
+ require_paths:
54
+ - lib
55
+ required_ruby_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: 2.3.0
60
+ required_rubygems_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: '0'
65
+ requirements: []
66
+ rubygems_version: 3.1.4
67
+ signing_key:
68
+ specification_version: 4
69
+ summary: A ruby library for the HostedHooks API
70
+ test_files: []