Class: HipTail::Authority
- Inherits:
-
Object
- Object
- HipTail::Authority
- Defined in:
- lib/hiptail/authority.rb
Instance Attribute Summary collapse
-
#group_id ⇒ String
readonly
Returns group_id for authority.
-
#oauth_id ⇒ String
readonly
Returns OAuth ID.
-
#room_id ⇒ String?
readonly
Returns room_id for room authority.
Instance Method Summary collapse
-
#add_member(params) ⇒ Hash
Issues add member API.
-
#as_hash ⇒ Hash
Hash representation.
-
#for_global? ⇒ Boolean
(also: #global?)
Represents whether the authority is for global or not.
-
#for_room? ⇒ Boolean
(also: #room?)
Represents whether the authority is for a room or not.
-
#get_all_members(params = {}) ⇒ HipTail::Users
Issues get all members API.
-
#get_all_participants(params = {}) ⇒ HipTail::Users
Issues get all participants API.
-
#get_all_rooms(params = {}) ⇒ HipTail::Rooms
Issues get all rooms API.
-
#get_all_users(params = {}) ⇒ HipTail::Users
Issues get all users API.
-
#get_room(params) ⇒ HipTail::Room::Detail
Issues get room API.
-
#initialize(params) ⇒ HipTail::Authority
constructor
A new instance of HipTail::Authority.
-
#remove_member(params) ⇒ Hash
Issues remove member API.
-
#reply_message(params) ⇒ Hash
Issues reply message API.
-
#send_notification(params) ⇒ Hash
Issues send notification API.
-
#view_user(params) ⇒ HipTail::User
Issues view user API.
Constructor Details
#initialize(params) ⇒ HipTail::Authority
A new instance of HipTail::Authority.
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/hiptail/authority.rb', line 42 def initialize(params) @oauth_id = params[:oauth_id] @oauth_secret = params[:oauth_secret] @authorization_url = params[:authorization_url] @token_url = params[:token_url] @room_id = params[:room_id] @group_id = params[:group_id] @room_id = @room_id.to_i if ! @room_id.nil? @group_id = @group_id.to_i if ! @group_id.nil? api_base_uri = params[:api_base].to_s unless api_base_uri.end_with?('/') api_base_uri += '/'; end @api_base = URI.parse(api_base_uri) end |
Instance Attribute Details
#group_id ⇒ String (readonly)
Returns group_id for authority.
18 19 20 |
# File 'lib/hiptail/authority.rb', line 18 def group_id @group_id end |
#oauth_id ⇒ String (readonly)
Returns OAuth ID.
10 11 12 |
# File 'lib/hiptail/authority.rb', line 10 def oauth_id @oauth_id end |
#room_id ⇒ String? (readonly)
Returns room_id for room authority. Nil for global authority.
15 16 17 |
# File 'lib/hiptail/authority.rb', line 15 def room_id @room_id end |
Instance Method Details
#add_member(params) ⇒ Hash
Issues add member API.
144 145 146 147 148 149 150 151 152 |
# File 'lib/hiptail/authority.rb', line 144 def add_member(params) room_id = self.room_id || params.delete(:room_id) raise ArgumentError.new("room_id required") unless room_id user_name = user_name_from_params(params) raise ArgumentError.new("user_id or user_mention or user_email required") unless user_name call_api(:method => :put, :uri => @api_base.merge("room/#{room_id}/member/#{user_name}"), :body_params => params) end |
#as_hash ⇒ Hash
Returns Hash representation. Convenient for persistency.
62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/hiptail/authority.rb', line 62 def as_hash { :oauth_id => @oauth_id, :oauth_secret => @oauth_secret, :authorization_url => @authorization_url, :token_url => @token_url, :room_id => @room_id, :group_id => @group_id, :api_base => @api_base, } end |
#for_global? ⇒ Boolean Also known as: global?
Returns Represents whether the authority is for global or not.
21 22 23 |
# File 'lib/hiptail/authority.rb', line 21 def for_global? ! @room_id end |
#for_room? ⇒ Boolean Also known as: room?
Returns Represents whether the authority is for a room or not.
27 28 29 |
# File 'lib/hiptail/authority.rb', line 27 def for_room? ! for_global? end |
#get_all_members(params = {}) ⇒ HipTail::Users
Issues get all members API.
118 119 120 121 122 123 124 |
# File 'lib/hiptail/authority.rb', line 118 def get_all_members(params = {}) room_id = self.room_id || params.delete(:room_id) raise ArgumentError.new("room_id required") unless room_id res = call_api(:method => :get, :uri => @api_base.merge("room/#{room_id}/member"), :query_params => params) return unless res.successful? Users.new(res.data) end |
#get_all_participants(params = {}) ⇒ HipTail::Users
Issues get all participants API.
129 130 131 132 133 134 135 |
# File 'lib/hiptail/authority.rb', line 129 def get_all_participants(params = {}) room_id = self.room_id || params.delete(:room_id) raise ArgumentError.new("room_id required") unless room_id res = call_api(:method => :get, :uri => @api_base.merge("room/#{room_id}/participant"), :query_params => params) return unless res.successful? Users.new(res.data) end |
#get_all_rooms(params = {}) ⇒ HipTail::Rooms
Issues get all rooms API.
97 98 99 100 101 |
# File 'lib/hiptail/authority.rb', line 97 def get_all_rooms(params = {}) res = call_api(:method => :get, :uri => @api_base.merge("room"), :query_params => params) return unless res.successful? Rooms.new(res.data) end |
#get_all_users(params = {}) ⇒ HipTail::Users
Issues get all users API.
186 187 188 189 190 |
# File 'lib/hiptail/authority.rb', line 186 def get_all_users(params = {}) res = call_api(:method => :get, :uri => @api_base.merge("user"), :query_params => params) return unless res.successful? Users.new(res.data) end |
#get_room(params) ⇒ HipTail::Room::Detail
Issues get room API.
107 108 109 110 111 112 113 |
# File 'lib/hiptail/authority.rb', line 107 def get_room(params) room_id = self.room_id || params.delete(:room_id) raise ArgumentError.new("room_id required") unless room_id res = call_api(:method => :get, :uri => @api_base.merge("room/#{room_id}"), :query_params => params) return unless res.successful? Room::Detail.new(res.data) end |
#remove_member(params) ⇒ Hash
Issues remove member API.
161 162 163 164 165 166 167 168 169 |
# File 'lib/hiptail/authority.rb', line 161 def remove_member(params) room_id = self.room_id || params.delete(:room_id) raise ArgumentError.new("room_id required") unless room_id user_name = user_name_from_params(params) raise ArgumentError.new("user_id or user_mention or user_email required") unless user_name call_api(:method => :delete, :uri => @api_base.merge("room/#{room_id}/member/#{user_name}"), :body_params => params) end |
#reply_message(params) ⇒ Hash
Issues reply message API.
88 89 90 91 92 |
# File 'lib/hiptail/authority.rb', line 88 def (params) room_id = self.room_id || params.delete(:room_id) raise ArgumentError.new("room_id required") unless room_id call_api(:method => :post, :uri => @api_base.merge("room/#{room_id}/reply"), :body_params => params) end |
#send_notification(params) ⇒ Hash
Issues send notification API.
78 79 80 81 82 |
# File 'lib/hiptail/authority.rb', line 78 def send_notification(params) room_id = self.room_id || params.delete(:room_id) raise ArgumentError.new("room_id required") unless room_id call_api(:method => :post, :uri => @api_base.merge("room/#{room_id}/notification"), :body_params => params) end |
#view_user(params) ⇒ HipTail::User
Issues view user API.
175 176 177 178 179 180 181 |
# File 'lib/hiptail/authority.rb', line 175 def view_user(params) user_id = params.delete(:user_id) raise ArgumentError.new("user_id required") unless user_id res = call_api(:method => :get, :uri => @api_base.merge("user/#{user_id}"), :query_params => params) return unless res.successful? User::Person.new(res.data) end |