Class: EpochApi::Client
Instance Method Summary collapse
- #_response(response) ⇒ Object
-
#initialize(token, options = {}) ⇒ Client
constructor
A new instance of Client.
- #message(room_token, from, message, options = {color: 'yellow', notify: false}) ⇒ Object
- #topic(new_topic, options = {from: 'API'}) ⇒ Object
Constructor Details
#initialize(token, options = {}) ⇒ Client
Returns a new instance of Client.
17 18 19 20 |
# File 'lib/epoch_api.rb', line 17 def initialize token, ={} @token = token self end |
Instance Method Details
#_response(response) ⇒ Object
48 49 50 51 52 53 54 55 |
# File 'lib/epoch_api.rb', line 48 def _response response case response.code when 200 then response.body when 404 then raise UnknownRoom , "Unknown room: `#{room_id}'" when 401 then raise Unauthorized , "Access denied to room `#{room_id}'" else; raise UnknownResponseCode, "Unexpected #{response.code} for room `#{room_id}'" end end |
#message(room_token, from, message, options = {color: 'yellow', notify: false}) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/epoch_api.rb', line 22 def room_token, from, , = {color: 'yellow', notify: false} err_msg = "Username #{from} is `#{from.length} characters long. Limit is 15'" raise UsernameTooLong, err_msg if from.length > 15 response = self.class.put "/#{room_id}/message", query: { auth_token: @token }, body: { from: from, message: , color: [:color], notify: [:notify] ? 1 : 0 } _response response end |
#topic(new_topic, options = {from: 'API'}) ⇒ Object
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/epoch_api.rb', line 37 def topic new_topic, = {from: 'API'} response = self.class.put "/#{room_id}/topic", query: { auth_token: @token }, body: { from: [:from], topic: new_topic} _response response end |