twinpush 0.0.9 → 0.0.10

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 (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/measure.rb +90 -0
  3. data/lib/twinpush.rb +5 -3
  4. metadata +3 -16
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5717985c13a01538526eefd8897d495a56bbd2599e8efc514a746cb1aa5d5294
4
- data.tar.gz: 16a4084d2f15a26dbd48087e2a1930f2ba146e8125a5bcc445d7b60d76d153f8
3
+ metadata.gz: 7af25d5705a6968e4b1ba122f8325ee9df5154d5db42c2ff1eb01393a491468b
4
+ data.tar.gz: 698e57e6265a70c0bdce905a63948cf8d7ec37b3e911cee9d3f1309a6b814853
5
5
  SHA512:
6
- metadata.gz: 6df9844c1551a35585aa66be4c1cee35183d095b8ea6a1e4c98e41c289fdde92db111cb25fa2a25fce407de2851d335f3dcc7aaf47db58afe8e22bd13b7dda70
7
- data.tar.gz: 2b840efd8bc67d8c8b4e1d48541d3aab090b276b616df04c9c65d256354d771a166c1bd8174179658ba11cab0a00a7b9103fee60d0cef16ae6c39ccd378680a2
6
+ metadata.gz: 8c43b09576841ace12cb9ab9a658b3eadcfd19c4b7ba08f6079e0fb2df87b99a793cb7e8605c24b1b4b1a356a2c8c4388a80849956ac5ad93b0545510c4675e4
7
+ data.tar.gz: 85dff4fee862a75e9a7ef3c3b216028b0c95399d45802f4a0d6af22469dc4b286acde1038a66ffeb27172f3997a577050c38747da6ebe36496fc240668ce1dbf
data/lib/measure.rb ADDED
@@ -0,0 +1,90 @@
1
+ #!/bin/env ruby
2
+
3
+ # lazy hack from Robert Klemme
4
+
5
+ module Memory
6
+ # sizes are guessed, I was too lazy to look
7
+ # them up and then they are also platform
8
+ # dependent
9
+ REF_SIZE = 4 # ?
10
+ OBJ_OVERHEAD = 4 # ?
11
+ FIXNUM_SIZE = 4 # ?
12
+
13
+ # informational output from analysis
14
+ MemoryInfo = Struct.new :roots, :objects, :bytes, :loops
15
+
16
+ def self.analyze(*roots)
17
+ an = Analyzer.new
18
+ an.roots = roots
19
+ an.analyze
20
+ end
21
+
22
+ class Analyzer
23
+ attr_accessor :roots
24
+ attr_reader :result
25
+
26
+ def analyze
27
+ @result = MemoryInfo.new roots, 0, 0, 0
28
+ @objs = {}
29
+
30
+ queue = roots.dup
31
+
32
+ until queue.empty?
33
+ obj = queue.shift
34
+
35
+ case obj
36
+ # special treatment for some types
37
+ # some are certainly missing from this
38
+ when IO
39
+ visit(obj)
40
+ when String
41
+ visit(obj) { @result.bytes += obj.size }
42
+ when Fixnum
43
+ @result.bytes += FIXNUM_SIZE
44
+ when Array
45
+ visit(obj) do
46
+ @result.bytes += obj.size * REF_SIZE
47
+ queue.concat(obj)
48
+ end
49
+ when Hash
50
+ visit(obj) do
51
+ @result.bytes += obj.size * REF_SIZE * 2
52
+ obj.each {|k,v| queue.push(k).push(v)}
53
+ end
54
+ when Enumerable
55
+ visit(obj) do
56
+ obj.each do |o|
57
+ @result.bytes += REF_SIZE
58
+ queue.push(o)
59
+ end
60
+ end
61
+ else
62
+ visit(obj) do
63
+ obj.instance_variables.each do |var|
64
+ @result.bytes += REF_SIZE
65
+ queue.push(obj.instance_variable_get(var))
66
+ end
67
+ end
68
+ end
69
+ end
70
+
71
+ @result
72
+ end
73
+
74
+ private
75
+ def visit(obj)
76
+ id = obj.object_id
77
+
78
+ if @objs.has_key? id
79
+ @result.loops += 1
80
+ false
81
+ else
82
+ @objs[id] = true
83
+ @result.bytes += OBJ_OVERHEAD
84
+ @result.objects += 1
85
+ yield obj if block_given?
86
+ true
87
+ end
88
+ end
89
+ end
90
+ end
data/lib/twinpush.rb CHANGED
@@ -1,9 +1,11 @@
1
1
  require 'faraday'
2
2
  require 'cgi'
3
3
  require 'json'
4
- require "knjrbfw"
4
+ require 'measure'
5
5
 
6
6
  class TWINPUSH
7
+ include Memory
8
+
7
9
  DEFAULT_TIMEOUT = 30
8
10
  FORMAT = :json
9
11
  BASE_URI = 'https://subdomain.twinpush.com'
@@ -45,8 +47,8 @@ class TWINPUSH
45
47
 
46
48
  #creates a new notification to be delivered from the platform
47
49
  def create_notification(notification_params)
48
- analyzer = Knj::Memory_analyzer::Object_size_counter.new(notification_params)
49
- if analyzer.calculate_size < 2048 # 2KB limit
50
+ memory_size = Memory.analyze(notification_params)
51
+ if memory_size.bytes < 2048 # 2KB limit
50
52
  path = "#{API_URL}/#{app_id}/notifications"
51
53
  for_uri(uri) do |connection|
52
54
  response = connection.post(path, notification_params.to_json)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: twinpush
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Amaury González
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-12-29 00:00:00.000000000 Z
11
+ date: 2021-12-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -30,20 +30,6 @@ dependencies:
30
30
  - - ">="
31
31
  - !ruby/object:Gem::Version
32
32
  version: 0.12.2
33
- - !ruby/object:Gem::Dependency
34
- name: knjrbfw
35
- requirement: !ruby/object:Gem::Requirement
36
- requirements:
37
- - - "~>"
38
- - !ruby/object:Gem::Version
39
- version: 0.0.113
40
- type: :runtime
41
- prerelease: false
42
- version_requirements: !ruby/object:Gem::Requirement
43
- requirements:
44
- - - "~>"
45
- - !ruby/object:Gem::Version
46
- version: 0.0.113
47
33
  description: TwinPush gem provides ruby bindings to TwinPush a messaging solution
48
34
  that lets you reliably deliver messages and notifications at no cost to Android,
49
35
  iOS or Web browsers.
@@ -53,6 +39,7 @@ executables: []
53
39
  extensions: []
54
40
  extra_rdoc_files: []
55
41
  files:
42
+ - lib/measure.rb
56
43
  - lib/twinpush.rb
57
44
  - spec/spec_helper.rb
58
45
  - spec/twinpush_spec.rb