tinder 1.4.1 → 1.4.2

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.txt CHANGED
@@ -1,3 +1,7 @@
1
+ 1.4.2 - 2010-11-13
2
+ * Use Faraday instead of HTTParty [eric]
3
+ * Fix file uploads [eric]
4
+
1
5
  1.4.1 - 2010-10-09
2
6
  * Make SSL the default since it is available for all Campfire accounts.
3
7
  * Added MIT License
data/Rakefile CHANGED
@@ -9,7 +9,8 @@ begin
9
9
  gem.homepage = 'http://github.com/collectiveidea/tinder'
10
10
  gem.rubyforge_project = "tinder"
11
11
  gem.add_dependency "activesupport"
12
- gem.add_dependency "httparty"
12
+ gem.add_dependency "faraday", "~> 0.5.1"
13
+ gem.add_dependency "multipart-post"
13
14
  gem.add_dependency "mime-types"
14
15
  gem.add_dependency "twitter-stream"
15
16
  gem.add_dependency "eventmachine"
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.4.1
1
+ 1.4.2
data/lib/tinder.rb CHANGED
@@ -1,10 +1,11 @@
1
1
  require 'active_support'
2
2
  require 'active_support/json'
3
+ require 'mime/types'
3
4
 
4
5
  require 'tinder/connection'
5
- require 'tinder/multipart'
6
6
  require 'tinder/campfire'
7
7
  require 'tinder/room'
8
+ require 'tinder/middleware'
8
9
 
9
10
  module Tinder
10
11
  class Error < StandardError; end
@@ -45,7 +45,7 @@ module Tinder
45
45
 
46
46
  # Creates and returns a new Room with the given +name+ and optionally a +topic+
47
47
  def create_room(name, topic = nil)
48
- connection.post('/rooms.json', :body => { :room => { :name => name, :topic => topic } }.to_json)
48
+ connection.post('/rooms.json', { :room => { :name => name, :topic => topic } })
49
49
  find_room_by_name(name)
50
50
  end
51
51
 
@@ -1,75 +1,93 @@
1
- require 'httparty'
2
- require 'active_support/core_ext/hash/indifferent_access'
3
-
4
- # override HTTParty's json parser to return a HashWithIndifferentAccess
5
- module HTTParty
6
- class Parser
7
- protected
8
- def json
9
- result = Crack::JSON.parse(body)
10
- if result.is_a?(Hash)
11
- result = HashWithIndifferentAccess.new(result)
12
- end
13
- result
14
- end
15
- end
16
- end
1
+ require 'faraday'
17
2
 
18
3
  module Tinder
19
4
  class Connection
20
5
  HOST = "campfirenow.com"
21
6
 
22
7
  attr_reader :subdomain, :uri, :options
23
-
8
+
9
+ def self.connection
10
+ @connection ||= Faraday::Connection.new do |conn|
11
+ conn.use Faraday::Request::ActiveSupportJson
12
+ conn.adapter Faraday.default_adapter
13
+ conn.use Tinder::FaradayResponse::RaiseOnAuthenticationFailure
14
+ conn.use Faraday::Response::ActiveSupportJson
15
+ conn.use Tinder::FaradayResponse::WithIndifferentAccess
16
+
17
+ conn.headers['Content-Type'] = 'application/json'
18
+ end
19
+ end
20
+
21
+ def self.raw_connection
22
+ @raw_connection ||= Faraday::Connection.new do |conn|
23
+ conn.adapter Faraday.default_adapter
24
+ conn.use Tinder::FaradayResponse::RaiseOnAuthenticationFailure
25
+ conn.use Faraday::Response::ActiveSupportJson
26
+ conn.use Tinder::FaradayResponse::WithIndifferentAccess
27
+ end
28
+ end
29
+
24
30
  def initialize(subdomain, options = {})
25
31
  @subdomain = subdomain
26
32
  @options = { :ssl => true, :proxy => ENV['HTTP_PROXY'] }.merge(options)
27
33
  @uri = URI.parse("#{@options[:ssl] ? 'https' : 'http' }://#{subdomain}.#{HOST}")
28
34
  @token = options[:token]
29
-
30
-
31
- class << self
32
- include HTTParty
33
- extend HTTPartyExtensions
34
-
35
- headers 'Content-Type' => 'application/json'
36
- end
37
-
38
- if @options[:proxy]
39
- proxy_uri = URI.parse(@options[:proxy])
40
- http_proxy proxy_uri.host, proxy_uri.port
35
+
36
+ connection.basic_auth token, 'X'
37
+ raw_connection.basic_auth token, 'X'
38
+ end
39
+
40
+ def basic_auth_settings
41
+ { :username => token, :password => 'X' }
42
+ end
43
+
44
+ def connection
45
+ @connection ||= begin
46
+ conn = self.class.connection.dup
47
+ conn.url_prefix = @uri.to_s
48
+ conn.proxy options[:proxy]
49
+ conn
41
50
  end
42
- base_uri @uri.to_s
43
- basic_auth token, 'X'
44
51
  end
45
-
46
- module HTTPartyExtensions
47
- def perform_request(http_method, path, options) #:nodoc:
48
- response = super
49
- raise AuthenticationFailed if response.code == 401
50
- response
52
+
53
+ def raw_connection
54
+ @raw_connection ||= begin
55
+ conn = self.class.raw_connection.dup
56
+ conn.url_prefix = @uri.to_s
57
+ conn.proxy options[:proxy]
58
+ conn
51
59
  end
52
60
  end
53
-
61
+
54
62
  def token
55
63
  @token ||= begin
56
- self.basic_auth(options[:username], options[:password])
57
- self.get('/users/me.json')['user']['api_auth_token']
64
+ connection.basic_auth(options[:username], options[:password])
65
+ get('/users/me.json')['user']['api_auth_token']
58
66
  end
59
67
  end
60
68
 
61
- def metaclass
62
- class << self; self; end
69
+ def get(url, *args)
70
+ response = connection.get(url, *args)
71
+ response.body
72
+ end
73
+
74
+ def post(url, body = nil, *args)
75
+ response = connection.post(url, body, *args)
76
+ response.body
63
77
  end
64
78
 
65
- def method_missing(*args, &block)
66
- metaclass.send(*args, &block)
79
+ def raw_post(url, body = nil, *args)
80
+ response = raw_connection.post(url, body, *args)
67
81
  end
68
-
82
+
83
+ def put(url, body = nil, *args)
84
+ response = connection.put(url, body, *args)
85
+ response.body
86
+ end
87
+
69
88
  # Is the connection to campfire using ssl?
70
89
  def ssl?
71
90
  uri.scheme == 'https'
72
91
  end
73
-
74
92
  end
75
93
  end
@@ -0,0 +1,30 @@
1
+ module Tinder
2
+ module FaradayResponse
3
+ class WithIndifferentAccess < ::Faraday::Response::Middleware
4
+ begin
5
+ require 'active_support/core_ext/hash/indifferent_access'
6
+ rescue LoadError, NameError => error
7
+ self.load_error = error
8
+ end
9
+
10
+ def self.register_on_complete(env)
11
+ env[:response].on_complete do |response|
12
+ json = response[:body]
13
+ if json.is_a?(Hash)
14
+ response[:body] = ::HashWithIndifferentAccess.new(json)
15
+ elsif json.is_a?(Array) and json.first.is_a?(Hash)
16
+ response[:body] = json.map{|item| ::HashWithIndifferentAccess.new(item) }
17
+ end
18
+ end
19
+ end
20
+ end
21
+
22
+ class RaiseOnAuthenticationFailure < ::Faraday::Response::Middleware
23
+ def self.register_on_complete(env)
24
+ env[:response].on_complete do |response|
25
+ raise AuthenticationFailed if response[:status] == 401
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
data/lib/tinder/room.rb CHANGED
@@ -49,7 +49,7 @@ module Tinder
49
49
  end
50
50
 
51
51
  def update(attrs)
52
- connection.put("/room/#{@id}.json", :body => {:room => attrs}.to_json)
52
+ connection.put("/room/#{@id}.json", {:room => attrs})
53
53
  end
54
54
 
55
55
  # Get the current topic
@@ -125,7 +125,7 @@ module Tinder
125
125
 
126
126
  require 'twitter/json_stream'
127
127
 
128
- auth = connection.default_options[:basic_auth]
128
+ auth = connection.basic_auth_settings
129
129
  options = {
130
130
  :host => "streaming.#{Connection::HOST}",
131
131
  :path => room_url_for(:live),
@@ -178,11 +178,9 @@ module Tinder
178
178
  end
179
179
  end
180
180
 
181
- def upload(filename)
182
- File.open(filename, "rb") do |file|
183
- params = Multipart::MultipartPost.new('upload' => file)
184
- post(:uploads, :body => params.query)
185
- end
181
+ def upload(file, content_type = nil, filename = nil)
182
+ content_type ||= MIME::Types.type_for(filename || file)
183
+ raw_post(:uploads, { :upload => Faraday::UploadIO.new(file, content_type, filename) })
186
184
  end
187
185
 
188
186
  # Get the list of latest files for this room
@@ -210,15 +208,19 @@ module Tinder
210
208
  end
211
209
 
212
210
  def send_message(message, type = 'TextMessage')
213
- post 'speak', :body => {:message => {:body => message, :type => type}}.to_json
211
+ post 'speak', {:message => {:body => message, :type => type}}
212
+ end
213
+
214
+ def get(action)
215
+ connection.get(room_url_for(action))
214
216
  end
215
217
 
216
- def get(action, options = {})
217
- connection.get(room_url_for(action), options)
218
+ def post(action, body = nil)
219
+ connection.post(room_url_for(action), body)
218
220
  end
219
221
 
220
- def post(action, options = {})
221
- connection.post(room_url_for(action), options)
222
+ def raw_post(action, body = nil)
223
+ connection.raw_post(room_url_for(action), body)
222
224
  end
223
225
 
224
226
  def room_url_for(action)
data/spec/spec_helper.rb CHANGED
@@ -10,4 +10,18 @@ FakeWeb.allow_net_connect = false
10
10
 
11
11
  def fixture(name)
12
12
  File.read(File.dirname(__FILE__) + "/fixtures/#{name}")
13
+ end
14
+
15
+ def stub_connection(object, &block)
16
+ @stubs ||= Faraday::Adapter::Test::Stubs.new
17
+
18
+ object.connection.build do |conn|
19
+ conn.use Faraday::Request::ActiveSupportJson
20
+ conn.adapter :test, @stubs
21
+ conn.use Tinder::FaradayResponse::RaiseOnAuthenticationFailure
22
+ conn.use Faraday::Response::ActiveSupportJson
23
+ conn.use Tinder::FaradayResponse::WithIndifferentAccess
24
+ end
25
+
26
+ block.call(@stubs)
13
27
  end
@@ -7,8 +7,9 @@ describe Tinder::Campfire do
7
7
 
8
8
  describe "rooms" do
9
9
  before do
10
- FakeWeb.register_uri(:get, "https://mytoken:X@test.campfirenow.com/rooms.json",
11
- :body => fixture('rooms.json'), :content_type => "application/json")
10
+ stub_connection(@campfire.connection) do |stub|
11
+ stub.get('/rooms.json') {[ 200, {}, fixture('rooms.json') ]}
12
+ end
12
13
  end
13
14
 
14
15
  it "should return rooms" do
@@ -25,11 +26,12 @@ describe Tinder::Campfire do
25
26
 
26
27
  describe "users" do
27
28
  before do
28
- FakeWeb.register_uri(:get, "https://mytoken:X@test.campfirenow.com/rooms.json",
29
- :body => fixture('rooms.json'), :content_type => "application/json")
30
- [80749, 80751].each do |id|
31
- FakeWeb.register_uri(:get, "https://mytoken:X@test.campfirenow.com/room/#{id}.json",
32
- :body => fixture("rooms/room#{id}.json"), :content_type => "application/json")
29
+ stub_connection(@campfire.connection) do |stub|
30
+ stub.get('/rooms.json') {[ 200, {}, fixture('rooms.json') ]}
31
+
32
+ [80749, 80751].each do |id|
33
+ stub.get("/room/#{id}.json") {[ 200, {}, fixture("rooms/room#{id}.json") ]}
34
+ end
33
35
  end
34
36
  end
35
37
 
@@ -42,8 +44,9 @@ describe Tinder::Campfire do
42
44
 
43
45
  describe "me" do
44
46
  before do
45
- FakeWeb.register_uri(:get, "https://mytoken:X@test.campfirenow.com/users/me.json",
46
- :body => fixture('users/me.json'), :content_type => "application/json")
47
+ stub_connection(@campfire.connection) do |stub|
48
+ stub.get("/users/me.json") {[ 200, {}, fixture('users/me.json') ]}
49
+ end
47
50
  end
48
51
 
49
52
  it "should return the current user's information" do
@@ -3,27 +3,30 @@ require 'spec_helper'
3
3
  describe Tinder::Connection do
4
4
  describe "authentication" do
5
5
  it "should raise an exception with bad credentials" do
6
- FakeWeb.register_uri(:get, "https://foo:X@test.campfirenow.com/rooms.json",
7
- :status => ["401", "Unauthorized"])
6
+ stub_connection(Tinder::Connection) do |stub|
7
+ stub.get("/rooms.json") {[ 401, {}, "Unauthorized" ]}
8
+ end
9
+
8
10
  connection = Tinder::Connection.new('test', :token => 'foo')
9
11
  lambda { connection.get('/rooms.json') }.should raise_error(Tinder::AuthenticationFailed)
10
12
  end
11
13
 
12
14
  it "should lookup token when username/password provided" do
13
- FakeWeb.register_uri(:get, "https://user:pass@test.campfirenow.com/users/me.json",
14
- :body => fixture('users/me.json'), :content_type => "application/json")
15
+ stub_connection(Tinder::Connection) do |stub|
16
+ stub.get("/users/me.json") {[ 200, {}, fixture('users/me.json') ]}
17
+ end
18
+
15
19
  connection = Tinder::Connection.new('test', :username => 'user', :password => 'pass')
16
20
  connection.token.should.should == "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
17
21
  end
18
22
 
19
23
 
20
24
  it "should use basic auth for credentials" do
21
- FakeWeb.register_uri(:get, "https://mytoken:X@test.campfirenow.com/rooms.json",
22
- :body => fixture('rooms.json'), :content_type => "application/json")
25
+ stub_connection(Tinder::Connection) do |stub|
26
+ stub.get("/rooms.json") {[ 200, {}, fixture('rooms.json') ]}
27
+ end
23
28
  connection = Tinder::Connection.new('test', :token => 'mytoken')
24
29
  lambda { connection.get('/rooms.json') }.should_not raise_error
25
30
  end
26
31
  end
27
-
28
-
29
32
  end
@@ -2,9 +2,13 @@ require 'spec_helper'
2
2
 
3
3
  describe Tinder::Room do
4
4
  before do
5
- FakeWeb.register_uri(:get, "https://mytoken:X@test.campfirenow.com/room/80749.json",
6
- :body => fixture('rooms/show.json'), :content_type => "application/json")
7
- @room = Tinder::Room.new(Tinder::Connection.new('test', :token => 'mytoken'), 'id' => 80749)
5
+ @connection = Tinder::Connection.new('test', :token => 'mytoken')
6
+
7
+ stub_connection(@connection) do |stub|
8
+ stub.get('/room/80749.json') {[ 200, {}, fixture('rooms/show.json') ]}
9
+ end
10
+
11
+ @room = Tinder::Room.new(@connection, 'id' => 80749)
8
12
 
9
13
  # Get EventMachine out of the way. We could be using em-spec, but seems like overkill
10
14
  require 'twitter/json_stream'
@@ -15,7 +19,12 @@ describe Tinder::Room do
15
19
  end
16
20
 
17
21
  describe "join" do
18
- FakeWeb.register_uri(:post, "https://mytoken:X@test.campfirenow.com/room/80749/join.json", :status => '200')
22
+ before do
23
+ stub_connection(@connection) do |stub|
24
+ stub.post('/room/80749/join.json') {[ 200, {}, "" ]}
25
+ end
26
+ end
27
+
19
28
 
20
29
  it "should post to join url" do
21
30
  @room.join
@@ -24,7 +33,9 @@ describe Tinder::Room do
24
33
 
25
34
  describe "leave" do
26
35
  before do
27
- FakeWeb.register_uri(:post, "https://mytoken:X@test.campfirenow.com/room/80749/leave.json", :status => '200')
36
+ stub_connection(@connection) do |stub|
37
+ stub.post('/room/80749/leave.json') {[ 200, {}, "" ]}
38
+ end
28
39
  end
29
40
 
30
41
  it "should post to leave url" do
@@ -39,7 +50,9 @@ describe Tinder::Room do
39
50
 
40
51
  describe "lock" do
41
52
  before do
42
- FakeWeb.register_uri(:post, "https://mytoken:X@test.campfirenow.com/room/80749/lock.json", :status => '200')
53
+ stub_connection(@connection) do |stub|
54
+ stub.post('/room/80749/lock.json') {[ 200, {}, "" ]}
55
+ end
43
56
  end
44
57
 
45
58
  it "should post to lock url" do
@@ -49,7 +62,9 @@ describe Tinder::Room do
49
62
 
50
63
  describe "unlock" do
51
64
  before do
52
- FakeWeb.register_uri(:post, "https://mytoken:X@test.campfirenow.com/room/80749/unlock.json", :status => '200')
65
+ stub_connection(@connection) do |stub|
66
+ stub.post('/room/80749/unlock.json') {[ 200, {}, "" ]}
67
+ end
53
68
  end
54
69
 
55
70
  it "should post to unlock url" do
@@ -79,13 +94,21 @@ describe Tinder::Room do
79
94
 
80
95
  describe "name=" do
81
96
  it "should put to update the room" do
82
- FakeWeb.register_uri(:put, "https://mytoken:X@test.campfirenow.com/room/80749.json",
83
- :status => '200')
97
+ stub_connection(@connection) do |stub|
98
+ stub.put('/room/80749.json') {[ 200, {}, "" ]}
99
+ end
100
+
84
101
  @room.name = "Foo"
85
102
  end
86
103
  end
87
104
 
88
105
  describe "listen" do
106
+ before do
107
+ stub_connection(@connection) do |stub|
108
+ stub.post('/room/80749/join.json') {[ 200, {}, "" ]}
109
+ end
110
+ end
111
+
89
112
  it "should get from the streaming url" do
90
113
  Twitter::JSONStream.should_receive(:connect).
91
114
  with({:host=>"streaming.campfirenow.com", :path=>"/room/80749/live.json", :auth=>"mytoken:X", :timeout=>6, :ssl=>true}).
@@ -109,6 +132,10 @@ describe Tinder::Room do
109
132
 
110
133
  describe "stop_listening" do
111
134
  before do
135
+ stub_connection(@connection) do |stub|
136
+ stub.post('/room/80749/join.json') {[ 200, {}, "" ]}
137
+ end
138
+
112
139
  Twitter::JSONStream.stub!(:connect).and_return(@stream)
113
140
  @stream.stub!(:stop)
114
141
  end
data/tinder.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{tinder}
8
- s.version = "1.4.1"
8
+ s.version = "1.4.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Brandon Keepers"]
12
- s.date = %q{2010-10-09}
12
+ s.date = %q{2010-11-13}
13
13
  s.description = %q{A Ruby API for interfacing with Campfire, the 37Signals chat application.}
14
14
  s.email = %q{brandon@opensoul.org}
15
15
  s.extra_rdoc_files = [
@@ -26,7 +26,7 @@ Gem::Specification.new do |s|
26
26
  "lib/tinder.rb",
27
27
  "lib/tinder/campfire.rb",
28
28
  "lib/tinder/connection.rb",
29
- "lib/tinder/multipart.rb",
29
+ "lib/tinder/middleware.rb",
30
30
  "lib/tinder/room.rb",
31
31
  "site/index.html",
32
32
  "site/stylesheets/style.css",
@@ -61,7 +61,8 @@ Gem::Specification.new do |s|
61
61
 
62
62
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
63
63
  s.add_runtime_dependency(%q<activesupport>, [">= 0"])
64
- s.add_runtime_dependency(%q<httparty>, [">= 0"])
64
+ s.add_runtime_dependency(%q<faraday>, ["~> 0.5.1"])
65
+ s.add_runtime_dependency(%q<multipart-post>, [">= 0"])
65
66
  s.add_runtime_dependency(%q<mime-types>, [">= 0"])
66
67
  s.add_runtime_dependency(%q<twitter-stream>, [">= 0"])
67
68
  s.add_runtime_dependency(%q<eventmachine>, [">= 0"])
@@ -69,7 +70,8 @@ Gem::Specification.new do |s|
69
70
  s.add_development_dependency(%q<fakeweb>, [">= 0"])
70
71
  else
71
72
  s.add_dependency(%q<activesupport>, [">= 0"])
72
- s.add_dependency(%q<httparty>, [">= 0"])
73
+ s.add_dependency(%q<faraday>, ["~> 0.5.1"])
74
+ s.add_dependency(%q<multipart-post>, [">= 0"])
73
75
  s.add_dependency(%q<mime-types>, [">= 0"])
74
76
  s.add_dependency(%q<twitter-stream>, [">= 0"])
75
77
  s.add_dependency(%q<eventmachine>, [">= 0"])
@@ -78,7 +80,8 @@ Gem::Specification.new do |s|
78
80
  end
79
81
  else
80
82
  s.add_dependency(%q<activesupport>, [">= 0"])
81
- s.add_dependency(%q<httparty>, [">= 0"])
83
+ s.add_dependency(%q<faraday>, ["~> 0.5.1"])
84
+ s.add_dependency(%q<multipart-post>, [">= 0"])
82
85
  s.add_dependency(%q<mime-types>, [">= 0"])
83
86
  s.add_dependency(%q<twitter-stream>, [">= 0"])
84
87
  s.add_dependency(%q<eventmachine>, [">= 0"])
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 1
7
7
  - 4
8
- - 1
9
- version: 1.4.1
8
+ - 2
9
+ version: 1.4.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - Brandon Keepers
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-10-09 00:00:00 -04:00
17
+ date: 2010-11-13 00:00:00 -06:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -30,19 +30,21 @@ dependencies:
30
30
  type: :runtime
31
31
  version_requirements: *id001
32
32
  - !ruby/object:Gem::Dependency
33
- name: httparty
33
+ name: faraday
34
34
  prerelease: false
35
35
  requirement: &id002 !ruby/object:Gem::Requirement
36
36
  requirements:
37
- - - ">="
37
+ - - ~>
38
38
  - !ruby/object:Gem::Version
39
39
  segments:
40
40
  - 0
41
- version: "0"
41
+ - 5
42
+ - 1
43
+ version: 0.5.1
42
44
  type: :runtime
43
45
  version_requirements: *id002
44
46
  - !ruby/object:Gem::Dependency
45
- name: mime-types
47
+ name: multipart-post
46
48
  prerelease: false
47
49
  requirement: &id003 !ruby/object:Gem::Requirement
48
50
  requirements:
@@ -54,7 +56,7 @@ dependencies:
54
56
  type: :runtime
55
57
  version_requirements: *id003
56
58
  - !ruby/object:Gem::Dependency
57
- name: twitter-stream
59
+ name: mime-types
58
60
  prerelease: false
59
61
  requirement: &id004 !ruby/object:Gem::Requirement
60
62
  requirements:
@@ -66,7 +68,7 @@ dependencies:
66
68
  type: :runtime
67
69
  version_requirements: *id004
68
70
  - !ruby/object:Gem::Dependency
69
- name: eventmachine
71
+ name: twitter-stream
70
72
  prerelease: false
71
73
  requirement: &id005 !ruby/object:Gem::Requirement
72
74
  requirements:
@@ -78,7 +80,7 @@ dependencies:
78
80
  type: :runtime
79
81
  version_requirements: *id005
80
82
  - !ruby/object:Gem::Dependency
81
- name: rspec
83
+ name: eventmachine
82
84
  prerelease: false
83
85
  requirement: &id006 !ruby/object:Gem::Requirement
84
86
  requirements:
@@ -87,10 +89,10 @@ dependencies:
87
89
  segments:
88
90
  - 0
89
91
  version: "0"
90
- type: :development
92
+ type: :runtime
91
93
  version_requirements: *id006
92
94
  - !ruby/object:Gem::Dependency
93
- name: fakeweb
95
+ name: rspec
94
96
  prerelease: false
95
97
  requirement: &id007 !ruby/object:Gem::Requirement
96
98
  requirements:
@@ -101,6 +103,18 @@ dependencies:
101
103
  version: "0"
102
104
  type: :development
103
105
  version_requirements: *id007
106
+ - !ruby/object:Gem::Dependency
107
+ name: fakeweb
108
+ prerelease: false
109
+ requirement: &id008 !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ segments:
114
+ - 0
115
+ version: "0"
116
+ type: :development
117
+ version_requirements: *id008
104
118
  description: A Ruby API for interfacing with Campfire, the 37Signals chat application.
105
119
  email: brandon@opensoul.org
106
120
  executables: []
@@ -120,7 +134,7 @@ files:
120
134
  - lib/tinder.rb
121
135
  - lib/tinder/campfire.rb
122
136
  - lib/tinder/connection.rb
123
- - lib/tinder/multipart.rb
137
+ - lib/tinder/middleware.rb
124
138
  - lib/tinder/room.rb
125
139
  - site/index.html
126
140
  - site/stylesheets/style.css
@@ -1,63 +0,0 @@
1
- require 'mime/types'
2
- require 'net/http'
3
- require 'cgi'
4
-
5
- module Multipart #:nodoc:
6
- # From: http://deftcode.com/code/flickr_upload/multipartpost.rb
7
- ## Helper class to prepare an HTTP POST request with a file upload
8
- ## Mostly taken from
9
- #http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/113774
10
- ### WAS:
11
- ## Anything that's broken and wrong probably the fault of Bill Stilwell
12
- ##(bill@marginalia.org)
13
- ### NOW:
14
- ## Everything wrong is due to keith@oreilly.com
15
-
16
- class Param #:nodoc:
17
- attr_accessor :k, :v
18
- def initialize(k, v)
19
- @k = k
20
- @v = v
21
- end
22
-
23
- def to_multipart
24
- "Content-Disposition: form-data; name=\"#{k}\"\r\n\r\n#{v}\r\n"
25
- end
26
- end
27
-
28
- class FileParam #:nodoc:
29
- attr_accessor :k, :filename, :content
30
- def initialize(k, filename, content)
31
- @k = k
32
- @filename = filename
33
- @content = content
34
- end
35
-
36
- def to_multipart
37
- "Content-Disposition: form-data; name=\"#{k}\"; filename=\"#{filename}\"\r\n" +
38
- "Content-Transfer-Encoding: binary\r\n" +
39
- "Content-Type: #{MIME::Types.type_for(@filename)}\r\n\r\n" +
40
- @content + "\r\n"
41
- end
42
- end
43
-
44
- class MultipartPost #:nodoc:
45
- BOUNDARY = 'campfire-is-awesome'
46
- HEADER = {"Content-type" => "multipart/form-data, boundary=" + BOUNDARY + " "}
47
- TIMEOUT_SECONDS = 30
48
-
49
- attr_accessor :params, :query, :headers
50
- def initialize(params)
51
- @params = params
52
- @query = {}
53
- self.prepare_query
54
- end
55
-
56
- def prepare_query()
57
- @query = @params.map do |k,v|
58
- param = v.respond_to?(:read) ? FileParam.new(k, v.path, v.read) : Param.new(k, v)
59
- "--#{BOUNDARY}\r\n#{param.to_multipart}"
60
- end.join("") + "--#{BOUNDARY}--"
61
- end
62
- end
63
- end