mns_subscriber 0.3.0 → 0.4.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 90f35a8e8bc315fd0c91f6cb1e2ce45032fe94f0
4
- data.tar.gz: 8a344b4521594bb9f4d3b3d87d92f98be220d478
3
+ metadata.gz: 4b958aaf19191730c5bdc42f5497f9d16bb1ffbd
4
+ data.tar.gz: 7b8cb6cdb2e9274b0d8b5a5cf98b2746353ac817
5
5
  SHA512:
6
- metadata.gz: 283368c39d7fcaf006e1f5fd82be1c7d1b842df3ce8203e1091f447f8d6020663f578598fbac1026e9936132c9cb784cfb81e656ce1499b3a9602c74c37332d2
7
- data.tar.gz: 23190d6c2733ab1714c99d759d61782dfd261186b96948f5f76aadf0230afb46d574cf7735c52fa84c0b72f2dd26ee98aaeafdc6c819c7ff12c11bd20d0adcfd
6
+ metadata.gz: 6dbc91d24adfde108c55c1e6d38bde31ba37af24c005cf69c1c4def49fe075dabab3aa7376ca312a86efa21d038611036fc5e744261cf6c6e748ba50f5ccb033
7
+ data.tar.gz: 334024bc57cc0c3f7a82543e71f588393767205bda4e655bc3dab140ad0ddda5a59f74fd86afacb69c567bf430177df70f54ad0b99214c512af96757daff346b
checksums.yaml.gz.sig CHANGED
Binary file
@@ -5,9 +5,8 @@
5
5
 
6
6
  require 'mtlite'
7
7
  require 'sps-sub'
8
- require "sqlite3"
9
- require 'fileutils'
10
8
  require 'daily_notices'
9
+ require 'recordx_sqlite'
11
10
 
12
11
 
13
12
  class MNSSubscriber < SPSSub
@@ -42,20 +41,24 @@ class MNSSubscriber < SPSSub
42
41
  puts "%s: %s %s" % [topic, Time.now.to_s, msg.inspect]
43
42
 
44
43
 
45
- case a.last
44
+ case a.last.to_sym
46
45
 
47
- when 'profile'
46
+ when :profile
48
47
 
49
48
  update_attributes(:description, subtopic=a[-2], profile=msg)
50
49
 
51
- when 'link'
50
+ when :link
52
51
 
53
52
  update_attributes(:link, subtopic=a[-2], link=msg)
54
53
 
55
- when 'title'
54
+ when :title
56
55
 
57
56
  update_attributes(:title, subtopic=a[-2], title=msg)
58
57
 
58
+ when :delete
59
+
60
+ delete_notice(subtopic=a[-2], msg)
61
+
59
62
  else
60
63
 
61
64
  subtopic = a.last
@@ -65,52 +68,62 @@ class MNSSubscriber < SPSSub
65
68
 
66
69
  end
67
70
 
68
- def add_notice(topic, msg)
71
+ def add_notice(topic, raw_msg)
69
72
 
70
73
  topic_dir = File.join(@filepath, topic)
71
74
  notices = DailyNotices.new topic_dir, @options.merge(identifier: topic,
72
75
  title: topic.capitalize + ' daily notices')
76
+
77
+ id = Time.now.to_i
73
78
 
79
+ # strip out any JSON from the end of the message
80
+ msg, raw_json = raw_msg.split(/(?=\{.*)/)
74
81
 
75
-
76
- id = Time.now.to_i.to_s
77
-
78
82
  h = {
79
83
  description: MTLite.new(msg).to_html,
80
84
  topic: topic
81
85
  }
82
- return_status = notices.add(item: h, id: id)
86
+ return_status = notices.add(item: h, id: id.to_s)
83
87
 
84
88
  return if return_status == :duplicate
85
-
86
- dbfilename = File.join(topic_dir, topic + '.db')
87
89
 
88
- if File.exists? dbfilename then
89
-
90
- db = SQLite3::Database.new dbfilename
90
+ notices = RecordxSqlite.new(File.join(topic_dir, 'notices.db'),
91
+ table: {notices: {id: 0, message: ''}})
92
+ notices.create id: id.to_s, message: msg
93
+
94
+ if raw_json then
91
95
 
92
- else
93
-
94
- db = SQLite3::Database.new dbfilename
96
+ record = {id: id}.merge(JSON.parse(raw_json))
97
+ index = RecordxSqlite.new(File.join(topic_dir, 'index.db'),
98
+ table: {items: record})
99
+ index.create record
95
100
 
96
- db.execute <<-SQL
97
- create table notices (
98
- ID INT PRIMARY KEY NOT NULL,
99
- MESSAGE TEXT
100
- );
101
- SQL
102
-
103
101
  end
104
102
 
105
-
106
- db.execute("INSERT INTO notices (id, message)
107
- VALUES (?, ?)", [id, msg])
108
-
109
103
  self.notice "%s/add: %s/status/%s" % [@timeline, topic, id] if @timeline
110
104
 
111
105
  sleep 0.3
112
106
 
113
107
  end
108
+
109
+ def delete_notice(topic, msg)
110
+
111
+ topic_dir = File.join(@filepath, topic)
112
+
113
+ notices = RecordxSqlite.new(File.join(topic_dir, 'notices.db'),
114
+ table: 'notices')
115
+ id = msg.to_i
116
+ notices.delete id
117
+
118
+ indexdb = File.join(topic_dir, 'index.db')
119
+
120
+ if File.exists? indexdb then
121
+
122
+ RecordxSqlite.new(indexdb, table: 'items').delete id
123
+
124
+ end
125
+
126
+ end
114
127
 
115
128
  def update_attributes(attribute, topic, value)
116
129
 
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mns_subscriber
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
@@ -31,7 +31,7 @@ cert_chain:
31
31
  wBAv1HG6hlSk9BepsW4e+NbsgNYQdx0NkPtppfh502tww8DydLyWZNnEte5tAbjg
32
32
  mBoofo/5xUxN5A==
33
33
  -----END CERTIFICATE-----
34
- date: 2017-05-04 00:00:00.000000000 Z
34
+ date: 2017-07-01 00:00:00.000000000 Z
35
35
  dependencies:
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: mtlite
@@ -42,7 +42,7 @@ dependencies:
42
42
  version: '0.3'
43
43
  - - ">="
44
44
  - !ruby/object:Gem::Version
45
- version: 0.3.2
45
+ version: 0.3.3
46
46
  type: :runtime
47
47
  prerelease: false
48
48
  version_requirements: !ruby/object:Gem::Requirement
@@ -52,7 +52,7 @@ dependencies:
52
52
  version: '0.3'
53
53
  - - ">="
54
54
  - !ruby/object:Gem::Version
55
- version: 0.3.2
55
+ version: 0.3.3
56
56
  - !ruby/object:Gem::Dependency
57
57
  name: sps-sub
58
58
  requirement: !ruby/object:Gem::Requirement
@@ -62,7 +62,7 @@ dependencies:
62
62
  version: '0.3'
63
63
  - - ">="
64
64
  - !ruby/object:Gem::Version
65
- version: 0.3.3
65
+ version: 0.3.5
66
66
  type: :runtime
67
67
  prerelease: false
68
68
  version_requirements: !ruby/object:Gem::Requirement
@@ -72,47 +72,47 @@ dependencies:
72
72
  version: '0.3'
73
73
  - - ">="
74
74
  - !ruby/object:Gem::Version
75
- version: 0.3.3
75
+ version: 0.3.5
76
76
  - !ruby/object:Gem::Dependency
77
- name: sqlite3
77
+ name: daily_notices
78
78
  requirement: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '1.3'
82
+ version: '0.5'
83
83
  - - ">="
84
84
  - !ruby/object:Gem::Version
85
- version: 1.3.12
85
+ version: 0.5.9
86
86
  type: :runtime
87
87
  prerelease: false
88
88
  version_requirements: !ruby/object:Gem::Requirement
89
89
  requirements:
90
90
  - - "~>"
91
91
  - !ruby/object:Gem::Version
92
- version: '1.3'
92
+ version: '0.5'
93
93
  - - ">="
94
94
  - !ruby/object:Gem::Version
95
- version: 1.3.12
95
+ version: 0.5.9
96
96
  - !ruby/object:Gem::Dependency
97
- name: daily_notices
97
+ name: recordx_sqlite
98
98
  requirement: !ruby/object:Gem::Requirement
99
99
  requirements:
100
100
  - - "~>"
101
101
  - !ruby/object:Gem::Version
102
- version: '0.4'
102
+ version: '0.2'
103
103
  - - ">="
104
104
  - !ruby/object:Gem::Version
105
- version: 0.4.3
105
+ version: 0.2.4
106
106
  type: :runtime
107
107
  prerelease: false
108
108
  version_requirements: !ruby/object:Gem::Requirement
109
109
  requirements:
110
110
  - - "~>"
111
111
  - !ruby/object:Gem::Version
112
- version: '0.4'
112
+ version: '0.2'
113
113
  - - ">="
114
114
  - !ruby/object:Gem::Version
115
- version: 0.4.3
115
+ version: 0.2.4
116
116
  description:
117
117
  email: james@jamesrobertson.eu
118
118
  executables: []
metadata.gz.sig CHANGED
@@ -1,4 +1 @@
1
- FerM���7b_Q�Cn���G�sNx��£T���<�a�%���t9���PL��R,n|�V�K����Q�
2
- r���+����ScU��B*�Q�Es���|����"c�<->NS��.�( 5��������
3
- Y�B����H�d!R!Nsi@U�,��Y/ؔ���mcF���^8l|�� Z����Q���j�; �E����,� �,�M���MT
4
- EJ-qq��K�4ѴR�/�]�
1
+ ��Lss��z��Iq�� �\p��i�����C*��g���!ZEM�,��