ambient_iot 0.1.0
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 +11 -0
- data/.rspec +3 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +48 -0
- data/LICENSE.txt +21 -0
- data/README.md +84 -0
- data/README_ja.md +83 -0
- data/Rakefile +6 -0
- data/ambient_iot.gemspec +29 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/ambient_iot.rb +28 -0
- data/lib/ambient_iot/client.rb +171 -0
- data/lib/ambient_iot/version.rb +25 -0
- metadata +124 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 02ff16a078c81ee9ed621d082760770539c02f6d48a0c077fe502f657e2f3c50
|
|
4
|
+
data.tar.gz: b08000d6faa32e9b659e48257ac7e29ba9b25ee68612b84c8385b16fa7e6e65d
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 21fd9ed9b4495ef3a0f7560e03764810c0f8a3ef0d4def93a6acbf33e734a945e8c41b640c7aa24c579afd4b86f2893765171815c0ce03442e42f85ff055fde5
|
|
7
|
+
data.tar.gz: b0b15e67574c4764765bac37ff2db097fd9ad6113264a3e7db0ebf8f463abb7ab8b9083d4b2eff530deb18c67d404147fd42997d75c2a2f730f30fa118679383
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
|
2
|
+
|
|
3
|
+
## Our Pledge
|
|
4
|
+
|
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
|
10
|
+
orientation.
|
|
11
|
+
|
|
12
|
+
## Our Standards
|
|
13
|
+
|
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
|
15
|
+
include:
|
|
16
|
+
|
|
17
|
+
* Using welcoming and inclusive language
|
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
|
19
|
+
* Gracefully accepting constructive criticism
|
|
20
|
+
* Focusing on what is best for the community
|
|
21
|
+
* Showing empathy towards other community members
|
|
22
|
+
|
|
23
|
+
Examples of unacceptable behavior by participants include:
|
|
24
|
+
|
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
|
26
|
+
advances
|
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
|
28
|
+
* Public or private harassment
|
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
|
30
|
+
address, without explicit permission
|
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
|
32
|
+
professional setting
|
|
33
|
+
|
|
34
|
+
## Our Responsibilities
|
|
35
|
+
|
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
|
38
|
+
response to any instances of unacceptable behavior.
|
|
39
|
+
|
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
|
44
|
+
threatening, offensive, or harmful.
|
|
45
|
+
|
|
46
|
+
## Scope
|
|
47
|
+
|
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
|
49
|
+
when an individual is representing the project or its community. Examples of
|
|
50
|
+
representing a project or community include using an official project e-mail
|
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
|
53
|
+
further defined and clarified by project maintainers.
|
|
54
|
+
|
|
55
|
+
## Enforcement
|
|
56
|
+
|
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
|
58
|
+
reported by contacting the project team at kito@itosoft.com. All
|
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
|
63
|
+
|
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
|
66
|
+
members of the project's leadership.
|
|
67
|
+
|
|
68
|
+
## Attribution
|
|
69
|
+
|
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
|
72
|
+
|
|
73
|
+
[homepage]: http://contributor-covenant.org
|
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
ambient_iot (0.1.0)
|
|
5
|
+
activesupport (~> 4.2, >= 4.2.7)
|
|
6
|
+
|
|
7
|
+
GEM
|
|
8
|
+
remote: https://rubygems.org/
|
|
9
|
+
specs:
|
|
10
|
+
activesupport (4.2.10)
|
|
11
|
+
i18n (~> 0.7)
|
|
12
|
+
minitest (~> 5.1)
|
|
13
|
+
thread_safe (~> 0.3, >= 0.3.4)
|
|
14
|
+
tzinfo (~> 1.1)
|
|
15
|
+
concurrent-ruby (1.0.5)
|
|
16
|
+
diff-lcs (1.3)
|
|
17
|
+
i18n (0.9.5)
|
|
18
|
+
concurrent-ruby (~> 1.0)
|
|
19
|
+
minitest (5.11.3)
|
|
20
|
+
rake (10.5.0)
|
|
21
|
+
rspec (3.7.0)
|
|
22
|
+
rspec-core (~> 3.7.0)
|
|
23
|
+
rspec-expectations (~> 3.7.0)
|
|
24
|
+
rspec-mocks (~> 3.7.0)
|
|
25
|
+
rspec-core (3.7.1)
|
|
26
|
+
rspec-support (~> 3.7.0)
|
|
27
|
+
rspec-expectations (3.7.0)
|
|
28
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
29
|
+
rspec-support (~> 3.7.0)
|
|
30
|
+
rspec-mocks (3.7.0)
|
|
31
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
32
|
+
rspec-support (~> 3.7.0)
|
|
33
|
+
rspec-support (3.7.1)
|
|
34
|
+
thread_safe (0.3.6)
|
|
35
|
+
tzinfo (1.2.5)
|
|
36
|
+
thread_safe (~> 0.1)
|
|
37
|
+
|
|
38
|
+
PLATFORMS
|
|
39
|
+
ruby
|
|
40
|
+
|
|
41
|
+
DEPENDENCIES
|
|
42
|
+
ambient_iot!
|
|
43
|
+
bundler (~> 1.16)
|
|
44
|
+
rake (~> 10.0)
|
|
45
|
+
rspec (~> 3.0)
|
|
46
|
+
|
|
47
|
+
BUNDLED WITH
|
|
48
|
+
1.16.1
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2018 ITO SOFT DESIGN 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
|
|
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,84 @@
|
|
|
1
|
+
# AmbientIot
|
|
2
|
+
|
|
3
|
+
This is a Gem library to access Ambient ( https://ambidata.io ) service which is provided by AmbientData Inc.
|
|
4
|
+
You can upload data (such as a IoT) to Ambient.
|
|
5
|
+
Then Ambient draw a Graph of the data.
|
|
6
|
+
|
|
7
|
+
AmbientIot is a port from [ambient-python-lib](https://github.com/AmbientDataInc/ambient-python-lib).
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
Add this line to your application's Gemfile:
|
|
12
|
+
|
|
13
|
+
```ruby
|
|
14
|
+
gem 'ambient_iot'
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
And then execute:
|
|
18
|
+
|
|
19
|
+
$ bundle
|
|
20
|
+
|
|
21
|
+
Or install it yourself as:
|
|
22
|
+
|
|
23
|
+
$ gem install ambient_iot
|
|
24
|
+
|
|
25
|
+
## Usage
|
|
26
|
+
|
|
27
|
+
First, you should get an account for Ambient.
|
|
28
|
+
Next you make a channel on the Ambient.
|
|
29
|
+
Then you can get a channel id, a write key and a read key for the channel.
|
|
30
|
+
|
|
31
|
+
### Uploading data:
|
|
32
|
+
|
|
33
|
+
Ambient data take keys d1 to d8.
|
|
34
|
+
You set a data as a hash.
|
|
35
|
+
|
|
36
|
+
channel_id = 1234 # set your channel id here
|
|
37
|
+
write_key = "abc.." # set write key of the channel
|
|
38
|
+
client = AmbientIot::Client.new channel_id, write_key:write_key # create a client
|
|
39
|
+
client << { d1:1, d2:2, d3:3} # append a data
|
|
40
|
+
client.sync # send to Ambient site
|
|
41
|
+
|
|
42
|
+
Timestamp is automatically added.
|
|
43
|
+
If you don't want to set timestamp, set false the timestamp property.
|
|
44
|
+
|
|
45
|
+
client.append_timestamp = false
|
|
46
|
+
|
|
47
|
+
In this case, timestamp is set by Ambient.
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
### Getting uploaded data:
|
|
51
|
+
|
|
52
|
+
channel_id = 1234 # set your channel id here
|
|
53
|
+
read_key = "abc.." # set read key of the channel
|
|
54
|
+
client = AmbientIot::Client.new channel_id, read_key:read_key # create a client
|
|
55
|
+
client.read
|
|
56
|
+
|
|
57
|
+
# with specific date
|
|
58
|
+
client.read date:Time.new(2018, 4, 26)
|
|
59
|
+
|
|
60
|
+
# with specific range
|
|
61
|
+
client.read start:Time.new(2018, 4, 20), end:Time.new(2018, 4, 26)
|
|
62
|
+
|
|
63
|
+
# with number of data
|
|
64
|
+
client.read n:1, step:5
|
|
65
|
+
|
|
66
|
+
### Getting a channel information and recent updated data
|
|
67
|
+
|
|
68
|
+
channel_id = 1234 # set your channel id here
|
|
69
|
+
read_key = "abc.." # set read key of the channel
|
|
70
|
+
client = AmbientIot::Client.new channel_id, read_key:read_key # create a client
|
|
71
|
+
client.info
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
## Contributing
|
|
75
|
+
|
|
76
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/ito-soft-design/ambient_iot. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
|
77
|
+
|
|
78
|
+
## License
|
|
79
|
+
|
|
80
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
|
81
|
+
|
|
82
|
+
## Code of Conduct
|
|
83
|
+
|
|
84
|
+
Everyone interacting in the AmbientIot project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/ito-soft-design/ambient_iot/blob/master/CODE_OF_CONDUCT.md).
|
data/README_ja.md
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
# AmbientIot
|
|
2
|
+
|
|
3
|
+
AmbientIotは Ambient ( https://ambidata.io ) にアクセスするためのGemライブラリーです。
|
|
4
|
+
Ambientはアップロードされたデータをグラフとして表示してくれるサービスでAmbientData Inc. が提供しています。
|
|
5
|
+
|
|
6
|
+
AmbientIotは [ambient-python-lib](https://github.com/AmbientDataInc/ambient-python-lib)を基にRuby用に作ったものです。
|
|
7
|
+
|
|
8
|
+
## インストール
|
|
9
|
+
|
|
10
|
+
Gemfileに下の行を追加します。
|
|
11
|
+
|
|
12
|
+
```ruby
|
|
13
|
+
gem 'ambient_iot'
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
そして bundle コマンドを実行します。
|
|
17
|
+
|
|
18
|
+
$ bundle
|
|
19
|
+
|
|
20
|
+
またはgemコマンドでインストールします。
|
|
21
|
+
|
|
22
|
+
$ gem install ambient_iot
|
|
23
|
+
|
|
24
|
+
## 使い方
|
|
25
|
+
|
|
26
|
+
始めにAmbientのアカウントを取得する必要があります。
|
|
27
|
+
続いてチャンネルを作成します。
|
|
28
|
+
チャンネルを作成するとチャンネルID、ライトキー、リードキーが得られます。
|
|
29
|
+
|
|
30
|
+
### データを送信する場合:
|
|
31
|
+
|
|
32
|
+
Ambientのデータはd1からd8のキーでデータ系列を表現します。
|
|
33
|
+
データを与える場合Hashデータとして渡します。
|
|
34
|
+
|
|
35
|
+
channel_id = 1234 # チャンネル IDをセットします。
|
|
36
|
+
write_key = "abc.." # チャンネルのライトキーをセットします。
|
|
37
|
+
client = AmbientIot::Client.new channel_id, write_key:write_key # クライアント生成
|
|
38
|
+
client << { d1:1, d2:2, d3:3} # データを追加します。
|
|
39
|
+
client.sync # データを送信します
|
|
40
|
+
|
|
41
|
+
時刻はデータ追加時に自動で設定されます。
|
|
42
|
+
時刻を追加したくない場合は append_timestamp にfalseを設定します。
|
|
43
|
+
|
|
44
|
+
client.append_timestamp = false
|
|
45
|
+
|
|
46
|
+
この場合はAmbientサイト上で時刻が設定されます。
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
### 送信済みの最新のデータを取得する場合:
|
|
50
|
+
|
|
51
|
+
channel_id = 1234 # チャンネル IDをセットします。
|
|
52
|
+
read_key = "abc.." # チャンネルのリードキーをセットします。
|
|
53
|
+
client = AmbientIot::Client.new channel_id, read_key:read_key # クライアント生成
|
|
54
|
+
client.read # 送信済みのデータを読み込みます
|
|
55
|
+
|
|
56
|
+
# 特定の日付のデータを取得する場合
|
|
57
|
+
client.read date:Time.new(2018, 4, 26)
|
|
58
|
+
|
|
59
|
+
# 特定の範囲のデータを取得する場合
|
|
60
|
+
client.read start:Time.new(2018, 4, 20), end:Time.new(2018, 4, 26)
|
|
61
|
+
|
|
62
|
+
# データ数を指定する場合
|
|
63
|
+
client.read n:1, step:5
|
|
64
|
+
|
|
65
|
+
### チャンネル情報や最新のデータを取得する場合
|
|
66
|
+
|
|
67
|
+
channel_id = 1234 # チャンネル IDをセットします。
|
|
68
|
+
read_key = "abc.." # チャンネルのリードキーをセットします。
|
|
69
|
+
client = AmbientIot::Client.new channel_id, read_key:read_key # クライアント生成
|
|
70
|
+
client.info # 情報取得
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
## Contributing
|
|
74
|
+
|
|
75
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/ito-soft-design/ambient_iot. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
|
76
|
+
|
|
77
|
+
## License
|
|
78
|
+
|
|
79
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
|
80
|
+
|
|
81
|
+
## Code of Conduct
|
|
82
|
+
|
|
83
|
+
Everyone interacting in the AmbientIot project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/ito-soft-design/ambient_iot/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/ambient_iot.gemspec
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
|
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
require "ambient_iot/version"
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = "ambient_iot"
|
|
8
|
+
spec.version = AmbientIot::VERSION
|
|
9
|
+
spec.authors = ["Katsuyoshi Ito"]
|
|
10
|
+
spec.email = ["kito@itosoft.com"]
|
|
11
|
+
|
|
12
|
+
spec.summary = %q{AmbientIot is a ruby library which helps to upload IoT data to the Ambient service.}
|
|
13
|
+
spec.description = %q{AmbientIot is a ruby library which helps to upload IoT data to the Ambient service.}
|
|
14
|
+
spec.homepage = "https://github.com/ito-soft-design/ambient_iot"
|
|
15
|
+
spec.license = "MIT"
|
|
16
|
+
|
|
17
|
+
spec.add_runtime_dependency 'activesupport', '~> 4.2', '>= 4.2.7'
|
|
18
|
+
|
|
19
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
|
20
|
+
f.match(%r{^(test|spec|features)/})
|
|
21
|
+
end
|
|
22
|
+
spec.bindir = "exe"
|
|
23
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
24
|
+
spec.require_paths = ["lib"]
|
|
25
|
+
|
|
26
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
|
27
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
|
28
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
|
29
|
+
end
|
data/bin/console
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require "bundler/setup"
|
|
4
|
+
require "ambient_iot"
|
|
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 "irb"
|
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/lib/ambient_iot.rb
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# The MIT License (MIT)
|
|
2
|
+
#
|
|
3
|
+
# Copyright (c) 2018 ITO SOFT DESIGN 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
|
|
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.
|
|
22
|
+
|
|
23
|
+
require "ambient_iot/version"
|
|
24
|
+
require "ambient_iot/client"
|
|
25
|
+
|
|
26
|
+
module AmbientIot
|
|
27
|
+
# Your code goes here...
|
|
28
|
+
end
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
# The MIT License (MIT)
|
|
2
|
+
#
|
|
3
|
+
# Copyright (c) 2018 ITO SOFT DESIGN 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
|
|
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.
|
|
22
|
+
|
|
23
|
+
require 'net/http'
|
|
24
|
+
require 'json'
|
|
25
|
+
require 'active_support'
|
|
26
|
+
require 'active_support/core_ext'
|
|
27
|
+
|
|
28
|
+
module AmbientIot
|
|
29
|
+
class Client
|
|
30
|
+
|
|
31
|
+
def initialize channel_id, options={}
|
|
32
|
+
@channel_id = channel_id
|
|
33
|
+
@write_key = options[:write_key]
|
|
34
|
+
@read_key = options[:read_key]
|
|
35
|
+
@user_key = options[:user_key]
|
|
36
|
+
|
|
37
|
+
@post_data = []
|
|
38
|
+
@append_timestamp = true
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def << data
|
|
42
|
+
data = [data] unless data.is_a? Array
|
|
43
|
+
if append_timestamp?
|
|
44
|
+
now = time_to_s Time.now
|
|
45
|
+
data.each{|d| d["created"] = now}
|
|
46
|
+
end
|
|
47
|
+
@post_data += data
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def append_timestamp?
|
|
51
|
+
@append_timestamp
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def append_timestamp= flag
|
|
55
|
+
@append_timestamp = flag
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def write
|
|
59
|
+
post
|
|
60
|
+
end
|
|
61
|
+
alias :sync :write
|
|
62
|
+
alias :synchronize :write
|
|
63
|
+
|
|
64
|
+
def read options={}
|
|
65
|
+
get options
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def info
|
|
69
|
+
get_property
|
|
70
|
+
end
|
|
71
|
+
alias :prop :info
|
|
72
|
+
alias :property :info
|
|
73
|
+
|
|
74
|
+
private
|
|
75
|
+
|
|
76
|
+
def post
|
|
77
|
+
raise "'write_key' is required." unless @write_key
|
|
78
|
+
|
|
79
|
+
url = URI("http://ambidata.io/api/v2/channels/#{@channel_id}/dataarray")
|
|
80
|
+
req = Net::HTTP::Post.new(url.path, 'Content-Type' => 'application/json')
|
|
81
|
+
payload = {writeKey:@write_key, data:@post_data}
|
|
82
|
+
req.body = payload.to_json
|
|
83
|
+
res = Net::HTTP.new(url.host, url.port).start {|http|
|
|
84
|
+
http.request(req)
|
|
85
|
+
}
|
|
86
|
+
case res
|
|
87
|
+
when Net::HTTPSuccess#, Net::HTTPRedirection
|
|
88
|
+
@post_data = []
|
|
89
|
+
else
|
|
90
|
+
res.value
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
def get_with_url url
|
|
95
|
+
req = Net::HTTP::Get.new(url)
|
|
96
|
+
res = Net::HTTP.new(url.host, url.port).start {|http|
|
|
97
|
+
http.request(req)
|
|
98
|
+
}
|
|
99
|
+
case res
|
|
100
|
+
when Net::HTTPSuccess#, Net::HTTPRedirection
|
|
101
|
+
obj_to_symbolize JSON.parse(res.body)
|
|
102
|
+
else
|
|
103
|
+
res.value
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
def get options={}
|
|
108
|
+
raise "'read_key' is required." unless @read_key
|
|
109
|
+
|
|
110
|
+
url = URI("http://ambidata.io/api/v2/channels/#{@channel_id}/data")
|
|
111
|
+
query = { readKey:@read_key }
|
|
112
|
+
if options[:date]
|
|
113
|
+
query[:date] = time_to_s options[:date]
|
|
114
|
+
elsif options[:start] and options[:end]
|
|
115
|
+
query[:start] = time_to_s options[:start]
|
|
116
|
+
query[:end] = time_to_s options[:end]
|
|
117
|
+
elsif options[:n]
|
|
118
|
+
query[:n] = options[:n]
|
|
119
|
+
query[:skip] = options[:skip] if options[:skip]
|
|
120
|
+
end
|
|
121
|
+
url.query = query.to_param
|
|
122
|
+
get_with_url url
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
def get_property
|
|
126
|
+
raise "'read_key' is required." unless @read_key
|
|
127
|
+
|
|
128
|
+
url = URI("http://ambidata.io/api/v2/channels/#{@channel_id}")
|
|
129
|
+
url.query = { readKey:@read_key }.to_param
|
|
130
|
+
get_with_url url
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
def time_to_s time
|
|
134
|
+
time.strftime("%Y-%m-%d %H:%M:%S.%L")
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
def date_to_s date
|
|
138
|
+
date.strftime("%Y-%m-%d")
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
def obj_to_symbolize obj
|
|
142
|
+
begin
|
|
143
|
+
case obj
|
|
144
|
+
when Hash
|
|
145
|
+
obj = obj.deep_symbolize_keys!
|
|
146
|
+
obj.each do |k, v|
|
|
147
|
+
case v
|
|
148
|
+
when String
|
|
149
|
+
if /\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z/ =~ v
|
|
150
|
+
obj[k] = Time.parse(v).localtime
|
|
151
|
+
end
|
|
152
|
+
when Array, Hash
|
|
153
|
+
obj[k] = obj_to_symbolize v
|
|
154
|
+
end
|
|
155
|
+
end
|
|
156
|
+
when Array
|
|
157
|
+
obj.map{|h|
|
|
158
|
+
case h
|
|
159
|
+
when Hash, Array
|
|
160
|
+
h = obj_to_symbolize h
|
|
161
|
+
end
|
|
162
|
+
h
|
|
163
|
+
}
|
|
164
|
+
end
|
|
165
|
+
rescue
|
|
166
|
+
obj
|
|
167
|
+
end
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
end
|
|
171
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# The MIT License (MIT)
|
|
2
|
+
#
|
|
3
|
+
# Copyright (c) 2018 ITO SOFT DESIGN 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
|
|
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.
|
|
22
|
+
|
|
23
|
+
module AmbientIot
|
|
24
|
+
VERSION = "0.1.0"
|
|
25
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: ambient_iot
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Katsuyoshi Ito
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: exe
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2018-04-27 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: activesupport
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '4.2'
|
|
20
|
+
- - ">="
|
|
21
|
+
- !ruby/object:Gem::Version
|
|
22
|
+
version: 4.2.7
|
|
23
|
+
type: :runtime
|
|
24
|
+
prerelease: false
|
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
26
|
+
requirements:
|
|
27
|
+
- - "~>"
|
|
28
|
+
- !ruby/object:Gem::Version
|
|
29
|
+
version: '4.2'
|
|
30
|
+
- - ">="
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: 4.2.7
|
|
33
|
+
- !ruby/object:Gem::Dependency
|
|
34
|
+
name: bundler
|
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
|
36
|
+
requirements:
|
|
37
|
+
- - "~>"
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: '1.16'
|
|
40
|
+
type: :development
|
|
41
|
+
prerelease: false
|
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
43
|
+
requirements:
|
|
44
|
+
- - "~>"
|
|
45
|
+
- !ruby/object:Gem::Version
|
|
46
|
+
version: '1.16'
|
|
47
|
+
- !ruby/object:Gem::Dependency
|
|
48
|
+
name: rake
|
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
|
50
|
+
requirements:
|
|
51
|
+
- - "~>"
|
|
52
|
+
- !ruby/object:Gem::Version
|
|
53
|
+
version: '10.0'
|
|
54
|
+
type: :development
|
|
55
|
+
prerelease: false
|
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
57
|
+
requirements:
|
|
58
|
+
- - "~>"
|
|
59
|
+
- !ruby/object:Gem::Version
|
|
60
|
+
version: '10.0'
|
|
61
|
+
- !ruby/object:Gem::Dependency
|
|
62
|
+
name: rspec
|
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
|
64
|
+
requirements:
|
|
65
|
+
- - "~>"
|
|
66
|
+
- !ruby/object:Gem::Version
|
|
67
|
+
version: '3.0'
|
|
68
|
+
type: :development
|
|
69
|
+
prerelease: false
|
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
71
|
+
requirements:
|
|
72
|
+
- - "~>"
|
|
73
|
+
- !ruby/object:Gem::Version
|
|
74
|
+
version: '3.0'
|
|
75
|
+
description: AmbientIot is a ruby library which helps to upload IoT data to the Ambient
|
|
76
|
+
service.
|
|
77
|
+
email:
|
|
78
|
+
- kito@itosoft.com
|
|
79
|
+
executables: []
|
|
80
|
+
extensions: []
|
|
81
|
+
extra_rdoc_files: []
|
|
82
|
+
files:
|
|
83
|
+
- ".gitignore"
|
|
84
|
+
- ".rspec"
|
|
85
|
+
- ".travis.yml"
|
|
86
|
+
- CODE_OF_CONDUCT.md
|
|
87
|
+
- Gemfile
|
|
88
|
+
- Gemfile.lock
|
|
89
|
+
- LICENSE.txt
|
|
90
|
+
- README.md
|
|
91
|
+
- README_ja.md
|
|
92
|
+
- Rakefile
|
|
93
|
+
- ambient_iot.gemspec
|
|
94
|
+
- bin/console
|
|
95
|
+
- bin/setup
|
|
96
|
+
- lib/ambient_iot.rb
|
|
97
|
+
- lib/ambient_iot/client.rb
|
|
98
|
+
- lib/ambient_iot/version.rb
|
|
99
|
+
homepage: https://github.com/ito-soft-design/ambient_iot
|
|
100
|
+
licenses:
|
|
101
|
+
- MIT
|
|
102
|
+
metadata: {}
|
|
103
|
+
post_install_message:
|
|
104
|
+
rdoc_options: []
|
|
105
|
+
require_paths:
|
|
106
|
+
- lib
|
|
107
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
108
|
+
requirements:
|
|
109
|
+
- - ">="
|
|
110
|
+
- !ruby/object:Gem::Version
|
|
111
|
+
version: '0'
|
|
112
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
113
|
+
requirements:
|
|
114
|
+
- - ">="
|
|
115
|
+
- !ruby/object:Gem::Version
|
|
116
|
+
version: '0'
|
|
117
|
+
requirements: []
|
|
118
|
+
rubyforge_project:
|
|
119
|
+
rubygems_version: 2.7.6
|
|
120
|
+
signing_key:
|
|
121
|
+
specification_version: 4
|
|
122
|
+
summary: AmbientIot is a ruby library which helps to upload IoT data to the Ambient
|
|
123
|
+
service.
|
|
124
|
+
test_files: []
|