tamashii-manager 0.2.4 → 0.2.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +8 -2
- data/README.md +133 -15
- data/lib/tamashii/manager/server.rb +4 -0
- data/lib/tamashii/manager/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e261e9f42acf76a96f678f43a6c95d6ca206680c
|
4
|
+
data.tar.gz: e1a3c8fa43ecbd156abff71ba9d1a73a39cf79a1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 407385d718724a79a0aad75aeeba1ebe8cdf6ed363fff05683a57d16244d3f9caa04698961caf3e1671e27f95f096f32542873861aa24167ca3747249d23c541
|
7
|
+
data.tar.gz: e1494e24c0ffa4a5bd6789ab9ff5d2dd9b2cf6fbabc955f6615404b6fea13dad0d7e2e1849e41990b909d8eae51257e1002dafd595f25ad366d95d77975e35f6
|
data/.travis.yml
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
sudo: false
|
2
|
+
cache: bundler
|
2
3
|
language: ruby
|
3
4
|
rvm:
|
4
|
-
- 2.
|
5
|
-
|
5
|
+
- 2.4.1
|
6
|
+
before_script:
|
7
|
+
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
|
8
|
+
- chmod +x ./cc-test-reporter
|
9
|
+
- ./cc-test-reporter before-build
|
10
|
+
after_script:
|
11
|
+
- if [ "$TRAVIS_PULL_REQUEST" == "false" ]; then ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT; fi
|
data/README.md
CHANGED
@@ -1,38 +1,156 @@
|
|
1
|
-
|
1
|
+
Tamashii Manager [![Gem Version](https://badge.fury.io/rb/tamashii-manager.svg)](https://badge.fury.io/rb/tamashii-manager) [![Build Status](https://travis-ci.org/tamashii-io/tamashii-manager.svg?branch=master)](https://travis-ci.org/tamashii-io/tamashii-manager) [![Test Coverage](https://codeclimate.com/github/tamashii-io/tamashii-manager/badges/coverage.svg)](https://codeclimate.com/github/tamashii-io/tamashii-manager/coverage) [![Code Climate](https://codeclimate.com/github/tamashii-io/tamashii-manager/badges/gpa.svg)](https://codeclimate.com/github/tamashii-io/tamashii-manager)
|
2
|
+
===
|
2
3
|
|
3
|
-
|
4
|
-
|
5
|
-
TODO: Delete this and the text above, and describe your gem
|
4
|
+
Tamashii Manager is a package for managing IoT devices that can handle communication between IoT devices in a way similar to Rack.
|
6
5
|
|
7
6
|
## Installation
|
8
7
|
|
9
|
-
Add
|
8
|
+
Add the following code to your `Gemfile`:
|
10
9
|
|
11
10
|
```ruby
|
12
11
|
gem 'tamashii-manager'
|
13
12
|
```
|
14
13
|
|
15
14
|
And then execute:
|
15
|
+
```ruby
|
16
|
+
$ bundle install
|
17
|
+
```
|
16
18
|
|
17
|
-
|
19
|
+
Or install it yourself with:
|
20
|
+
```ruby
|
21
|
+
$ gem install tamashii-manager
|
22
|
+
```
|
18
23
|
|
19
|
-
|
24
|
+
## Usage
|
20
25
|
|
21
|
-
|
26
|
+
Tamashii Manager can be started directly through `tamashii-manager` .
|
22
27
|
|
23
|
-
|
28
|
+
$ tamashii-manager
|
29
|
+
|
30
|
+
Because the connection of IoT devices may need verification, we implement a simple Token authentication function, which can achieve through the configuration file.
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
# config.rb
|
34
|
+
|
35
|
+
Tamashii::Manager.config do |config|
|
36
|
+
config.env = :test
|
37
|
+
config.auth_type = :token
|
38
|
+
config.token = 'abc123'
|
39
|
+
config.port = ENV['PORT'] || 3000
|
40
|
+
end
|
41
|
+
```
|
42
|
+
|
43
|
+
Then start with `tamashii-manager` :
|
44
|
+
|
45
|
+
$ tamashii-manager -C config.rb
|
46
|
+
|
47
|
+
### Rack
|
48
|
+
|
49
|
+
To integrate with the project that use Rack through `config.ru` .
|
50
|
+
|
51
|
+
```ruby
|
52
|
+
# config.ru
|
53
|
+
|
54
|
+
require 'tamashii/manager'
|
55
|
+
require './config.rb'
|
56
|
+
|
57
|
+
run Tamashii::Manager.server
|
58
|
+
```
|
59
|
+
|
60
|
+
Then start Tamashii Manager through the web server.
|
61
|
+
|
62
|
+
$ puma
|
63
|
+
|
64
|
+
Use `Rack :: URLMap` to consolidate your project when collocating with Sinatra and other frameworks.
|
65
|
+
|
66
|
+
```ruby
|
67
|
+
# config.ru
|
68
|
+
|
69
|
+
Rack::URLMap.new(
|
70
|
+
'/' => App,
|
71
|
+
'/tamashii' => Tamashii::Manager.server
|
72
|
+
)
|
73
|
+
```
|
74
|
+
|
75
|
+
### Rails
|
76
|
+
|
77
|
+
To integrate with the Rails project, you can use the `mount` function to plug Tamashii Manager onto Rails.
|
78
|
+
|
79
|
+
```ruby
|
80
|
+
# config/routes.rb
|
81
|
+
|
82
|
+
Rails.application.routes.draw do
|
83
|
+
mount Tamashii::Manager.server => '/tamashii'
|
84
|
+
end
|
85
|
+
```
|
86
|
+
|
87
|
+
In Rails, we will want to intercept information in the Tamashii Manager, processed in advance and then send to each IoT device, so it will use Tamashii Resolver function.
|
88
|
+
|
89
|
+
```ruby
|
90
|
+
# config/initializer/tamashii.rb
|
91
|
+
|
92
|
+
Tamashii::Manager.config do |config|
|
93
|
+
config.env = Rails.env
|
94
|
+
config.log_file = Rails.root.join('log', 'tamashii.log')
|
95
|
+
config.auth_type = :token
|
96
|
+
config.token = 'example'
|
97
|
+
end
|
98
|
+
|
99
|
+
Tamashii::Resolver.config do
|
100
|
+
hook RailsHookForTamashii
|
101
|
+
end
|
102
|
+
```
|
103
|
+
|
104
|
+
Use the `call` method in Resolver function to handle incoming packets.
|
105
|
+
|
106
|
+
```ruby
|
107
|
+
# app/tamashii/rails_hook_for_tamashii.rb
|
108
|
+
|
109
|
+
class RailsHookForTamashii < Tamashii::Hook
|
110
|
+
def initialize(*args)
|
111
|
+
super
|
112
|
+
@client = @env[:client]
|
113
|
+
end
|
114
|
+
|
115
|
+
def call(packet)
|
116
|
+
# Handle packets here
|
117
|
+
return false if packet.nil? # The processing failed and let the other Handler go on
|
118
|
+
true # Finished processing
|
119
|
+
end
|
120
|
+
end
|
121
|
+
```
|
122
|
+
|
123
|
+
In this way, you can use the Hook to handle the packets sent to Tamashii Manager.
|
124
|
+
|
125
|
+
### send_to method
|
24
126
|
|
25
|
-
|
127
|
+
Tamashii Manager will require a `serial number` as a machine ID when authenticating, and so we can use the` send_to` function to send packets to a specify machine.
|
128
|
+
|
129
|
+
```ruby
|
130
|
+
Tamashii::Manager::Client.send_to('example', '...')
|
131
|
+
```
|
26
132
|
|
27
133
|
## Development
|
28
134
|
|
29
|
-
|
135
|
+
To get the source code
|
136
|
+
|
137
|
+
$ git clone git@github.com:tamashii-io/tamashii-manager.git
|
138
|
+
|
139
|
+
Initialize the development environment
|
140
|
+
|
141
|
+
$ ./bin/setup
|
142
|
+
|
143
|
+
Run the spec
|
144
|
+
|
145
|
+
$ rspec
|
146
|
+
|
147
|
+
Installation the version of development on localhost
|
30
148
|
|
31
|
-
|
149
|
+
$ bundle exec rake install
|
32
150
|
|
33
|
-
##
|
151
|
+
## Contribution
|
34
152
|
|
35
|
-
|
153
|
+
Please report to us on [Github](https://github.com/tamashii-io/tamashii-manager) if there is any bug or suggested modified.
|
36
154
|
|
37
|
-
|
155
|
+
The project was developed by [5xruby Inc.](https://5xruby.tw/)
|
38
156
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tamashii-manager
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- 蒼時弦也
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: exe
|
12
12
|
cert_chain: []
|
13
|
-
date: 2017-
|
13
|
+
date: 2017-09-20 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: puma
|