sj-tinder 1.9.3
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 +15 -0
- data/.gemtest +0 -0
- data/.gitignore +5 -0
- data/.rspec +3 -0
- data/.travis.yml +13 -0
- data/CHANGELOG.txt +79 -0
- data/Gemfile +7 -0
- data/MIT-LICENSE +20 -0
- data/README.markdown +45 -0
- data/Rakefile +9 -0
- data/init.rb +1 -0
- data/lib/faraday/response/raise_on_authentication_failure.rb +10 -0
- data/lib/faraday/response/remove_whitespace.rb +10 -0
- data/lib/tinder.rb +20 -0
- data/lib/tinder/campfire.rb +76 -0
- data/lib/tinder/connection.rb +115 -0
- data/lib/tinder/room.rb +307 -0
- data/lib/tinder/version.rb +4 -0
- data/site/index.html +101 -0
- data/site/stylesheets/style.css +77 -0
- data/spec/fixtures/rooms.json +18 -0
- data/spec/fixtures/rooms/recent.json +19 -0
- data/spec/fixtures/rooms/room80749.json +21 -0
- data/spec/fixtures/rooms/room80751.json +21 -0
- data/spec/fixtures/rooms/show.json +21 -0
- data/spec/fixtures/users/me.json +11 -0
- data/spec/spec_helper.rb +27 -0
- data/spec/tinder/campfire_spec.rb +93 -0
- data/spec/tinder/connection_spec.rb +104 -0
- data/spec/tinder/room_spec.rb +330 -0
- data/tinder.gemspec +31 -0
- metadata +246 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
Yzc5YmJkYTg5YmYyOWZiNjZmOGQyMjlkNTYwMWZhMDMyYjQ3NWNmMg==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
NjQ5ZTk4ZTVlNmJmMzg5Zjk3YzIxMTFiY2IyZjk0Y2FjYjMxYzljNg==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
OWZlMTEwOTYyNzQ2NDFmYjE4MDg5ZTQ4MTk4MzEzYWViMTg4YTg1MDI5NzA1
|
10
|
+
YjM4ZjY5ZWQxOTM3ZTU5ZDM2Zjk0MTdhM2RiMzNiM2E2NjkwN2QxZjIxNDI1
|
11
|
+
YTg4ZDRhMWIwMjVmNThiNmUyZDY0MDAwNDkwYjA3NzI1NTY5M2I=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
NmU4M2YwZmQ0NGVlZWE3MDA3ZTY4N2I1NDRiOWY2ZmIyZWVmZmU4ZjJkZTg2
|
14
|
+
YzA3ZDRhODM0MjM4ZjFjNTBkM2MxM2Q3NjFhNTQ3OGE4MWI0Y2Y3N2QxZGRk
|
15
|
+
ZjY1NWU1ZDQzZDYwNThiYjA5MWU5NzM2YWM4MTI2ZWQzOGI1MTI=
|
data/.gemtest
ADDED
File without changes
|
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CHANGELOG.txt
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
1.9.2 - 2013-01-04
|
2
|
+
* Update dependencies to latest versions
|
3
|
+
|
4
|
+
1.9.0 - 2012-07-16
|
5
|
+
* Add Room#recent to get a list of recent messages
|
6
|
+
* Add Room#search to search a room's transcripts
|
7
|
+
|
8
|
+
1.4.3 - 2010-12-07
|
9
|
+
* explicitly require 'uri'
|
10
|
+
* added Room#tweet(url)
|
11
|
+
|
12
|
+
1.4.2 - 2010-11-13
|
13
|
+
* Use Faraday instead of HTTParty [eric]
|
14
|
+
* Fix file uploads [eric]
|
15
|
+
|
16
|
+
1.4.1 - 2010-10-09
|
17
|
+
* Make SSL the default since it is available for all Campfire accounts.
|
18
|
+
* Added MIT License
|
19
|
+
|
20
|
+
1.4 - 2010-05-11
|
21
|
+
* Remove methods no longer supported by API
|
22
|
+
Campfire#available_transcripts, Room#ping, Room#destroy, Room#toggle_guest_access
|
23
|
+
* Added Room#play
|
24
|
+
* ActiveSupport 3.0 support
|
25
|
+
* Fix streaming API support
|
26
|
+
* Allow SSL for listening
|
27
|
+
* Add support for HTTP proxies [c13bcc0b]
|
28
|
+
|
29
|
+
1.3.1 - 2009-12-17
|
30
|
+
* Declare HTTParty dependency
|
31
|
+
* Fix Room#paste
|
32
|
+
|
33
|
+
1.3.0 - 2009-12-15
|
34
|
+
* Rewrite to use Official Campfire API
|
35
|
+
|
36
|
+
1.2.2 - 2009-09-12
|
37
|
+
* Work around CSRF protection bug
|
38
|
+
* Fixes for changes to Campfire markup
|
39
|
+
* Include timestamps in the transcript
|
40
|
+
|
41
|
+
1.2.1 - 2009-08-27
|
42
|
+
* Fixes for listening after campfire updates [Jordan Byron]
|
43
|
+
|
44
|
+
1.2.0 - 2009-01-28
|
45
|
+
* Get the list of available files [Christopher MacGown]
|
46
|
+
* Upload files [Joshua Wand]
|
47
|
+
* Find rooms even when full [Josh Owens]
|
48
|
+
* Join rooms as a guest [Ian Lesperance]
|
49
|
+
|
50
|
+
1.1.7 - 2008-07-24
|
51
|
+
* Don't join the room when only speaking [Brian Donovan]
|
52
|
+
* Added support for HTTP proxies
|
53
|
+
* Fix listening for messages that contain URLs [Jared Kuolt]
|
54
|
+
|
55
|
+
0.1.6 - 2008-03-07
|
56
|
+
* Added Room#topic for getting the current topic [Even Weaver]
|
57
|
+
* Trap INT in #listen(&block) [borrowed from Chris Shea's Pyre]
|
58
|
+
|
59
|
+
0.1.5 - 2008-01-25
|
60
|
+
* Fixed Room#listen, which was broken by latest Campfire deploy
|
61
|
+
* Fixed timeout when listening but not speaking that will eventually log you out [Clinton R. Nixon]
|
62
|
+
|
63
|
+
0.1.4 - 2007-07-23
|
64
|
+
* Support for transcripts
|
65
|
+
* Fixed Room#leave, which was broken by a Campfire deployment [Andy Smith]
|
66
|
+
|
67
|
+
0.1.3 - 2007-02-12
|
68
|
+
* added ssl support [Tero Parviainen]
|
69
|
+
|
70
|
+
0.1.2 - 2007-01-27
|
71
|
+
* fixed bug preventing #listen from working without a block
|
72
|
+
|
73
|
+
0.1.1 - 2007-01-27
|
74
|
+
* fix bug preventing speak from working
|
75
|
+
* incorporated "watching" from http://soylentfoo.jnewland.com/articles/2006/12/07/updates-to-marshmallow-the-campfire-bot
|
76
|
+
|
77
|
+
0.1.0 - 2007-01-23
|
78
|
+
* Initial release as gem
|
79
|
+
* Get the users in a room [Tero Parviainen]
|
data/Gemfile
ADDED
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2006-2010 Brandon Keepers, Collective Idea
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOa AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SaALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.markdown
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
# Tinder - get the Campfire started
|
2
|
+
|
3
|
+
Tinder is a library for interfacing with Campfire, the chat application from 37Signals, allowing you to programmatically manage and speak/listen in chat rooms. As of December 2009, thanks to initial work from Joshua Peek at 37signals, it now makes use of the official Campfire API (described at: http://developer.37signals.com/campfire/).
|
4
|
+
|
5
|
+
## Usage
|
6
|
+
|
7
|
+
campfire = Tinder::Campfire.new 'mysubdomain', :token => '546884b3d8fee4d80665g561caf7h9f3ea7b999e'
|
8
|
+
# or you can still use username/password and Tinder will look up your token
|
9
|
+
# campfire = Tinder::Campfire.new 'mysubdomain', :username => 'user', :password => 'pass'
|
10
|
+
# or if you have an OAuth token then you can use that to connect
|
11
|
+
# campfire = Tinder::Campfire.new 'mysubdomain', :oauth_token => '546884b3d8fee4d80665g561caf7h9f3ea7b999e'
|
12
|
+
|
13
|
+
room = campfire.rooms.first
|
14
|
+
room.rename 'New Room Names'
|
15
|
+
room.speak 'Hello world!'
|
16
|
+
room.paste "my pasted\ncode"
|
17
|
+
|
18
|
+
room = campfire.find_room_by_guest_hash 'abc123', 'John Doe'
|
19
|
+
room.speak 'Hello world!'
|
20
|
+
|
21
|
+
See the RDoc for more details.
|
22
|
+
|
23
|
+
## Installation
|
24
|
+
|
25
|
+
gem install tinder
|
26
|
+
|
27
|
+
## Continuous Integration
|
28
|
+
|
29
|
+
[](http://travis-ci.org/collectiveidea/tinder) [](https://gemnasium.com/collectiveidea/tinder)
|
30
|
+
|
31
|
+
## How to contribute
|
32
|
+
|
33
|
+
If you find what looks like a bug:
|
34
|
+
|
35
|
+
1. Check the GitHub issue tracker to see if anyone else has had the same issue.
|
36
|
+
http://github.com/collectiveidea/tinder/issues/
|
37
|
+
2. If you don't see anything, create an issue with information on how to reproduce it.
|
38
|
+
|
39
|
+
If you want to contribute an enhancement or a fix:
|
40
|
+
|
41
|
+
1. Fork the project on github.
|
42
|
+
http://github.com/collectiveidea/tinder
|
43
|
+
2. Make your changes with tests.
|
44
|
+
3. Commit the changes without making changes to the Rakefile, VERSION, or any other files that aren't related to your enhancement or fix
|
45
|
+
4. Send a pull request.
|
data/Rakefile
ADDED
data/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'tinder'
|
data/lib/tinder.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require 'tinder/connection'
|
3
|
+
require 'tinder/campfire'
|
4
|
+
require 'tinder/room'
|
5
|
+
require 'logger'
|
6
|
+
|
7
|
+
module Tinder
|
8
|
+
class Error < StandardError; end
|
9
|
+
class SSLRequiredError < Error; end
|
10
|
+
class AuthenticationFailed < Error; end
|
11
|
+
class ListenFailed < Error; end
|
12
|
+
|
13
|
+
def self.logger
|
14
|
+
@logger ||= Logger.new(ENV['TINDER_LOGGING'] ? STDOUT : nil)
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.logger=(logger)
|
18
|
+
@logger = logger
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
module Tinder
|
3
|
+
|
4
|
+
# == Usage
|
5
|
+
#
|
6
|
+
# campfire = Tinder::Campfire.new 'mysubdomain', :token => 'xyz'
|
7
|
+
#
|
8
|
+
# room = campfire.create_room 'New Room', 'My new campfire room to test tinder'
|
9
|
+
# room.speak 'Hello world!'
|
10
|
+
# room.destroy
|
11
|
+
#
|
12
|
+
# room = campfire.find_room_by_guest_hash 'abc123', 'John Doe'
|
13
|
+
# room.speak 'Hello world!'
|
14
|
+
class Campfire
|
15
|
+
attr_reader :connection
|
16
|
+
|
17
|
+
# Create a new connection to the campfire account with the given +subdomain+.
|
18
|
+
#
|
19
|
+
# == Options:
|
20
|
+
# * +:ssl+: use SSL for the connection, which is required if you have a Campfire SSL account.
|
21
|
+
# Defaults to true
|
22
|
+
# * +:ssl_options+: SSL options passed to the underlaying Faraday connection. Allows to specify if the SSL certificate should be verified (:verify => true|false) and to specify the path to the ssl certs directory (:ca_path => "path/certs")
|
23
|
+
# Defaults to {:verify => true}
|
24
|
+
# * +:proxy+: a proxy URI. (e.g. :proxy => 'http://user:pass@example.com:8000')
|
25
|
+
#
|
26
|
+
# c = Tinder::Campfire.new("mysubdomain", :ssl => true)
|
27
|
+
def initialize(subdomain, options = {})
|
28
|
+
@connection = Connection.new(subdomain, options)
|
29
|
+
end
|
30
|
+
|
31
|
+
# Get an array of all the available rooms
|
32
|
+
# TODO: detect rooms that are full (no link)
|
33
|
+
def rooms
|
34
|
+
connection.get('/rooms.json')['rooms'].map do |room|
|
35
|
+
Room.new(connection, room)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
# Find a campfire room by id
|
40
|
+
# NOTE: id should be of type Integer
|
41
|
+
def find_room_by_id(id)
|
42
|
+
id = id.to_i
|
43
|
+
rooms.detect { |room| room.id == id }
|
44
|
+
end
|
45
|
+
|
46
|
+
# Find a campfire room by name
|
47
|
+
def find_room_by_name(name)
|
48
|
+
rooms.detect { |room| room.name == name }
|
49
|
+
end
|
50
|
+
|
51
|
+
# Find a campfire room by its guest hash
|
52
|
+
def find_room_by_guest_hash(hash, name)
|
53
|
+
rooms.detect { |room| room.guest_invite_code == hash }
|
54
|
+
end
|
55
|
+
|
56
|
+
# Creates and returns a new Room with the given +name+ and optionally a +topic+
|
57
|
+
def create_room(name, topic = nil)
|
58
|
+
connection.post('/rooms.json', { :room => { :name => name, :topic => topic } })
|
59
|
+
find_room_by_name(name)
|
60
|
+
end
|
61
|
+
|
62
|
+
def find_or_create_room_by_name(name)
|
63
|
+
find_room_by_name(name) || create_room(name)
|
64
|
+
end
|
65
|
+
|
66
|
+
# List the users that are currently chatting in any room
|
67
|
+
def users
|
68
|
+
rooms.map(&:users).flatten.compact.uniq.sort_by {|u| u[:name]}
|
69
|
+
end
|
70
|
+
|
71
|
+
# get the user info of the current user
|
72
|
+
def me
|
73
|
+
connection.get("/users/me.json")["user"]
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,115 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require 'faraday'
|
3
|
+
require 'faraday/response/raise_on_authentication_failure'
|
4
|
+
require 'faraday/response/remove_whitespace'
|
5
|
+
require 'faraday_middleware'
|
6
|
+
require 'json'
|
7
|
+
require 'uri'
|
8
|
+
|
9
|
+
module Tinder
|
10
|
+
class Connection
|
11
|
+
HOST = 'campfirenow.com'
|
12
|
+
|
13
|
+
attr_reader :subdomain, :uri, :options
|
14
|
+
|
15
|
+
def self.connection
|
16
|
+
@connection ||= Faraday.new do |builder|
|
17
|
+
builder.use FaradayMiddleware::EncodeJson
|
18
|
+
builder.use FaradayMiddleware::Mashify
|
19
|
+
builder.use FaradayMiddleware::ParseJson
|
20
|
+
builder.use Faraday::Response::RemoveWhitespace
|
21
|
+
builder.use Faraday::Response::RaiseOnAuthenticationFailure
|
22
|
+
builder.adapter Faraday.default_adapter
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.raw_connection
|
27
|
+
@raw_connection ||= Faraday.new do |builder|
|
28
|
+
builder.use Faraday::Request::Multipart
|
29
|
+
builder.use FaradayMiddleware::Mashify
|
30
|
+
builder.use FaradayMiddleware::ParseJson
|
31
|
+
builder.use Faraday::Response::RemoveWhitespace
|
32
|
+
builder.use Faraday::Response::RaiseOnAuthenticationFailure
|
33
|
+
builder.adapter Faraday.default_adapter
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def initialize(subdomain, options = {})
|
38
|
+
@subdomain = subdomain
|
39
|
+
@options = {:ssl => true, :ssl_options => {:verify => true}, :proxy => ENV['HTTP_PROXY']}
|
40
|
+
@options[:ssl_options][:verify] = options.delete(:ssl_verify) unless options[:ssl_verify].nil?
|
41
|
+
@options.merge!(options)
|
42
|
+
@uri = URI.parse("#{@options[:ssl] ? 'https' : 'http' }://#{subdomain}.#{HOST}")
|
43
|
+
@token = options[:token]
|
44
|
+
@oauth_token = options[:oauth_token]
|
45
|
+
|
46
|
+
if @oauth_token
|
47
|
+
connection.headers["Authorization"] = "Bearer #{@oauth_token}"
|
48
|
+
raw_connection.headers["Authorization"] = "Bearer #{@oauth_token}"
|
49
|
+
else
|
50
|
+
connection.basic_auth token, 'X'
|
51
|
+
raw_connection.basic_auth token, 'X'
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def basic_auth_settings
|
56
|
+
{:username => token, :password => 'X'}
|
57
|
+
end
|
58
|
+
|
59
|
+
def connection
|
60
|
+
@connection ||= begin
|
61
|
+
conn = self.class.connection.dup
|
62
|
+
set_connection_options(conn)
|
63
|
+
conn
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def raw_connection
|
68
|
+
@raw_connection ||= begin
|
69
|
+
conn = self.class.raw_connection.dup
|
70
|
+
set_connection_options(conn)
|
71
|
+
conn
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def token
|
76
|
+
@token ||= begin
|
77
|
+
connection.basic_auth(options[:username], options[:password])
|
78
|
+
get('/users/me.json')['user']['api_auth_token']
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
def get(url, *args)
|
83
|
+
response = connection.get(url, *args)
|
84
|
+
response.body
|
85
|
+
end
|
86
|
+
|
87
|
+
def post(url, body = nil, *args)
|
88
|
+
response = connection.post(url, body, *args)
|
89
|
+
response.body
|
90
|
+
end
|
91
|
+
|
92
|
+
def raw_post(url, body = nil, *args)
|
93
|
+
response = raw_connection.post(url, body, *args)
|
94
|
+
end
|
95
|
+
|
96
|
+
def put(url, body = nil, *args)
|
97
|
+
response = connection.put(url, body, *args)
|
98
|
+
response.body
|
99
|
+
end
|
100
|
+
|
101
|
+
# Is the connection to campfire using ssl?
|
102
|
+
def ssl?
|
103
|
+
uri.scheme == 'https'
|
104
|
+
end
|
105
|
+
|
106
|
+
private
|
107
|
+
def set_connection_options(conn)
|
108
|
+
conn.url_prefix = @uri.to_s
|
109
|
+
conn.proxy options[:proxy]
|
110
|
+
if options[:ssl_options]
|
111
|
+
conn.ssl.merge!(options[:ssl_options])
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|