This repository has been archived by the owner on Jul 21, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Renaming lib to ChatGram. Add a Campfire service.
- Loading branch information
1 parent
65c2c20
commit c69853c
Showing
3 changed files
with
87 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
module ChatGram | ||
# Defines the simple API that all chat services should honor. | ||
class Service | ||
def initialize(options = {}) | ||
raise NotImplementedError | ||
end | ||
|
||
def speak(text) | ||
raise NotImplementedError | ||
end | ||
|
||
require 'faraday' | ||
|
||
# This is a class that knows how to speak in a Campfire channel. | ||
class Campfire | ||
# Sets up an HTTP client with the following Campfire options. | ||
# | ||
# options - Hash of options: | ||
# domain - The String subdomain of the Campfire account. | ||
# room - The String Campfire Room ID. | ||
# token - The String token for the Campfire account. | ||
# | ||
# Returns nothing. | ||
def initialize(options = {}) | ||
url = "https://%s.campfirenow.com/room/%s" % [ | ||
options[:domain], | ||
options[:room]] | ||
@conn = Faraday.new url do |b| | ||
b.request :yajl | ||
b.adapter :excon | ||
end | ||
@conn.basic_auth options[:token], 'X' | ||
end | ||
|
||
# Posts the given message to the Campfire room. | ||
# | ||
# text - The String message to be sent to the chat room. | ||
# | ||
# Returns nothing. | ||
def speak(text) | ||
@conn.post 'speak.json', :message => {:body => text} | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters