Class: Soracom::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/soracom/client.rb

Overview

Soracom API Client

Instance Method Summary collapse

Constructor Details

#initialize(profile: nil, endpoint: ENV['SORACOM_ENDPOINT'] || API_BASE_URL, email: ENV['SORACOM_EMAIL'], password: ENV['SORACOM_PASSWORD'], auth_key_id: ENV['SORACOM_AUTH_KEY_ID'], auth_key: ENV['SORACOM_AUTH_KEY'], operator_id: ENV['SORACOM_OPERATOR_ID'], user_name: ENV['SORACOM_USER_NAME'], api_key: nil, token: nil) ⇒ Client

設定されなかった場合には、環境変数から認証情報を取得



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/soracom/client.rb', line 15

def initialize(
    profile: nil,
    endpoint: ENV['SORACOM_ENDPOINT'] || API_BASE_URL,
    email:ENV['SORACOM_EMAIL'], password:ENV['SORACOM_PASSWORD'],
    auth_key_id:ENV['SORACOM_AUTH_KEY_ID'], auth_key:ENV['SORACOM_AUTH_KEY'],
    operator_id:ENV['SORACOM_OPERATOR_ID'], user_name:ENV['SORACOM_USER_NAME'],
    api_key:nil, token:nil
  )
  @log = Logger.new(STDERR)
  @log.level = ENV['SORACOM_DEBUG'] ? Logger::DEBUG : Logger::WARN
  @endpoint = endpoint
  begin
    if api_key && token && operator_id
      @auth = {
        :apiKey => api_key,
        :token => token,
        :operatorId => operator_id
      }
    elsif profile
      @auth = auth_by_profile(profile)
    elsif auth_key_id && auth_key
      @auth = auth_by_key(auth_key_id, auth_key, @endpoint)
    elsif email && password
      @auth = auth_by_email(email, password, @endpoint)
    elsif operator_id && user_name && password
      @auth = auth_by_user(operator_id, user_name, password, @endpoint)
    else
      @auth = auth_by_profile('default')
    end
  rescue => evar
    abort 'ERROR: ' + evar.to_s
  end
  if @auth
    @api = Soracom::ApiClient.new(@auth, @endpoint)
  else
    fail 'Could not find any credentials(authKeyId & authKey or email & password or operatorId & userName and password)'
  end
end

Instance Method Details

#activate_subscriber(imsis) ⇒ Object

SIMの利用開始(再開)



88
89
90
91
92
93
94
95
96
97
98
# File 'lib/soracom/client.rb', line 88

def activate_subscriber(imsis)
  imsis = [imsis] if imsis.class != Array
  threads = [], result = []
  imsis.map do |imsi|
    threads << Thread.new do
      result << { 'imsi' => imsi }.merge(@api.post(path: "/subscribers/#{imsi}/activate"))
    end
  end
  threads.each(&:join)
  result
end

#api_keyObject

APIキーを取得



491
492
493
# File 'lib/soracom/client.rb', line 491

def api_key
  @auth[:apiKey]
end

#attach_role_to_user(user_name, role_id) ⇒ Object

SAMユーザーにロールをアタッチ



466
467
468
# File 'lib/soracom/client.rb', line 466

def attach_role_to_user(user_name, role_id)
  @api.post(path: "/operators/#{@auth[:operatorId]}/users/#{user_name}/roles", payload: {roleId: role_id})
end

#create_credentials(credentials_id, credentials) ⇒ Object



352
353
354
# File 'lib/soracom/client.rb', line 352

def create_credentials(credentials_id, credentials)
  @api.post(path: "/credentials/#{credentials_id}", payload: credentials)
end

#create_event_handler(req) ⇒ Object

イベントハンドラーを新規作成する



300
301
302
# File 'lib/soracom/client.rb', line 300

def create_event_handler(req)
  @api.post(path: '/event_handlers', payload: req)
end

#create_group(tags = nil) ⇒ Object

SIMグループを新規作成



250
251
252
253
# File 'lib/soracom/client.rb', line 250

def create_group(tags=nil)
  payload = (tags) ? { tags: tags } : {}
  @api.post(path: '/groups', payload: payload)
end

#create_role(role_id, permission, description = '') ⇒ Object

Role を新しく追加する



446
447
448
# File 'lib/soracom/client.rb', line 446

def create_role(role_id, permission, description='')
  @api.post(path: "/operators/#{@auth[:operatorId]}/roles/#{role_id}", payload:{description: description, permission: permission})
end

#create_user(username, description = '') ⇒ Object

SAMユーザーを新しく追加する



376
377
378
# File 'lib/soracom/client.rb', line 376

def create_user(username, description='')
  @api.post(path: "/operators/#{@auth[:operatorId]}/users/#{username}", payload: { description: description })
end

#create_user_password(username = , password) ⇒ Object

SAMユーザーのパスワードを作成する



416
417
418
# File 'lib/soracom/client.rb', line 416

def create_user_password(username=@auth[:userName], password)
  @api.post(path: "/operators/#{@auth[:operatorId]}/users/#{username}/password", payload:{password: password})
end

#deactivate_subscriber(imsis) ⇒ Object

SIMの利用休止



101
102
103
104
105
106
107
108
109
110
111
# File 'lib/soracom/client.rb', line 101

def deactivate_subscriber(imsis)
  imsis = [imsis] if imsis.class != Array
  threads = [], result = []
  imsis.map do |imsi|
    threads << Thread.new do
      result << { 'imsi' => imsi }.merge(@api.post(path: "/subscribers/#{imsi}/deactivate"))
    end
  end
  threads.each(&:join)
  result
end

#delete_credentials(credentials_id) ⇒ Object



356
357
358
# File 'lib/soracom/client.rb', line 356

def delete_credentials(credentials_id)
  @api.delete(path: "/credentials/#{credentials_id}")
end

#delete_event_handler(handler_id) ⇒ Object

イベントハンドラーを削除する



310
311
312
# File 'lib/soracom/client.rb', line 310

def delete_event_handler(handler_id)
  @api.delete(path: "/event_handlers/#{handler_id}")
end

#delete_group(group_id) ⇒ Object

SIMグループの削除



256
257
258
# File 'lib/soracom/client.rb', line 256

def delete_group(group_id)
  @api.delete(path: "/groups/#{group_id}")
end

#delete_group_configuration(group_id, namespace, name) ⇒ Object

コンフィグパラメータ内の設定を削除



272
273
274
# File 'lib/soracom/client.rb', line 272

def delete_group_configuration(group_id, namespace, name)
  @api.delete(path: "/groups/#{group_id}/configuration/#{namespace}/#{name}")
end

#delete_group_tags(group_id, name) ⇒ Object

コンフィグパラメータ内の設定を削除



282
283
284
# File 'lib/soracom/client.rb', line 282

def delete_group_tags(group_id, name)
  @api.delete(path: "/groups/#{group_id}/tags/#{name}")
end

#delete_operator_auth_key(auth_key_id) ⇒ Object

OperatorのAuthKey削除



486
487
488
# File 'lib/soracom/client.rb', line 486

def delete_operator_auth_key(auth_key_id)
  @api.delete(path: "/operators/#{@auth[:operatorId]}/auth_keys/#{auth_key_id}")
end

#delete_role(role_id) ⇒ Object

Role を削除する



436
437
438
# File 'lib/soracom/client.rb', line 436

def delete_role(role_id)
  @api.delete(path: "/operators/#{@auth[:operatorId]}/roles/#{role_id}")
end

#delete_role_from_user(user_name, role_id) ⇒ Object

SAMユーザーからロールをデタッチ



471
472
473
# File 'lib/soracom/client.rb', line 471

def delete_role_from_user(user_name, role_id)
  @api.delete(path: "/operators/#{@auth[:operatorId]}/users/#{user_name}/roles/#{role_id}")
end

#delete_subscriber_session(imsis) ⇒ Object

SIMの利用休止



114
115
116
117
118
119
120
121
122
123
124
# File 'lib/soracom/client.rb', line 114

def delete_subscriber_session(imsis)
  imsis = [imsis] if imsis.class != Array
  threads = [], result = []
  imsis.map do |imsi|
    threads << Thread.new do
      result << { 'imsi' => imsi }.merge(@api.post(path: "/subscribers/#{imsi}/delete_session"))
    end
  end
  threads.each(&:join)
  result
end

#delete_subscriber_tag(imsis, tag_name) ⇒ Object

指定タグの削除



179
180
181
182
183
184
185
186
187
188
189
# File 'lib/soracom/client.rb', line 179

def delete_subscriber_tag(imsis, tag_name)
  imsis = [imsis] if imsis.class != Array
  threads = [], result = []
  imsis.map do |imsi|
    threads << Thread.new do
      result << { 'imsi' => imsi }.merge(@api.delete(path: "/subscribers/#{imsi}/tags/#{CGI.escape(tag_name)}"))
    end
  end
  threads.each(&:join)
  result
end

#delete_user(username) ⇒ Object

SAMユーザーを削除する



366
367
368
# File 'lib/soracom/client.rb', line 366

def delete_user(username)
  @api.delete(path: "/operators/#{@auth[:operatorId]}/users/#{username}")
end

#delete_user_password(username = ) ⇒ Object

SAMユーザーのパスワードを削除する



406
407
408
# File 'lib/soracom/client.rb', line 406

def delete_user_password(username=@auth[:userName])
  @api.delete(path: "/operators/#{@auth[:operatorId]}/users/#{username}/password")
end

#delete_users_auth_key(username, auth_key_id) ⇒ Object

SAMユーザーのAuthKey削除



396
397
398
# File 'lib/soracom/client.rb', line 396

def delete_users_auth_key(username, auth_key_id)
  @api.delete(path: "/operators/#{@auth[:operatorId]}/users/#{username}/auth_keys/#{auth_key_id}")
end

#disable_termination(imsis) ⇒ Object

指定されたSubscriberをTerminate不可能に設定する



153
154
155
156
157
158
159
160
161
162
163
# File 'lib/soracom/client.rb', line 153

def disable_termination(imsis)
  imsis = [imsis] if imsis.class != Array
  threads = [], result = []
  imsis.map do |imsi|
    threads << Thread.new do
      result << { 'imsi' => imsi }.merge(@api.post(path: "/subscribers/#{imsi}/disable_termination"))
    end
  end
  threads.each(&:join)
  result
end

#enable_termination(imsis) ⇒ Object

指定されたSubscriberをTerminate可能に設定する



140
141
142
143
144
145
146
147
148
149
150
# File 'lib/soracom/client.rb', line 140

def enable_termination(imsis)
  imsis = [imsis] if imsis.class != Array
  threads = [], result = []
  imsis.map do |imsi|
    threads << Thread.new do
      result << { 'imsi' => imsi }.merge(@api.post(path: "/subscribers/#{imsi}/enable_termination"))
    end
  end
  threads.each(&:join)
  result
end

#export_air_usage(operator_id: , from: Time.parse("#{Time.now.year}-#{Time.now.month}-#{Time.now.day}").to_i, to: Time.now.to_i, period: 'day') ⇒ Object

Operator配下の全Subscriberに関するAir使用状況をダウンロードする(デフォルトでは今月)



331
332
333
334
# File 'lib/soracom/client.rb', line 331

def export_air_usage(operator_id:@auth[:operatorId] , from:Time.parse("#{Time.now.year}-#{Time.now.month}-#{Time.now.day}").to_i, to:Time.now.to_i, period:'day')
  res = @api.post(path: "/stats/air/operators/#{operator_id}/export", payload: { from: from, to: to, period: period })
  open(res['url']).read
end

#export_beam_usage(operator_id: , from: Time.parse("#{Time.now.year}-#{Time.now.month}-#{Time.now.day}").to_i, to: Time.now.to_i, period: 'day') ⇒ Object

Operator配下の全Subscriberに関するBeam使用状況をダウンロードする(デフォルトでは今月)



337
338
339
340
# File 'lib/soracom/client.rb', line 337

def export_beam_usage(operator_id:@auth[:operatorId] , from:Time.parse("#{Time.now.year}-#{Time.now.month}-#{Time.now.day}").to_i, to:Time.now.to_i, period:'day')
  res = @api.post(path: "/stats/beam/operators/#{operator_id}/export", payload: { from: from, to: to, period: period })
  open(res['url']).read
end

#generate_operator_auth_keyObject

OperatorのAuthKey生成



481
482
483
# File 'lib/soracom/client.rb', line 481

def generate_operator_auth_key()
  @api.post(path: "/operators/#{@auth[:operatorId]}/auth_keys")
end

#generate_users_auth_key(username = ) ⇒ Object

SAMユーザーのAuthKey生成



391
392
393
# File 'lib/soracom/client.rb', line 391

def generate_users_auth_key(username=@auth[:userName])
  @api.post(path: "/operators/#{@auth[:operatorId]}/users/#{username}/auth_keys")
end

#get_air_usage(imsi: nil, from: (Time.now.to_i - 24 * 60 * 60), to: Time.now.to_i, period: 'minutes') ⇒ Object

Subscriber毎のAir使用状況を得る(デフォルトでは直近1日)



321
322
323
# File 'lib/soracom/client.rb', line 321

def get_air_usage(imsi:nil, from:(Time.now.to_i - 24 * 60 * 60), to:Time.now.to_i, period:'minutes')
  @api.get(path: "/stats/air/subscribers/#{imsi}", params: { from: from, to: to, period: period })
end

#get_beam_usage(imsi: nil, from: (Time.now.to_i - 24 * 60 * 60), to: Time.now.to_i, period: 'minutes') ⇒ Object

Subscriber毎のBeam使用状況を得る(デフォルトでは直近1日)



326
327
328
# File 'lib/soracom/client.rb', line 326

def get_beam_usage(imsi:nil, from:(Time.now.to_i - 24 * 60 * 60), to:Time.now.to_i, period:'minutes')
  @api.get(path: "/stats/beam/subscribers/#{imsi}", params: { from: from, to: to, period: period })
end

#get_event_handler(handler_id) ⇒ Object

イベントハンドラーの情報を得る



305
306
307
# File 'lib/soracom/client.rb', line 305

def get_event_handler(handler_id)
  @api.get(path: "/event_handlers/#{handler_id}")
end

#get_role(role_id) ⇒ Object

Role を取得する



441
442
443
# File 'lib/soracom/client.rb', line 441

def get_role(role_id)
  @api.get(path: "/operators/#{@auth[:operatorId]}/roles/#{role_id}")
end

#get_support_url(return_to: 'https://soracom.zendesk.com/hc/ja/requests') ⇒ Object

サポートサイトのURLを取得



343
344
345
346
# File 'lib/soracom/client.rb', line 343

def get_support_url(return_to: 'https://soracom.zendesk.com/hc/ja/requests')
  res = @api.post(path: "/operators/#{@auth[:operatorId]}/support/token")
  "https://soracom.zendesk.com/access/jwt?jwt=#{res['token']}&return_to=#{return_to}"
end

#get_user(username = ) ⇒ Object

SAMユーザー取得



371
372
373
# File 'lib/soracom/client.rb', line 371

def get_user(username=@auth[:userName])
  @api.get(path: "/operators/#{@auth[:operatorId]}/users/#{username}")
end

#get_user_permission(username = ) ⇒ Object

SAMユーザーの権限設定を取得する



421
422
423
# File 'lib/soracom/client.rb', line 421

def get_user_permission(username=@auth[:userName])
  @api.get(path: "/operators/#{@auth[:operatorId]}/users/#{username}/permission")
end

#get_users_auth_key(username, auth_key_id) ⇒ Object

SAMユーザーのAuthKey取得



401
402
403
# File 'lib/soracom/client.rb', line 401

def get_users_auth_key(username, auth_key_id)
  @api.get(path: "/operators/#{@auth[:operatorId]}/users/#{username}/auth_keys/#{auth_key_id}")
end

#has_user_password(username = ) ⇒ Object

SAMユーザーのパスワードがセットされているかを取得する



411
412
413
# File 'lib/soracom/client.rb', line 411

def has_user_password(username=@auth[:userName])
  @api.get(path: "/operators/#{@auth[:operatorId]}/users/#{username}/password")
end

#list_credentialsObject



348
349
350
# File 'lib/soracom/client.rb', line 348

def list_credentials()
  @api.get(path: '/credentials')
end

#list_event_handlers(handler_id: nil, target: nil, imsi: nil) ⇒ Object

イベントハンドラーの一覧を得る



287
288
289
290
291
292
293
294
295
296
297
# File 'lib/soracom/client.rb', line 287

def list_event_handlers(handler_id:nil, target:nil, imsi:nil)
  if handler_id
    [@api.get(path: "/event_handlers/#{handler_id}")]
  elsif imsi
    @api.get(path: "/event_handlers/subscribers/#{imsi}")
  elsif target # target is one of imsi/operator/tag
    @api.get(path: '/event_handlers', params: { target: target })
  else
    @api.get(path: "/event_handlers")
  end
end

#list_groups(group_id) ⇒ Object

SIMグループの一覧を取得



241
242
243
244
245
246
247
# File 'lib/soracom/client.rb', line 241

def list_groups(group_id)
  if group_id
    [ @api.get(path: "/groups/#{group_id}") ]
  else
    @api.get(path: '/groups')
  end
end

#list_operator_auth_keysObject

OperatorのAuthKey一覧取得



476
477
478
# File 'lib/soracom/client.rb', line 476

def list_operator_auth_keys()
  @api.get(path: "/operators/#{@auth[:operatorId]}/auth_keys")
end

#list_role_attached_users(role_id) ⇒ Object

Role に紐づくユーザーの一覧を取得する



456
457
458
# File 'lib/soracom/client.rb', line 456

def list_role_attached_users(role_id)
  @api.get(path: "/operators/#{@auth[:operatorId]}/roles/#{role_id}/users")
end

#list_rolesObject

Role一覧取得



431
432
433
# File 'lib/soracom/client.rb', line 431

def list_roles()
  @api.get(path: "/operators/#{@auth[:operatorId]}/roles")
end

#list_subscribers(operatorId: @auth[:operatorId], limit: 1024, filter: {}) ⇒ Object

特定Operator下のSubscriber一覧を取



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/soracom/client.rb', line 55

def list_subscribers(operatorId:@auth[:operatorId], limit:1024, filter:{})
  filter = Hash[filter.map { |k, v| [k.to_sym, v] }]
  if filter[:key].nil?
    return @api.get(path: '/subscribers', params: { operatorId: operatorId, limit: limit })
  end

  # filterありの場合
  case filter[:key]
  when 'imsi'
    [@api.get(path: "/subscribers/#{filter[:value]}", params: { operatorId: operatorId, limit: limit })]
  when 'msisdn'
    [@api.get(path: "/subscribers/msisdn/#{filter[:value]}", params: { operatorId: operatorId, limit: limit })]
  when 'status'
    @api.get(path: '/subscribers', params: { operatorId: operatorId, limit: limit, status_filter: filter[:value].gsub('|', '%7C') })
  when 'speed_class'
    @api.get(path: '/subscribers', params: { operatorId: operatorId, limit: limit, speed_class_filter: filter[:value] })
  else
    @api.get(path: '/subscribers', params: { operatorId: operatorId, limit: limit, tag_name: filter[:key], tag_value: filter[:value], tag_value_match_mode: filter[:mode] || 'exact' })
  end
end

#list_subscribers_in_group(group_id) ⇒ Object

SIMグループの削除



261
262
263
# File 'lib/soracom/client.rb', line 261

def list_subscribers_in_group(group_id)
  @api.get(path: "/groups/#{group_id}/subscribers")
end

#list_user_roles(user_name) ⇒ Object

SAMユーザーのロール一覧取得



461
462
463
# File 'lib/soracom/client.rb', line 461

def list_user_roles(user_name)
  @api.get(path: "/operators/#{@auth[:operatorId]}/users/#{user_name}/roles")
end

#list_usersObject

SAMユーザー一覧取得



361
362
363
# File 'lib/soracom/client.rb', line 361

def list_users()
  @api.get(path: "/operators/#{@auth[:operatorId]}/users")
end

#list_users_auth_key(username = ) ⇒ Object

SAMユーザーのAuthKey一覧取得



386
387
388
# File 'lib/soracom/client.rb', line 386

def list_users_auth_key(username=@auth[:userName])
  @api.get(path: "/operators/#{@auth[:operatorId]}/users/#{username}/auth_keys")
end

#operator_idObject

オペレータIDを取得



496
497
498
# File 'lib/soracom/client.rb', line 496

def operator_id
  @auth[:operatorId]
end

#register_subscriber(imsi: nil, registration_secret: nil, groupId: nil, tags: {}) ⇒ Object

SIMの登録



81
82
83
84
85
# File 'lib/soracom/client.rb', line 81

def register_subscriber(imsi:nil, registration_secret:nil, groupId:nil, tags:{})
  params = { registrationSecret: registration_secret, tags: tags }
  params[groupId] = groupId if groupId
  @api.post(path: "/subscribers/#{imsi}", payload: params)
end

#set_expiry_time(imsis, expiry_time) ⇒ Object

SIMの有効期限設定



205
206
207
208
209
210
211
212
213
214
215
# File 'lib/soracom/client.rb', line 205

def set_expiry_time(imsis, expiry_time)
  imsis = [imsis] if imsis.class != Array
  threads = [], result = []
  imsis.map do |imsi|
    threads << Thread.new do
      result << { 'imsi' => imsi }.merge(@api.post(path: "/subscribers/#{imsi}/set_expiry_time", payload: { expiryTime: expiry_time }))
    end
  end
  threads.each(&:join)
  result
end

#set_group(imsi, group_id) ⇒ Object

SIMの所属Groupを指定あるいは上書き変更



231
232
233
# File 'lib/soracom/client.rb', line 231

def set_group(imsi, group_id)
  @api.post(path: "/subscribers/#{imsi}/set_group", payload: { groupId: group_id })
end

#subscribers(operatorId: , limit: 1024, filter: {}) ⇒ Object



76
77
78
# File 'lib/soracom/client.rb', line 76

def subscribers(operatorId:@auth[:operatorId], limit:1024, filter:{})
  list_subscribers(operatorId: operatorId, limit: limit, filter: filter).map { |s| Soracom::Subscriber.new(s, self) }
end

#terminate_subscriber(imsis) ⇒ Object

SIMの解約



127
128
129
130
131
132
133
134
135
136
137
# File 'lib/soracom/client.rb', line 127

def terminate_subscriber(imsis)
  imsis = [imsis] if imsis.class != Array
  threads = [], result = []
  imsis.map do |imsi|
    threads << Thread.new do
      result << { 'imsi' => imsi }.merge(@api.post(path: "/subscribers/#{imsi}/terminate"))
    end
  end
  threads.each(&:join)
  result
end

#tokenObject

トークンを取得



506
507
508
# File 'lib/soracom/client.rb', line 506

def token
  @auth[:token]
end

#unset_expiry_time(imsis) ⇒ Object

SIMの有効期限設定を解除



218
219
220
221
222
223
224
225
226
227
228
# File 'lib/soracom/client.rb', line 218

def unset_expiry_time(imsis)
  imsis = [imsis] if imsis.class != Array
  threads = [], result = []
  imsis.map do |imsi|
    threads << Thread.new do
      result << { 'imsi' => imsi }.merge(@api.post(path: "/subscribers/#{imsi}/unset_expiry_time"))
    end
  end
  threads.each(&:join)
  result
end

#unset_group(imsi) ⇒ Object

SIMの所属Groupを指定を解除



236
237
238
# File 'lib/soracom/client.rb', line 236

def unset_group(imsi)
  @api.post(path: "/subscribers/#{imsi}/unset_group")
end

#update_event_handler(handler_id, req) ⇒ Object

イベントハンドラーを更新する



315
316
317
318
# File 'lib/soracom/client.rb', line 315

def update_event_handler(handler_id, req)
  req = transform_json req
  @api.put(path: "/event_handlers/#{handler_id}", payload: req)
end

#update_group_configuration(group_id, namespace, params) ⇒ Object

コンフィグパラメータの更新



266
267
268
269
# File 'lib/soracom/client.rb', line 266

def update_group_configuration(group_id, namespace, params)
  params = transform_json(params)
  @api.put(path: "/groups/#{group_id}/configuration/#{namespace}", payload: params)
end

#update_group_tags(group_id, tags = {}) ⇒ Object

コンフィグパラメータの更新



277
278
279
# File 'lib/soracom/client.rb', line 277

def update_group_tags(group_id, tags = {})
  @api.put(path: "/groups/#{group_id}/tags", payload: tags)
end

#update_role(role_id, permission, description = '') ⇒ Object

Role を編集する



451
452
453
# File 'lib/soracom/client.rb', line 451

def update_role(role_id, permission, description='')
  @api.put(path: "/operators/#{@auth[:operatorId]}/roles/#{role_id}", payload:{description: description, permission: permission})
end

#update_subscriber_speed_class(imsis, speed_class) ⇒ Object

SIMのプラン変更



192
193
194
195
196
197
198
199
200
201
202
# File 'lib/soracom/client.rb', line 192

def update_subscriber_speed_class(imsis, speed_class)
  imsis = [imsis] if imsis.class != Array
  threads = [], result = []
  imsis.map do |imsi|
    threads << Thread.new do
      result << { 'imsi' => imsi }.merge(@api.post(path: "/subscribers/#{imsi}/update_speed_class", payload: { speedClass: speed_class }))
    end
  end
  threads.each(&:join)
  result
end

#update_subscriber_tags(imsis, tags) ⇒ Object

タグの更新



166
167
168
169
170
171
172
173
174
175
176
# File 'lib/soracom/client.rb', line 166

def update_subscriber_tags(imsis, tags)
  imsis = [imsis] if imsis.class != Array
  threads = [], result = []
  imsis.map do |imsi|
    threads << Thread.new do
      result << { 'imsi' => imsi }.merge(@api.put(path: "/subscribers/#{imsi}/tags", payload: tags))
    end
  end
  threads.each(&:join)
  result
end

#update_user(username, description = '') ⇒ Object

SAMユーザーを更新する



381
382
383
# File 'lib/soracom/client.rb', line 381

def update_user(username, description='')
  @api.put(path: "/operators/#{@auth[:operatorId]}/users/#{username}", payload: { description: description })
end

#update_user_permission(username = , permission = "", description = "") ⇒ Object

SAMユーザーの権限を更新する



426
427
428
# File 'lib/soracom/client.rb', line 426

def update_user_permission(username=@auth[:userName], permission="", description="")
  @api.put(path: "/operators/#{@auth[:operatorId]}/users/#{username}/permission", payload:{description: description, permission: permission})
end

#user_nameObject

ユーザ名を取得



501
502
503
# File 'lib/soracom/client.rb', line 501

def user_name
  @auth[:userName]
end