icwot 0.3.3 → 0.3.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +88 -59
  3. data/bin/icwot +13 -6
  4. data/icwot.gemspec +1 -1
  5. data/lib/icwot/console.rb +1 -1
  6. metadata +18 -19
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cb968b7f9058426b8b88f3529efbd842b28d8a83
4
- data.tar.gz: 66c697961bab6edd2bda01f32b0c538104ed244b
3
+ metadata.gz: 773473aad14e5ed4062fad79be4441964f29f8e7
4
+ data.tar.gz: 0f2cbd799437e45e5eb8bebfe0c1165ccb9cf11b
5
5
  SHA512:
6
- metadata.gz: 905289642d5740d4d6ab84c87674429720cd90801e647220b4b81b1a33ae231f9e789386a66e51d21232a43325281526e134481a0c8f5775c7e96daf0c81e70a
7
- data.tar.gz: e37f838c5be217e31daf4c1c4509adb32d8edd17cbc99c329dc07da37a5d8b596558dde0d6db96da47e20f3ce553e6f90d7618e0a5d40227f50b4a115976c373
6
+ metadata.gz: a8db4381533ea0272faf11e4ba0f1edf11a89bcc89cb9c7ad85e807bef44e75b3ba59c01d2ce22e7ba64f5f8314d1189b3458fb4dfd85bbdccbfcc09eeffa31e
7
+ data.tar.gz: 0187bf5afd0f92ef09daa6b25326b6ff15d2b21e6103489f96645e23a72bd1ce0f07828210f5ae5c5033631149af54d3cf11a75c50bf787e6c5edb0b0179ac39
data/README.md CHANGED
@@ -1,64 +1,93 @@
1
- # Icwot
1
+ # Icwot [![GemVersion](https://badge.fury.io/rb/icwot.svg)](http://badge.fury.io/rb/icwot)
2
2
 
3
- RESTfull [sinatra](http://www.sinatrarb.com) server providing inversion of control for logging messages from another RESTfull application web-server
3
+ > Application [Sinatra](http://www.sinatrarb.com) permettant de logger les notifications envoyées par une application du Web de Objets utilisant l'inversion de contrôle.
4
4
 
5
- ## Installation
6
-
7
- Add this line to your application's Gemfile:
8
-
9
- gem 'icwot'
10
-
11
- And then execute:
12
-
13
- $ bundle install
14
-
15
- Or install it yourself as:
16
-
17
- $ gem install icwot
18
-
19
- ## Usage
20
-
21
- In a terminal run:
5
+ ## Description
6
+ Icwot pour Inversion of Control for Web Of Things est une application Web basée sur le framework [Sinatra](http://www.sinatrarb.com) qui démontre l’inversion de contrôle telle que définie dans le xWoT méta-modèle. C’est à dire qu’un serveur Web est mis en place côté client et est prêt à recevoir des requêtes HTTP POST du service Web auprès duquel il s’est enregistré (Webhook). Icwot a été développé grâce au langage Ruby et est distribué grâce au gestionnaire de bibliothèques Ruby, RubyGems.
22
7
 
23
- $ icwot <HOST>
8
+ ## Motivation
9
+ La motivation de réaliser un tel module était de démontrer avec quelle facilité il est possible d’implémenter l’inversion de contrôle et de le distribuer. Nous voulons également démontrer qu’il est possible d’implémenter avec facilité une application Web répondant à nos besoins. Si notre implémentation est extrêment basique, c’est par volonté de permettre à n’importe qui de comprendre le code et de là de développer une implémentation plus complète.
24
10
 
25
- It will:
26
-
27
- 1. Register to the specified host by ` POST ` method and sending in the body information(s).
28
- Currently, the body information is the uri needed for the host to send informations to the client.
29
- 2. Start a [sinatra](http://www.sinatrarb.com) server on default port 4567. Logging messages will be saved by default to :
30
- your-home-directory/log/icwot-msg.log
31
-
32
- By default, the header of the ` POST ` method will have these values:
33
-
34
- content-type=application/json
35
- accept=application/json
36
-
37
- You can change it by specifying the ` -c your-content-type ` and ` -a your-accept ` in the command line call. Actaually, it can encode the body in two different maners:
38
-
39
- * json, the body will typically be like this : ` {"uri": "your-ip-address:port-where-sinatra-is running"} `
40
- * xml, the body will typically be like this:
41
- ` <client xmlns=\"http://jaxb.xwot.first.ch.unifr.diuf\">
42
- <uri>your-ip-address:port-where-sinatra-is running</uri>
43
- </client> `
44
- The xml is not as the best for the moment. We recommand to use json.
45
-
46
- ### There are several options for the commande line:
47
-
48
- icwot <host>
49
- -h print help
50
- -l the host is localhost
51
- -c the content-type value for the header application/json by default
52
- -a the accept value for the header text/plain by default
53
- -p the port where to run the server
54
- -t the protocol to use http:// by default
55
- -l where to save the log. By default your-home-directory/log/icwot-{port}-msg.log
56
- host is where to register for the service.
57
-
58
- ## Contributing
11
+ ## Installation
59
12
 
60
- 1. Fork it
61
- 2. Create your feature branch (`git checkout -b my-new-feature`)
62
- 3. Commit your changes (`git commit -am 'Add some feature'`)
63
- 4. Push to the branch (`git push origin my-new-feature`)
64
- 5. Create new Pull Request
13
+ Dans le terminal exécuter la ligne suivante (nécessite Ruby et RubyGems d'installés):
14
+
15
+ gem install icwot
16
+
17
+ ## Installation depuis les sources
18
+
19
+ Faire un checkout des sources depuis le repo GIT. Puis lancer les commandes
20
+
21
+ gem build icwot.gemspec
22
+ gem install icwot-0.3.4.gem
23
+
24
+ ## Publier le GEM
25
+
26
+
27
+ ## Utilisation
28
+ Depuis un terminal lancer la commande
29
+
30
+ ```
31
+ icwot HOST
32
+ ```
33
+
34
+ où `HOST` est l’URL de la ressource d’un service Web de laquelle nous souhaitons recevoir des notifications. Cette commande va :
35
+
36
+ 1. Enregistrer le client par une requête HTTP POST sur l’URL fournie. Dans la requête POST une URL est transmise afin d’indiquer où recevoir des notifications. Par défaut ip-du-client:4567/
37
+ 2. Lancer le serveur Sinatra avec le port 4567 par défaut. Les notification reçues vont être enregistrées dans le dossier log/icwot/ du répertoire de l’utilisateur.
38
+
39
+ Par défaut, le header de la requête POST pour s’enregistrer est `accept:application/json ;content_type:application/json`. Il est possible de le changer en ajoutant les arguments ``-c le-content-type et -a le-accept`. Où `le-content-type` et `le-accept` peuvent chacun être soit json soit xml. Donc suivant la valeur de l’argument `le-accept`, le corps de la requête sera encodé de deux manières :
40
+ 1. En JSON :
41
+ ```json
42
+ {"url":"xx.xxx.x.x:4567/"}
43
+ ```
44
+ 2. En XML:
45
+ ```xml
46
+ <client xmlns="http://jaxb.xwot.first.ch.unifr.diuf">
47
+ <uri>xx.xxx.x.x:4567/</uri>
48
+ </client>
49
+ ```
50
+
51
+ De même que le serveur encode les données en XML si `le-content-type` est égale à `xml`, sinon en JSON.
52
+
53
+ Il y a également différentes options pour la ligne de commande pouvant être obtenue avec `icwot -h`:
54
+
55
+ ```
56
+ Usage : icwot <host>
57
+ -h print help
58
+ -l the host is localhost
59
+ -c the content-type value for the header application/json by default
60
+ -a the accept value for the header text/plain by default
61
+ -p the port where to run the server
62
+ -t the protocol to use http:// by default
63
+ -o where to save the log. By default your-home-directory/log/icwot-{port}-msg.log
64
+ <host> is the URL of the resource to register for the service.
65
+ ```
66
+
67
+ ## Structure
68
+ Icwot est structuré comme suit : le dossier` bin/` contient le fichier Ruby exécutable `icwot` qui permet de lancer `icwot` depuis le terminal. Le dossier `lib/` contient quatre fichiers nécessaires à l’implémentation :
69
+ 1. Le fichier `server_client.rb` contenant la classe `ServerClient` responsable de l’implémentation de l'application Web.
70
+ 2. Le fichier `console.rb` pour l’intéraction avec l’utilisateur.
71
+ 3. Le fichier `client.rb` pour enregistrer les information du client et les encoder en XML ou JSON.
72
+ 4. Le fichier `version.rb` pour maintenir un numéro de version de la gem.
73
+
74
+ ## Implémentation
75
+ Pour s’enregistrer vers le serveur afin de recevoir des notifications, la gem RestClient est utilisée. Si le code HTTP de la réponse renvoyée par le serveur est 200, nous estimons que l’enregistrement est réussi et nous démarrons le serveur Sinatra.
76
+
77
+ L’implémentation du serveur Sinatra est extrêmement simple, le code ci-dessous montre le code nécessaire pour que le serveur puisse recevoir une requête HTTP POST à l’URI / et l’enregistre dans un fichier de log.
78
+
79
+ ```ruby
80
+ post '/' do
81
+ # response is returned in text/plain
82
+ content_type 'text/plain'
83
+ # save in a special log the body of the received request
84
+ msg.info request.body.read
85
+ # write in main log (the console) that we have received a new notification
86
+ logger.info "message saved to #{self.class.logger_log_file.path}"
87
+ # return the HTTP code 200 with the text ok
88
+ 'ok'
89
+ end
90
+ ```
91
+
92
+ Nous avons défini que toutes les notifications envoyées à l'application sont enresitrées dans un fichier de log. Le format du logger pour enregistrer les notifications est de la forme : `date heure:break message`, où `date` et `heure` sont la date et l’heure à laquelle la notification est reçue, `break` indique un saut à la ligne et `message` est la notification reçue.
93
+ Quand l’application reçoit le signal `EXIT`, elle envoie une requête au serveur pour se désenregistrer de l’envoi de notifications et arrête le serveur Sinatra.
data/bin/icwot CHANGED
@@ -5,6 +5,7 @@ require 'icwot'
5
5
  require 'icwot/client'
6
6
  require 'icwot/console'
7
7
  require 'rest-client'
8
+ require 'json'
8
9
 
9
10
  console = Console.new
10
11
 
@@ -19,25 +20,31 @@ if Icwot.is_port_open?('localhost', console.port)
19
20
  end
20
21
 
21
22
  client = Client.new(port: console.port, content_type: console.produces)
22
- console.host_url = client.uri
23
+ #console.host_url = client.uri
24
+ console.host_url = ''
25
+
23
26
 
24
27
  begin
25
- response = RestClient.put console.url, client.to_s, console.header
28
+ #response = RestClient.put console.url, client.to_s, console.header
29
+ response = RestClient.post console.url, {"uri" => "#{client.uri}", "method" => "POST", "accept" => "application/json"}.to_json, console.header
26
30
  rescue RestClient::Exception => e
27
31
  puts "Error #{e.response.code} while contacting the host. The url is: '#{console.url}'"
28
- exit 0
32
+ exit 0
29
33
  rescue Errno::ECONNREFUSED => e
30
34
  puts "Connection refused. The url is: '#{console.url}'"
35
+ puts e
31
36
  exit 0
32
37
  end
33
38
 
34
39
  #TODO handle the case when the response of the host is not correct
35
40
  puts "The response server: '#{response}' with code #{response.code}"
36
- thr = Thread.new { app = Icwot.run(console.port, console.log_path) }
37
- thr.join
41
+ returnedclient = JSON.parse(response)
42
+
43
+ thr = Thread.new { app = Icwot.run(console.port, console.log_path) }
44
+ thr.join
38
45
  Signal.trap 'EXIT' do
39
46
  puts 'unregister from the server'
40
- RestClient.delete console.url
47
+ RestClient.delete "#{console.url}/#{returnedclient['id']}"
41
48
  app.quit!
42
49
  puts 'quitting sinatra...'
43
50
  end
data/icwot.gemspec CHANGED
@@ -5,7 +5,7 @@ require 'icwot/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "icwot"
8
- spec.version = '0.3.3'
8
+ spec.version = '0.3.4'
9
9
  spec.authors = ["leo"]
10
10
  spec.email = ["facenord.sud@gmail.com"]
11
11
  spec.description = %q{icwot : RESTfull sinatra server providing inversion of control for logging messages from another web-server}
data/lib/icwot/console.rb CHANGED
@@ -55,7 +55,7 @@ class Console
55
55
 
56
56
  def url
57
57
  base_uri = protocol+host
58
- base_uri += '/' unless base_uri[-1] == '/'
58
+ #base_uri += '/' unless base_uri[-1] == '/'
59
59
  base_uri + host_url
60
60
  end
61
61
 
metadata CHANGED
@@ -1,97 +1,97 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: icwot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - leo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-21 00:00:00.000000000 Z
11
+ date: 2015-01-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ~>
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
33
  version: '1.3'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ~>
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.3'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: sinatra
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ~>
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
47
  version: 1.4.4
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ~>
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: 1.4.4
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: thin
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - '>='
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - '>='
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rest-client
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ~>
73
+ - - "~>"
74
74
  - !ruby/object:Gem::Version
75
75
  version: 1.6.7
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ~>
80
+ - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: 1.6.7
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: json
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - ~>
87
+ - - "~>"
88
88
  - !ruby/object:Gem::Version
89
89
  version: 1.8.1
90
90
  type: :runtime
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - ~>
94
+ - - "~>"
95
95
  - !ruby/object:Gem::Version
96
96
  version: 1.8.1
97
97
  description: 'icwot : RESTfull sinatra server providing inversion of control for logging
@@ -103,7 +103,7 @@ executables:
103
103
  extensions: []
104
104
  extra_rdoc_files: []
105
105
  files:
106
- - .gitignore
106
+ - ".gitignore"
107
107
  - Gemfile
108
108
  - LICENSE.txt
109
109
  - README.md
@@ -125,19 +125,18 @@ require_paths:
125
125
  - lib
126
126
  required_ruby_version: !ruby/object:Gem::Requirement
127
127
  requirements:
128
- - - '>='
128
+ - - ">="
129
129
  - !ruby/object:Gem::Version
130
130
  version: '0'
131
131
  required_rubygems_version: !ruby/object:Gem::Requirement
132
132
  requirements:
133
- - - '>='
133
+ - - ">="
134
134
  - !ruby/object:Gem::Version
135
135
  version: '0'
136
136
  requirements: []
137
137
  rubyforge_project:
138
- rubygems_version: 2.0.3
138
+ rubygems_version: 2.4.2
139
139
  signing_key:
140
140
  specification_version: 4
141
141
  summary: 'icwot: inversion of control in RESTful applications'
142
142
  test_files: []
143
- has_rdoc: