Last active
August 29, 2015 14:14
-
-
Save gelias/195e3b5fcce2b657c103 to your computer and use it in GitHub Desktop.
Sample in Ruby to integrate with uMov.me API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'rest-client' | |
require 'xmlsimple' | |
class Resource | |
TOKEN = "PUT_YOUR_TOKEN_HERE" | |
BASE_URL = "http://api.umov.me/CenterWeb/api/#{TOKEN}" | |
def resource_name | |
end | |
def all(filter='') | |
do_get resource_name,filter | |
end | |
def get_by_alternative_id(alternative_id) | |
do_get "#{resource_name}/alternativeIdentifier/#{alternative_id}" | |
end | |
def do_get(uri=resource_name,filter='') | |
XmlSimple.xml_in(RestClient.get build_url(uri, filter)) | |
end | |
def build_url(uri, filter) | |
url = "#{BASE_URL}/#{uri}.xml?#{filter}" | |
puts url | |
url | |
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_post(entity, data) | |
XmlSimple.xml_in(RestClient.post BASE_URL + '/'+ entity + '.xml', :data => data, :content_type => 'application/x-www-form-urlencoded') | |
end | |
end | |
class Agent < Resource | |
def resource_name | |
'agent' | |
end | |
end | |
class ServiceLocal < Resource | |
def resource_name | |
'serviceLocal' | |
end | |
end | |
class Schedule < Resource | |
def resource_name | |
'schedule' | |
end | |
end | |
class ActivityHistory < Resource | |
def resource_name | |
'activityHistory' | |
end | |
def get_history_hierarchical(history_id) | |
do_get "activityHistoryHierarchical/#{history_id}" | |
end | |
def all_by_schedule(schedule_id_alt) | |
all "schedule.alternativeIdentifier=#{schedule_id_alt}" | |
end | |
end | |
# Add a new student | |
#agent = Agent.new | |
#puts agent.add "<agent><name>Student</name><login>student001</login><alternativeIdentifier>student001</alternativeIdentifier><agentType><alternativeIdentifier>student_type</alternativeIdentifier></agentType><centerwebUser>true</centerwebUser><centerwebUserRole>A</centerwebUserRole><mobileUser>true</mobileUser><email>[email protected]</email><password>010203040</password></agent>" | |
#puts agent.edit "fred","<agent><name>Student 001</name></agent>" | |
#puts agent.all | |
#puts agent.all "login=student001" | |
#puts agent.get_by_alternative_id "student001" | |
# Add a new serviceLocal | |
#serviceLocal = ServiceLocal.new | |
#puts serviceLocal.add "<serviceLocal><description>Virtual Room</description><country>Brasil</country><city>Porto Alegre</city><street>Av. Parana 2021</street><zipCode/><alternativeIdentifier>virtual_room</alternativeIdentifier><active>true</active></serviceLocal>" | |
#puts serviceLocal.edit "virtual_room","<serviceLocal><description>Virutal Room</description></serviceLocal>" | |
#puts serviceLocal.all | |
#puts serviceLocal.all "description=Virutal%20Room" | |
#puts serviceLocal.get_by_alternative_id "virtual_room" | |
# Add questions | |
#schedule = Schedule.new | |
#puts schedule.all | |
#puts schedule.get_by_alternative_id "schedule001" | |
#puts schedule.add "<schedule><alternativeIdentifier>question001</alternativeIdentifier><agent><alternativeIdentifier>guilherme</alternativeIdentifier></agent><serviceLocal><alternativeIdentifier>service_local_test</alternativeIdentifier></serviceLocal><activitiesOrigin>4</activitiesOrigin><date>2015-03-06</date><hour>16:00</hour><activityRelationship><activity><alternativeIdentifier>validacao</alternativeIdentifier></activity></activityRelationship></schedule>" | |
#schedule.edit("validacao", "<schedule><observation>Parabens Tarefa</observation></schedule>") | |
#history = ActivityHistory.new | |
#puts history.all | |
#puts history.all_by_schedule "question001" | |
#puts history.get_history_hierarchical <INTERNAL_ID_ACTIVITY_HISTORY> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment