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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5cd5c2086cd234c4391bb81093686ceae9558443
4
- data.tar.gz: 55f5929b7b4c2cb51d9b15ca7d6852de9441cc69
3
+ metadata.gz: d840a6b929ac6c798bc898818de84bd93f2a387c
4
+ data.tar.gz: 9e31de432f8cc6d9b550ead94ddf1e072ee27b92
5
5
  SHA512:
6
- metadata.gz: 23dd0d7d8ae38e67cd4e9d8c1340c1d849ddd62507226c04c66005f8773165e24a71ea728bc19c8d1d0e80dccd7d834edf229d94ae1e165d64c63a07d2900b70
7
- data.tar.gz: b205ea056c5a81e8cc52f934edd6f3eda820e641f8fe48db978ab8775c960cc779de9fd4f7cdba6081ef16bb1291a7294b806c295bcd33a68db2add77f7b192d
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.25"
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
- @@phonehomeURL = 'phonehome.io'
8
- def self.set_url(url)
9
- @@phonehomeURL = url
10
- end
11
-
12
- def self.call(secret_key, id) # id - from job, Event
13
- begin
14
- result = check_connection?{yield}
15
- if result == false
16
- p 'Something goes wrong. Server not responding'
17
- return false
18
- end
19
- check_secret_key(secret_key){yield}
20
- user_events = get_user_events(secret_key).split
21
- status = user_events.include?(id.to_s) ? true : false
22
- if status == false
23
- p 'You try to run not your event!' # Write error to console
24
- yield
25
- exit
26
- end
27
- start(secret_key, id){yield} # id - from job, Event
28
- yield
29
- stop(@id) # @id - from API, CurrentEvent
30
- rescue => e
31
- if e.class == RuntimeError && e.to_s =~ /All events are completed/
32
- return false
33
- else
34
- send_error(@id, e) # @id - from API, CurrentEvent
35
- end
36
- end
37
- end
38
-
39
- def self.start(secret_key, id) # id - from job, Event
40
- @begin = Time.now
41
- app_name = get_app_name(id)
42
- response = Excon.post("http://#{@@phonehomeURL}/query/#{secret_key}/#{get_status(1)}/#{id}", :headers => { "Content-Type" => "application/json" })
43
- if JSON.parse(response.body)['status'] == 'All events are completed'
44
- p "#{id}: All events are completed"
45
- yield
46
- raise "#{id}: All events are completed"
47
- end
48
- @id = JSON.parse(response.body)['id']
49
- @status = JSON.parse(response.body)['status']
50
-
51
- end
52
-
53
- def self.stop(id) # @id - from API, CurrentEvent
54
- finish = Time.now
55
- status = 'completed'
56
- if @status == 'late'
57
- status = 'late_completed'
58
- end
59
- text = "#{finish.to_i - @begin.to_i} seconds"
60
- Excon.post("http://#{@@phonehomeURL}/query_update/#{id}/#{status}/#{URI.encode_www_form('result' => text)}")
61
- end
62
-
63
- def self.send_error(id, e) # @id - from API, CurrentEvent
64
- Excon.post("http://#{@@phonehomeURL}/query_update/#{id}/failed/#{URI.encode_www_form('error' => e)}")
65
- end
66
-
67
- def self.get_app_name(id)
68
- response = Excon.post("http://#{@@phonehomeURL}/get_name/#{id}", :headers => { "Content-Type" => "application/json" })
69
- return response.data[:body]
70
- end
71
-
72
- def self.get_user_events(secret_key)
73
- response = Excon.post("http://#{@@phonehomeURL}/get_user_event/#{secret_key}")
74
- response.data[:body]
75
- return response.data[:body]
76
- end
77
-
78
- def self.check_secret_key(secret_key)
79
- response = Excon.post("http://#{@@phonehomeURL}/check_secret_key/#{secret_key}")
80
- if response.data[:body] != 'true'
81
- p 'Your secret key is invalid!'
82
- yield
83
- exit
84
- end
85
- end
86
-
87
- def self.check_connection
88
- begin
89
- response = Excon.get("http://#{@@phonehomeURL}")
90
- rescue Excon::Errors::SocketError => error
91
- p "#{error} - Server not responding"
92
- sleep(5)
93
- retry
94
- end
95
- end
96
-
97
- def self.check_connection? # check connection with server
98
- begin
99
- response = Excon.get("http://#{@@phonehomeURL}") # if all ok, return true
100
- return true # and continue run code
101
- rescue Excon::Errors::SocketError => error # if server is offline
102
- begin # don't know why, but here got exception
103
- yield # and fix it by rescue
104
- rescue
105
- return false
106
- end
107
- return false # return false and stop running code
108
- end
109
- end
110
-
111
- def self.get_status(type)
112
- if type == 1
113
- return 'working'
114
- else
115
- return 'completed'
116
- end
117
- end
118
-
119
- 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
+ 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,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 = ["dark-def"]
10
- spec.email = ["drkmen@rambler.ru"]
11
- spec.description = 'Connet 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 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.25
4
+ version: 0.0.26
5
5
  platform: ruby
6
6
  authors:
7
- - dark-def
7
+ - info@phonehome.io
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-22 00:00:00.000000000 Z
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: Connet to PhoneHome.io database
41
+ description: Connect to PhoneHome.io database
42
42
  email:
43
- - drkmen@rambler.ru
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.2.1
76
+ rubygems_version: 2.4.6
77
77
  signing_key:
78
78
  specification_version: 4
79
79
  summary: Write a gem summary