Created
September 11, 2012 11:45
-
-
Save michiels/3697799 to your computer and use it in GitHub Desktop.
API Sample
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
# Voorbeeld van het survey object in de interface applicatie. | |
# | |
class Survey | |
def self.all | |
# Code om bij API alle (of bijv limiet van max 30 per keer) op te halen en die als object in een | |
# array terug te geven. | |
end | |
def self.find(id) | |
# Code om een enquete uit de api op te halen. Iets van Faraday dat connect met /surveys/#{id} van de API. | |
# Sla gegevens die je uit JSON terug krijgt in een @attributes {} op oid. | |
end | |
def save | |
# Roept de API aan via Faraday en update de velden | |
end | |
end |
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
# | |
# Deze file had ik al voor een deel gemaakt in de API. Dit is gewoon standaard Rails code met | |
# wat wijzigingen om met SQL Server te kunnen verbinden. | |
# | |
class Survey < ActiveRecord::Base | |
set_table_name "Enquetes" | |
... | |
end |
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
class SurveysController < ApplicationController | |
def index | |
@surveys = Survey.all # Dit is de all method van hierboven die een call doet naar de API en de JSON inleest. | |
end | |
end |
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
class SurveysController < ApplicationController | |
respond_to :json | |
def index | |
@surveys = Survey.all # Via standaard ActiveRecord uit SQL database. | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment