cinch-strawpoll 0.0.9 → 0.1.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7dcf12ae48ab7672ee9e49cb92a18780b73a8054
4
- data.tar.gz: c19b56cb8e4e37be079e1597fe381f496ed431a6
3
+ metadata.gz: b720770da56c8fb949a017cc17458585dae6818d
4
+ data.tar.gz: b9fe95e703b1136f9f5956f90f9aed7134f75f39
5
5
  SHA512:
6
- metadata.gz: 62ab5e1b3c570207ad6414e60f2a4e9430f88d030e715b6977c7d38a203a231b34547ae22548c444f565493af90384e183c8bd147d19a13d9eadef5a04e11e8e
7
- data.tar.gz: 253a3720057ab89cdb4926f0ba50a6279f432512f025424288c2fa7b74d70dc69f9ff08c6f55ae80b4b3ab3dee2dc5ee560e251d16429f0ce0edfac32f839e9c
6
+ metadata.gz: c3504195cd83234c735f2fe0bbcc6b5ab37f983a286ee6a76218ccae2c8bd6e01a85b8375b1e44614c01401a9aca0f724d47a6e5105cf914dd40b93ef90ec8c8
7
+ data.tar.gz: 72dcb15ce4c37a07a5302d918fa357bd174f57a1143b19629bfb8d834c68afb5d40710002db69ccb50761cf88fd73938ef01012bf400be93f7f8f054233c274d
data/.gitattributes ADDED
@@ -0,0 +1,17 @@
1
+ # Auto detect text files and perform LF normalization
2
+ * text=auto
3
+
4
+ # Custom for Visual Studio
5
+ *.cs diff=csharp
6
+
7
+ # Standard to msysgit
8
+ *.doc diff=astextplain
9
+ *.DOC diff=astextplain
10
+ *.docx diff=astextplain
11
+ *.DOCX diff=astextplain
12
+ *.dot diff=astextplain
13
+ *.DOT diff=astextplain
14
+ *.pdf diff=astextplain
15
+ *.PDF diff=astextplain
16
+ *.rtf diff=astextplain
17
+ *.RTF diff=astextplain
data/README.md CHANGED
@@ -1,17 +1,23 @@
1
+ [![Chatrealm IRC][irc-chatrealm-badge]][irc-chatrealm-link]
2
+ [![Support tinnvec][support-tinnvec-badge]][support-tinnvec-link]
3
+
1
4
  # cinch-strawpoll
2
5
  Strawpoll plugin for Cinch. http://strawpoll.me
3
6
 
4
7
  ## Installation
8
+
5
9
  In your `Gemfile`
6
- ```ruby
10
+ ```Ruby
7
11
  gem 'cinch-strawpoll'
8
12
  ```
9
- Don't forget to `bundle`
10
- ```bash
11
- $ bundle
13
+
14
+ Don't forget to `bundle install`
15
+ ```Shell
16
+ bundle install
12
17
  ```
18
+
13
19
  Add to your bot config
14
- ```ruby
20
+ ```Ruby
15
21
  require 'cinch'
16
22
  require 'cinch/plugins/strawpoll'
17
23
  ...
@@ -25,8 +31,8 @@ bot = Cinch::Bot.new do
25
31
  c.plugins.options = {
26
32
  ...
27
33
  Cinch::Plugins::Strawpoll => {
28
- repeat_time: 60 # Seconds to wait between poll notifications
29
- repeat_count: 3 # Total number of poll notifications
34
+ repeat_time: 60, # Seconds to wait between poll notifications
35
+ repeat_count: 3 # Total number of poll notifications
30
36
  }
31
37
  }
32
38
  end
@@ -34,10 +40,15 @@ end
34
40
  ```
35
41
 
36
42
  ## Usage
37
- ```
43
+ ```IRC
38
44
  !poll <title> | <option>, <option>
39
45
  ```
40
- Requests a straw poll using `<title>` and a minimum of 2 `<option>` separated by commas.
46
+ Request a strawpoll using `<title>` and a minimum of 2 `<option>` separated by commas.
47
+
48
+ Announcements will be made `repeat_count` times, one every `repeat_time` seconds.
49
+
50
+ [irc-chatrealm-link]: http://irc.chatrealm.net
51
+ [irc-chatrealm-badge]: https://img.shields.io/badge/irc-chatrealm-orange.svg?style=flat-square
41
52
 
42
- ## Support
43
- Like my code? Want to support my coffee habit? http://tinnvec.com/support
53
+ [support-tinnvec-link]: http://tinnvec.com/support
54
+ [support-tinnvec-badge]: https://img.shields.io/badge/Support-tinnvec-blue.svg?style=flat-square
data/bin/htmldiff CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
  #
3
4
  # This file was generated by Bundler.
4
5
  #
@@ -6,11 +7,11 @@
6
7
  # this file is here to facilitate running it.
7
8
  #
8
9
 
9
- require 'pathname'
10
- ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
10
+ require "pathname"
11
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
11
12
  Pathname.new(__FILE__).realpath)
12
13
 
13
- require 'rubygems'
14
- require 'bundler/setup'
14
+ require "rubygems"
15
+ require "bundler/setup"
15
16
 
16
- load Gem.bin_path('diff-lcs', 'htmldiff')
17
+ load Gem.bin_path("cinch-strawpoll", "htmldiff")
data/bin/ldiff CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
  #
3
4
  # This file was generated by Bundler.
4
5
  #
@@ -6,11 +7,11 @@
6
7
  # this file is here to facilitate running it.
7
8
  #
8
9
 
9
- require 'pathname'
10
- ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
10
+ require "pathname"
11
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
11
12
  Pathname.new(__FILE__).realpath)
12
13
 
13
- require 'rubygems'
14
- require 'bundler/setup'
14
+ require "rubygems"
15
+ require "bundler/setup"
15
16
 
16
- load Gem.bin_path('diff-lcs', 'ldiff')
17
+ load Gem.bin_path("cinch-strawpoll", "ldiff")
data/bin/rake CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
  #
3
4
  # This file was generated by Bundler.
4
5
  #
@@ -6,11 +7,11 @@
6
7
  # this file is here to facilitate running it.
7
8
  #
8
9
 
9
- require 'pathname'
10
- ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
10
+ require "pathname"
11
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
11
12
  Pathname.new(__FILE__).realpath)
12
13
 
13
- require 'rubygems'
14
- require 'bundler/setup'
14
+ require "rubygems"
15
+ require "bundler/setup"
15
16
 
16
- load Gem.bin_path('rake', 'rake')
17
+ load Gem.bin_path("cinch-strawpoll", "rake")
data/bin/rspec CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
  #
3
4
  # This file was generated by Bundler.
4
5
  #
@@ -6,11 +7,11 @@
6
7
  # this file is here to facilitate running it.
7
8
  #
8
9
 
9
- require 'pathname'
10
- ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
10
+ require "pathname"
11
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
11
12
  Pathname.new(__FILE__).realpath)
12
13
 
13
- require 'rubygems'
14
- require 'bundler/setup'
14
+ require "rubygems"
15
+ require "bundler/setup"
15
16
 
16
- load Gem.bin_path('rspec-core', 'rspec')
17
+ load Gem.bin_path("cinch-strawpoll", "rspec")
@@ -1,30 +1,32 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'cinch/plugins/strawpoll/version'
5
-
6
- Gem::Specification.new do |spec|
7
- spec.name = 'cinch-strawpoll'
8
- spec.version = Cinch::Plugins::Strawpoll::VERSION
9
- spec.authors = ['Alex Hanna']
10
- spec.email = ['tinnvec@gmail.com']
11
- spec.description = 'A Strawpoll plugin for Cinch.'
12
- spec.summary = 'A Cinch plugin for creating polls on http://strawpoll.me'
13
- spec.homepage = 'https://github.com/tinnvec/cinch-strawpoll'
14
- spec.license = 'MIT'
15
-
16
- spec.files = `git ls-files`.split("\n")
17
- spec.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
- spec.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
- spec.require_paths = ['lib']
20
-
21
- # Gem dependencies
22
- spec.add_dependency 'cinch', '~> 2.3.1', '>= 2.3.1'
23
- spec.add_dependency 'cinch-authentication', '~> 0.1.1'
24
- spec.add_dependency 'json', '~> 1.8.3', '>= 1.8.3'
25
-
26
- # Development dependencies
27
- spec.add_development_dependency 'bundler', '~> 1.3'
28
- spec.add_development_dependency 'rake', '~> 0'
29
- spec.add_development_dependency 'rspec', '~> 0'
30
- end
1
+ # coding: utf-8
2
+ # file: cinch-strawpoll.gemspec
3
+
4
+ lib = File.expand_path('../lib', __FILE__)
5
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
6
+ require 'cinch/plugins/strawpoll/version'
7
+
8
+ Gem::Specification.new do |spec|
9
+ spec.name = 'cinch-strawpoll'
10
+ spec.version = Cinch::Plugins::Strawpoll::VERSION
11
+ spec.authors = ['Alex Hanna']
12
+ spec.email = ['tinnvec@gmail.com']
13
+ spec.description = 'A Strawpoll plugin for Cinch.'
14
+ spec.summary = 'A Cinch plugin for creating polls on http://strawpoll.me'
15
+ spec.homepage = 'https://github.com/tinnvec/cinch-strawpoll'
16
+ spec.license = 'MIT'
17
+
18
+ spec.files = `git ls-files`.split("\n")
19
+ spec.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
20
+ spec.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
21
+ spec.require_paths = ['lib']
22
+
23
+ # Gem dependencies
24
+ spec.add_dependency 'cinch', '~> 2.3.1', '>= 2.3.1'
25
+ spec.add_dependency 'cinch-authentication', '~> 0.1.1'
26
+ spec.add_dependency 'httparty', '~> 0.13.7'
27
+ spec.add_dependency 'json', '~> 1.8.3', '>= 1.8.3'
28
+
29
+ # Development dependencies
30
+ spec.add_development_dependency 'bundler', '~> 1.3'
31
+ spec.add_development_dependency 'rake', '~> 0'
32
+ end
@@ -1,57 +1,59 @@
1
- require 'cinch'
2
- require 'cinch/extensions/authentication'
3
- require 'json'
4
- require 'net/http'
5
- require 'uri'
6
-
7
- module Cinch
8
- module Plugins
9
-
10
- class Strawpoll
11
- include Cinch::Plugin
12
- include Cinch::Extensions::Authentication
13
-
14
- enable_authentication
15
- set :plugin_name, 'strawpoll'
16
- set :help, <<-HELP.gsub(/^ {6}/, '')
17
- !poll <title> | <option>, <option>
18
- Requests a straw poll using <title> and a minimum of 2 <option> separated by commas.
19
- HELP
20
-
21
- def initialize(*args)
22
- super
23
- @repeat_time = config[:repeat_time] || 60
24
- @repeat_count = config[:repeat_count] || 3
25
- @allow_pol = config[:allow_pol] || false
26
- end
27
-
28
- match /(poll?)\s(.+)\|(.+)/
29
- def execute(m, mode, title, options_string)
30
- return if mode == "pol" && !@allow_pol
31
- options = options_string.split(",").collect { |o| o = o.strip }
32
- options << "pol pot" if mode == "pol" && @allow_pol
33
- response = request_poll(title.strip, options)
34
- unless response['id'].nil?
35
- 3.times do
36
- Channel(@bot.channels.first).send "#{Format(:white, :blue, " VOTE ")} #{title.strip} https://strawpoll.me/#{response['id']}"
37
- sleep 60
38
- end
39
- else
40
- m.user.notice "Error: #{response['error']}"
41
- end
42
- end
43
-
44
- private
45
-
46
- def request_poll(title, options)
47
- uri = URI('https://strawpoll.me/api/v2/polls/')
48
- req = Net::HTTP::Post.new(uri.path, { 'Content-Type' => 'application/json' })
49
- req.body = { title: title, options: options, multi: false }.to_json
50
- @bot.debug "Request body: #{req.body}"
51
- res = Net::HTTP.start(uri.host, uri.port, :use_ssl => true) { |http| http.request req }
52
- JSON.parse(res.body)
53
- end
54
- end
55
-
56
- end
57
- end
1
+ # coding: utf-8
2
+ # file: lib/cinch/plugins/strawpoll.rb
3
+
4
+ require 'cinch'
5
+ require 'cinch/extensions/authentication'
6
+
7
+ require 'strawpoll/api'
8
+
9
+ module Cinch
10
+ module Plugins
11
+ class Strawpoll
12
+ include Cinch::Plugin
13
+ include Cinch::Extensions::Authentication
14
+
15
+ enable_authentication
16
+
17
+ set :plugin_name, 'strawpoll'
18
+ set :help, '!poll <title> | <choice>, <choice> - Request a ' +
19
+ 'strawpoll using <title> and a minimum of 2 <choice> ' +
20
+ 'separated by commas.'
21
+
22
+ match(/(poll?)\s(.+)\|(.+)/)
23
+
24
+ def initialize(*args)
25
+ super
26
+ @repeat_time = config[:repeat_time] || 60
27
+ @repeat_count = config[:repeat_count] || 3
28
+ @allow_pol = config[:allow_pol] || false
29
+
30
+ @strawpoll_api = Cinch::Plugins::Strawpoll::Api.new
31
+ end
32
+
33
+ def execute(m, mode, title, choices_string)
34
+ return if mode == 'pol' && !@allow_pol
35
+
36
+ choices = choices_string.split(',').collect { |o| o = o.strip }
37
+ choices << 'pol pot' if mode == 'pol' && @allow_pol
38
+
39
+ response = @strawpoll_api.create_poll(title.strip, choices)
40
+
41
+ if !response['id'].nil? && @repeat_count > 0
42
+ Thread.new(Channel(m.channel)) do |channel|
43
+ @repeat_count.times do
44
+ announcement = Format(:white, :blue, " VOTE ")
45
+ announcement += " #{title.strip}"
46
+ announcement += " https://strawpoll.me/#{response['id']}"
47
+ channel.send(announcement)
48
+ sleep @repeat_time
49
+ end
50
+ end
51
+ else
52
+ m.user.notice "Error: #{response['error']}"
53
+ end
54
+ end
55
+
56
+ private
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,35 @@
1
+ # coding: utf-8
2
+ # file: lib/cinch/plugins/strawpoll/api.rb
3
+
4
+ require 'httparty'
5
+ require 'json'
6
+
7
+ module Cinch
8
+ module Plugins
9
+ module Strawpoll
10
+ class Api
11
+ include HTTParty
12
+
13
+ base_uri 'https://strawpoll.me/api/v2'
14
+
15
+ def create_poll(title, choices)
16
+ response = create_poll_request(title, choices)
17
+ return response
18
+ end
19
+
20
+ private
21
+
22
+ def create_poll_request(title, choices)
23
+ options = {
24
+ headers: { 'Content-Type' => 'application/json' },
25
+ body: {
26
+ title: title, options: choices, multi: false
27
+ }.to_json
28
+ }
29
+ response = self.class.post('/polls', options)
30
+ return JSON.parse(response)
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -1,7 +1,10 @@
1
- module Cinch
2
- module Plugins
3
- module Strawpoll
4
- VERSION = '0.0.9'
5
- end
6
- end
7
- end
1
+ # coding: utf-8
2
+ # file: lib/cinch/plugins/strawpoll/version.rb
3
+
4
+ module Cinch
5
+ module Plugins
6
+ module Strawpoll
7
+ VERSION = '0.1.6'
8
+ end
9
+ end
10
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cinch-strawpoll
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Hanna
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-12-04 00:00:00.000000000 Z
11
+ date: 2016-05-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cinch
@@ -44,6 +44,20 @@ dependencies:
44
44
  - - "~>"
45
45
  - !ruby/object:Gem::Version
46
46
  version: 0.1.1
47
+ - !ruby/object:Gem::Dependency
48
+ name: httparty
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: 0.13.7
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: 0.13.7
47
61
  - !ruby/object:Gem::Dependency
48
62
  name: json
49
63
  requirement: !ruby/object:Gem::Requirement
@@ -92,20 +106,6 @@ dependencies:
92
106
  - - "~>"
93
107
  - !ruby/object:Gem::Version
94
108
  version: '0'
95
- - !ruby/object:Gem::Dependency
96
- name: rspec
97
- requirement: !ruby/object:Gem::Requirement
98
- requirements:
99
- - - "~>"
100
- - !ruby/object:Gem::Version
101
- version: '0'
102
- type: :development
103
- prerelease: false
104
- version_requirements: !ruby/object:Gem::Requirement
105
- requirements:
106
- - - "~>"
107
- - !ruby/object:Gem::Version
108
- version: '0'
109
109
  description: A Strawpoll plugin for Cinch.
110
110
  email:
111
111
  - tinnvec@gmail.com
@@ -117,6 +117,7 @@ executables:
117
117
  extensions: []
118
118
  extra_rdoc_files: []
119
119
  files:
120
+ - ".gitattributes"
120
121
  - ".gitignore"
121
122
  - Gemfile
122
123
  - LICENSE
@@ -127,6 +128,7 @@ files:
127
128
  - bin/rspec
128
129
  - cinch-strawpoll.gemspec
129
130
  - lib/cinch/plugins/strawpoll.rb
131
+ - lib/cinch/plugins/strawpoll/api.rb
130
132
  - lib/cinch/plugins/strawpoll/version.rb
131
133
  homepage: https://github.com/tinnvec/cinch-strawpoll
132
134
  licenses:
@@ -148,7 +150,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
148
150
  version: '0'
149
151
  requirements: []
150
152
  rubyforge_project:
151
- rubygems_version: 2.4.6
153
+ rubygems_version: 2.5.1
152
154
  signing_key:
153
155
  specification_version: 4
154
156
  summary: A Cinch plugin for creating polls on http://strawpoll.me