Class: HipTail::Authority

Inherits:
Object
  • Object
show all
Defined in:
lib/hiptail/authority.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params) ⇒ HipTail::Authority

A new instance of HipTail::Authority.

Parameters:

  • params (Hash)

Options Hash (params):

  • :oauth_id (String)
  • :oauth_secret (String)
  • :authorization_url (String)
  • :token_url (String)
  • :room_id (String)
  • :group_id (String)
  • :api_base (String)


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_idString (readonly)

Returns group_id for authority.

Returns:

  • (String)


18
19
20
# File 'lib/hiptail/authority.rb', line 18

def group_id
  @group_id
end

#oauth_idString (readonly)

Returns OAuth ID.

Returns:

  • (String)

    Returns OAuth ID.



10
11
12
# File 'lib/hiptail/authority.rb', line 10

def oauth_id
  @oauth_id
end

#room_idString? (readonly)

Returns room_id for room authority. Nil for global authority.

Returns:

  • (String)
  • (nil)


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.

Parameters:

  • params (Hash)

    Parameters for add member API with :room_id.

Options Hash (params):

  • :room_id (String)

    Room ID. Optional but mandatory for global authority.

  • :user_id (String)

    One of :user_id, :user_mention, :user_email is required.

  • :user_mention (String)
  • :user_email (String)

Returns:

  • (Hash)

    Resulting response of API.

Raises:

  • (ArgumentError)


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_hashHash

Returns Hash representation. Convenient for persistency.

Returns:

  • (Hash)

    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.

Returns:

  • (Boolean)

    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.

Returns:

  • (Boolean)

    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.

Parameters:

  • params (Hash) (defaults to: {})

    Parameters for get all members API.

Returns:

Raises:

  • (ArgumentError)


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.

Parameters:

  • params (Hash) (defaults to: {})

    Parameters for get all participants API.

Returns:

Raises:

  • (ArgumentError)


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.

Parameters:

  • params (Hash) (defaults to: {})

    Parameters for get all rooms API.

Returns:



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.

Parameters:

  • params (Hash) (defaults to: {})

    Parameters for get all users API.

Returns:



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.

Parameters:

  • params (Hash)

    Parameters for get all room API.

Options Hash (params):

  • :room_id (String)

    Room ID. Optional but mandatory for global authority.

Returns:

Raises:

  • (ArgumentError)


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.

Parameters:

  • params (Hash)

    Parameters for remove member API with :room_id.

Options Hash (params):

  • :room_id (String)

    Room ID. Optional but mandatory for global authority.

  • :user_id (String)

    One of :user_id, :user_mention, :user_email is required.

  • :user_mention (String)
  • :user_email (String)

Returns:

  • (Hash)

    Resulting response of API.

Raises:

  • (ArgumentError)


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.

Parameters:

  • params (Hash)

    Parameters for reply message API with :room_id.

Options Hash (params):

  • :room_id (String)

    Room ID. Optional but mandatory for global authority.

Returns:

  • (Hash)

    Resulting response of API.

Raises:

  • (ArgumentError)


88
89
90
91
92
# File 'lib/hiptail/authority.rb', line 88

def reply_message(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.

Parameters:

  • params (Hash)

    Parameters for notification API with :room_id.

Options Hash (params):

  • :room_id (String)

    Room ID. Optional but mandatory for global authority.

Returns:

  • (Hash)

    Resulting response of API.

Raises:

  • (ArgumentError)


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.

Parameters:

  • params (Hash)

    Parameters for view user API with :user_id.

Options Hash (params):

  • :user_id (String)

    User ID or email or mention name (beginning with an ‘@’).

Returns:

Raises:

  • (ArgumentError)


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