thredded-pushover-notifier 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 14c7d00afee25b4c123a25999d6d8c586d82cb93
4
+ data.tar.gz: 4a991a5f59392f765a36927d5559e29c4bbe3250
5
+ SHA512:
6
+ metadata.gz: 45d3ac6bbe84efb64d1630764e17636426b03522e356361789a59c15b43cfff43ae886b58bd1da208b7ce8e48c48305506895fc92e0405f3b74febc60aca7184
7
+ data.tar.gz: a1a519717bf7fb696ed70d11c81726083c7021e8ecd25929013dca7a24d4dd7d20b17de515479a26457ad5999f528308af83fe87be226b278a75e3269caaa9ea
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /log
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,14 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.3
3
+ Exclude:
4
+ - './spec/dummy/**/*'
5
+ DisplayCopNames: true
6
+ Metrics/BlockLength:
7
+ Enabled: false
8
+ Metrics/LineLength:
9
+ Max: 120
10
+ Metrics/MethodLength:
11
+ Enabled: false
12
+ Style/Documentation:
13
+ Enabled: false
14
+
@@ -0,0 +1,11 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.3.1
4
+ cache: bundler
5
+ bundler_args: --path ../../vendor/bundle --without debug
6
+ gemfile:
7
+ - Gemfile
8
+
9
+ script:
10
+ - bundle exec rspec
11
+ - bundle exec rubocop
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at tim@red56.co.uk. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in thredded-pushover-notifier.gemspec
6
+ # gem 'thredded', github: 'thredded/thredded', branch: 'master'
7
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Tim Diggins
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,58 @@
1
+ # Thredded Pushover Notifier [![Build Status](https://travis-ci.org/thredded/thredded-pushover-notifier.svg?branch=master)](https://travis-ci.org/thredded/thredded-pushover-notifier)
2
+
3
+
4
+ A notifier for [Thredded](https://github.com/thredded/thredded/) allowing push notifications to be sent via [Pushover](https://pushover.net/)
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile
9
+
10
+ ```ruby
11
+ gem 'thredded-pushover-notifier'
12
+ ```
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install thredded-pushover-notifier
21
+
22
+ ## Usage
23
+
24
+ * You will need a Pushover app token (see the first option on https://pushover.net/api)
25
+ * Let's assume you've added your Pushover app token as an environment variable `PUSHOVER_APP_TOKEN`.
26
+ * You will need to have Thredded working already (at least v0.13.4) and have an initializer already in your rails app.
27
+ * Let's assume your app is being served at http://example.com
28
+
29
+ To setup two notifiers - email and pushover, add the following to the bottom of your thredded.rb initializer:
30
+
31
+ ```ruby
32
+ Thredded::Engine.config.to_prepare do
33
+ require 'thredded/pushover_notifier/content_helper'
34
+ Thredded::PushoverNotifier::ContentHelper.include Thredded::Engine.routes.url_helpers
35
+ pushover_notifier = Thredded::PushoverNotifier.new(ENV['PUSHOVER_APP_TOKEN'], 'http://example.com')
36
+ Thredded.notifiers = [Thredded::EmailNotifier.new, pushover_notifier]
37
+ end
38
+ ```
39
+
40
+
41
+
42
+
43
+
44
+ ## Development
45
+
46
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
47
+
48
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
49
+
50
+ ## Contributing
51
+
52
+ Bug reports and pull requests are welcome on GitHub at https://github.com/thredded/thredded-pushover-notifier. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
53
+
54
+
55
+ ## License
56
+
57
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
58
+
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'thredded/pushover/notifier'
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require 'irb'
15
+ IRB.start
@@ -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,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'net/https'
4
+
5
+ module Thredded
6
+ class PushoverNotifier
7
+ VERSION = '0.1.0'
8
+
9
+ def initialize(pushover_app_token, root_url)
10
+ @pushover_app_token = pushover_app_token
11
+ @root_url = root_url
12
+ end
13
+
14
+ def key
15
+ 'pushover'
16
+ end
17
+
18
+ def human_name
19
+ I18n.t('pushover_notifier.by_pushover')
20
+ end
21
+
22
+ def new_post(post, users)
23
+ require 'thredded/pushover_notifier/content_helper'
24
+ helper = Thredded::PushoverNotifier::ContentHelper.new(@root_url, post)
25
+ args = [helper.message_for_new_topic_post, helper.title_for_new_topic_post, helper.post_url]
26
+ users.map(&:pushover_user_key).each do |user_key|
27
+ send_message(user_key, *args) if user_key.present?
28
+ end
29
+ end
30
+
31
+ def new_private_post; end
32
+
33
+ def send_message(user_key, message, title, url)
34
+ pushover_url = URI.parse('https://api.pushover.net/1/messages.json')
35
+ req = Net::HTTP::Post.new(pushover_url.path)
36
+ data = {
37
+ token: @pushover_app_token,
38
+ user: user_key,
39
+ message: message,
40
+ title: title,
41
+ url: url,
42
+ url_title: 'View topic'
43
+ }
44
+ req.set_form_data(data)
45
+ res = Net::HTTP.new(pushover_url.host, pushover_url.port)
46
+ res.use_ssl = true
47
+ res.verify_mode = OpenSSL::SSL::VERIFY_PEER
48
+ res.start { |http| http.request(req) }
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails'
4
+ require 'action_view'
5
+
6
+ module Thredded
7
+ class PushoverNotifier
8
+ class ContentHelper
9
+ include ActionView::Helpers::TextHelper
10
+
11
+ attr_reader :post, :root_url
12
+
13
+ def initialize(root_url, post)
14
+ @root_url = root_url
15
+ @post = post
16
+ end
17
+
18
+ def message_for_new_topic_post
19
+ content_truncated(replace_images)
20
+ end
21
+
22
+ def title_for_new_topic_post
23
+ "#{post.postable.title} by @#{post.user.thredded_display_name} [#{post.messageboard.name}]"
24
+ end
25
+
26
+ def post_url
27
+ "#{root_url}#{post_permalink_path(post.id)}"
28
+ end
29
+
30
+ protected
31
+
32
+ def replace_images
33
+ post.content.gsub(/!\[[^\]]*?\]\(([^)]*?)\)/, '[IMAGE]')
34
+ end
35
+
36
+ def content_truncated(content)
37
+ truncate(content, length: 100, separator: ' ')
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ # frozen_string_literal: true
3
+
4
+ lib = File.expand_path('../lib', __FILE__)
5
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
6
+ require 'thredded/pushover_notifier'
7
+
8
+ Gem::Specification.new do |spec|
9
+ spec.name = 'thredded-pushover-notifier'
10
+ spec.version = Thredded::PushoverNotifier::VERSION
11
+ spec.authors = ['Tim Diggins', 'Ella Schofield']
12
+ spec.email = ['tim@red56.uk']
13
+
14
+ spec.summary = 'A notifier for Thredded to push new post notifications to the Pushover app'
15
+ spec.homepage = 'https://github.com/thredded/thredded-pushover-notifier'
16
+ spec.license = 'MIT'
17
+
18
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
19
+ spec.bindir = 'exe'
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ['lib']
22
+
23
+ spec.add_runtime_dependency 'thredded', '~> 0.13', '>= 0.13.4'
24
+ spec.add_runtime_dependency 'actionview'
25
+
26
+ spec.add_development_dependency 'bundler', '~> 1.12'
27
+ spec.add_development_dependency 'rake', '~> 10.0'
28
+ spec.add_development_dependency 'rspec', '~> 3.0'
29
+ spec.add_development_dependency 'sqlite3'
30
+ spec.add_development_dependency 'rubocop', '~> 0.49.1'
31
+ end
metadata ADDED
@@ -0,0 +1,163 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: thredded-pushover-notifier
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Tim Diggins
8
+ - Ella Schofield
9
+ autorequire:
10
+ bindir: exe
11
+ cert_chain: []
12
+ date: 2017-09-11 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: thredded
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '0.13'
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 0.13.4
24
+ type: :runtime
25
+ prerelease: false
26
+ version_requirements: !ruby/object:Gem::Requirement
27
+ requirements:
28
+ - - "~>"
29
+ - !ruby/object:Gem::Version
30
+ version: '0.13'
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 0.13.4
34
+ - !ruby/object:Gem::Dependency
35
+ name: actionview
36
+ requirement: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ type: :runtime
42
+ prerelease: false
43
+ version_requirements: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ - !ruby/object:Gem::Dependency
49
+ name: bundler
50
+ requirement: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.12'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.12'
62
+ - !ruby/object:Gem::Dependency
63
+ name: rake
64
+ requirement: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ type: :development
70
+ prerelease: false
71
+ version_requirements: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '10.0'
76
+ - !ruby/object:Gem::Dependency
77
+ name: rspec
78
+ requirement: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ type: :development
84
+ prerelease: false
85
+ version_requirements: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.0'
90
+ - !ruby/object:Gem::Dependency
91
+ name: sqlite3
92
+ requirement: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ type: :development
98
+ prerelease: false
99
+ version_requirements: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ - !ruby/object:Gem::Dependency
105
+ name: rubocop
106
+ requirement: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 0.49.1
111
+ type: :development
112
+ prerelease: false
113
+ version_requirements: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: 0.49.1
118
+ description:
119
+ email:
120
+ - tim@red56.uk
121
+ executables: []
122
+ extensions: []
123
+ extra_rdoc_files: []
124
+ files:
125
+ - ".gitignore"
126
+ - ".rspec"
127
+ - ".rubocop.yml"
128
+ - ".travis.yml"
129
+ - CODE_OF_CONDUCT.md
130
+ - Gemfile
131
+ - LICENSE.txt
132
+ - README.md
133
+ - Rakefile
134
+ - bin/console
135
+ - bin/setup
136
+ - lib/thredded/pushover_notifier.rb
137
+ - lib/thredded/pushover_notifier/content_helper.rb
138
+ - thredded-pushover-notifier.gemspec
139
+ homepage: https://github.com/thredded/thredded-pushover-notifier
140
+ licenses:
141
+ - MIT
142
+ metadata: {}
143
+ post_install_message:
144
+ rdoc_options: []
145
+ require_paths:
146
+ - lib
147
+ required_ruby_version: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - ">="
150
+ - !ruby/object:Gem::Version
151
+ version: '0'
152
+ required_rubygems_version: !ruby/object:Gem::Requirement
153
+ requirements:
154
+ - - ">="
155
+ - !ruby/object:Gem::Version
156
+ version: '0'
157
+ requirements: []
158
+ rubyforge_project:
159
+ rubygems_version: 2.6.10
160
+ signing_key:
161
+ specification_version: 4
162
+ summary: A notifier for Thredded to push new post notifications to the Pushover app
163
+ test_files: []