Permalink
Browse files

keep working on mapping requests

  • Loading branch information...
1 parent 118e168 commit c6375373d4c638cf4f154794d21583ddb9f84aad @nu7hatch nu7hatch committed May 28, 2012
View
9 app/controllers/admin/mapping_requests_controller.rb
@@ -7,6 +7,15 @@ def new
end
def create
+ @response = @mapping.request(@endpoint.name, params[:request]) || {}
+
+ if @response.status >= 400
+ flash[:error] = @response.body
+ render 'new'
+ else
+ # FIXME: handle it
+ render :inline => @response.inspect
+ end
end
private
View
2 app/helpers/admin/mapping_requests_helper.rb
@@ -1,7 +1,7 @@
module Admin::MappingRequestsHelper
def mapping_field_for(form, field)
form.input field.name, {
- as: field.type.to_sym,
+ as: (field.type || :string).to_sym,
hint: field.help_text,
label: field.title,
collection: field.options,
View
6 app/views/admin/mapping_requests/new.html
@@ -1,6 +1,6 @@
-<h2><%= @mapping.name %> &rsaquo; <%= @endpoint.title %> &rsaquo; New Request</h2>
+<h2><%= @mapping.name %> &rsaquo; <%= @endpoint.title %> &rsaquo; New Datacard</h2>
-<%= simple_form_for :request, html: { class: "form-horizontal" } do |f| %>
+<%= simple_form_for :request, method: :post, url: admin_mapping_requests_path(@mapping.id, @endpoint.name), html: { class: "form-horizontal" } do |f| %>
<h3>Settings</h3>
<div class="settings">
<% @mapping.settings.values.each do |setting| %>
@@ -16,6 +16,6 @@
</div>
<div class="form-actions">
- <%= f.button :submit, class: "btn-primary" %>
+ <%= f.button :submit, value: "Request Datacard", class: "btn-primary" %>
</div>
<% end %>
View
2 app/views/admin/mappings/_endpoints.html
@@ -3,6 +3,6 @@
<td><%= endpoint.name %></td>
<td><%= endpoint.title %></td>
<td><%= endpoint.uri %></td>
- <td><%= button_to "Request", new_admin_mapping_request_path(@mapping.id, endpoint.name), class: "btn btn-small", method: "get" %></td>
+ <td><%= button_to "New Datacard", new_admin_mapping_request_path(@mapping.id, endpoint.name), class: "btn btn-small", method: "get" %></td>
</tr>
<% end -%>
View
28 lib/datajam/mappings/example.rb
@@ -1,28 +0,0 @@
-class ExampleMapping < Datajam::Datacard::APIMapping::Base
- name "Example mapping"
- version "1.0"
- authors "Chris Kowalik"
- email "chris@cuboxlabs.com"
- homepage "http://cuboxlabs.com/"
- summary "An example API"
- description "..."
- base_uri "http://127.0.0.1/example/"
-
- setting :api_key, "API Key", :type => :string
-
- get :items, "Example items" do
- uri "/items.json"
-
- param :filter, "Filter", :type => :string
- param :group, "Select group" do
- type :select, :options => ['Foo', 'Bar', 'Baz']
- prompt 'Select something...'
- end
- end
-
- get :users, "Examle users" do
- uri "/users.json"
-
- param :filter, "Filter", :type => :string
- end
-end
2 spec/datajam
@@ -1 +1 @@
-Subproject commit 3add44a7d3f9ab89fa822159073e043bc56c1290
+Subproject commit 68ba1f03f0557575ecec2759766a0e24ee0eeb85

0 comments on commit c637537

Please sign in to comment.