Class: Blend::Client::HipchatClient
- Defined in:
- lib/blend/client/hipchat_client.rb
Instance Attribute Summary collapse
-
#api ⇒ Object
Returns the value of attribute api.
Instance Method Summary collapse
- #create_room(name, topic) ⇒ Object
-
#initialize(api) ⇒ HipchatClient
constructor
A new instance of HipchatClient.
- #post_message(room, message, color = 'yellow', notify = false, type = 'text') ⇒ Object
- #room_by_name(name) ⇒ Object
- #room_info(name) ⇒ Object
- #room_name_from_xmpp_jid(name) ⇒ Object
- #rooms ⇒ Object
- #set_topic(room, topic) ⇒ Object
- #user_by_name(name) ⇒ Object
- #users ⇒ Object
Constructor Details
#initialize(api) ⇒ HipchatClient
Returns a new instance of HipchatClient.
6 7 8 |
# File 'lib/blend/client/hipchat_client.rb', line 6 def initialize( api ) @api = api end |
Instance Attribute Details
#api ⇒ Object
Returns the value of attribute api.
4 5 6 |
# File 'lib/blend/client/hipchat_client.rb', line 4 def api @api end |
Instance Method Details
#create_room(name, topic) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/blend/client/hipchat_client.rb', line 10 def create_room( name, topic ) creator = user_by_name 'Will Schenk' ret = api.rooms_create name, creator['user_id'], 'public', topic if ret["error"] pp ret["error"] end @rooms = nil end |
#post_message(room, message, color = 'yellow', notify = false, type = 'text') ⇒ Object
69 70 71 72 73 74 75 |
# File 'lib/blend/client/hipchat_client.rb', line 69 def ( room, , color = 'yellow', notify = false, type = 'text' ) room = room_by_name room if room api. room['room_id'], 'hfc', , notify ? "1" : "0", color, type end end |
#room_by_name(name) ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'lib/blend/client/hipchat_client.rb', line 32 def room_by_name( name ) rooms.each do |r| return r if r['name'] == name end puts "Room #{name} not found".red nil end |
#room_info(name) ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/blend/client/hipchat_client.rb', line 41 def room_info( name ) room = room_by_name name if( room ) api.rooms_show( room['room_id'] ).parsed_response['room'] end end |
#room_name_from_xmpp_jid(name) ⇒ Object
28 29 30 |
# File 'lib/blend/client/hipchat_client.rb', line 28 def room_name_from_xmpp_jid( name ) rooms.select{|x| x['xmpp_jid'] == name}.first['name'] rescue nil end |
#rooms ⇒ Object
22 23 24 25 26 |
# File 'lib/blend/client/hipchat_client.rb', line 22 def rooms @rooms ||= api.rooms_list.parsed_response['rooms'] raise Exceptions::HipchatAuthenticationFailure if @rooms.nil? @rooms end |
#set_topic(room, topic) ⇒ Object
61 62 63 64 65 66 67 |
# File 'lib/blend/client/hipchat_client.rb', line 61 def set_topic( room, topic ) room = room_by_name room if room api.rooms_topic( room['room_id'], topic) end end |
#user_by_name(name) ⇒ Object
53 54 55 56 57 58 59 |
# File 'lib/blend/client/hipchat_client.rb', line 53 def user_by_name( name ) users.each do |u| return u if u['name'] == name end puts "User #{name} not found".red end |
#users ⇒ Object
49 50 51 |
# File 'lib/blend/client/hipchat_client.rb', line 49 def users @users ||= api.users_list.parsed_response['users'] end |