handiv 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/handiv.rb +9 -14
- data/lib/handiv/client.rb +48 -0
- data/lib/handiv/connection.rb +5 -4
- data/lib/handiv/logger.rb +8 -2
- data/lib/handiv/tasks/reporter.rb +12 -16
- data/lib/handiv/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c7221625e188b1e35f787f6c6def31a3cd17e7a1
|
4
|
+
data.tar.gz: d218d25ac66a50ca574bae30769b325b5b0e358e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 17c8de51b76af37f6bd90c59269c805ba4c9dd4a216034da3aa30c369c4ab7f8e882631d4206413a7647b5a218afbc7d863699106aa26d016d0b5410a942c8d0
|
7
|
+
data.tar.gz: d7605d1d5e0b33045e85596e5826ff5c631ce550e01953bb38946c1d4a781a626657ef35edde76b0c7062d3b2a4a86e3d99bb1f716e6048223d704d5566e4f93
|
data/lib/handiv.rb
CHANGED
@@ -1,27 +1,22 @@
|
|
1
1
|
require 'handiv/version'
|
2
|
-
require 'handiv/configuration'
|
3
|
-
require 'handiv/logger'
|
4
2
|
require 'handiv/connection'
|
5
|
-
|
6
|
-
require 'handiv/tasks/reporter'
|
3
|
+
require 'handiv/client'
|
7
4
|
|
8
5
|
module Handiv
|
9
6
|
class << self
|
10
|
-
def
|
11
|
-
@
|
7
|
+
def client
|
8
|
+
@client ||= Handiv::Client.new
|
12
9
|
end
|
13
10
|
|
14
|
-
|
15
|
-
@configuration ||= Configuration.new
|
16
|
-
end
|
11
|
+
private
|
17
12
|
|
18
|
-
def
|
19
|
-
|
20
|
-
|
13
|
+
def method_missing(method_name, *args, &block)
|
14
|
+
return super unless client.respond_to?(method_name)
|
15
|
+
client.send(method_name, *args, &block)
|
21
16
|
end
|
22
17
|
|
23
|
-
def
|
24
|
-
|
18
|
+
def respond_to_missing?(method_name, include_private = false)
|
19
|
+
client.respond_to?(method_name, include_private)
|
25
20
|
end
|
26
21
|
end
|
27
22
|
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'handiv/configuration'
|
2
|
+
require 'handiv/logger'
|
3
|
+
|
4
|
+
require 'handiv/tasks/reporter'
|
5
|
+
|
6
|
+
module Handiv
|
7
|
+
class Client
|
8
|
+
attr_reader :options
|
9
|
+
|
10
|
+
def initialize(options = {})
|
11
|
+
@options = options
|
12
|
+
|
13
|
+
set_config_from_options
|
14
|
+
end
|
15
|
+
|
16
|
+
def logger
|
17
|
+
@logger ||= Logger.new(self)
|
18
|
+
end
|
19
|
+
|
20
|
+
def configuration
|
21
|
+
@configuration ||= Configuration.new
|
22
|
+
end
|
23
|
+
alias config configuration
|
24
|
+
|
25
|
+
def connection
|
26
|
+
Connection.new(self)
|
27
|
+
end
|
28
|
+
|
29
|
+
def configure
|
30
|
+
yield(configuration) if block_given?
|
31
|
+
true
|
32
|
+
end
|
33
|
+
|
34
|
+
def report_task(task_id, options = {})
|
35
|
+
Tasks::Reporter.new(self, task_id, options).report
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def set_config_from_options
|
41
|
+
options.each do |key, value|
|
42
|
+
next unless configuration.respond_to?("#{key}=")
|
43
|
+
|
44
|
+
configuration.send("#{key}=", value)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
data/lib/handiv/connection.rb
CHANGED
@@ -6,9 +6,10 @@ module Handiv
|
|
6
6
|
class Connection
|
7
7
|
USER_AGENT = "handiv-ruby/#{Handiv::VERSION}".freeze
|
8
8
|
|
9
|
-
attr_reader :connection
|
9
|
+
attr_reader :client, :connection
|
10
10
|
|
11
|
-
def initialize
|
11
|
+
def initialize(client)
|
12
|
+
@client = client
|
12
13
|
@connection = set_connection
|
13
14
|
end
|
14
15
|
|
@@ -18,7 +19,7 @@ module Handiv
|
|
18
19
|
response = post_data(path, data)
|
19
20
|
response.status
|
20
21
|
rescue => e
|
21
|
-
|
22
|
+
client.logger.error "Failed to send a message (#{e.class} - #{e.message})"
|
22
23
|
500 # Return status
|
23
24
|
end
|
24
25
|
|
@@ -56,7 +57,7 @@ module Handiv
|
|
56
57
|
end
|
57
58
|
|
58
59
|
def config
|
59
|
-
|
60
|
+
client.config
|
60
61
|
end
|
61
62
|
end
|
62
63
|
end
|
data/lib/handiv/logger.rb
CHANGED
@@ -2,11 +2,13 @@ require 'logger'
|
|
2
2
|
|
3
3
|
module Handiv
|
4
4
|
class Logger
|
5
|
+
attr_reader :client
|
6
|
+
|
5
7
|
LOG_PREFIX = '** [Handiv] '.freeze
|
6
8
|
LOG_LEVELS = [:fatal, :error, :warn, :info, :debug].freeze
|
7
9
|
|
8
10
|
LOG_LEVELS.each do |level|
|
9
|
-
define_method(level)do |*args, &block|
|
11
|
+
define_method(level) do |*args, &block|
|
10
12
|
msg = args[0] # Block-level default args is a 1.9 feature
|
11
13
|
msg ||= block.call if block
|
12
14
|
|
@@ -14,6 +16,10 @@ module Handiv
|
|
14
16
|
end
|
15
17
|
end
|
16
18
|
|
19
|
+
def initialize(client)
|
20
|
+
@client = client
|
21
|
+
end
|
22
|
+
|
17
23
|
def logger
|
18
24
|
custom_logger || default_logger
|
19
25
|
end
|
@@ -25,7 +31,7 @@ module Handiv
|
|
25
31
|
end
|
26
32
|
|
27
33
|
def custom_logger
|
28
|
-
|
34
|
+
client.configuration.logger
|
29
35
|
end
|
30
36
|
end
|
31
37
|
end
|
@@ -1,40 +1,36 @@
|
|
1
1
|
module Handiv
|
2
2
|
module Tasks
|
3
3
|
class Reporter
|
4
|
-
attr_reader :task_id, :options
|
4
|
+
attr_reader :client, :task_id, :options
|
5
5
|
|
6
|
-
def initialize(task_id, options = {})
|
6
|
+
def initialize(client, task_id, options = {})
|
7
|
+
@client = client
|
7
8
|
@task_id = task_id
|
8
9
|
@options = options.is_a?(String) ? { message: options } : options
|
9
10
|
end
|
10
11
|
|
11
12
|
def report
|
12
|
-
|
13
|
+
client.logger.debug "Sending event about task #{task_id}"
|
13
14
|
|
14
|
-
status = connection.send_data("tasks/#{task_id}", options)
|
15
|
+
status = client.connection.send_data("tasks/#{task_id}", options)
|
15
16
|
log_status(status)
|
16
17
|
|
17
|
-
status
|
18
|
+
status >= 200 && status < 300 # Return success
|
18
19
|
end
|
19
20
|
|
20
21
|
private
|
21
22
|
|
22
23
|
def log_status(status)
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
"Failed to send event for #{task_id} task."
|
24
|
+
if status >= 200 && status < 300 # Return success
|
25
|
+
client.logger.debug "Successfully sent event about task #{task_id}"
|
26
|
+
elsif status == 404
|
27
|
+
client.logger.error(
|
28
|
+
"Task #{task_id} was not found with these credentials."
|
29
29
|
)
|
30
30
|
else
|
31
|
-
|
31
|
+
client.logger.error "Failed to send event about task #{task_id}"
|
32
32
|
end
|
33
33
|
end
|
34
|
-
|
35
|
-
def connection
|
36
|
-
@connection ||= Connection.new
|
37
|
-
end
|
38
34
|
end
|
39
35
|
end
|
40
36
|
end
|
data/lib/handiv/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: handiv
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Justas Palumickas
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-11-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -100,6 +100,7 @@ files:
|
|
100
100
|
- bin/setup
|
101
101
|
- handiv.gemspec
|
102
102
|
- lib/handiv.rb
|
103
|
+
- lib/handiv/client.rb
|
103
104
|
- lib/handiv/configuration.rb
|
104
105
|
- lib/handiv/connection.rb
|
105
106
|
- lib/handiv/logger.rb
|
@@ -125,7 +126,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
125
126
|
version: '0'
|
126
127
|
requirements: []
|
127
128
|
rubyforge_project:
|
128
|
-
rubygems_version: 2.5.
|
129
|
+
rubygems_version: 2.5.2
|
129
130
|
signing_key:
|
130
131
|
specification_version: 4
|
131
132
|
summary: A gem that provides a client interface for Handiv
|