phonehome 0.0.26 → 0.0.27

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d840a6b929ac6c798bc898818de84bd93f2a387c
4
- data.tar.gz: 9e31de432f8cc6d9b550ead94ddf1e072ee27b92
3
+ metadata.gz: 4ba6471963c33751e3050c5b722da8e108e97bbd
4
+ data.tar.gz: dbb644a75b130d8a73974691beba998823240472
5
5
  SHA512:
6
- metadata.gz: 83bd87d18b375223a41fbb3dd0397711fdc23fac9e05a4f60838b8ab0d510dca73ae03865b1f7d2f00b6939f617bae744e45637617dd46601a60ad62ffa596aa
7
- data.tar.gz: ce8b098dff15356a115a77c20983e15da8babad2003b863354cf82daa6e3e8305cbeecd6ebe0f39ea85b7dbb432bf41fb2a8f6a6f924b3506ffaf31ac1a7d8db
6
+ metadata.gz: d0889e3db18ce0a6fd1b71fc753b5bb43d40e987a667fac5e2e6068f070f0a5e9c5d2a692c5acbaee1705220623e94274c0d18510501383140e6c164d14b8d2f
7
+ data.tar.gz: 38e1ca75947077307e22207a2fdfdb790530123ef0a7660dc076cda5e99f719af9b39bad516145ee5324196d9a3ef7d3cb7922e156b6f9c7e64c31643ed7a125
data/.gitignore CHANGED
@@ -1,18 +1,18 @@
1
- *.gem
2
- *.rbc
3
- .bundle
4
- .config
5
- .yardoc
6
- Gemfile.lock
7
- InstalledFiles
8
- _yardoc
9
- coverage
10
- doc/
11
- lib/bundler/man
12
- pkg
13
- rdoc
14
- spec/reports
15
- test/tmp
16
- test/version_tmp
17
- tmp
18
- /.idea
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ /.idea
data/Gemfile CHANGED
@@ -1,7 +1,7 @@
1
- source 'https://rubygems.org'
2
-
3
- # Specify your gem's dependencies in phonehome-gem.gemspec
4
- gemspec
5
-
6
- gem 'excon' # For HTTP request
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in phonehome-gem.gemspec
4
+ gemspec
5
+
6
+ gem 'excon' # For HTTP request
7
7
  gem 'json'
data/LICENSE.txt CHANGED
@@ -1,22 +1,22 @@
1
- Copyright (c) 2013 dark-def
2
-
3
- MIT License
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining
6
- a copy of this software and associated documentation files (the
7
- "Software"), to deal in the Software without restriction, including
8
- without limitation the rights to use, copy, modify, merge, publish,
9
- distribute, sublicense, and/or sell copies of the Software, and to
10
- permit persons to whom the Software is furnished to do so, subject to
11
- the following conditions:
12
-
13
- The above copyright notice and this permission notice shall be
14
- included in all copies or substantial portions of the Software.
15
-
16
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1
+ Copyright (c) 2013 dark-def
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -1,29 +1,29 @@
1
- # Phonehome::Gem
2
-
3
- TODO: Write a gem description
4
-
5
- ## Installation
6
-
7
- Add this line to your application's Gemfile:
8
-
9
- gem 'phonehome-gem'
10
-
11
- And then execute:
12
-
13
- $ bundle
14
-
15
- Or install it yourself as:
16
-
17
- $ gem install phonehome-gem
18
-
19
- ## Usage
20
-
21
- TODO: Write usage instructions here
22
-
23
- ## Contributing
24
-
25
- 1. Fork it
26
- 2. Create your feature branch (`git checkout -b my-new-feature`)
27
- 3. Commit your changes (`git commit -am 'Add some feature'`)
28
- 4. Push to the branch (`git push origin my-new-feature`)
29
- 5. Create new Pull Request
1
+ # Phonehome::Gem
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'phonehome-gem'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install phonehome-gem
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile CHANGED
@@ -1 +1 @@
1
- require "bundler/gem_tasks"
1
+ require "bundler/gem_tasks"
@@ -1,5 +1,5 @@
1
- module Phonehome
2
- module Gem
3
- VERSION = "0.0.26"
4
- end
5
- end
1
+ module Phonehome
2
+ module Gem
3
+ VERSION = "0.0.27"
4
+ end
5
+ end
data/lib/phonehome.rb CHANGED
@@ -1,137 +1,167 @@
1
- require 'phonehome/gem/version'
2
- require 'excon'
3
- require 'json'
4
-
5
- module Phonehome
6
-
7
- JobInfo = Struct.new(:api_job_id, :status, :begin_time)
8
- @events_info = {} # {job_id, [JobInfo]}
9
-
10
- @@phonehomeURL = "phonehome.io"
11
- def self.set_url(url)
12
- @@phonehomeURL = url
13
- end
14
-
15
- def self.call(secret_key, id) # id - from job, Event
16
- begin
17
- result = check_connection?{yield}
18
- if result == false
19
- p 'Something goes wrong. Server not responding'
20
- return false
21
- end
22
- check_secret_key(secret_key){yield}
23
- user_events = get_user_events(secret_key).split
24
- status = user_events.include?(id.to_s) ? true : false
25
- if status == false
26
- p 'You try to run not your event!' # Write error to console
27
- yield
28
- exit
29
- end
30
- start(secret_key, id){yield} # id - from job, Event
31
- yield
32
- stop(id)
33
- rescue => e
34
- if e.class == RuntimeError && e.to_s =~ /All events are completed/
35
- return false
36
- else
37
- send_error(id, e) # id - from API, CurrentEvent
38
- # Let the calling method know what happenned
39
- raise e
40
- end
41
- end
42
- end
43
-
44
- def self.start(secret_key, id) # id - from job, Event
45
- begin_time = Time.now
46
- app_name = get_app_name(id)
47
- response = Excon.post("http://#{@@phonehomeURL}/query/#{secret_key}/#{get_status(1)}/#{id}", :headers => { "Content-Type" => "application/json" })
48
- if JSON.parse(response.body)['status'] == 'All events are completed'
49
- p "#{id}: All events are completed"
50
- yield
51
- raise "#{id}: All events are completed"
52
- end
53
-
54
- job_info = JobInfo.new(JSON.parse(response.body)['id'], JSON.parse(response.body)['status'], begin_time)
55
- @events_info[id] = job_info
56
-
57
- job_info
58
- end
59
-
60
- def self.stop(id)
61
- finish = Time.now
62
- status = 'completed'
63
-
64
- if @events_info.include?(id)
65
- job_info = @events_info[id]
66
- if job_info.status == 'late'
67
- status = 'late_completed'
68
- end
69
-
70
- text = "#{finish.to_i - job_info.begin_time.to_i} seconds"
71
- Excon.post("http://#{@@phonehomeURL}/query_update/#{job_info.api_job_id}/#{status}/#{URI.encode_www_form('result' => text)}")
72
- else
73
- puts "Event with id '#{id}' not found in events_info"
74
- pp events_info
75
- end
76
- end
77
-
78
- def self.send_error(id, e)
79
- if @events_info.include?(id)
80
- job_info = @events_info[id]
81
- Excon.post("http://#{@@phonehomeURL}/query_update/#{job_info.api_job_id}/failed/#{URI.encode_www_form('error' => e)}")
82
- end
83
- end
84
-
85
- def self.get_app_name(id)
86
- response = Excon.post("http://#{@@phonehomeURL}/get_name/#{id}", :headers => { "Content-Type" => "application/json" })
87
- return response.data[:body]
88
- end
89
-
90
- def self.get_user_events(secret_key)
91
- response = Excon.post("http://#{@@phonehomeURL}/get_user_event/#{secret_key}")
92
- response.data[:body]
93
- return response.data[:body]
94
- end
95
-
96
- def self.check_secret_key(secret_key)
97
- response = Excon.post("http://#{@@phonehomeURL}/check_secret_key/#{secret_key}")
98
- if response.data[:body] != 'true'
99
- p 'Your secret key is invalid!'
100
- yield
101
- exit
102
- end
103
- end
104
-
105
- def self.check_connection
106
- begin
107
- response = Excon.get("http://#{@@phonehomeURL}")
108
- rescue Excon::Errors::SocketError => error
109
- p "#{error} - Server not responding"
110
- sleep(5)
111
- retry
112
- end
113
- end
114
-
115
- def self.check_connection? # check connection with server
116
- begin
117
- response = Excon.get("http://#{@@phonehomeURL}") # if all ok, return true
118
- return true # and continue run code
119
- rescue Excon::Errors::SocketError => error # if server is offline
120
- begin # don't know why, but here got exception
121
- yield # and fix it by rescue
122
- rescue
123
- return false
124
- end
125
- return false # return false and stop running code
126
- end
127
- end
128
-
129
- def self.get_status(type)
130
- if type == 1
131
- return 'working'
132
- else
133
- return 'completed'
134
- end
135
- end
136
-
137
- end
1
+ require 'phonehome/gem/version'
2
+ require 'excon'
3
+ require 'json'
4
+
5
+ module Phonehome
6
+
7
+ JobInfo = Struct.new(:api_job_id, :status, :begin_time)
8
+ @events_info = {} # {job_id, [JobInfo]}
9
+
10
+ @@phonehomeURL = "phonehome.io"
11
+ def self.set_url(url)
12
+ @@phonehomeURL = url
13
+ end
14
+
15
+ def self.call(secret_key, id) # id - from job, Event
16
+ begin
17
+ debug("Checking connection")
18
+ result = check_connection?{yield}
19
+ if result == false
20
+ p 'Phonehome not responding'
21
+ return false
22
+ end
23
+ debug("Checking secret key")
24
+ check_secret_key(secret_key){yield}
25
+ debug("Checking User events")
26
+ user_events = get_user_events(secret_key).split
27
+ status = user_events.include?(id.to_s) ? true : false
28
+ if status == false
29
+ p 'You try to run not your event!' # Write error to console
30
+ yield
31
+ exit
32
+ end
33
+ debug("Calling start")
34
+ start(secret_key, id){yield} # id - from job, Event
35
+ result_of_work = yield
36
+ debug("Calling stop." + result_of_work.to_s)
37
+ stop(id,result_of_work)
38
+ rescue => e
39
+ if e.class == RuntimeError && e.to_s =~ /All events are completed/
40
+ return false
41
+ else
42
+ debug("Sending error to server")
43
+ send_error(id, e) # id - from API, CurrentEvent
44
+ # Let the calling method know what happenned
45
+ raise e
46
+ end
47
+ end
48
+ end
49
+
50
+ def self.start(secret_key, id) # id - from job, Event
51
+ begin_time = Time.now
52
+ app_name = get_app_name(id)
53
+ response = excon_post_json("http://#{@@phonehomeURL}/query/#{secret_key}/#{get_status(1)}/#{id}")
54
+ if JSON.parse(response.body)['status'] == 'All events are completed'
55
+ p "#{id}: All events are completed"
56
+ yield
57
+ raise "#{id}: All events are completed"
58
+ end
59
+
60
+ job_info = JobInfo.new(JSON.parse(response.body)['id'], JSON.parse(response.body)['status'], begin_time)
61
+ @events_info[id] = job_info
62
+
63
+ job_info
64
+ end
65
+
66
+ def self.stop(id,result_of_work = nil)
67
+ finish = Time.now
68
+ status = 'completed'
69
+
70
+ if @events_info.include?(id)
71
+ job_info = @events_info[id]
72
+ if job_info.status == 'late'
73
+ status = 'late_completed'
74
+ end
75
+
76
+ text = "#{finish.to_i - job_info.begin_time.to_i} secs"
77
+ if (result_of_work.nil?)
78
+ # text =
79
+ else
80
+ text = result_of_work.to_s + " (" + text + ")"
81
+ end
82
+ excon_post("http://#{@@phonehomeURL}/query_update/#{job_info.api_job_id}/#{status}/#{URI.encode_www_form('result' => text)}")
83
+ else
84
+ puts "Event with id '#{id}' not found in events_info"
85
+ pp events_info
86
+ end
87
+ end
88
+
89
+ def self.send_error(id, e)
90
+ if @events_info.include?(id)
91
+ job_info = @events_info[id]
92
+ excon_post("http://#{@@phonehomeURL}/query_update/#{job_info.api_job_id}/failed/#{URI.encode_www_form('error' => e)}")
93
+ end
94
+ end
95
+
96
+ def self.get_app_name(id)
97
+ response = excon_post_json("http://#{@@phonehomeURL}/get_name/#{id}")
98
+ return response.data[:body]
99
+ end
100
+
101
+ def self.get_user_events(secret_key)
102
+ response = excon_post("http://#{@@phonehomeURL}/get_user_event/#{secret_key}")
103
+ response.data[:body]
104
+ return response.data[:body]
105
+ end
106
+
107
+ def self.check_secret_key(secret_key)
108
+ response = excon_post("http://#{@@phonehomeURL}/check_secret_key/#{secret_key}")
109
+ if response.data[:body] != 'true'
110
+ p 'Your secret key is invalid!'
111
+ yield
112
+ exit
113
+ end
114
+ end
115
+
116
+ def self.check_connection
117
+ begin
118
+ response = excon_get("http://#{@@phonehomeURL}")
119
+ rescue Excon::Errors::SocketError => error
120
+ p "#{error} - Server not responding"
121
+ sleep(5)
122
+ retry
123
+ end
124
+ end
125
+
126
+ def self.check_connection? # check connection with server
127
+ begin
128
+ response = excon_get("http://#{@@phonehomeURL}") # if all ok, return true
129
+ return true # and continue run code
130
+ rescue Excon::Errors::SocketError => error # if server is offline
131
+ begin # don't know why, but here got exception
132
+ yield # and fix it by rescue
133
+ rescue
134
+ return false
135
+ end
136
+ return false # return false and stop running code
137
+ end
138
+ end
139
+
140
+ def self.excon_post(url)
141
+ debug("Excon.post #{url}")
142
+ Excon.post(url)
143
+ end
144
+
145
+ def self.excon_post_json(url)
146
+ debug("Excon.post JSON #{url}")
147
+ Excon.post(url, :headers => { "Content-Type" => "application/json" })
148
+ end
149
+
150
+ def self.excon_get(url)
151
+ debug("Excon.get #{url}")
152
+ Excon.get(url)
153
+ end
154
+
155
+ def self.get_status(type)
156
+ if type == 1
157
+ return 'working'
158
+ else
159
+ return 'completed'
160
+ end
161
+ end
162
+
163
+ def self.debug(message)
164
+ # puts("DEBUG:"+message)
165
+ end
166
+
167
+ end
@@ -1,23 +1,23 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'phonehome/gem/version'
5
-
6
- Gem::Specification.new do |spec|
7
- spec.name = "phonehome"
8
- spec.version = Phonehome::Gem::VERSION
9
- spec.authors = ["info@phonehome.io"]
10
- spec.email = ["info@phonehome.io"]
11
- spec.description = 'Connect to PhoneHome.io database'
12
- spec.summary = 'Write a gem summary'
13
- spec.homepage = ""
14
- spec.license = "MIT"
15
-
16
- spec.files = `git ls-files`.split($/)
17
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
- spec.require_paths = ["lib"]
20
-
21
- spec.add_development_dependency "bundler", "~> 1.3"
22
- spec.add_development_dependency "rake"
23
- end
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'phonehome/gem/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "phonehome"
8
+ spec.version = Phonehome::Gem::VERSION
9
+ spec.authors = ["info@phonehome.io"]
10
+ spec.email = ["info@phonehome.io"]
11
+ spec.description = 'Connect to PhoneHome.io'
12
+ spec.summary = 'Write a gem summary'
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ end
data/tests/test.rb ADDED
@@ -0,0 +1,14 @@
1
+ load './lib/phonehome.rb'
2
+
3
+ TOKEN = 'ebad5611be34fed1f67fedbf0b1b21'
4
+ JOB_ID = 87
5
+
6
+ # Phonehome.set_url("localhost:3333")
7
+
8
+ Phonehome.call(TOKEN, JOB_ID) do
9
+ secs = 6
10
+ puts "RUNNING SLEEP PROCESS START"
11
+ sleep(secs)
12
+ puts "RUNNING SLEEP PROCESS END"
13
+ "Done"
14
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: phonehome
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.26
4
+ version: 0.0.27
5
5
  platform: ruby
6
6
  authors:
7
7
  - info@phonehome.io
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-07-12 00:00:00.000000000 Z
11
+ date: 2018-08-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -38,7 +38,7 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
- description: Connect to PhoneHome.io database
41
+ description: Connect to PhoneHome.io
42
42
  email:
43
43
  - info@phonehome.io
44
44
  executables: []
@@ -53,6 +53,7 @@ files:
53
53
  - lib/phonehome.rb
54
54
  - lib/phonehome/gem/version.rb
55
55
  - phonehome-gem.gemspec
56
+ - tests/test.rb
56
57
  homepage: ''
57
58
  licenses:
58
59
  - MIT
@@ -73,7 +74,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
73
74
  version: '0'
74
75
  requirements: []
75
76
  rubyforge_project:
76
- rubygems_version: 2.4.6
77
+ rubygems_version: 2.5.1
77
78
  signing_key:
78
79
  specification_version: 4
79
80
  summary: Write a gem summary