soracom 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +35 -0
- data/CODE_OF_CONDUCT.md +13 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +47 -0
- data/LICENSE +22 -0
- data/LICENSE.txt +21 -0
- data/README.md +138 -0
- data/Rakefile +1 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/exe/soracom +8 -0
- data/lib/soracom/api_client.rb +60 -0
- data/lib/soracom/cli.rb +320 -0
- data/lib/soracom/client.rb +332 -0
- data/lib/soracom/event_handler.rb +44 -0
- data/lib/soracom/rest_client.rb +48 -0
- data/lib/soracom/subscriber.rb +17 -0
- data/lib/soracom/version.rb +4 -0
- data/lib/soracom.rb +8 -0
- data/samples/test.rb +24 -0
- data/soracom.gemspec +29 -0
- metadata +152 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: bf9c968900c4cc36ed26da56a4b5ffc7a6be2de2
|
4
|
+
data.tar.gz: df2a46235dc380794f02d80c796a34165210b7ac
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7a20100192a89f3a8c30a42203474242a489d4b430d63c8d29084d06dd3fd2b0469c6c2202c54b65a37904d19d45e4aacc8002702bb5bec9a408f5a70073ca2a
|
7
|
+
data.tar.gz: 14501213f04f904551ce27464aac18c04c3f83e6e705fa8c61b14ffc8a6e16d34bb521394b1601ef13503319b44158b0e7f4d19285c19a22e22b505484f2ec8d
|
data/.gitignore
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
/.config
|
4
|
+
/coverage/
|
5
|
+
/InstalledFiles
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/test/tmp/
|
9
|
+
/test/version_tmp/
|
10
|
+
/tmp/
|
11
|
+
|
12
|
+
## Specific to RubyMotion:
|
13
|
+
.dat*
|
14
|
+
.repl_history
|
15
|
+
build/
|
16
|
+
|
17
|
+
## Documentation cache and generated files:
|
18
|
+
/.yardoc/
|
19
|
+
/_yardoc/
|
20
|
+
/doc/
|
21
|
+
/rdoc/
|
22
|
+
|
23
|
+
## Environment normalisation:
|
24
|
+
/.bundle/
|
25
|
+
/vendor/bundle
|
26
|
+
/lib/bundler/man/
|
27
|
+
|
28
|
+
# for a library or gem, you might want to ignore these files since the code is
|
29
|
+
# intended to run in multiple environments; otherwise, check them in:
|
30
|
+
# Gemfile.lock
|
31
|
+
# .ruby-version
|
32
|
+
# .ruby-gemset
|
33
|
+
|
34
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
35
|
+
.rvmrc
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
|
4
|
+
|
5
|
+
We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
|
6
|
+
|
7
|
+
Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
|
8
|
+
|
9
|
+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
|
10
|
+
|
11
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
|
12
|
+
|
13
|
+
This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
soracom (1.0.1)
|
5
|
+
io-console
|
6
|
+
thor
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
coderay (1.1.0)
|
12
|
+
diff-lcs (1.2.5)
|
13
|
+
io-console (0.4.2)
|
14
|
+
method_source (0.8.2)
|
15
|
+
pry (0.10.2)
|
16
|
+
coderay (~> 1.1.0)
|
17
|
+
method_source (~> 0.8.1)
|
18
|
+
slop (~> 3.4)
|
19
|
+
rake (10.4.2)
|
20
|
+
rspec (3.3.0)
|
21
|
+
rspec-core (~> 3.3.0)
|
22
|
+
rspec-expectations (~> 3.3.0)
|
23
|
+
rspec-mocks (~> 3.3.0)
|
24
|
+
rspec-core (3.3.2)
|
25
|
+
rspec-support (~> 3.3.0)
|
26
|
+
rspec-expectations (3.3.1)
|
27
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
28
|
+
rspec-support (~> 3.3.0)
|
29
|
+
rspec-mocks (3.3.2)
|
30
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
31
|
+
rspec-support (~> 3.3.0)
|
32
|
+
rspec-support (3.3.0)
|
33
|
+
slop (3.6.0)
|
34
|
+
thor (0.19.1)
|
35
|
+
|
36
|
+
PLATFORMS
|
37
|
+
ruby
|
38
|
+
|
39
|
+
DEPENDENCIES
|
40
|
+
bundler (~> 1.9)
|
41
|
+
pry
|
42
|
+
rake (~> 10.0)
|
43
|
+
rspec
|
44
|
+
soracom!
|
45
|
+
|
46
|
+
BUNDLED WITH
|
47
|
+
1.10.3
|
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Soracom, Inc.
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
22
|
+
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 MATSUI,Motokatsu
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,138 @@
|
|
1
|
+
# SORACOM SDK for Ruby
|
2
|
+
SORACOM SDK for Ruby は、株式会社 SORACOM の提供する IoT プラットフォームの API を Ruby プログラムからコールするためのライブラリとなります。
|
3
|
+
またコマンドラインインターフェース(CLI)も付属していますので、プログラムを組まなくてもシェルスクリプト等から API を呼び出す事が可能となります。
|
4
|
+
|
5
|
+
## インストール
|
6
|
+
|
7
|
+
```
|
8
|
+
$ (sudo) gem install soracom # 環境により sudo が必要となる場合があります
|
9
|
+
```
|
10
|
+
|
11
|
+
としてインストールする事で、ライブラリおよびコマンドラインインターフェース ( soracom コマンド)が導入されます。
|
12
|
+
|
13
|
+
## 使用方法
|
14
|
+
|
15
|
+
### SDK
|
16
|
+
|
17
|
+
#### 使用例
|
18
|
+
サンプルコード: SIMの一覧を取得し、プランを s1.fast に変更する
|
19
|
+
```ruby
|
20
|
+
#!/usr/bin/env ruby
|
21
|
+
require 'soracom'
|
22
|
+
|
23
|
+
# SORACOM APIアクセス用クライアントの初期化方法
|
24
|
+
# 1. client = Soracom::Client.new(email: '登録メールアドレス', password: 'パスワード')
|
25
|
+
# 2. client = Soracom::Client.new
|
26
|
+
# (環境変数 SORACOM_EMAIL & SORACOM_PASSWORD を参照)
|
27
|
+
|
28
|
+
client = Soracom::Client.new
|
29
|
+
|
30
|
+
# サブスクライバー(SIM)の一覧を取得
|
31
|
+
sims = client.list_subscribers
|
32
|
+
|
33
|
+
puts "found #{sims.count} SIMs."
|
34
|
+
|
35
|
+
# 操作対象のIMSI配列を用意
|
36
|
+
imsis = sims.map { |sim| sim['imsi'] }
|
37
|
+
|
38
|
+
puts 'change plan to s1.fast'
|
39
|
+
|
40
|
+
# プラン変更のためのAPIをコールする
|
41
|
+
client.update_subscriber_speed_class(imsis, 's1.fast')
|
42
|
+
|
43
|
+
puts 'done'
|
44
|
+
|
45
|
+
```
|
46
|
+
|
47
|
+
### コマンドラインインターフェース
|
48
|
+
#### 認証情報の設定
|
49
|
+
環境変数にメールアドレス・パスワードを設定します。
|
50
|
+
```
|
51
|
+
$ export SORACOM_EMAIL='somebody@example.com'
|
52
|
+
$ export SORACOM_PASSWORD='mypassword'
|
53
|
+
```
|
54
|
+
|
55
|
+
認証情報が正しく設定されているかどうかを確認するには、**soracom auth** コマンドを使用します。
|
56
|
+
```
|
57
|
+
~$ soracom auth
|
58
|
+
testing authentication...
|
59
|
+
authentication succeeded.
|
60
|
+
apiKey: APIキー
|
61
|
+
operatorId: OPで始まるオペレータID
|
62
|
+
```
|
63
|
+
|
64
|
+
#### 使用例
|
65
|
+
SIMの一覧を取得する
|
66
|
+
```
|
67
|
+
$ soracom subscriber list
|
68
|
+
[
|
69
|
+
{
|
70
|
+
(SIMの情報)
|
71
|
+
},
|
72
|
+
:
|
73
|
+
{
|
74
|
+
(SIMの情報)
|
75
|
+
}
|
76
|
+
]
|
77
|
+
```
|
78
|
+
|
79
|
+
出力されたJSONフォーマットのデータから特定のパラメータを抜き出すには、**jq** コマンドが有用です。
|
80
|
+
```
|
81
|
+
$ soracom subscriber list | jq -r '.[].imsi' | tee imsi.txt
|
82
|
+
001010000000000
|
83
|
+
001010000000001
|
84
|
+
001010000000002
|
85
|
+
:
|
86
|
+
```
|
87
|
+
|
88
|
+
複数のSIMに対して、プランを s1.fast に変更する
|
89
|
+
```
|
90
|
+
$ soracom subscriber update_speed_class --imsi $(cat imsi.txt) --type s1.fast
|
91
|
+
[
|
92
|
+
{
|
93
|
+
(変更後のSIMの情報)
|
94
|
+
},
|
95
|
+
:
|
96
|
+
{
|
97
|
+
(変更後のSIMの情報)
|
98
|
+
}
|
99
|
+
]
|
100
|
+
```
|
101
|
+
|
102
|
+
#### コマンドライン補完
|
103
|
+
利用しているシェルが bash/zsh であれば、
|
104
|
+
```
|
105
|
+
eval "$(soracom complete)"
|
106
|
+
```
|
107
|
+
と .bashrc や .zshrc などに書く事で、soracom コマンドのコマンド名補完が可能です。
|
108
|
+
|
109
|
+
```
|
110
|
+
$ soracom [tab]
|
111
|
+
~$ soracom
|
112
|
+
auth stats
|
113
|
+
event_handler subscriber
|
114
|
+
group support
|
115
|
+
sim version
|
116
|
+
|
117
|
+
$ soracom sub[tab]
|
118
|
+
|
119
|
+
$ soracom subscriber [tab]
|
120
|
+
activate
|
121
|
+
deactivate
|
122
|
+
delete_tag
|
123
|
+
disable_termination
|
124
|
+
enable_termination
|
125
|
+
help
|
126
|
+
list
|
127
|
+
register
|
128
|
+
set_expiry_time
|
129
|
+
set_group
|
130
|
+
terminate
|
131
|
+
unset_expiry_time
|
132
|
+
unset_group
|
133
|
+
update_speed_class
|
134
|
+
update_tags
|
135
|
+
|
136
|
+
$ soracom subscriber li[tab]
|
137
|
+
$ soracom subscriber list
|
138
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'soracom'
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require 'pry'
|
14
|
+
Pry.start
|
data/bin/setup
ADDED
data/exe/soracom
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
module Soracom
|
2
|
+
# Class to handle API requests
|
3
|
+
class ApiClient
|
4
|
+
def initialize(auth, endpoint)
|
5
|
+
@log = Logger.new(STDERR)
|
6
|
+
@log.level = ENV['SORACOM_DEBUG'] ? Logger::DEBUG : Logger::WARN
|
7
|
+
@auth = auth
|
8
|
+
@endpoint = (endpoint.nil?) ? API_BASE_URL : endpoint
|
9
|
+
end
|
10
|
+
|
11
|
+
def get(path:'', params:{})
|
12
|
+
res = RestClient.get @endpoint + path, accept: 'application/json', params: params, 'X-Soracom-API-Key' => @auth[:apiKey], 'X-Soracom-Token' => @auth[:token]
|
13
|
+
return parse(res.body) if res.body && res.body.length > 0
|
14
|
+
return { result: (res.code =~ /2../) ? 'success' : 'failure' }
|
15
|
+
rescue => evar
|
16
|
+
@log.debug evar
|
17
|
+
return { result: "failure: #{evar}" }
|
18
|
+
end
|
19
|
+
|
20
|
+
def post(path:'', params:{}, payload:{})
|
21
|
+
res = RestClient.post @endpoint + path, payload,
|
22
|
+
content_type: 'application/json', accept: 'application/json', params: params, 'X-Soracom-API-Key' => @auth[:apiKey], 'X-Soracom-Token' => @auth[:token]
|
23
|
+
return parse(res.body) if res.body && res.body.length > 0
|
24
|
+
return { result: (res.code =~ /2../) ? 'success' : 'failure' }
|
25
|
+
rescue => evar
|
26
|
+
@log.debug evar
|
27
|
+
return { result: "failure: #{evar}" }
|
28
|
+
end
|
29
|
+
|
30
|
+
def put(path:'', params:{}, payload:{})
|
31
|
+
res = RestClient.put @endpoint + path, payload,
|
32
|
+
content_type: 'application/json', accept: 'application/json', params: params, 'X-Soracom-API-Key' => @auth[:apiKey], 'X-Soracom-Token' => @auth[:token]
|
33
|
+
return parse(res.body) if res.body && res.body.length > 0
|
34
|
+
return { result: (res.code =~ /2../) ? 'success' : 'failure' }
|
35
|
+
rescue => evar
|
36
|
+
@log.debug evar
|
37
|
+
return { result: "failure: #{evar}" }
|
38
|
+
end
|
39
|
+
|
40
|
+
def delete(path:'', params:{})
|
41
|
+
res = RestClient.delete @endpoint + path, accept: 'application/json', params: params, 'X-Soracom-API-Key' => @auth[:apiKey], 'X-Soracom-Token' => @auth[:token]
|
42
|
+
@log.debug res.body
|
43
|
+
return parse(res.body) if res.body && res.body.length > 0
|
44
|
+
return { result: (res.code =~ /2../) ? 'success' : 'failure' }
|
45
|
+
rescue => evar
|
46
|
+
@log.debug evar
|
47
|
+
return { result: "failure: #{evar}" }
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
|
52
|
+
def parse(response)
|
53
|
+
begin
|
54
|
+
return JSON.parse(response)
|
55
|
+
rescue JSON::ParserError => e
|
56
|
+
return {result: response}
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|