jive-webhook 0.0.1

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
+ SHA1:
3
+ metadata.gz: 21381e2c037c1b21b6da266558900e29bf04cf2c
4
+ data.tar.gz: 96d7b42ec40278919589bc08d6212604a5ecd2fd
5
+ SHA512:
6
+ metadata.gz: 8cc691b447610573f4c8f12d8cc27ec3848584cdc719e54884ed3e6af07c2e25da091d569f1f86f98d08aeacc22d52f86d6594f8bc1358c966d57c1b85c7335c
7
+ data.tar.gz: 65b6921ec877e21cb4b2ab1be756cf01747b89b3e32016856afd4fbb820713f9fd731a8dbd481d6988485808e91468867c5999ac21e56bca97658242ef0692a9
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.0
4
+ before_install: gem install bundler -v 1.11.2
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in jive-webhook.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,46 @@
1
+ [![Gem Version](https://badge.fury.io/rb/jive-webhook.svg)](http://badge.fury.io/rb/jive-webhook)
2
+ [![Build Status](https://travis-ci.org/butchmarshall/ruby-jive-webhook.svg?branch=master)](https://travis-ci.org/butchmarshall/ruby-jive-webhook)
3
+
4
+ # Jive::Webhook
5
+
6
+ An implemention of Jives Webhooks using ActiveRecord.
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem 'jive-webhook'
14
+ ```
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install jive-webhook
23
+
24
+ then run
25
+
26
+ ```ruby
27
+ rails generate jive:webhook:active_record
28
+ ```
29
+
30
+ ## Usage
31
+
32
+ To the ActiveRecord model:
33
+
34
+ ```ruby
35
+ Jive::Webhook.new(...)
36
+ ```
37
+
38
+ ## Contributing
39
+
40
+ Bug reports and pull requests are welcome on GitHub at https://github.com/butchmarshall/ruby-jive-webhook.
41
+
42
+
43
+ ## License
44
+
45
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
46
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "jive/webhook"
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
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,38 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'jive/webhook/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "jive-webhook"
8
+ spec.version = Jive::Webhook::VERSION
9
+ spec.authors = ["Butch Marshall"]
10
+ spec.email = ["butch.a.marshall@gmail.com"]
11
+ spec.summary = "Jive Webhook functionality implemented using ActiveRecord."
12
+ spec.description = "Implements the functionality required for dealing with and storing Jive Webhooks using ActiveRecord as a storage backend."
13
+ spec.homepage = "https://github.com/butchmarshall/ruby-jive-webhook"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "activerecord", [">= 3.0", "< 5.0"]
22
+ spec.add_dependency "jive-add_on", ">= 0.0.2"
23
+ spec.add_dependency "jive-oauth_token", ">= 0.0.3"
24
+
25
+ if RUBY_PLATFORM == 'java'
26
+ spec.add_development_dependency "jdbc-sqlite3", "> 0"
27
+ spec.add_development_dependency "activerecord-jdbcsqlite3-adapter", "> 0"
28
+ else
29
+ spec.add_development_dependency "sqlite3", "> 0"
30
+ end
31
+
32
+ spec.add_development_dependency "database_cleaner"
33
+ spec.add_development_dependency "factory_girl", "> 4.0"
34
+ spec.add_development_dependency "bundler", "~> 1.11"
35
+ spec.add_development_dependency "rake", "~> 10.0"
36
+ spec.add_development_dependency "rspec", "~> 3.0"
37
+ spec.add_development_dependency "webmock"
38
+ end
@@ -0,0 +1,24 @@
1
+ require "generators/jive/webhook/webhook_generator"
2
+ require "generators/jive/webhook/next_migration_version"
3
+ require "rails/generators/migration"
4
+ require "rails/generators/active_record"
5
+
6
+ # Extend the HasDynamicColumnsGenerator so that it creates an AR migration
7
+ module Jive
8
+ class Webhook < ActiveRecord::Base
9
+ class ActiveRecordGenerator < ::Jive::Webhook::Generator
10
+ include Rails::Generators::Migration
11
+ extend NextMigrationVersion
12
+
13
+ source_paths << File.join(File.dirname(__FILE__), "templates")
14
+
15
+ def create_migration_file
16
+ migration_template "migration_0.1.0.rb", "db/migrate/add_jive_webhooks_0_1_0_migration.rb"
17
+ end
18
+
19
+ def self.next_migration_number(dirname)
20
+ ::ActiveRecord::Generators::Base.next_migration_number dirname
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,16 @@
1
+ module Jive
2
+ class Webhook < ActiveRecord::Base
3
+ module NextMigrationVersion
4
+ # while methods have moved around this has been the implementation
5
+ # since ActiveRecord 3.0
6
+ def next_migration_number(dirname)
7
+ next_migration_number = current_migration_number(dirname) + 1
8
+ if ActiveRecord::Base.timestamped_migrations
9
+ [Time.now.utc.strftime("%Y%m%d%H%M%S"), format("%.14d", next_migration_number)].max
10
+ else
11
+ format("%.3d", next_migration_number)
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,20 @@
1
+ class AddJiveWebhooks010Migration < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :jive_webhooks do |t|
4
+ t.integer :jive_add_on_id
5
+ t.integer :jive_oauth_token_id
6
+
7
+ t.integer :webhook_id
8
+
9
+ t.string :events
10
+ t.string :object
11
+ t.string :callback
12
+
13
+ t.timestamps null: false
14
+ end
15
+ end
16
+
17
+ def self.down
18
+ drop_table :jive_webhooks
19
+ end
20
+ end
@@ -0,0 +1,10 @@
1
+ require 'rails/generators/base'
2
+ require 'jive/webhook/compatibility'
3
+
4
+ module Jive
5
+ class Webhook < ActiveRecord::Base
6
+ class Generator < Rails::Generators::Base
7
+ source_paths << File.join(File.dirname(__FILE__), 'templates')
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,20 @@
1
+ require "active_support"
2
+ require "active_support/dependencies"
3
+ require "active_record"
4
+
5
+ require "jive/add_on"
6
+ require "jive/oauth_token"
7
+
8
+ require "jive/webhook/version"
9
+ require "jive/webhook/class_methods"
10
+ require "jive/webhook/instance_methods"
11
+ require "jive/webhook/compatibility"
12
+ require "jive/webhook/configuration"
13
+
14
+ module Jive
15
+ class Webhook < ::ActiveRecord::Base
16
+ end
17
+ end
18
+
19
+ Jive::Webhook.send :include, Jive::Webhook::InstanceMethods
20
+ Jive::Webhook.send :extend, Jive::Webhook::ClassMethods
@@ -0,0 +1,26 @@
1
+ module Jive
2
+ class Webhook < ActiveRecord::Base
3
+ module ClassMethods
4
+ def self.extended(base)
5
+ base.send(:attr_accessor, :configuration)
6
+ base.belongs_to :add_on, :class_name => "Jive::AddOn", :foreign_key => :jive_add_on_id
7
+ base.belongs_to :oauth_token, :class_name => "Jive::OauthToken", :foreign_key => :jive_oauth_token_id
8
+ base.validates :add_on, presence: true
9
+ base.validates :oauth_token, presence: true
10
+ base.validates :callback, presence: true
11
+ base.before_create :register_webhook
12
+ base.before_destroy :unregister_webhook
13
+ base.before_validation :ensure_callback_from_configuration
14
+ end
15
+
16
+ def configuration
17
+ @configuration
18
+ end
19
+
20
+ def configure
21
+ @configuration ||= Jive::Webhook::Configuration.new
22
+ yield(@configuration)
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,29 @@
1
+ require 'jive/webhook/version'
2
+
3
+ module Jive
4
+ class Webhook < ActiveRecord::Base
5
+ module Compatibility
6
+ if ActiveSupport::VERSION::MAJOR >= 4
7
+ require 'active_support/proxy_object'
8
+
9
+ def self.executable_prefix
10
+ 'bin'
11
+ end
12
+
13
+ def self.proxy_object_class
14
+ ActiveSupport::ProxyObject
15
+ end
16
+ else
17
+ require 'active_support/basic_object'
18
+
19
+ def self.executable_prefix
20
+ 'script'
21
+ end
22
+
23
+ def self.proxy_object_class
24
+ ActiveSupport::BasicObject
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,11 @@
1
+ module Jive
2
+ class Webhook < ActiveRecord::Base
3
+ class Configuration
4
+ attr_accessor :callback
5
+
6
+ def initialize
7
+ @callback = nil
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,76 @@
1
+ module Jive
2
+ class Webhook < ActiveRecord::Base
3
+ module InstanceMethods
4
+ def self.included(base)
5
+ base.table_name = "jive_webhooks"
6
+ end
7
+
8
+ private
9
+ def ensure_callback_from_configuration
10
+ if self.callback.to_s.empty?
11
+ self.callback = Jive::Webhook.configuration ? Jive::Webhook.configuration.callback : ""
12
+ end
13
+ end
14
+
15
+ # Unregisters the webhook with Jive
16
+ def unregister_webhook
17
+ require "open-uri"
18
+ require "net/http"
19
+ require "openssl"
20
+
21
+ return if self.add_on.nil? # Can't do it without a token!
22
+ return if self.oauth_token.nil? # Can't do it without a token!
23
+
24
+ uri = URI.parse("#{self.add_on.jive_url}/api/core/v3/webhooks/#{self.webhook_id}")
25
+ http = Net::HTTP.new(uri.host, uri.port)
26
+ http.use_ssl = true
27
+
28
+ request = Net::HTTP::Delete.new(uri.request_uri)
29
+
30
+ request["Content-Type"] = "application/json"
31
+ request["Authorization"] = "Bearer #{self.oauth_token.access_token}"
32
+
33
+ response = http.request(request)
34
+
35
+ # Got access token from Jive
36
+ if (response.code.to_i === 201)
37
+ #json_body = JSON.parse(response.body)
38
+ end
39
+ end
40
+
41
+ # Registers the webhook with Jive
42
+ def register_webhook
43
+ require "open-uri"
44
+ require "net/http"
45
+ require "openssl"
46
+
47
+ uri = URI.parse("#{self.add_on.jive_url}/api/core/v3/webhooks")
48
+ http = Net::HTTP.new(uri.host, uri.port)
49
+ http.use_ssl = true
50
+
51
+ request = Net::HTTP::Post.new(uri.request_uri)
52
+
53
+ request["Content-Type"] = "application/json"
54
+ request["Authorization"] = "Bearer #{self.oauth_token.access_token}"
55
+
56
+ request.body = {
57
+ "events" => self.events,
58
+ "callback" => self.callback,
59
+ "object" => self.object,
60
+ }.to_json
61
+
62
+ response = http.request(request)
63
+
64
+ errors[:base] << "#{request.inspect} => #{response.inspect}"
65
+
66
+ # Got access token from Jive
67
+ if !response.code.to_i.between?(200, 299)
68
+ #json_body = JSON.parse(response.body)
69
+ return false
70
+ end
71
+
72
+ true
73
+ end
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,7 @@
1
+ require "active_record"
2
+
3
+ module Jive
4
+ class Webhook < ActiveRecord::Base
5
+ VERSION = "0.0.1"
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,210 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jive-webhook
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Butch Marshall
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-02-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activerecord
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '3.0'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '5.0'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: '3.0'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '5.0'
33
+ - !ruby/object:Gem::Dependency
34
+ name: jive-add_on
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: 0.0.2
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: 0.0.2
47
+ - !ruby/object:Gem::Dependency
48
+ name: jive-oauth_token
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: 0.0.3
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: 0.0.3
61
+ - !ruby/object:Gem::Dependency
62
+ name: sqlite3
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">"
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">"
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ - !ruby/object:Gem::Dependency
76
+ name: database_cleaner
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ - !ruby/object:Gem::Dependency
90
+ name: factory_girl
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">"
94
+ - !ruby/object:Gem::Version
95
+ version: '4.0'
96
+ type: :development
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">"
101
+ - !ruby/object:Gem::Version
102
+ version: '4.0'
103
+ - !ruby/object:Gem::Dependency
104
+ name: bundler
105
+ requirement: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - "~>"
108
+ - !ruby/object:Gem::Version
109
+ version: '1.11'
110
+ type: :development
111
+ prerelease: false
112
+ version_requirements: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - "~>"
115
+ - !ruby/object:Gem::Version
116
+ version: '1.11'
117
+ - !ruby/object:Gem::Dependency
118
+ name: rake
119
+ requirement: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - "~>"
122
+ - !ruby/object:Gem::Version
123
+ version: '10.0'
124
+ type: :development
125
+ prerelease: false
126
+ version_requirements: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - "~>"
129
+ - !ruby/object:Gem::Version
130
+ version: '10.0'
131
+ - !ruby/object:Gem::Dependency
132
+ name: rspec
133
+ requirement: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - "~>"
136
+ - !ruby/object:Gem::Version
137
+ version: '3.0'
138
+ type: :development
139
+ prerelease: false
140
+ version_requirements: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - "~>"
143
+ - !ruby/object:Gem::Version
144
+ version: '3.0'
145
+ - !ruby/object:Gem::Dependency
146
+ name: webmock
147
+ requirement: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - ">="
150
+ - !ruby/object:Gem::Version
151
+ version: '0'
152
+ type: :development
153
+ prerelease: false
154
+ version_requirements: !ruby/object:Gem::Requirement
155
+ requirements:
156
+ - - ">="
157
+ - !ruby/object:Gem::Version
158
+ version: '0'
159
+ description: Implements the functionality required for dealing with and storing Jive
160
+ Webhooks using ActiveRecord as a storage backend.
161
+ email:
162
+ - butch.a.marshall@gmail.com
163
+ executables: []
164
+ extensions: []
165
+ extra_rdoc_files: []
166
+ files:
167
+ - ".gitignore"
168
+ - ".rspec"
169
+ - ".travis.yml"
170
+ - Gemfile
171
+ - README.md
172
+ - Rakefile
173
+ - bin/console
174
+ - bin/setup
175
+ - jive-webhook.gemspec
176
+ - lib/generators/jive/webhook/active_record_generator.rb
177
+ - lib/generators/jive/webhook/next_migration_version.rb
178
+ - lib/generators/jive/webhook/templates/migration_0.1.0.rb
179
+ - lib/generators/jive/webhook/webhook_generator.rb
180
+ - lib/jive/webhook.rb
181
+ - lib/jive/webhook/class_methods.rb
182
+ - lib/jive/webhook/compatibility.rb
183
+ - lib/jive/webhook/configuration.rb
184
+ - lib/jive/webhook/instance_methods.rb
185
+ - lib/jive/webhook/version.rb
186
+ homepage: https://github.com/butchmarshall/ruby-jive-webhook
187
+ licenses:
188
+ - MIT
189
+ metadata: {}
190
+ post_install_message:
191
+ rdoc_options: []
192
+ require_paths:
193
+ - lib
194
+ required_ruby_version: !ruby/object:Gem::Requirement
195
+ requirements:
196
+ - - ">="
197
+ - !ruby/object:Gem::Version
198
+ version: '0'
199
+ required_rubygems_version: !ruby/object:Gem::Requirement
200
+ requirements:
201
+ - - ">="
202
+ - !ruby/object:Gem::Version
203
+ version: '0'
204
+ requirements: []
205
+ rubyforge_project:
206
+ rubygems_version: 2.4.6
207
+ signing_key:
208
+ specification_version: 4
209
+ summary: Jive Webhook functionality implemented using ActiveRecord.
210
+ test_files: []