qm 1.1.12 → 1.1.13

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.
Files changed (6) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +5 -4
  3. data/lib/defs-mongo.rb +39 -11
  4. data/lib/qm.rb +19 -7
  5. data/lib/service.rb +8 -3
  6. metadata +13 -13
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c404fd6af1628ffecc1b74c37bb6ea79510a0838
4
- data.tar.gz: a5ce742f60e5b7234af3019321d8472a1babdeed
3
+ metadata.gz: 16cc41b763071acd523aeadbf511b2054b452bce
4
+ data.tar.gz: d5b066cb5971393d93e19bb4a42e5de03b4646a6
5
5
  SHA512:
6
- metadata.gz: e808c306e2e806c964c5425eeb1925ad9795ab4afaa52b0d54c4528c62353daf506c9637b5f329d9559fc0e6b6aab322ece6b0d2901dc6105c4b0c39ebbe88c2
7
- data.tar.gz: 1ad66076c0d3b6b516fb71ae9ab15918562add2176eb941d29cd3a981801e900995aac6299b201698d9000efb844b3da84101a5a7f63c456e5e9447178c4fad4
6
+ metadata.gz: b87e6b7b61d278ab706c7f158309855c5e113bad1c30e2b4665235cdb1ac5a5622d0d98764eede6f632b56e0c503efec85f963a19eeb6e8b987d8579d9c022bb
7
+ data.tar.gz: 488d67da2bdb009e35926b921e59cd621db873ade71d3727af2a9914eb6796a8ac57236fdc2050890c47b9b7dc7d518f51f7650c6f6d2e41dea57501727f2619
data/README.md CHANGED
@@ -2,9 +2,10 @@
2
2
 
3
3
  The `qm` gem for [Ruby](http://www.ruby-lang.org/) implements both the API
4
4
  server and web server components of [QMachine](https://www.qmachine.org) (QM).
5
- The gem currently only supports [MongoDB](http://www.mongodb.org/) for
6
- persistent storage, although the repository contains working definitions for
7
- [SQLite](https://www.sqlite.org/).
5
+ It uses [MongoDB](http://www.mongodb.org/) for persistent storage, and it can
6
+ optionally log traffic data into a different MongoDB collection instead of
7
+ logging to stdout. The repository still contains working definitions for using
8
+ [SQLite](https://www.sqlite.org/) as persistent storage, however.
8
9
 
9
10
  Install
10
11
  -------
@@ -15,6 +16,6 @@ To install the latest release, run
15
16
 
16
17
  ===
17
18
 
18
- [![Gem Version](https://badge.fury.io/rb/qm.png)](http://badge.fury.io/rb/qm) [![Dependency Status](https://gemnasium.com/qmachine/qm-ruby.png)](https://gemnasium.com/qmachine/qm-ruby)
19
+ [![Gem Version](https://badge.fury.io/rb/qm.svg)](http://badge.fury.io/rb/qm) [![Dependency Status](https://gemnasium.com/qmachine/qm-ruby.png)](https://gemnasium.com/qmachine/qm-ruby)
19
20
 
20
21
  <!-- vim:set syntax=markdown: -->
data/lib/defs-mongo.rb CHANGED
@@ -2,9 +2,8 @@
2
2
 
3
3
  #- defs-mongo.rb ~~
4
4
  # ~~ (c) SRW, 16 Jul 2014
5
- # ~~ last updated 18 Jul 2014
5
+ # ~~ last updated 28 Jul 2014
6
6
 
7
- require 'bson'
8
7
  require 'json'
9
8
  require 'mongo'
10
9
  require 'sinatra/base'
@@ -14,7 +13,7 @@ module Sinatra
14
13
 
15
14
  module MongoConnect
16
15
 
17
- def mongo_connect()
16
+ def mongo_api_connect()
18
17
  # This function needs documentation.
19
18
  db = URI.parse(settings.persistent_storage[:mongo])
20
19
  db_name = db.path.gsub(/^\//, '')
@@ -22,24 +21,36 @@ module Sinatra
22
21
  unless db.user.nil? or db.password.nil?
23
22
  conn.authenticate(db.user, db.password)
24
23
  end
25
- set db: conn
26
- settings.db['avars'].ensure_index('box_status', {
24
+ set api_db: conn
25
+ settings.api_db['avars'].ensure_index('box_status', {
27
26
  background: true,
28
27
  sparse: true
29
28
  })
30
- settings.db['avars'].ensure_index('exp_date', {
29
+ settings.api_db['avars'].ensure_index('exp_date', {
31
30
  expireAfterSeconds: settings.avar_ttl
32
31
  })
33
32
  return
34
33
  end
35
34
 
35
+ def mongo_log_connect()
36
+ # This function needs documentation.
37
+ db = URI.parse(settings.trafficlog_storage[:mongo])
38
+ db_name = db.path.gsub(/^\//, '')
39
+ conn = Mongo::Connection.new(db.host, db.port).db(db_name)
40
+ unless db.user.nil? or db.password.nil?
41
+ conn.authenticate(db.user, db.password)
42
+ end
43
+ set log_db: conn, logging: false
44
+ return
45
+ end
46
+
36
47
  end
37
48
 
38
- module MongoDefs
49
+ module MongoAPIDefs
39
50
 
40
51
  def get_avar(params)
41
52
  # This helper function needs documentation.
42
- bk, db = "#{params[0]}&#{params[1]}", settings.db
53
+ bk, db = "#{params[0]}&#{params[1]}", settings.api_db
43
54
  x = db['avars'].find_one({_id: bk})
44
55
  y = (x.nil?) ? '{}' : x['body']
45
56
  return y
@@ -47,7 +58,7 @@ module Sinatra
47
58
 
48
59
  def get_list(params)
49
60
  # This helper function needs documentation.
50
- bs, db, x = "#{params[0]}&#{params[1]}", settings.db, []
61
+ bs, db, x = "#{params[0]}&#{params[1]}", settings.api_db, []
51
62
  db['avars'].find({box_status: bs}).each do |doc|
52
63
  # This block needs documentation.
53
64
  x.push(doc['key'])
@@ -58,7 +69,7 @@ module Sinatra
58
69
 
59
70
  def set_avar(params)
60
71
  # This helper function needs documentation.
61
- db = settings.db
72
+ db = settings.api_db
62
73
  doc = {
63
74
  _id: "#{params[0]}&#{params[1]}",
64
75
  body: params[2],
@@ -76,7 +87,24 @@ module Sinatra
76
87
 
77
88
  end
78
89
 
79
- helpers MongoDefs
90
+ module MongoLogDefs
91
+
92
+ def log_to_db()
93
+ # This method needs documentation.
94
+ settings.log_db['traffic'].insert({
95
+ host: request.host,
96
+ ip: request.ip,
97
+ method: request.request_method,
98
+ timestamp: Time.now,
99
+ #status: response.status,
100
+ url: request.fullpath
101
+ })
102
+ return
103
+ end
104
+
105
+ end
106
+
107
+ helpers MongoAPIDefs, MongoLogDefs
80
108
  register MongoConnect
81
109
 
82
110
  end
data/lib/qm.rb CHANGED
@@ -2,20 +2,20 @@
2
2
 
3
3
  #- qm.rb ~~
4
4
  # ~~ (c) SRW, 12 Apr 2013
5
- # ~~ last updated 18 Jul 2014
5
+ # ~~ last updated 31 Jul 2014
6
6
 
7
7
  module QM
8
8
 
9
9
  def self::launch_client(options = {})
10
10
  # This function needs documentation.
11
- puts '(placeholder: `launch_client`)'
12
- return
11
+ require 'client'
12
+ return QMachineClient.new(options)
13
13
  end
14
14
 
15
15
  def self::launch_service(options = {})
16
16
  # This function creates, configures, and launches a fresh Sinatra app
17
17
  # that inherits from the original "teaching version".
18
- require 'service.rb'
18
+ require 'service'
19
19
  require 'defs-mongo'
20
20
  #require 'defs-sqlite'
21
21
  app = Sinatra.new(QMachineService) do
@@ -34,14 +34,26 @@ module QM
34
34
  end
35
35
  options = convert.call(options)
36
36
  set options
37
- set bind: :hostname, run: false, static: :enable_web_server
37
+
38
+ # I'm not sure if the next three lines are necessary or not ...
39
+ set bind: settings.hostname,
40
+ run: false,
41
+ static: settings.enable_web_server
42
+
38
43
  if (settings.persistent_storage.has_key?(:mongo)) then
39
- helpers Sinatra::MongoDefs
40
- mongo_connect
44
+ helpers Sinatra::MongoAPIDefs
45
+ mongo_api_connect
41
46
  #elsif (settings.persistent_storage.has_key?(:sqlite)) then
42
47
  # helpers Sinatra::SQLiteDefs
43
48
  # sqlite_connect
44
49
  end
50
+ if (settings.trafficlog_storage.has_key?(:mongo)) then
51
+ helpers Sinatra::MongoLogDefs
52
+ mongo_log_connect
53
+ after do
54
+ log_to_db
55
+ end
56
+ end
45
57
  end
46
58
  end
47
59
  return app.run!
data/lib/service.rb CHANGED
@@ -16,7 +16,7 @@
16
16
  # of a 'box', 'key', or 'status' value.
17
17
  #
18
18
  # ~~ (c) SRW, 24 Apr 2013
19
- # ~~ last updated 17 Jul 2014
19
+ # ~~ last updated 31 Jul 2014
20
20
 
21
21
  require 'sinatra'
22
22
  require 'sinatra/cross_origin'
@@ -34,14 +34,19 @@ class QMachineService < Sinatra::Base
34
34
  enable_CORS: false,
35
35
  enable_web_server: false,
36
36
  hostname: '0.0.0.0',
37
+ logging: true,
37
38
  persistent_storage: {},
38
39
  port: 8177,
39
- public_folder: 'public'
40
+ public_folder: 'public',
41
+ trafficlog_storage: {}
40
42
 
41
43
  # Sinatra mappings and options needed by QMachine.
42
44
 
43
45
  mime_type webapp: 'application/x-web-app-manifest+json'
44
- set bind: :hostname, run: false, static: :enable_web_server
46
+
47
+ set bind: settings.hostname, # Actually, I am not sure if
48
+ run: false, # these lines are actually
49
+ static: settings.enable_web_server # necessary anymore ...
45
50
 
46
51
  # See also: http://www.sinatrarb.com/configuration.html
47
52
 
metadata CHANGED
@@ -1,17 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: qm
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.12
4
+ version: 1.1.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sean Wilkinson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-18 00:00:00.000000000 Z
11
+ date: 2014-07-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: bson
14
+ name: bson_ext
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - '='
@@ -25,33 +25,33 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: 1.10.2
27
27
  - !ruby/object:Gem::Dependency
28
- name: bson_ext
28
+ name: json
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - '='
32
32
  - !ruby/object:Gem::Version
33
- version: 1.10.2
33
+ version: 1.8.1
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
- version: 1.10.2
40
+ version: 1.8.1
41
41
  - !ruby/object:Gem::Dependency
42
- name: json
42
+ name: httparty
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - '='
46
46
  - !ruby/object:Gem::Version
47
- version: 1.8.1
47
+ version: 0.13.1
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
- version: 1.8.1
54
+ version: 0.13.1
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: mongo
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -95,19 +95,19 @@ dependencies:
95
95
  - !ruby/object:Gem::Version
96
96
  version: 0.3.2
97
97
  - !ruby/object:Gem::Dependency
98
- name: thin
98
+ name: therubyracer
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
101
  - - '='
102
102
  - !ruby/object:Gem::Version
103
- version: 1.6.2
103
+ version: 0.12.1
104
104
  type: :runtime
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - '='
109
109
  - !ruby/object:Gem::Version
110
- version: 1.6.2
110
+ version: 0.12.1
111
111
  description: This is a port of the QMachine web service.
112
112
  email: sean@mathbiol.org
113
113
  executables: []
@@ -142,7 +142,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
142
142
  version: '0'
143
143
  requirements: []
144
144
  rubyforge_project:
145
- rubygems_version: 2.4.1
145
+ rubygems_version: 2.2.2
146
146
  signing_key:
147
147
  specification_version: 4
148
148
  summary: A platform for World Wide Computing