tarumi 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: b1dc45129272a733c25133c4f0735da412585237
4
+ data.tar.gz: 8960015ed1b1ec4234dd8c11cee4996e17393f08
5
+ SHA512:
6
+ metadata.gz: 9d8dea22f78f6411cff9ebe642bb8e7d24df26358b013334e419054f98ab4a304b1c9e9d9449fdc7b279e65eabe44730efb562b85cce1baf9a896e5643fa6c1c
7
+ data.tar.gz: abed9a0ea945f41be881160f847a2a26629499cfe4e9d663e634715164b2131d1ec9dbafb52cb78fc6404c105e6e8c9ed4b9c44b2c20dda70889683e2b5d05b2
data/.gitignore ADDED
@@ -0,0 +1,32 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+
19
+ # OS specific files
20
+ .DS_Store
21
+ .netrc
22
+
23
+ *.diff
24
+ *.err
25
+ *.orig
26
+ *.log
27
+ *.rej
28
+ *.swo
29
+ *.swp
30
+ *.zip
31
+ *.vi
32
+ *~
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in tarumi.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) <year> <copyright holders>
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/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Abraham Kuri
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,88 @@
1
+ # Tarumi
2
+ ===
3
+
4
+ Tarumi is a super simple library written in Ruby to interact with [Slack](https://slack.com/) webhooks. It was written by [Abraham Kuri](https://github.com/kurenn) from [Icalia Labs](https://github.com/IcaliaLabs).
5
+
6
+ ## Table of contents
7
+ - [Configure Slack](#configure-slack)
8
+ - [Installation & Usage](#installation-&-usage)
9
+ - [Contributing](#contributing)
10
+ - [Heroes](#heroes)
11
+ - [License](#license)
12
+
13
+ ## Configure Slack
14
+
15
+ Before you can start integrating the gem, you need to first add a webhook to which the bot wil ping and then send out the message, so let's do that:
16
+
17
+ 1. Open [https://api.slack.com/](https://api.slack.com/) and sign in if you haven't
18
+ 2. Go to the [Integrations](https://icalialabs.slack.com/services/new) section
19
+ 3. Then look for the [Incoming WebHooks](https://icalialabs.slack.com/services/new/incoming-webhook) integration
20
+ 4. Select the channel you wish to hook the service
21
+ 5. You'll be redirected to a page with some steps to test the webhook, just take note of the token on the left.
22
+
23
+ You are now ready to go!
24
+
25
+
26
+ ## Installation & Usage
27
+
28
+ You can install and use Tarumi as a stand-alone library, to install it just run:
29
+
30
+ ```console
31
+ $ gem install tarumi
32
+ ```
33
+
34
+ If you are using Rails, just add it to your Gemfile:
35
+
36
+ ```ruby
37
+ gem "tarumi"
38
+ ```
39
+
40
+ And then run the `bundle` command to install it:
41
+
42
+ ```console
43
+ $ bundle
44
+ ```
45
+
46
+ A simple example on how to use it is presented below:
47
+
48
+ ```ruby
49
+ require 'tarumi'
50
+
51
+ slackBot = Tarumi::Bot.new("yourteam", "yourtoken", hash_of_options)
52
+ slackBot.ping "A text to post"
53
+ ```
54
+
55
+ The example above will post a message to the `#general` channel, but you can easily customize it with the hash of options when initializing the bot:
56
+
57
+ ```ruby
58
+ options = {
59
+ username: "usernametopost",
60
+ channel: "#anotherchannel",
61
+ hook_name: "webhookname"
62
+ }
63
+ ```
64
+ That should be it for you to easily configure the bot and start sending messages.
65
+
66
+
67
+
68
+ ## Contributing
69
+
70
+ 1. Fork it ( http://github.com/<my-github-username>/tarumi/fork )
71
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
72
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
73
+ 4. Push to the branch (`git push origin my-new-feature`)
74
+ 5. Create new Pull Request
75
+
76
+
77
+ ## Heroes
78
+
79
+ **Abraham Kuri**
80
+
81
+ + [http://twitter.com/kurenn](http://twitter.com/kurenn)
82
+ + [http://github.com/kurenn](http://github.com/kurenn)
83
+ + [http://klout.com/#/kurenn](http://klout.com/#/kurenn)
84
+
85
+
86
+ ## Copyright and license
87
+
88
+ Code and documentation copyright 2013-2014 Icalia Labs. Code released under [the MIT license](LICENSE).
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/lib/tarumi/bot.rb ADDED
@@ -0,0 +1,40 @@
1
+ require 'httparty'
2
+
3
+ module Tarumi
4
+ class Bot
5
+ include HTTParty
6
+
7
+ attr_reader :options, :username, :channel,
8
+ :hook_name
9
+
10
+ # Add the default format to be json on each request
11
+ format :json
12
+
13
+ # We don't want Rails to be nasty with the parameters we send
14
+ disable_rails_query_string_format if defined?(Rails)
15
+
16
+ def initialize(team, token, options = {})
17
+ self.class.base_uri("https://#{team}.slack.com")
18
+ self.class.default_params(token: token) #we sent this token on each request
19
+
20
+ @username = options[:username] || "webhookbot"
21
+ @channel = options[:channel] || "#general"
22
+ @hook_name = options[:hook_name] || "incoming-webhook"
23
+
24
+ raise ArgumentError, 'You need to specify a team' if team.blank?
25
+ raise ArgumentError, 'You need to specify the token, to get one go to https://yourteamname.slack.com/services/new' if token.blank?
26
+ end
27
+
28
+ def ping(text, options = {})
29
+ payload = { text: text, channel: @channel, username: @username }.merge(options)
30
+ body = { body: "payload=#{payload.to_json}"}
31
+
32
+ response = self.class.post("/services/hooks/#{@hook_name}", body)
33
+
34
+ raise ArgumentError, 'You need to specify a text' if text.blank?
35
+
36
+ "#{response.body} - #{response.code}"
37
+ end
38
+
39
+ end
40
+ end
@@ -0,0 +1,3 @@
1
+ module Tarumi
2
+ VERSION = "0.0.1"
3
+ end
data/lib/tarumi.rb ADDED
@@ -0,0 +1,8 @@
1
+ require "tarumi/version"
2
+ require 'active_support/dependencies'
3
+
4
+ module Tarumi
5
+ extend ActiveSupport::Autoload
6
+
7
+ autoload :Bot
8
+ end
data/tarumi.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 'tarumi/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "tarumi"
8
+ spec.version = Tarumi::VERSION
9
+ spec.authors = ["Abraham Kuri"]
10
+ spec.email = ["kurenn@icalialabs.com"]
11
+ spec.summary = %q{A super simple library to interact with Slack webhooks}
12
+ spec.description = %q{A super simple library to interact with Slack webhooks}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.5"
22
+ spec.add_development_dependency "rake"
23
+
24
+ spec.add_dependency "httparty"
25
+ spec.add_dependency "activesupport"
26
+ end
metadata ADDED
@@ -0,0 +1,111 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tarumi
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Abraham Kuri
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-09-06 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.5'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
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: httparty
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: activesupport
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: A super simple library to interact with Slack webhooks
70
+ email:
71
+ - kurenn@icalialabs.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - Gemfile
78
+ - LICENSE
79
+ - LICENSE.txt
80
+ - README.md
81
+ - Rakefile
82
+ - lib/tarumi.rb
83
+ - lib/tarumi/bot.rb
84
+ - lib/tarumi/version.rb
85
+ - tarumi.gemspec
86
+ homepage: ''
87
+ licenses:
88
+ - MIT
89
+ metadata: {}
90
+ post_install_message:
91
+ rdoc_options: []
92
+ require_paths:
93
+ - lib
94
+ required_ruby_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ required_rubygems_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ requirements: []
105
+ rubyforge_project:
106
+ rubygems_version: 2.2.1
107
+ signing_key:
108
+ specification_version: 4
109
+ summary: A super simple library to interact with Slack webhooks
110
+ test_files: []
111
+ has_rdoc: