phonehome 0.0.25 → 0.0.26
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +18 -18
- data/Gemfile +6 -6
- data/LICENSE.txt +22 -22
- data/README.md +29 -29
- data/Rakefile +1 -1
- data/lib/phonehome/gem/version.rb +5 -5
- data/lib/phonehome.rb +137 -119
- data/phonehome-gem.gemspec +23 -23
- metadata +13 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d840a6b929ac6c798bc898818de84bd93f2a387c
|
4
|
+
data.tar.gz: 9e31de432f8cc6d9b550ead94ddf1e072ee27b92
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 83bd87d18b375223a41fbb3dd0397711fdc23fac9e05a4f60838b8ab0d510dca73ae03865b1f7d2f00b6939f617bae744e45637617dd46601a60ad62ffa596aa
|
7
|
+
data.tar.gz: ce8b098dff15356a115a77c20983e15da8babad2003b863354cf82daa6e3e8305cbeecd6ebe0f39ea85b7dbb432bf41fb2a8f6a6f924b3506ffaf31ac1a7d8db
|
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.
|
4
|
-
end
|
5
|
-
end
|
1
|
+
module Phonehome
|
2
|
+
module Gem
|
3
|
+
VERSION = "0.0.26"
|
4
|
+
end
|
5
|
+
end
|
data/lib/phonehome.rb
CHANGED
@@ -1,119 +1,137 @@
|
|
1
|
-
require 'phonehome/gem/version'
|
2
|
-
require 'excon'
|
3
|
-
require 'json'
|
4
|
-
|
5
|
-
module Phonehome
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
end
|
77
|
-
|
78
|
-
def self.
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
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
|
data/phonehome-gem.gemspec
CHANGED
@@ -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 = ["
|
10
|
-
spec.email = ["
|
11
|
-
spec.description = '
|
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 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
|
metadata
CHANGED
@@ -1,51 +1,51 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: phonehome
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.26
|
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:
|
11
|
+
date: 2016-07-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - ~>
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '1.3'
|
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: '1.3'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
34
|
type: :development
|
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: '0'
|
41
|
-
description:
|
41
|
+
description: Connect to PhoneHome.io database
|
42
42
|
email:
|
43
|
-
-
|
43
|
+
- info@phonehome.io
|
44
44
|
executables: []
|
45
45
|
extensions: []
|
46
46
|
extra_rdoc_files: []
|
47
47
|
files:
|
48
|
-
- .gitignore
|
48
|
+
- ".gitignore"
|
49
49
|
- Gemfile
|
50
50
|
- LICENSE.txt
|
51
51
|
- README.md
|
@@ -63,17 +63,17 @@ require_paths:
|
|
63
63
|
- lib
|
64
64
|
required_ruby_version: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
70
|
requirements:
|
71
|
-
- -
|
71
|
+
- - ">="
|
72
72
|
- !ruby/object:Gem::Version
|
73
73
|
version: '0'
|
74
74
|
requirements: []
|
75
75
|
rubyforge_project:
|
76
|
-
rubygems_version: 2.
|
76
|
+
rubygems_version: 2.4.6
|
77
77
|
signing_key:
|
78
78
|
specification_version: 4
|
79
79
|
summary: Write a gem summary
|