ruboty-sqs 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +39 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/lib/ruboty-sqs.rb +1 -0
- data/lib/ruboty/handlers/sqs.rb +65 -0
- data/lib/ruboty/sqs.rb +2 -0
- data/lib/ruboty/sqs/version.rb +5 -0
- data/ruboty-sqs.gemspec +26 -0
- metadata +112 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 45832cb0bd18de2d32571a9cb19f4034cdd7a10a
|
4
|
+
data.tar.gz: 102c5addcc9da3152118c7b15e592a6f7c46599f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 59ee549ae22652852f57031d6e9ea186dbf7dc63b49a8a1fa57c1ca4bdf6cfd5159e376ca3b3ae772e505528ee68192e6839c2362e6fd21d3109b47e48607cbc
|
7
|
+
data.tar.gz: 1889756ed61c9ef5735239b885c67830fe1ac9a51a64b0e73dc712e68e306d7b3931e696142a5d669dfdbd4700a56063318d50cac09352b9f3c9ef4974398f23
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Sho Kusano
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# Ruboty::Sqs
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/ruboty/sqs`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'ruboty-sqs'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install ruboty-sqs
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
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` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
1. Fork it ( https://github.com/rosylilly/ruboty-sqs/fork )
|
36
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
37
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
38
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
39
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "ruboty/sqs"
|
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
data/lib/ruboty-sqs.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'ruboty/sqs'
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'ruboty'
|
2
|
+
require 'aws-sdk'
|
3
|
+
|
4
|
+
class Ruboty::Handlers::SQS < Ruboty::Handlers::Base
|
5
|
+
env :SQS_ROOM, 'Default room for receive message'
|
6
|
+
env :SQS_URL, 'URL of SQS Endpoint'
|
7
|
+
env :AWS_REGION, 'Region of AWS', optional: true
|
8
|
+
|
9
|
+
def initialize(*args)
|
10
|
+
super
|
11
|
+
|
12
|
+
polling
|
13
|
+
end
|
14
|
+
|
15
|
+
def send_message(message)
|
16
|
+
channel = (message[:message_attributes] || {})['channel']
|
17
|
+
channel = channel ? channel[:string_value] : ENV['SQS_ROOM']
|
18
|
+
|
19
|
+
robot.say(
|
20
|
+
body: message[:body],
|
21
|
+
to: channel
|
22
|
+
)
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def sqs
|
28
|
+
@sqs = ::Aws::SQS::Client.new()
|
29
|
+
end
|
30
|
+
|
31
|
+
def polling
|
32
|
+
@polling_thread ||= begin
|
33
|
+
th = Thread.new(self, sqs) do |robot, sqs|
|
34
|
+
loop do
|
35
|
+
begin
|
36
|
+
resp = sqs.receive_message(
|
37
|
+
queue_url: ENV['SQS_URL'],
|
38
|
+
attribute_names: %w(All),
|
39
|
+
message_attribute_names: [],
|
40
|
+
max_number_of_messages: 3,
|
41
|
+
wait_time_seconds: 10
|
42
|
+
)
|
43
|
+
|
44
|
+
messages = resp[:messages]
|
45
|
+
|
46
|
+
messages.each do |message|
|
47
|
+
robot.send_message(message)
|
48
|
+
end
|
49
|
+
|
50
|
+
sqs.delete_message_batch(
|
51
|
+
queue_url: ENV['SQS_URL'],
|
52
|
+
entries: messages.map { |m| { id: m[:message_id], receipt_handle: m[:receipt_handle] } }
|
53
|
+
) unless messages.empty?
|
54
|
+
rescue Aws::SQS::Errors::ServiceError => e
|
55
|
+
p e
|
56
|
+
rescue => e
|
57
|
+
p e
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
th.run
|
62
|
+
th
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
data/lib/ruboty/sqs.rb
ADDED
data/ruboty-sqs.gemspec
ADDED
@@ -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
|
+
require 'ruboty/sqs/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "ruboty-sqs"
|
8
|
+
spec.version = Ruboty::Sqs::VERSION
|
9
|
+
spec.authors = ["Sho Kusano"]
|
10
|
+
spec.email = ["rosylilly@aduca.org"]
|
11
|
+
|
12
|
+
spec.summary = %q{AWS SQS binding for ruboty}
|
13
|
+
spec.description = spec.summary
|
14
|
+
spec.homepage = "https://github.com/rosylilly/ruboty-sqs"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.8"
|
23
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
24
|
+
spec.add_dependency 'ruboty'
|
25
|
+
spec.add_dependency 'aws-sdk', '~> 2'
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,112 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ruboty-sqs
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sho Kusano
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-03-16 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.8'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.8'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: ruboty
|
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: aws-sdk
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '2'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '2'
|
69
|
+
description: AWS SQS binding for ruboty
|
70
|
+
email:
|
71
|
+
- rosylilly@aduca.org
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- Gemfile
|
78
|
+
- LICENSE.txt
|
79
|
+
- README.md
|
80
|
+
- Rakefile
|
81
|
+
- bin/console
|
82
|
+
- bin/setup
|
83
|
+
- lib/ruboty-sqs.rb
|
84
|
+
- lib/ruboty/handlers/sqs.rb
|
85
|
+
- lib/ruboty/sqs.rb
|
86
|
+
- lib/ruboty/sqs/version.rb
|
87
|
+
- ruboty-sqs.gemspec
|
88
|
+
homepage: https://github.com/rosylilly/ruboty-sqs
|
89
|
+
licenses:
|
90
|
+
- MIT
|
91
|
+
metadata: {}
|
92
|
+
post_install_message:
|
93
|
+
rdoc_options: []
|
94
|
+
require_paths:
|
95
|
+
- lib
|
96
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
97
|
+
requirements:
|
98
|
+
- - ">="
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: '0'
|
101
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
103
|
+
- - ">="
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '0'
|
106
|
+
requirements: []
|
107
|
+
rubyforge_project:
|
108
|
+
rubygems_version: 2.4.6
|
109
|
+
signing_key:
|
110
|
+
specification_version: 4
|
111
|
+
summary: AWS SQS binding for ruboty
|
112
|
+
test_files: []
|