emapic_consul 0.1.5.2 → 0.1.5.3
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.
- checksums.yaml +4 -4
- data/README.md +14 -20
- data/lib/emapic_consul/api.rb +8 -15
- data/lib/emapic_consul/request.rb +12 -14
- data/lib/emapic_consul/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d2827f188d89f5cdb50de0d31be713639ed9b8a5
|
4
|
+
data.tar.gz: 04023f99306ec75c5320f9a5e688a633bf951382
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 543eb69d9a1703d478668ae6cfdbd7f8a579a00257ce532f40218db99663551e5c83bbef9092ed4ab6b9db362f54b26c5bfce7f70906d288a57a2421e6ca048a
|
7
|
+
data.tar.gz: 47b55f6a5b0e59ac62b83e7a4ed848bd4ae1c04e64cda879a31b184059331573ab0c8bda6fe07bac4d01041e16155830ac78668580139ab2dc233fb8eef4d639
|
data/README.md
CHANGED
@@ -43,39 +43,33 @@ To register proposal creation in Emapic:
|
|
43
43
|
|
44
44
|
```ruby
|
45
45
|
# /app/models/custom/proposal.rb
|
46
|
-
|
46
|
+
require_dependency Rails.root.join('app', 'models', 'proposal').to_s
|
47
|
+
|
48
|
+
class Proposal < ActiveRecord::Base
|
47
49
|
after_create :notify_emapic
|
48
50
|
|
49
51
|
def notify_emapic
|
50
|
-
EmapicConsul::Api.
|
52
|
+
EmapicConsul::Api.create_location_group(self)
|
51
53
|
end
|
52
54
|
end
|
53
55
|
```
|
54
56
|
|
55
|
-
To register
|
57
|
+
To register proposal voting in Emapic you need to modify the original
|
58
|
+
`Proposal.register_vote` method, adding the following line:
|
56
59
|
|
57
60
|
```ruby
|
58
|
-
|
59
|
-
class Debate
|
60
|
-
after_create :notify_emapic
|
61
|
-
|
62
|
-
def notify_emapic
|
63
|
-
EmapicConsul::Api.notify_group_creation(self)
|
64
|
-
end
|
65
|
-
end
|
61
|
+
EmapicConsul::Api.vote_location_group(user, self)
|
66
62
|
```
|
67
63
|
|
68
|
-
|
64
|
+
So it ends looking like this:
|
69
65
|
|
70
66
|
```ruby
|
71
|
-
# /app/models/
|
72
|
-
class
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
if VOTABLE_GROUPS.include? votable.type
|
78
|
-
EmapicConsul::Api.notify_vote(self)
|
67
|
+
# /app/models/proposal.rb
|
68
|
+
class Proposal
|
69
|
+
def register_vote(user, vote_value)
|
70
|
+
if votable_by?(user) && !archived?
|
71
|
+
vote_by(voter: user, vote: vote_value)
|
72
|
+
EmapicConsul::Api.vote_location_group(user, self)
|
79
73
|
end
|
80
74
|
end
|
81
75
|
end
|
data/lib/emapic_consul/api.rb
CHANGED
@@ -26,12 +26,12 @@ module EmapicConsul
|
|
26
26
|
print_debug_end(response.code)
|
27
27
|
end
|
28
28
|
|
29
|
-
#
|
30
|
-
def self.
|
29
|
+
# vote_location_group(usre_instance, proposal_instance)
|
30
|
+
def self.vote_location_group(voter, group)
|
31
31
|
print_debug_start("to notify vote creation")
|
32
32
|
|
33
|
-
request = build_generic_request("/api/locationgroup/#{emapic_login}/#{
|
34
|
-
request.params = { user_id:
|
33
|
+
request = build_generic_request("/api/locationgroup/#{emapic_login}/#{group.id}")
|
34
|
+
request.params = { user_id: voter.id, address: get_random_address }
|
35
35
|
response = request.send
|
36
36
|
|
37
37
|
puts "Response body: #{response.body}"
|
@@ -41,8 +41,10 @@ module EmapicConsul
|
|
41
41
|
def self.get_random_address
|
42
42
|
print_debug_start("to get the address")
|
43
43
|
|
44
|
-
uri = build_uri('/api/randomMadrid')
|
45
|
-
|
44
|
+
uri = EmapicConsul::Request.build_uri(api_host, '/api/randomMadrid', api_port)
|
45
|
+
# The build_http_object is not meant to be called from this class. But when
|
46
|
+
# the get_random_address method disappears this call will be deleted
|
47
|
+
http = EmapicConsul::Request.build_http_object(uri)
|
46
48
|
request = Net::HTTP::Get.new(uri)
|
47
49
|
|
48
50
|
response = http.request(request)
|
@@ -98,14 +100,5 @@ module EmapicConsul
|
|
98
100
|
def self.api_secret
|
99
101
|
ENV['EMAPIC_SECRET']
|
100
102
|
end
|
101
|
-
|
102
|
-
# TODO: this code is duplicated inside EmapicConsul::Request. Must delete
|
103
|
-
# this when the get_random_address method is deleted
|
104
|
-
def self.build_http_object(uri)
|
105
|
-
http = Net::HTTP.new(uri.host, uri.port)
|
106
|
-
http.use_ssl = true
|
107
|
-
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
108
|
-
http
|
109
|
-
end
|
110
103
|
end
|
111
104
|
end
|
@@ -4,17 +4,13 @@ require 'openssl'
|
|
4
4
|
module EmapicConsul
|
5
5
|
class Request
|
6
6
|
def initialize(options = {})
|
7
|
-
uri =
|
8
|
-
|
9
|
-
path: options[:path],
|
10
|
-
port: options[:port]
|
11
|
-
)
|
12
|
-
@http = build_http_object(uri)
|
7
|
+
uri = EmapicConsul::Request.build_uri(options[:host], options[:path], options[:port])
|
8
|
+
@http = EmapicConsul::Request.build_http_object(uri)
|
13
9
|
@request = Net::HTTP::Post.new(uri)
|
14
10
|
@request.basic_auth(options[:api_key], options[:api_secret])
|
15
11
|
end
|
16
12
|
|
17
|
-
#
|
13
|
+
# Usage:
|
18
14
|
# request.params = { id: 1, title: 'My title', geoloc: 'xyz' }
|
19
15
|
def params=(params)
|
20
16
|
@request.set_form_data(params)
|
@@ -24,13 +20,15 @@ module EmapicConsul
|
|
24
20
|
@http.request(@request)
|
25
21
|
end
|
26
22
|
|
27
|
-
|
23
|
+
def self.build_uri(host, path, port)
|
24
|
+
URI::HTTP.build(host: host, path: path, port: port)
|
25
|
+
end
|
28
26
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
27
|
+
def self.build_http_object(uri)
|
28
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
29
|
+
http.use_ssl = true
|
30
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
31
|
+
http
|
32
|
+
end
|
35
33
|
end
|
36
34
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: emapic_consul
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.5.
|
4
|
+
version: 0.1.5.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alberto Miedes Garcés
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-12-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|