Permalink
Browse files

Created API for getting devices for a certain customer

  • Loading branch information...
1 parent 7260736 commit ddb7353bda21f27b834e7b5801c2ad779e35588c Bob Van Landuyt committed Nov 29, 2010
@@ -0,0 +1,5 @@
+class ApiController < ApplicationController
+ def get_devices_for_customer
+ @customer = Company.find_by_customer_number(params[:customer_number])
+ end
+end
@@ -0,0 +1,2 @@
+module ApiHelper
+end
@@ -0,0 +1,50 @@
+<?xml version="1.0"?>
+<devices>
+ <% @customer.devices.each do |device| %>
+ <device>
+ <name>
+ <%= device.name %>
+ </name>
+ <comment>
+ <%=device.comment %>
+ </comment
+ <location>
+ <datacenter>
+ <%= device.server_rack.datacenter.name %>
+ </datacenter>
+ <rack>
+ <%= device.server_rack.name %>
+ </rack>
+ <units>
+ <% device.units.each do |unit| %>
+ <unit>
+ <%= unit.number %>
+ </unit>
+ <% end %>
+ </units>
+ </location>
+ <interfaces>
+ <% device.interfaces.each do |interface| %>
+ <interface>
+ <type>
+ <%= interface.interface_type(:name)%>
+ </type>
+ <name>
+ <%= interface.name %>
+ </name>
+ <% if interface.other %>
+ <connection>
+ <other>
+ <%= interface.other.to_s%>
+ </other>
+ <color>
+ <%= interface.cable_connection.color %>
+ </color>
+ </connection>
+ <% end %>
+ </interface>
+ <% end %>
+ </interfaces>
+ </device>
+ <% end %>
+</devices>
View
@@ -12,6 +12,8 @@
get "search/find_colors"
get "search/company_names"
get "devices/collect_interfaces"
+
+ match "api/get_devices_for_customer/:customer_number" => "api#get_devices_for_customer", :defaults => { :format => 'xml' }
#resources :cable_connections
#resources :interfaces
@@ -0,0 +1,8 @@
+require 'test_helper'
+
+class ApiControllerTest < ActionController::TestCase
+ # Replace this with your real tests.
+ test "the truth" do
+ assert true
+ end
+end
@@ -0,0 +1,4 @@
+require 'test_helper'
+
+class ApiHelperTest < ActionView::TestCase
+end

0 comments on commit ddb7353

Please sign in to comment.