class EmapicConsul::Api

Public Class Methods

build_generic_request(path) click to toggle source
# File lib/emapic_consul/api.rb, line 7
def self.build_generic_request(path)
  EmapicConsul::Request.new(
    host: api_host,
    path: path,
    port: api_port,
    api_key: api_key,
    api_secret: api_secret
  )
end
create_location_group(group) click to toggle source

create_location_group(proposal_instance)

# File lib/emapic_consul/api.rb, line 18
def self.create_location_group(group)
  print_debug_start("to notify proposal creation")

  request = build_generic_request("/api/locationgroup/#{emapic_login}")
  request.params = { id: "proposal_#{group.id}", title: group.title }
  response = request.send

  puts "Response body: #{response.body}"
  print_debug_end(response.code)
end
vote_location_group(group, latitude, longitude) click to toggle source

vote_location_group(proposal_instance, latitude, longitude)

# File lib/emapic_consul/api.rb, line 30
def self.vote_location_group(group, latitude, longitude)
  print_debug_start("to notify vote creation with lat/lng")

  request = build_generic_request("/api/locationgroup/#{emapic_login}/proposal_#{group.id}")
  request.params = { user_id: nil, lat: latitude, lng: longitude }
  response = request.send

  puts "Response body: #{response.body}"
  print_debug_end(response.code)
end

Private Class Methods

api_host() click to toggle source
# File lib/emapic_consul/api.rb, line 84
def self.api_host
  ENV['EMAPIC_HOST'].split(':')[0]
end
api_key() click to toggle source
# File lib/emapic_consul/api.rb, line 97
def self.api_key
  ENV['EMAPIC_KEY']
end
api_port() click to toggle source
# File lib/emapic_consul/api.rb, line 88
def self.api_port
  port = ENV['EMAPIC_HOST'].split(':')[1]
  (port.nil? 80 : port)
end
api_secret() click to toggle source
# File lib/emapic_consul/api.rb, line 101
def self.api_secret
  ENV['EMAPIC_SECRET']
end
emapic_login() click to toggle source
# File lib/emapic_consul/api.rb, line 93
def self.emapic_login
  ENV['EMAPIC_LOGIN']
end
print_debug_end(http_code) click to toggle source
print_debug_start(description = "") click to toggle source

def self.register_random_location(group_id, user_id)

print_debug_start("to register a vote with a random address")

uri = build_uri('/api/locationgroup/' + group_id)
http = build_http_object(uri)
request = Net::HTTP::Post.new(uri)
request.basic_auth(api_key, api_secret)
request.set_form_data('usr_id': user_id, 'address': get_random_address)

response = http.request(request)

print_debug_end(response.code)

end