ruboty-adapters-twitter_direct_message 0.0.1

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: add8929f74364d2d3aa4a768f55c7a3f3cc9fedb
4
+ data.tar.gz: a37009474bf174b52353570283acb9d7b9ee5759
5
+ SHA512:
6
+ metadata.gz: ca272819cba70196c2aec7383a2ece05ce87c1b30b42375ebe5ce5bb67fb157109b1900b40a44622a5128d4a02759ff90251117f053101339b09df4a230142cf
7
+ data.tar.gz: f9d98e6a47331121c8fef73e2f5120ca48c356e55c55e395d79ebed99c7cb52f7c10128cec33ac3b31487a72eaa27458ec4ff59d240d92c2e1e340c7d7d29b46
@@ -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
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.1
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ruboty-adapters-twitter_direct_message.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 en30
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,24 @@
1
+ # Ruboty::Adapters::TwitterDirectMessage
2
+ A [Ruboty](https://github.com/r7kamura/ruboty) adapter, which reacts to Twitter direct messages.
3
+
4
+ ## Usage
5
+ ```ruby
6
+ # Gemfile
7
+ gem 'ruboty-adapters-twitter_direct_message'
8
+ ```
9
+
10
+ ## ENV
11
+ ```
12
+ TWITTER_ACCESS_TOKEN - Twitter access token
13
+ TWITTER_ACCESS_TOKEN_SECRET - Twitter access token secret
14
+ TWITTER_CONSUMER_KEY - Twitter consumer key (a.k.a. API key)
15
+ TWITTER_CONSUMER_SECRET - Twitter consumer secret (a.k.a. API secret)
16
+ ```
17
+
18
+ ## Contributing
19
+
20
+ 1. Fork it ( https://github.com/[my-github-username]/ruboty-adapters-twitter_direct_message/fork )
21
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
22
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
23
+ 4. Push to the branch (`git push origin my-new-feature`)
24
+ 5. Create a new Pull Request
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "ruboty/adapters/twitter_direct_message"
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
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,79 @@
1
+ require 'ruboty'
2
+ require 'mem'
3
+ require 'twitter'
4
+ require 'active_support/inflector'
5
+
6
+ module Ruboty
7
+ module Adapters
8
+ class TwitterDirectMessage < Base
9
+ include Mem
10
+
11
+ VERSION = Gem.loaded_specs[name.underscore.tr('/', '-')].version.to_s.freeze
12
+ SMALL_WHITE_SPACE_EMOJI = "\xE2\x96\xAB"
13
+
14
+ env :TWITTER_ACCESS_TOKEN, 'Twitter access token'
15
+ env :TWITTER_ACCESS_TOKEN_SECRET, 'Twitter access token secret'
16
+ env :TWITTER_CONSUMER_KEY, 'Twitter consumer key (a.k.a. API key)'
17
+ env :TWITTER_CONSUMER_SECRET, 'Twitter consumer secret (a.k.a. API secret)'
18
+
19
+ def run
20
+ Thread.abort_on_exception = true
21
+ listen
22
+ end
23
+
24
+ def say(message)
25
+ split_for_tweet(message[:body]).each do |msg|
26
+ utter msg, target: message[:original][:from]
27
+ end
28
+ end
29
+
30
+ private
31
+
32
+ def listen
33
+ stream.user do |message|
34
+ if message.is_a? ::Twitter::DirectMessage
35
+ robot.receive(
36
+ body: message.text,
37
+ from: message.sender.screen_name
38
+ )
39
+ end
40
+ end
41
+ end
42
+
43
+ def configure
44
+ proc do |config|
45
+ config.consumer_key = ENV['TWITTER_CONSUMER_KEY']
46
+ config.consumer_secret = ENV['TWITTER_CONSUMER_SECRET']
47
+ config.access_token = ENV['TWITTER_ACCESS_TOKEN']
48
+ config.access_token_secret = ENV['TWITTER_ACCESS_TOKEN_SECRET']
49
+ end
50
+ end
51
+ memoize :configure
52
+
53
+ def client
54
+ ::Twitter::REST::Client.new(&configure)
55
+ end
56
+ memoize :client
57
+
58
+ def stream
59
+ ::Twitter::Streaming::Client.new(&configure)
60
+ end
61
+ memoize :stream
62
+
63
+ def split_for_tweet(text)
64
+ text.scan(/(?:\S{100,140}(?=\r?\n)|\S{120,140}(?=\s)|.{1,140})/)
65
+ end
66
+
67
+ def utter(text, target: , limit: 5)
68
+ client.create_direct_message(target, text)
69
+ rescue ::Twitter::Error => e
70
+ if e.message.include?('You already said that') and limit > 1
71
+ # twitter ignores normal white spaces
72
+ utter(text << SMALL_WHITE_SPACE_EMOJI, target: target, limit: limit - 1)
73
+ else
74
+ Ruboty.logger.error(e)
75
+ end
76
+ end
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "ruboty-adapters-twitter_direct_message"
7
+ spec.version = "0.0.1"
8
+ spec.authors = ["en30"]
9
+ spec.email = ["en30.git@gmail.com"]
10
+
11
+ spec.summary = %q{A Ruboty adapter for twitter direct messages.}
12
+ spec.homepage = "https://github.com/en30/ruboty-adapters-twitter_direct_message"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
16
+ spec.bindir = "exe"
17
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_dependency "mem"
21
+ spec.add_dependency "ruboty"
22
+ spec.add_dependency "activesupport"
23
+ spec.add_dependency "twitter", ">= 5.0.0"
24
+ spec.add_development_dependency "bundler", "~> 1.8"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ end
metadata ADDED
@@ -0,0 +1,140 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruboty-adapters-twitter_direct_message
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - en30
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-03-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: mem
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
+ - !ruby/object:Gem::Dependency
28
+ name: ruboty
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: activesupport
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: twitter
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: 5.0.0
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: 5.0.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: bundler
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.8'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.8'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '10.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '10.0'
97
+ description:
98
+ email:
99
+ - en30.git@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".rspec"
106
+ - ".travis.yml"
107
+ - CODE_OF_CONDUCT.md
108
+ - Gemfile
109
+ - LICENSE.txt
110
+ - README.md
111
+ - Rakefile
112
+ - bin/console
113
+ - bin/setup
114
+ - lib/ruboty/adapters/twitter_direct_message.rb
115
+ - ruboty-adapters-twitter_direct_message.gemspec
116
+ homepage: https://github.com/en30/ruboty-adapters-twitter_direct_message
117
+ licenses:
118
+ - MIT
119
+ metadata: {}
120
+ post_install_message:
121
+ rdoc_options: []
122
+ require_paths:
123
+ - lib
124
+ required_ruby_version: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - ">="
127
+ - !ruby/object:Gem::Version
128
+ version: '0'
129
+ required_rubygems_version: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - ">="
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ requirements: []
135
+ rubyforge_project:
136
+ rubygems_version: 2.4.5
137
+ signing_key:
138
+ specification_version: 4
139
+ summary: A Ruboty adapter for twitter direct messages.
140
+ test_files: []