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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5586a8f4a5d00fb7900df64a663109e67d2a9dae
4
- data.tar.gz: 4313624bbc557a07e79d11a0b287d7a2476f684b
3
+ metadata.gz: d2827f188d89f5cdb50de0d31be713639ed9b8a5
4
+ data.tar.gz: 04023f99306ec75c5320f9a5e688a633bf951382
5
5
  SHA512:
6
- metadata.gz: 50e2e100b9a081139b90c87b702ecb37d0c4cc681d9da91f6fb290f7e46fc29bbeb838bf994609432144a122fb527e510e453789b15c6da44f1847fd0975bf23
7
- data.tar.gz: 40d8aceec369b84ec447c67032e268526b385c618201f05bad3828933bcfb6570a52fa6369ecd039ad63f8b7bd0d2ae1198053890124328a3e1a6e8d666995f7
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
- class Proposal
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.notify_group_creation(self)
52
+ EmapicConsul::Api.create_location_group(self)
51
53
  end
52
54
  end
53
55
  ```
54
56
 
55
- To register debate creation in Emapic:
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
- # /app/models/custom/debate.rb
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
- To register vote creation in Emapic:
64
+ So it ends looking like this:
69
65
 
70
66
  ```ruby
71
- # /app/models/custom/vote.rb
72
- class Vote
73
- after_create :notify_emapic
74
- VOTABLE_GROUPS = ['proposal', 'debate']
75
-
76
- def notify_emapic
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
@@ -26,12 +26,12 @@ module EmapicConsul
26
26
  print_debug_end(response.code)
27
27
  end
28
28
 
29
- # notify_vote(vote_instance)
30
- def self.notify_vote(vote)
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}/#{vote.votable_id}")
34
- request.params = { user_id: vote.voter_id, address: get_random_address }
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
- http = build_http_object(uri)
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 = URI::HTTP.build(
8
- host: options[:host],
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
- # usage:
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
- private
23
+ def self.build_uri(host, path, port)
24
+ URI::HTTP.build(host: host, path: path, port: port)
25
+ end
28
26
 
29
- def self.build_http_object(uri)
30
- http = Net::HTTP.new(uri.host, uri.port)
31
- http.use_ssl = true
32
- http.verify_mode = OpenSSL::SSL::VERIFY_NONE
33
- http
34
- end
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
@@ -1,3 +1,3 @@
1
1
  module EmapicConsul
2
- VERSION = "0.1.5.2"
2
+ VERSION = "0.1.5.3"
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.2
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-30 00:00:00.000000000 Z
11
+ date: 2016-12-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler