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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a335563539e21af4f8170ea1be9828ec39307752
4
- data.tar.gz: 4164a2be411a7c5b3d57b039cd0d2fed1b9032b5
3
+ metadata.gz: 1af07728bb87ecdec7d331c2f91fc59d8cfd7f1f
4
+ data.tar.gz: 5d5105e8b37569182f1cf81c990567855988d3b5
5
5
  SHA512:
6
- metadata.gz: 148fc8e46a965e6a0a95739639a2677a074c135395072ec04e802afdbf95fd46070e8572dab215d09f28b534e520b62e6bfe3f8bd3651555c881802ffb7937a0
7
- data.tar.gz: c852fbcaba33c6520e5ab36ff089ce298e960e51a818d19f55465f765b68396dd3e25613b594f1bef5a11008323a97fd8387cb21c32320a46243c272ffedfd21
6
+ metadata.gz: b59af9ea9b654f0b4e3c51d39ef57c2efafa9b189514d913b56a0a891265dd5879839af271c40428c7aeaf4e3a7256d10f23ba368c0c3f0a2b55c521d16bff40
7
+ data.tar.gz: 38374403aae22507a19e6a572f7bb337d0bee6046566bcbec0990dd404c12a7adfc3517090ddba8d73a939bc226e97c9492c1684f77d9cba3668aa6e3a0c697f
data/README.md CHANGED
@@ -1,7 +1,8 @@
1
1
  # EmapicConsul
2
2
 
3
- Put your Ruby code in the file `lib/emapic_consul`. To experiment with that code, run `bin/console` for an interactive prompt.
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 EMAPIC_PORT="3000"
35
- export EMAPIC_LOGIN="amiedes2"
36
- export EMAPIC_KEY="12"
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 in Emapic:
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 it ends looking like this:
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(user, self)
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
- ## Development
90
+ Modify the `ProposalsController.vote` method so it looks like the following:
79
91
 
80
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
81
-
82
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
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/[USERNAME]/emapic_consul.
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
 
@@ -26,34 +26,34 @@ module EmapicConsul
26
26
  print_debug_end(response.code)
27
27
  end
28
28
 
29
- # vote_location_group(usre_instance, proposal_instance)
30
- def self.vote_location_group(voter, 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: voter.id, address: get_random_address }
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
- 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
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['EMAPIC_PORT']
89
+ port = ENV['EMAPIC_HOST'].split(':')[1]
90
+ (port.nil? 80 : port)
90
91
  end
91
92
 
92
93
  def self.emapic_login
@@ -1,3 +1,3 @@
1
1
  module EmapicConsul
2
- VERSION = "0.1.5.4"
2
+ VERSION = "0.1.5.5"
3
3
  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
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-01 00:00:00.000000000 Z
11
+ date: 2016-12-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler