Permalink
Browse files

Moved Client class to a separate file.

  • Loading branch information...
1 parent b729870 commit e470e32d0e36e5b4ed83cc0b4f943020f3d13f30 @rodrigopinto rodrigopinto committed Jan 13, 2014
Showing with 55 additions and 51 deletions.
  1. +1 −51 lib/hipchat.rb
  2. +54 −0 lib/hipchat/client.rb
View
@@ -1,58 +1,8 @@
require 'hipchat/railtie' if defined?(Rails::Railtie)
require "hipchat/version"
-require 'hipchat/api_version'
module HipChat
require 'hipchat/errors'
require 'hipchat/room'
-
- class Client
- include HTTParty
-
- format :json
-
- def initialize(token, options={})
- @token = token
- @api_version = options[:api_version]
- @api = HipChat::ApiVersion::Client.new(@api_version)
- self.class.base_uri(@api.base_uri)
- http_proxy = options[:http_proxy] || ENV['http_proxy']
- setup_proxy(http_proxy) if http_proxy
- end
-
- def rooms
- @rooms ||= _rooms
- end
-
- def [](name)
- Room.new(@token, :room_id => name, :api_version => @api_version)
- end
-
- private
- def setup_proxy(proxy_url)
- proxy_url = URI.parse(proxy_url)
-
- self.class.http_proxy(proxy_url.host, proxy_url.port,
- proxy_url.user, proxy_url.password)
- HipChat::Room.http_proxy(proxy_url.host, proxy_url.port,
- proxy_url.user, proxy_url.password)
- end
-
- def _rooms
- response = self.class.get(@api.rooms_config[:url],
- :query => {
- :auth_token => @token
- },
- :headers => @api.headers
- )
- case response.code
- when 200
- response[@api.rooms_config[:data_key]].map do |r|
- Room.new(@token, r.merge(:api_version => @api_version))
- end
- else
- raise UnknownResponseCode, "Unexpected #{response.code} for room `#{room_id}'"
- end
- end
- end
+ require 'hipchat/client'
end
View
@@ -0,0 +1,54 @@
+require 'hipchat/api_version'
+
+module HipChat
+
+ class Client
+ include HTTParty
+
+ format :json
+
+ def initialize(token, options={})
+ @token = token
+ @api_version = options[:api_version]
+ @api = HipChat::ApiVersion::Client.new(@api_version)
+ self.class.base_uri(@api.base_uri)
+ http_proxy = options[:http_proxy] || ENV['http_proxy']
+ setup_proxy(http_proxy) if http_proxy
+ end
+
+ def rooms
+ @rooms ||= _rooms
+ end
+
+ def [](name)
+ Room.new(@token, :room_id => name, :api_version => @api_version)
+ end
+
+ private
+ def setup_proxy(proxy_url)
+ proxy_url = URI.parse(proxy_url)
+
+ self.class.http_proxy(proxy_url.host, proxy_url.port,
+ proxy_url.user, proxy_url.password)
+ HipChat::Room.http_proxy(proxy_url.host, proxy_url.port,
+ proxy_url.user, proxy_url.password)
+ end
+
+ def _rooms
+ response = self.class.get(@api.rooms_config[:url],
+ :query => {
+ :auth_token => @token
+ },
+ :headers => @api.headers
+ )
+ case response.code
+ when 200
+ response[@api.rooms_config[:data_key]].map do |r|
+ Room.new(@token, r.merge(:api_version => @api_version))
+ end
+ else
+ raise UnknownResponseCode, "Unexpected #{response.code} for room `#{room_id}'"
+ end
+ end
+ end
+end

0 comments on commit e470e32

Please sign in to comment.