emapic_consul 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +48 -5
- data/lib/emapic_consul/api.rb +48 -84
- data/lib/emapic_consul/request.rb +40 -0
- data/lib/emapic_consul/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fd6ddb072872376689e08bfb69665bf2507c849e
|
4
|
+
data.tar.gz: 695cda5b3ee72cc98d197433bbe001a0206ef801
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e445a4e534e2344c500273ff4f17525077c78b595f59d2bc4a10b79d1e5048ee5a04dc9617a71059a514351b845dc414a4275b6af40dbe13dcb60fc55abb530f
|
7
|
+
data.tar.gz: 0d4465f707641a7b0a80ca4c17d7832a0098a306e67697f48d9ea3c700fe2823948a0bf025075643f45d06bdcfe782e71f8d4c4ac3b822caa91af9cc36335057
|
data/README.md
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
# EmapicConsul
|
2
2
|
|
3
|
-
|
3
|
+
Put your Ruby code in the file `lib/emapic_consul`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
4
|
|
5
|
-
TODO: Delete this and the text above, and describe your gem
|
6
5
|
|
7
6
|
## Installation
|
8
7
|
|
@@ -14,11 +13,15 @@ gem 'emapic_consul'
|
|
14
13
|
|
15
14
|
And then execute:
|
16
15
|
|
17
|
-
|
16
|
+
```
|
17
|
+
$ bundle
|
18
|
+
```
|
18
19
|
|
19
20
|
Or install it yourself as:
|
20
21
|
|
21
|
-
|
22
|
+
```
|
23
|
+
$ gem install emapic_consul
|
24
|
+
```
|
22
25
|
|
23
26
|
## Setup
|
24
27
|
|
@@ -35,7 +38,47 @@ export EMAPIC_SECRET="4321"
|
|
35
38
|
|
36
39
|
## Usage
|
37
40
|
|
38
|
-
|
41
|
+
To register proposal creation in Emapic:
|
42
|
+
|
43
|
+
```ruby
|
44
|
+
# /app/models/custom/proposal.rb
|
45
|
+
class Proposal
|
46
|
+
after_create :notify_emapic
|
47
|
+
|
48
|
+
def notify_emapic
|
49
|
+
EmapicConsul::Api.notify_group_creation(self)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
```
|
53
|
+
|
54
|
+
To register debate creation in Emapic:
|
55
|
+
|
56
|
+
```ruby
|
57
|
+
# /app/models/custom/debate.rb
|
58
|
+
class Debate
|
59
|
+
after_create :notify_emapic
|
60
|
+
|
61
|
+
def notify_emapic
|
62
|
+
EmapicConsul::Api.notify_group_creation(self)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
```
|
66
|
+
|
67
|
+
To register vote creation in Emapic:
|
68
|
+
|
69
|
+
```ruby
|
70
|
+
# /app/models/custom/vote.rb
|
71
|
+
class Vote
|
72
|
+
after_create :notify_emapic
|
73
|
+
VOTABLE_GROUPS = ['proposal', 'debate']
|
74
|
+
|
75
|
+
def notify_emapic
|
76
|
+
if VOTABLE_GROUPS.include? votable.type
|
77
|
+
EmapicConsul::Api.notify_vote(self)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
```
|
39
82
|
|
40
83
|
## Development
|
41
84
|
|
data/lib/emapic_consul/api.rb
CHANGED
@@ -1,117 +1,81 @@
|
|
1
|
-
require '
|
2
|
-
require 'openssl'
|
1
|
+
require 'request'
|
3
2
|
|
4
3
|
module EmapicConsul
|
5
4
|
class Api
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
puts "Response body: #{response.body}"
|
18
|
-
print_debug_end(response.code)
|
19
|
-
|
20
|
-
if options[:fake_data]
|
21
|
-
district_perimeter = %|{type:"FeatureCollection",features:[{type:"Feature",properties:{name:"Palacio",cartodb_id:1,created_at:"2013-12-02T07:16:22+0100",updated_at:"2013-12-02T07:16:22+0100"},geometry:{type:"MultiPolygon",coordinates:[[[[-3.704621,40.421469],[-3.705029,40.421354],[-3.706807,40.421419],[-3.706605,40.421049],[-3.706691,40.420811],[-3.706828,40.420346],[-3.706879,40.420067],[-3.707141,40.419581],[-3.707164,40.419541],[-3.707216,40.419454],[-3.707472,40.419009],[-3.70727,40.418979],[-3.707365,40.418399],[-3.707394,40.418295],[-3.707416,40.418204],[-3.707378,40.41796],[-3.707376,40.417942],[-3.707346,40.41767],[-3.707314,40.417558],[-3.707387,40.417474],[-3.707357,40.417162],[-3.707409,40.417031],[-3.707502,40.416763],[-3.7073,40.416508],[-3.707238,40.416503],[-3.707173,40.4165],[-3.707123,40.416468],[-3.706879,40.415927],[-3.706723,40.415704],[-3.706807,40.415293],[-3.706949,40.414899],[-3.706416,40.414759],[-3.706169,40.414701],[-3.706119,40.41452],[-3.706264,40.413768],[-3.706407,40.413653],[-3.706925,40.412541],[-3.707119,40.41244],[-3.707174,40.412349],[-3.70784,40.411558],[-3.708794,40.410345],[-3.708919,40.410199],[-3.709736,40.409183],[-3.710369,40.407846],[-3.710739,40.407926],[-3.712384,40.408625],[-3.713922,40.409264],[-3.715461,40.409879],[-3.717029,40.412294],[-3.716542,40.413259],[-3.71563,40.415097],[-3.71723,40.415095],[-3.718123,40.415116],[-3.718328,40.415121],[-3.719186,40.415134],[-3.721644,40.415171],[-3.721541,40.416513],[-3.72107,40.418356],[-3.720851,40.419217],[-3.720744,40.419641],[-3.720533,40.419762],[-3.7202,40.419952],[-3.719757,40.4203],[-3.71939,40.420651],[-3.71909,40.421076],[-3.718989,40.42125],[-3.718886,40.421426],[-3.71888,40.421436],[-3.716751,40.421506],[-3.715493,40.421523],[-3.71467,40.421535],[-3.714195,40.421584],[-3.714195,40.421584],[-3.712587,40.422659],[-3.712072,40.423003],[-3.712022,40.423086],[-3.711865,40.42324],[-3.711734,40.423369],[-3.710413,40.424145],[-3.709853,40.424473],[-3.709608,40.424603],[-3.709585,40.424615],[-3.70886,40.42413],[-3.70662,40.422724],[-3.704621,40.421469]]]]}}]}|
|
22
|
-
bunch_of_points = %|{"type":"FeatureCollection","features":[{"type":"Feature","geometry":{"type":"Point","coordinates":[174.7685,-36.879]},"properties":{"file":"auckland_new-zealand.geojson","name":"Auckland, New Zealand"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[153.3565,-27.961]},"properties":{"file":"gold-coast_australia.geojson","name":"Gold Coast, Australia"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[172.455,-43.4825]},"properties":{"file":"christchurch_new-zealand.geojson","name":"Christchurch, New Zealand"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[115.1215,-8.256]},"properties":{"file":"bali_indonesia.geojson","name":"Bali, Indonesia"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[153.0245,-27.3615]},"properties":{"file":"brisbane_australia.geojson","name":"Brisbane, Australia"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[175.4725,-41.1365]},"properties":{"file":"wellington_new-zealand.geojson","name":"Wellington, New Zealand"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[130.9115,-12.4185]},"properties":{"file":"darwin_australia.geojson","name":"Darwin, Australia"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[106.7975,-6.248]},"properties":{"file":"jakarta_indonesia.geojson","name":"Jakarta, Indonesia"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[152.995,-26.6755]},"properties":{"file":"sunshine-coast_australia.geojson","name":"Sunshine Coast, Australia"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[149.1425,-35.237]},"properties":{"file":"canberra_australia.geojson","name":"Canberra, Australia"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[115.8235,-32.102]},"properties":{"file":"perth_australia.geojson","name":"Perth, Australia"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[138.6355,-34.9155]},"properties":{"file":"adelaide_australia.geojson","name":"Adelaide, Australia"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[151.1375,-33.913]},"properties":{"file":"sydney_australia.geojson","name":"Sydney, Australia"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[145.038,-37.9585]},"properties":{"file":"melbourne_australia.geojson","name":"Melbourne, Australia"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[145.722,-16.9315]},"properties":{"file":"cairns_australia.geojson","name":"Cairns, Australia"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[51.5205,25.294]},"properties":{"file":"doha_qatar.geojson","name":"Doha, Qatar"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[35.2065,31.789]},"properties":{"file":"jerusalem_israel.geojson","name":"Jerusalem, Israel"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[29.015,40.235]},"properties":{"file":"bursa_turkey.geojson","name":"Bursa, Turkey"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[39.211,21.455]},"properties":{"file":"jeddah_saudi-arabia.geojson","name":"Jeddah, Saudi Arabia"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[46.7145,24.695]},"properties":{"file":"riyadh_saudi-arabia.geojson","name":"Riyadh, Saudi Arabia"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[34.847,32.0875]},"properties":{"file":"tel-aviv_israel.geojson","name":"Tel Aviv, Israel"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[36.2855,33.4585]},"properties":{"file":"damascus_syria.geojson","name":"Damascus, Syria"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[44.5915,40.155]},"properties":{"file":"yerevan_armenia.geojson","name":"Yerevan, Armenia"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[35.9825,31.9195]},"properties":{"file":"amman_jordan.geojson","name":"Amman, Jordan"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[55.2335,25.137]},"properties":{"file":"dubai_abu-dhabi.geojson","name":"Dubai, Abu Dhabi"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[44.324,33.341]},"properties":{"file":"baghdad_iraq.geojson","name":"Baghdad, Iraq"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[34.804,31.2415]},"properties":{"file":"beer-sheba_israel.geojson","name":"Beer Sheba, Israel"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[69.17,34.5155]},"properties":{"file":"kabul_afghanistan.geojson","name":"Kabul, Afghanistan"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[27.0795,38.4175]},"properties":{"file":"izmir_turkey.geojson","name":"Izmir, Turkey"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[51.259,35.65]},"properties":{"file":"tehran_iran.geojson","name":"Tehran, Iran"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[39.8465,21.4345]},"properties":{"file":"mecca_saudi-arabia.geojson","name":"Mecca, Saudi Arabia"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[69.2545,41.271]},"properties":{"file":"tashkent_uzbekistan.geojson","name":"Tashkent, Uzbekistan"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[49.855,40.3955]},"properties":{"file":"baku_azerbaijan.geojson","name":"Baku, Azerbaijan"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[35.335,37.01]},"properties":{"file":"adana_turkey.geojson","name":"Adana, Turkey"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[35.505,38.715]},"properties":{"file":"kayseri_turkey.geojson","name":"Kayseri, Turkey"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[10.911,43.9865]},"properties":{"file":"pistoia_italy.geojson","name":"Pistoia, Italy"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[-8.4255,40.209]},"properties":{"file":"coimbra_portugal.geojson","name":"Coimbra, Portugal"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[13.3785,38.033]},"properties":{"file":"palermo_italy.geojson","name":"Palermo, Italy"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[8.779,44.426]},"properties":{"file":"genoa_italy.geojson","name":"Genoa, Italy"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[16.5715,40.6665]},"properties":{"file":"matera_italy.geojson","name":"Matera, Italy"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[-7.955,37.021]},"properties":{"file":"faro_portugal.geojson","name":"Faro, Portugal"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[9.1645,39.2255]},"properties":{"file":"cagliari_italy.geojson","name":"Cagliari, Italy"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[10.4,43.7035]},"properties":{"file":"pisa_italy.geojson","name":"Pisa, Italy"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[7.6395,45.068]},"properties":{"file":"turin_italy.geojson","name":"Turin, Italy"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[-2.959,43.2715]},"properties":{"file":"bilbao_spain.geojson","name":"Bilbao, Spain"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[-3.6045,37.1745]},"properties":{"file":"granada_spain.geojson","name":"Granada, Spain"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[8.2025,44.9185]},"properties":{"file":"asti_italy.geojson","name":"Asti, Italy"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[-5.734,43.427]},"properties":{"file":"gijon_spain.geojson","name":"Gijon, Spain"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[23.685,37.9395]},"properties":{"file":"athens_greece.geojson","name":"Athens, Greece"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[-6.2,36.575]},"properties":{"file":"cadiz_spain.geojson","name":"Cadiz, Spain"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[12.477,41.854]},"properties":{"file":"rome_italy.geojson","name":"Rome, Italy"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[10.2235,45.517]},"properties":{"file":"brescia_italy.geojson","name":"Brescia, Italy"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[22.9465,40.6215]},"properties":{"file":"thessaloniki_greece.geojson","name":"Thessaloniki, Greece"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[12.182,45.467]},"properties":{"file":"venice_italy.geojson","name":"Venice, Italy"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[-0.3605,39.462]},"properties":{"file":"valencia_spain.geojson","name":"Valencia, Spain"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[-3.7,42.3535]},"properties":{"file":"burgos_spain.geojson","name":"Burgos, Spain"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[11.4075,44.5025]},"properties":{"file":"bologna_italy.geojson","name":"Bologna, Italy"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[-9.046,38.754]},"properties":{"file":"lisbon_portugal.geojson","name":"Lisbon, Portugal"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[-7.915,38.562]},"properties":{"file":"evora_portugal.geojson","name":"Evora, Portugal"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[14.2465,40.854]},"properties":{"file":"naples_italy.geojson","name":"Naples, Italy"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[11.243,43.792]},"properties":{"file":"florence_italy.geojson","name":"Florence, Italy"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[11.109,46.066]},"properties":{"file":"trento_italy.geojson","name":"Trento, Italy"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[9.165,45.47]},"properties":{"file":"milan_italy.geojson","name":"Milan, Italy"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[2.105,41.3895]},"properties":{"file":"barcelona_spain.geojson","name":"Barcelona, Spain"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[10.468,43.859]},"properties":{"file":"lucca_italy.geojson","name":"Lucca, Italy"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[-8.3,43.4]},"properties":{"file":"acoruna_spain.geojson","name":"Acoruna, Spain"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[-3.675,40.415]},"properties":{"file":"madrid_spain.geojson","name":"Madrid, Spain"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[-5.9595,37.39]},"properties":{"file":"seville_spain.geojson","name":"Seville, Spain"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[-3.9965,43.138]},"properties":{"file":"cantabria_spain.geojson","name":"Cantabria, Spain"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[-8.718,42.238]},"properties":{"file":"vigo_spain.geojson","name":"Vigo, Spain"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[-8.5765,41.19]},"properties":{"file":"porto_portugal.geojson","name":"Porto, Portugal"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[10.818,63.313]},"properties":{"file":"trondheim_norway.geojson","name":"Trondheim, Norway"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[10.592,59.681]},"properties":{"file":"oslo_norway.geojson","name":"Oslo, Norway"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[18.192,59.4835]},"properties":{"file":"stockholm_sweden.geojson","name":"Stockholm, Sweden"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[5.317,60.386]},"properties":{"file":"bergen_norway.geojson","name":"Bergen, Norway"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[10.212,56.166]},"properties":{"file":"aarhus_denmark.geojson","name":"Aarhus, Denmark"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[24.8605,60.366]},"properties":{"file":"helsinki_finland.geojson","name":"Helsinki, Finland"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[12.941,55.5825]},"properties":{"file":"malmo_sweden.geojson","name":"Malmo, Sweden"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[-21.983,64.034]},"properties":{"file":"reykjavik_iceland.geojson","name":"Reykjavik, Iceland"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[23.7025,61.6175]},"properties":{"file":"tampere_finland.geojson","name":"Tampere, Finland"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[11.931,57.6675]},"properties":{"file":"gothenburg_sweden.geojson","name":"Gothenburg, Sweden"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[-65.7575,-19.5815]},"properties":{"file":"potosi_bolivia.geojson","name":"Potosi, Bolivia"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[-64.1535,10.445]},"properties":{"file":"cumana_venezuela.geojson","name":"Cumana, Venezuela"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[-76.9975,-12.001]},"properties":{"file":"lima_peru.geojson","name":"Lima, Peru"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[-75.482,10.4115]},"properties":{"file":"cartagena_colombia.geojson","name":"Cartagena, Colombia"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[-46.61,-23.721]},"properties":{"file":"sao-paulo_brazil.geojson","name":"Sao Paulo, Brazil"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[-79.899,-2.1595]},"properties":{"file":"guayaquil_ecuador.geojson","name":"Guayaquil, Ecuador"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[-68.7625,-11.0245]},"properties":{"file":"cobija_bolivia.geojson","name":"Cobija, Bolivia"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[-68.164,-16.5395]},"properties":{"file":"la-paz_bolivia.geojson","name":"La Paz, Bolivia"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[-64.184,-31.395]},"properties":{"file":"cordoba_argentina.geojson","name":"Cordoba, Argentina"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[-34.4365,-8.0435]},"properties":{"file":"recife_brazil.geojson","name":"Recife, Brazil"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[-62.2485,-38.786]},"properties":{"file":"bahia-blanca_argentina.geojson","name":"Bahia Blanca, Argentina"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[-51.265,-30.0545]},"properties":{"file":"porto-alegre_brazil.geojson","name":"Porto Alegre, Brazil"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[-61.02,14.634]},"properties":{"file":"martinique_french-caribbean.geojson","name":"Martinique, French Caribbean"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[-58.5455,-34.679]},"properties":{"file":"buenos-aires_argentina.geojson","name":"Buenos Aires, Argentina"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[-57.5225,-25.2935]},"properties":{"file":"asuncion_paraguay.geojson","name":"Asuncion, Paraguay"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[-43.964,-19.9025]},"properties":{"file":"belo-horizonte_brazil.geojson","name":"Belo Horizonte, Brazil"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[-74.094,4.6565]},"properties":{"file":"bogota_colombia.geojson","name":"Bogota, Colombia"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[-43.3055,-22.797]},"properties":{"file":"rio-de-janeiro_brazil.geojson","name":"Rio De Janeiro, Brazil"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[-64.7325,-21.543]},"properties":{"file":"tarija_bolivia.geojson","name":"Tarija, Bolivia"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[-56.1735,-34.8625]},"properties":{"file":"montevideo_uruguay.geojson","name":"Montevideo, Uruguay"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[-67.1115,-17.959]},"properties":{"file":"oruro_bolivia.geojson","name":"Oruro, Bolivia"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[-70.698,-33.4875]},"properties":{"file":"santiago_chile.geojson","name":"Santiago, Chile"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[-63.1595,-17.7945]},"properties":{"file":"santa-cruz_bolivia.geojson","name":"Santa Cruz, Bolivia"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[-78.4765,-0.2205]},"properties":{"file":"quito_ecuador.geojson","name":"Quito, Ecuador"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[-66.8865,10.4575]},"properties":{"file":"caracas_venezuela.geojson","name":"Caracas, Venezuela"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[-49.251,-25.435]},"properties":{"file":"curitiba_brazil.geojson","name":"Curitiba, Brazil"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[-38.3415,-12.886]},"properties":{"file":"salvador_brazil.geojson","name":"Salvador, Brazil"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[-65.2655,-19.0285]},"properties":{"file":"sucre_bolivia.geojson","name":"Sucre, Bolivia"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[-54.6735,-20.511]},"properties":{"file":"campo-grande_brazil.geojson","name":"Campo Grande, Brazil"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[-66.212,-17.3485]},"properties":{"file":"cochabamba_bolivia.geojson","name":"Cochabamba, Bolivia"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[-61.68,10.4425]},"properties":{"file":"trinidad-tobago.geojson","name":"Trinidad Tobago"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[-75.582,6.2535]},"properties":{"file":"medellin_colombia.geojson","name":"Medellin, Colombia"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[-84.081,9.8975]},"properties":{"file":"san-jose_costa-rica.geojson","name":"San Jose, Costa Rica"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[-47.9395,-15.8385]},"properties":{"file":"brasilia_brazil.geojson","name":"Brasilia, Brazil"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[29.992,31.228]},"properties":{"file":"alexandria_egypt.geojson","name":"Alexandria, Egypt"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[6.6475,36.354]},"properties":{"file":"constantine_algeria.geojson","name":"Constantine, Algeria"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[28.0395,-26.1985]},"properties":{"file":"johannesburg_south-africa.geojson","name":"Johannesburg, South Africa"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[-7.5965,33.5695]},"properties":{"file":"casablanca_morocco.geojson","name":"Casablanca, Morocco"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[-4.016,5.3715]},"properties":{"file":"abidjan_ivory-coast.geojson","name":"Abidjan, Ivory Coast"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[1.2375,6.1905]},"properties":{"file":"lome_togo.geojson","name":"Lome, Togo"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[39.2775,-6.811]},"properties":{"file":"dar-es-salaam_tanzania.geojson","name":"Dar Es Salaam, Tanzania"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[-17.3755,14.752]},"properties":{"file":"dakar_senegal.geojson","name":"Dakar, Senegal"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[-13.659,9.614]},"properties":{"file":"conakry_guinea.geojson","name":"Conakry, Guinea"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[18.5605,4.389]},"properties":{"file":"bangui_central-african-republic.geojson","name":"Bangui, Central African Republic"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[10.2355,36.8335]},"properties":{"file":"tunis_tunisia.geojson","name":"Tunis, Tunisia"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[31.3035,30.1625]},"properties":{"file":"cairo_egypt.geojson","name":"Cairo, Egypt"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[13.293,-8.909]},"properties":{"file":"luanda_angola.geojson","name":"Luanda, Angola"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[18.653,-33.917]},"properties":{"file":"cape-town_south-africa.geojson","name":"Cape Town, South Africa"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[47.5245,-18.8985]},"properties":{"file":"antananarivo_madagascar.geojson","name":"Antananarivo, Madagascar"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[38.7855,8.998]},"properties":{"file":"addis-abeba_ethiopia.geojson","name":"Addis Abeba, Ethiopia"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[15.323,-4.401]},"properties":{"file":"kinshasa_congo.geojson","name":"Kinshasa, Congo"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[30.9195,-29.9025]},"properties":{"file":"durban_south-africa.geojson","name":"Durban, South Africa"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[3.3615,6.615]},"properties":{"file":"lagos_nigeria.geojson","name":"Lagos, Nigeria"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[31.572,4.857]},"properties":{"file":"juba_south-sudan.geojson","name":"Juba, South Sudan"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[7.744,36.918]},"properties":{"file":"annaba_algeria.geojson","name":"Annaba, Algeria"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[3.042,36.753]},"properties":{"file":"algiers_algeria.geojson","name":"Algiers, Algeria"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[8.5265,12.0005]},"properties":{"file":"kano_nigeria.geojson","name":"Kano, Nigeria"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[-0.8405,9.418]},"properties":{"file":"tamale_ghana.geojson","name":"Tamale, Ghana"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[32.5485,-25.9275]},"properties":{"file":"maputo_mozambique.geojson","name":"Maputo, Mozambique"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[36.819,-1.2265]},"properties":{"file":"nairobi_kenya.geojson","name":"Nairobi, Kenya"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[2.1065,13.5045]},"properties":{"file":"niamey_niger.geojson","name":"Niamey, Niger"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[31.039,-17.8345]},"properties":{"file":"harare_zimbabwe.geojson","name":"Harare, Zimbabwe"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[-1.543,12.3725]},"properties":{"file":"ouagadougou_burkina-faso.geojson","name":"Ouagadougou, Burkina Faso"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[32.5765,0.2595]},"properties":{"file":"kampala_uganda.geojson","name":"Kampala, Uganda"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[30.099,-1.912]},"properties":{"file":"kigali_rwanda.geojson","name":"Kigali, Rwanda"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[28.296,-15.409]},"properties":{"file":"lusaka_zambia.geojson","name":"Lusaka, Zambia"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[33.779,-13.976]},"properties":{"file":"lilongwe_malawi.geojson","name":"Lilongwe, Malawi"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[32.532,15.617]},"properties":{"file":"khartoum_republic-of-sudan.geojson","name":"Khartoum, Republic Of Sudan"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[-0.254,5.575]},"properties":{"file":"accra_ghana.geojson","name":"Accra, Ghana"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[-10.7285,6.3145]},"properties":{"file":"monrovia_liberia.geojson","name":"Monrovia, Liberia"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[45.3305,2.0515]},"properties":{"file":"mogadishu_somalia.geojson","name":"Mogadishu, Somalia"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[-8.008,12.613]},"properties":{"file":"bamako_mali.geojson","name":"Bamako, Mali"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[29.355,-3.375]},"properties":{"file":"bujumbura_burundi.geojson","name":"Bujumbura, Burundi"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[57.5455,-20.1885]},"properties":{"file":"mauritius.geojson","name":"Mauritius"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[25.9055,-24.608]},"properties":{"file":"gaborone_botswana.geojson","name":"Gaborone, Botswana"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[2.425,6.37]},"properties":{"file":"cotonou_benin.geojson","name":"Cotonou, Benin"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[-0.6415,35.7075]},"properties":{"file":"oran_algeria.geojson","name":"Oran, Algeria"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[7.4825,9.0405]},"properties":{"file":"abuja_nigeria.geojson","name":"Abuja, Nigeria"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[141.248,42.985]},"properties":{"file":"sapporo_japan.geojson","name":"Sapporo, Japan"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[126.557,33.3425]},"properties":{"file":"jeju_south-korea.geojson","name":"Jeju, South Korea"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[68.689,38.5365]},"properties":{"file":"dushanbe_tajikistan.geojson","name":"Dushanbe, Tajikistan"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[80.0705,6.9865]},"properties":{"file":"colombo_sri-lanka.geojson","name":"Colombo, Sri Lanka"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[100.0035,9.5035]},"properties":{"file":"koh-samui_thailand.geojson","name":"Koh Samui, Thailand"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[100.453,13.84]},"properties":{"file":"bangkok_thailand.geojson","name":"Bangkok, Thailand"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[39.863,43.5135]},"properties":{"file":"sochi_russia.geojson","name":"Sochi, Russia"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[128.8475,35.215]},"properties":{"file":"busan_south-korea.geojson","name":"Busan, South Korea"}}]}|
|
23
|
-
return bunch_of_points
|
24
|
-
else
|
25
|
-
return response.body
|
26
|
-
end
|
5
|
+
FAKE_LOCATIONS = true
|
6
|
+
|
7
|
+
def self.build_generic_request(path)
|
8
|
+
EmapicConsul::Api::Request.new(
|
9
|
+
host: api_host,
|
10
|
+
path: path,
|
11
|
+
port: api_port,
|
12
|
+
api_key: api_key,
|
13
|
+
api_secret: api_secret
|
14
|
+
)
|
27
15
|
end
|
28
16
|
|
29
|
-
|
30
|
-
|
17
|
+
# Usage:
|
18
|
+
# notify_group_creation(proposal_instance)
|
19
|
+
def self.notify_group_creation(group)
|
20
|
+
print_debug_start("to notify #{type} creation")
|
31
21
|
|
32
|
-
|
33
|
-
|
34
|
-
request = Net::HTTP::Get.new(uri)
|
35
|
-
|
36
|
-
response = http.request(request)
|
37
|
-
|
38
|
-
puts "Address: #{JSON.parse(response.body)['display_name']}"
|
39
|
-
print_debug_end(response.code)
|
40
|
-
|
41
|
-
return JSON.parse(response.body)['display_name']
|
42
|
-
end
|
22
|
+
group_type = group.class.name.downcase
|
23
|
+
geolocation = (FAKE_LOCATIONS ? get_random_address : group.district.name)
|
43
24
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
uri = build_uri('/api/test')
|
48
|
-
http = build_http_object(uri)
|
49
|
-
request = Net::HTTP::Post.new(uri)
|
50
|
-
request.basic_auth(api_key, api_secret)
|
51
|
-
|
52
|
-
response = http.request(request)
|
25
|
+
request = build_generic_request("/api/#{group_type.pluralize}")
|
26
|
+
request.params = { type: group_type, id: group.id, geolocation: geolocation }
|
27
|
+
response = request.send
|
53
28
|
|
29
|
+
puts "Response body: #{response.body}"
|
54
30
|
print_debug_end(response.code)
|
55
31
|
end
|
56
32
|
|
57
|
-
|
58
|
-
|
33
|
+
# Usage:
|
34
|
+
# notify_vote_creation(vote_instance)
|
35
|
+
def self.notify_vote(vote)
|
36
|
+
print_debug_start("to notify vote creation")
|
59
37
|
|
60
|
-
|
61
|
-
http = build_http_object(uri)
|
62
|
-
request = Net::HTTP::Post.new(uri)
|
63
|
-
request.basic_auth(api_key, api_secret)
|
64
|
-
request.set_form_data('usr_id': user_id, 'address': get_random_address)
|
38
|
+
geolocation = (FAKE_LOCATIONS ? get_random_address : vote.voter.district.name)
|
65
39
|
|
66
|
-
|
40
|
+
request = build_generic_request("/api/votes/")
|
41
|
+
request.params = { votable: vote.votable_id, votable_type: vote.votable_type, geolocation: geolocation }
|
42
|
+
response = request.send
|
67
43
|
|
44
|
+
puts "Response body: #{response.body}"
|
68
45
|
print_debug_end(response.code)
|
69
46
|
end
|
70
47
|
|
71
|
-
def self.
|
72
|
-
print_debug_start("to get the
|
48
|
+
def self.get_random_address
|
49
|
+
print_debug_start("to get the address")
|
73
50
|
|
74
|
-
uri = build_uri('/api/
|
51
|
+
uri = build_uri('/api/randomMadrid')
|
75
52
|
http = build_http_object(uri)
|
76
53
|
request = Net::HTTP::Get.new(uri)
|
77
|
-
request.basic_auth(api_key, api_secret)
|
78
54
|
|
79
55
|
response = http.request(request)
|
80
56
|
|
81
|
-
puts "
|
57
|
+
puts "Address: #{JSON.parse(response.body)['display_name']}"
|
82
58
|
print_debug_end(response.code)
|
83
59
|
|
84
|
-
return response.body
|
60
|
+
return JSON.parse(response.body)['display_name']
|
85
61
|
end
|
86
62
|
|
87
|
-
def self.
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
end
|
63
|
+
# def self.register_random_location(group_id, user_id)
|
64
|
+
# print_debug_start("to register a vote with a random address")
|
65
|
+
#
|
66
|
+
# uri = build_uri('/api/locationgroup/' + group_id)
|
67
|
+
# http = build_http_object(uri)
|
68
|
+
# request = Net::HTTP::Post.new(uri)
|
69
|
+
# request.basic_auth(api_key, api_secret)
|
70
|
+
# request.set_form_data('usr_id': user_id, 'address': get_random_address)
|
71
|
+
#
|
72
|
+
# response = http.request(request)
|
73
|
+
#
|
74
|
+
# print_debug_end(response.code)
|
75
|
+
# end
|
100
76
|
|
101
77
|
private
|
102
78
|
|
103
|
-
# Example: '/api/survey/50ibWU/totals/countries'
|
104
|
-
def self.build_uri(path)
|
105
|
-
URI::HTTP.build(host: api_host, path: path, port: api_port)
|
106
|
-
end
|
107
|
-
|
108
|
-
def self.build_http_object(uri)
|
109
|
-
http = Net::HTTP.new(uri.host, uri.port)
|
110
|
-
http.use_ssl = true
|
111
|
-
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
112
|
-
http
|
113
|
-
end
|
114
|
-
|
115
79
|
def self.print_debug_start(description = "")
|
116
80
|
puts "\n\n\n" + "-"*60
|
117
81
|
puts "Sending request to EMAPIC API " + description
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'openssl'
|
3
|
+
|
4
|
+
module EmapicConsul
|
5
|
+
module Api
|
6
|
+
|
7
|
+
class Request
|
8
|
+
def initialize(options = {})
|
9
|
+
uri = URI::HTTP.build(
|
10
|
+
host: options[:host],
|
11
|
+
path: options[:path],
|
12
|
+
port: options[:port]
|
13
|
+
)
|
14
|
+
@http = build_http_object(uri)
|
15
|
+
@request = Net::HTTP::Post.new(uri)
|
16
|
+
@request.basic_auth(options[:api_key], options[:api_secret])
|
17
|
+
end
|
18
|
+
|
19
|
+
# usage:
|
20
|
+
# request.params = { id: 1, title: 'My title', geoloc: 'xyz' }
|
21
|
+
def params=(params)
|
22
|
+
@request.set_form_data(params)
|
23
|
+
end
|
24
|
+
|
25
|
+
def send
|
26
|
+
@http.request(@request)
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def self.build_http_object(uri)
|
32
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
33
|
+
http.use_ssl = true
|
34
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
35
|
+
http
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
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.
|
4
|
+
version: 0.1.2
|
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-
|
11
|
+
date: 2016-11-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -71,6 +71,7 @@ files:
|
|
71
71
|
- emapic_consul.gemspec
|
72
72
|
- lib/emapic_consul.rb
|
73
73
|
- lib/emapic_consul/api.rb
|
74
|
+
- lib/emapic_consul/request.rb
|
74
75
|
- lib/emapic_consul/version.rb
|
75
76
|
homepage: https://github.com/amiedes/emapic_consul
|
76
77
|
licenses:
|