Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moved Client class to a separate file.
- Loading branch information
1 parent
b729870
commit e470e32
Showing
2 changed files
with
55 additions
and
51 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
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,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 |