Skip to content

Instantly share code, notes, and snippets.

@MrCoffey
Created March 27, 2015 17:59
Show Gist options
  • Save MrCoffey/89409677887483ed006c to your computer and use it in GitHub Desktop.
Save MrCoffey/89409677887483ed006c to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'rest-client'
require 'xmlsimple'
require 'net/http'
require 'crack'
class Resource
TOKEN = "poner_token_aqui"
BASE_URL = "http://api.umov.me/CenterWeb/api/#{TOKEN}"
def resource_name
end
def all
do_get resource_name
end
def get_by_alternative_id(alternative_id)
do_get "#{resource_name}/alternativeIdentifier/#{alternative_id}"
end
def add data
do_post(resource_name, data)
end
def edit(alternative_id, data)
do_post "#{resource_name}/alternativeIdentifier/#{alternative_id}", data
end
def do_get(uri)
XmlSimple.xml_in(RestClient.get BASE_URL + '/' + uri + '.xml')
end
def do_post(entity, data)
XmlSimple.xml_in(RestClient.post BASE_URL + '/'+ entity + '.xml', :data => data, :content_type => 'application/x-www-form-urlencoded')
end
end
class AgentType < Resource
def resource_name
'agentType'
end
end
class Agent < Resource
def resource_name
'agent'
end
end
class Schedule < Resource
def resource_name
'schedule'
end
end
class ActivityHistory < Resource
# captura info por medio de la url
def umov_to_json(schedule_id)
url_activity = "http://api.umov.me/CenterWeb/api/#{TOKEN}/activityHistory.xml?schedule.alternativeIdentifier=#{schedule_id}"
umov_xml = Net::HTTP.get_response(URI.parse("#{url_activity}")).body
history_hierichal = Crack::XML.parse(umov_xml)['result']['entries']['entry']['id']
@activity_history_hierarchical_url = "http://api.umov.me/CenterWeb/api/#{TOKEN}/activityHistoryHierarchical/" + "#{history_hierichal}" + '.xml'
end
def get_data_history_hierichal
puts RestClient.get(@activity_history_hierarchical_url)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment