emapic_consul 0.1.5.4 → 0.1.5.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +30 -16
- data/lib/emapic_consul/api.rb +23 -22
- 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: 1af07728bb87ecdec7d331c2f91fc59d8cfd7f1f
|
4
|
+
data.tar.gz: 5d5105e8b37569182f1cf81c990567855988d3b5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b59af9ea9b654f0b4e3c51d39ef57c2efafa9b189514d913b56a0a891265dd5879839af271c40428c7aeaf4e3a7256d10f23ba368c0c3f0a2b55c521d16bff40
|
7
|
+
data.tar.gz: 38374403aae22507a19e6a572f7bb337d0bee6046566bcbec0990dd404c12a7adfc3517090ddba8d73a939bc226e97c9492c1684f77d9cba3668aa6e3a0c697f
|
data/README.md
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
# EmapicConsul
|
2
2
|
|
3
|
-
|
3
|
+
This gem was developed during the [Jornadas de Inteligencia Colectiva para la Democracia](http://medialab-prado.es/article/madrid-inteligencia-colectiva-para-la-democracia).
|
4
4
|
|
5
|
+
This gem was used in the [project](http://medialab-prado.es/article/inteligencia-colectiva-para-la-democracia-proyectos-seleccionados) which developed the [consul](https://github.com/consul/consul) + [emapic](https://github.com/Emapic) integration to provide consul with new functionalities such as proposal and votes geolocation.
|
5
6
|
|
6
7
|
## Installation
|
7
8
|
|
@@ -30,16 +31,18 @@ you are in *macOS*). An example setup might look like the following:
|
|
30
31
|
|
31
32
|
```bash
|
32
33
|
# ~/.bash_profile
|
33
|
-
export EMAPIC_HOST="192.168.1.199"
|
34
|
-
export
|
35
|
-
export
|
36
|
-
export
|
37
|
-
export EMAPIC_SECRET="12"
|
34
|
+
export EMAPIC_HOST="192.168.1.199:80"
|
35
|
+
export EMAPIC_LOGIN="example_login"
|
36
|
+
export EMAPIC_KEY="example_key"
|
37
|
+
export EMAPIC_SECRET="example_secret"
|
38
38
|
```
|
39
39
|
|
40
40
|
## Usage
|
41
41
|
|
42
|
-
To register proposal creation
|
42
|
+
To register proposal creation inside Emapic you need to follow the consul customization
|
43
|
+
[guide](https://github.com/consul/consul/blob/master/CUSTOMIZE_ES.md) to modify
|
44
|
+
existing models. You'll need to create a custom `Proposal` model with the following
|
45
|
+
code:
|
43
46
|
|
44
47
|
```ruby
|
45
48
|
# /app/models/custom/proposal.rb
|
@@ -54,6 +57,15 @@ class Proposal < ActiveRecord::Base
|
|
54
57
|
end
|
55
58
|
```
|
56
59
|
|
60
|
+
The approach to register proposal votes in Emapic is totally different since
|
61
|
+
the `Vote` class is not directly instantiated by consul but it's done inside the
|
62
|
+
`ActsAsVotable::Vote` clas of the [`acts_as_votable`](https://github.com/ryanto/acts_as_votable)
|
63
|
+
gem.
|
64
|
+
|
65
|
+
Probably the best way to handle this is to *monkey-patch* this class during the
|
66
|
+
rails boot, but I wasn't able to do this with my current knowledge of rails, so
|
67
|
+
I opted for a different approach.
|
68
|
+
|
57
69
|
To register proposal voting in Emapic you need to modify the original
|
58
70
|
`Proposal.register_vote` method, adding the following line:
|
59
71
|
|
@@ -61,30 +73,32 @@ To register proposal voting in Emapic you need to modify the original
|
|
61
73
|
EmapicConsul::Api.vote_location_group(user, self)
|
62
74
|
```
|
63
75
|
|
64
|
-
So
|
76
|
+
So its code ends up looking like this:
|
65
77
|
|
66
78
|
```ruby
|
67
79
|
# /app/models/proposal.rb
|
68
80
|
class Proposal
|
69
|
-
def register_vote(user, vote_value)
|
81
|
+
def register_vote(user, vote_value, lat, lng)
|
70
82
|
if votable_by?(user) && !archived?
|
71
83
|
vote_by(voter: user, vote: vote_value)
|
72
|
-
EmapicConsul::Api.vote_location_group(
|
84
|
+
EmapicConsul::Api.vote_location_group(self, nil, lat, lng) unless (lat.nil? || lng.nil?)
|
73
85
|
end
|
74
86
|
end
|
75
87
|
end
|
76
88
|
```
|
77
89
|
|
78
|
-
|
90
|
+
Modify the `ProposalsController.vote` method so it looks like the following:
|
79
91
|
|
80
|
-
|
81
|
-
|
82
|
-
|
92
|
+
```ruby
|
93
|
+
def vote
|
94
|
+
@proposal.register_vote(current_user, 'yes', params[:lat], params[:lng])
|
95
|
+
set_proposal_votes(@proposal)
|
96
|
+
end
|
97
|
+
```
|
83
98
|
|
84
99
|
## Contributing
|
85
100
|
|
86
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
87
|
-
|
101
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/amiedes/emapic_consul.
|
88
102
|
|
89
103
|
## License
|
90
104
|
|
data/lib/emapic_consul/api.rb
CHANGED
@@ -26,34 +26,34 @@ module EmapicConsul
|
|
26
26
|
print_debug_end(response.code)
|
27
27
|
end
|
28
28
|
|
29
|
-
# vote_location_group(
|
30
|
-
def self.vote_location_group(
|
31
|
-
print_debug_start("to notify vote creation")
|
29
|
+
# vote_location_group(proposal_instance, latitude, longitude)
|
30
|
+
def self.vote_location_group(group, latitude, longitude)
|
31
|
+
print_debug_start("to notify vote creation with lat/lng")
|
32
32
|
|
33
33
|
request = build_generic_request("/api/locationgroup/#{emapic_login}/proposal_#{group.id}")
|
34
|
-
request.params = { user_id:
|
34
|
+
request.params = { user_id: nil, lat: latitude, lng: longitude }
|
35
35
|
response = request.send
|
36
36
|
|
37
37
|
puts "Response body: #{response.body}"
|
38
38
|
print_debug_end(response.code)
|
39
39
|
end
|
40
40
|
|
41
|
-
def self.get_random_address
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
end
|
41
|
+
# def self.get_random_address
|
42
|
+
# print_debug_start("to get the address")
|
43
|
+
#
|
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)
|
48
|
+
# request = Net::HTTP::Get.new(uri)
|
49
|
+
#
|
50
|
+
# response = http.request(request)
|
51
|
+
#
|
52
|
+
# puts "Address: #{JSON.parse(response.body)['display_name']}"
|
53
|
+
# print_debug_end(response.code)
|
54
|
+
#
|
55
|
+
# return JSON.parse(response.body)['display_name']
|
56
|
+
# end
|
57
57
|
|
58
58
|
# def self.register_random_location(group_id, user_id)
|
59
59
|
# print_debug_start("to register a vote with a random address")
|
@@ -82,11 +82,12 @@ module EmapicConsul
|
|
82
82
|
end
|
83
83
|
|
84
84
|
def self.api_host
|
85
|
-
ENV['EMAPIC_HOST']
|
85
|
+
ENV['EMAPIC_HOST'].split(':')[0]
|
86
86
|
end
|
87
87
|
|
88
88
|
def self.api_port
|
89
|
-
ENV['
|
89
|
+
port = ENV['EMAPIC_HOST'].split(':')[1]
|
90
|
+
(port.nil? 80 : port)
|
90
91
|
end
|
91
92
|
|
92
93
|
def self.emapic_login
|
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.5
|
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-12-
|
11
|
+
date: 2016-12-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|