Class: HipChat::ApiVersion::Room

Inherits:
HipChat::ApiVersion show all
Defined in:
lib/hipchat/api_version.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from HipChat::ApiVersion

#bool_val

Constructor Details

#initialize(options = {}) ⇒ Room

Returns a new instance of Room.



99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/hipchat/api_version.rb', line 99

def initialize(options = {})
  @version = options[:api_version]
  options[:room_id] ||= options[get_id_attribute]
  @room_id = options[:room_id]
  if @version.eql?('v1')
    @base_uri = "#{options[:server_url]}/v1/rooms"
    @headers = {'Accept' => 'application/json',
       'Content-Type' => 'application/x-www-form-urlencoded'}
  else
    @base_uri = "#{options[:server_url]}/v2/room"
    @headers = {'Accept' => 'application/json',
       'Content-Type' => 'application/json'}
  end
end

Instance Attribute Details

#base_uriObject (readonly)

Returns the value of attribute base_uri.



114
115
116
# File 'lib/hipchat/api_version.rb', line 114

def base_uri
  @base_uri
end

#headersObject (readonly)

Returns the value of attribute headers.



114
115
116
# File 'lib/hipchat/api_version.rb', line 114

def headers
  @headers
end

#room_idObject (readonly)

Returns the value of attribute room_id.



114
115
116
# File 'lib/hipchat/api_version.rb', line 114

def room_id
  @room_id
end

#versionObject (readonly)

Returns the value of attribute version.



114
115
116
# File 'lib/hipchat/api_version.rb', line 114

def version
  @version
end

Instance Method Details

#add_member_configObject



167
168
169
170
171
172
173
174
# File 'lib/hipchat/api_version.rb', line 167

def add_member_config
  {
    'v2' => {
      :url => URI::escape("/#{room_id}/member"),
      :body_format => :to_json
    }
  }[version]
end

#delete_room_configObject



143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/hipchat/api_version.rb', line 143

def delete_room_config
  {
    'v1' => {
      :url => URI::escape("/delete"),
      :method => :post,
      :query_params => { :room_id => room_id }
    },
    'v2' => {
      :url => URI::escape("/#{room_id}"),
      :method => :delete,
      :query_params => {}
    }
  }[version]
end

#get_id_attributeObject



116
117
118
# File 'lib/hipchat/api_version.rb', line 116

def get_id_attribute
  version.eql?('v1') ? 'room_id' : 'id'
end

#get_room_configObject



120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/hipchat/api_version.rb', line 120

def get_room_config
  {
    'v1' => {
      :url => URI::escape('/show'),
      :query_params => { :room_id => room_id }
  },
    'v2' => {
      :url => URI::escape("/#{room_id}"),
      :query_params => { }
    }
  }[version]
end

#history_configObject



242
243
244
245
246
247
248
249
250
251
# File 'lib/hipchat/api_version.rb', line 242

def history_config
  {
    'v1' => {
      :url => '/history'
    },
    'v2' => {
      :url => URI::escape("/#{room_id}/history")
    }
  }[version]
end

#invite_configObject



158
159
160
161
162
163
164
165
# File 'lib/hipchat/api_version.rb', line 158

def invite_config
  {
    'v2' => {
      :url => URI::escape("/#{room_id}/invite"),
      :body_format => :to_json
    }
  }[version]
end

#reply_configObject



198
199
200
201
202
203
204
205
206
207
# File 'lib/hipchat/api_version.rb', line 198

def reply_config
  {
      'v2' => {
          :url => URI::escape("/#{room_id}/reply"),
          :method => :post,
          :query_params => { },
          :body_format => :to_json
      }
  }[version]
end

#send_configObject



185
186
187
188
189
190
191
192
193
194
195
196
# File 'lib/hipchat/api_version.rb', line 185

def send_config
  {
    'v1' => {
      :url => "/message",
      :body_format => :to_hash
    },
    'v2' => {
      :url => URI::escape("/#{room_id}/notification"),
      :body_format => :to_json
    }
  }[version]
end

#send_file_configObject



209
210
211
212
213
214
215
216
# File 'lib/hipchat/api_version.rb', line 209

def send_file_config
  {
    'v2' => {
      :url => URI::escape("/#{room_id}/share/file"),
      :body_format => :to_json
    }
  }[version]
end

#send_message_configObject



176
177
178
179
180
181
182
183
# File 'lib/hipchat/api_version.rb', line 176

def send_message_config
  {
    'v2' => {
      :url => URI::escape("/#{room_id}/message"),
      :body_format => :to_json
    }
  }[version]
end


218
219
220
221
222
223
224
225
# File 'lib/hipchat/api_version.rb', line 218

def share_link_config
  {
    'v2' => {
      :url => URI::escape("/#{room_id}/share/link"),
      :body_format => :to_json
    }
  }[version]
end

#statistics_configObject



253
254
255
256
257
258
259
# File 'lib/hipchat/api_version.rb', line 253

def statistics_config
  {
    'v2' => {
      :url => URI::escape("/#{room_id}/statistics")
    }
  }[version]
end

#topic_configObject



227
228
229
230
231
232
233
234
235
236
237
238
239
240
# File 'lib/hipchat/api_version.rb', line 227

def topic_config
  {
    'v1' => {
      :url => '/topic',
      :method => :post,
      :body_format => :to_hash
    },
    'v2' => {
      :url => URI::escape("/#{room_id}/topic"),
      :method => :put,
      :body_format => :to_json
    }
  }[version]
end

#update_room_configObject



133
134
135
136
137
138
139
140
141
# File 'lib/hipchat/api_version.rb', line 133

def update_room_config
  {
    'v2' => {
      :url => URI::escape("/#{room_id}"),
      :method => :put,
      :body_format => :to_json
    }
  }[version]
end

#webhook_configObject

Raises:



261
262
263
264
265
266
267
268
# File 'lib/hipchat/api_version.rb', line 261

def webhook_config
  raise InvalidApiVersion, 'This functionality is not supported in API v1' unless version.eql?('v2')
  {
    'v2' => {
      :url => URI::escape("/#{room_id}/webhook")
    }
  }[version]
end