Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Add upport for jsonp #51

Closed
wants to merge 1 commit into from

3 participants

@cmavromoustakos

Add callbacks to the URLS to support jsonp callbacks for cross domain access to copycopter API

@jonstorer
Collaborator

LGTM

@quentindecock
Collaborator

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 19, 2012
  1. @cmavromoustakos

    Add upport for jsonp

    cmavromoustakos authored
This page is out of date. Refresh to see the latest.
View
4 app/controllers/api/v2/draft_blurbs_controller.rb
@@ -2,9 +2,9 @@ class Api::V2::DraftBlurbsController < Api::V2::BaseController
def index
if stale? :etag => current_project.etag
if params[:format] == "hierarchy"
- render :json => current_project.draft_json(:hierarchy => true)
+ render :json => current_project.draft_json(:hierarchy => true), :callback => params[:callback]
else
- render :json => current_project.draft_json
+ render :json => current_project.draft_json, :callback => params[:callback]
end
end
end
View
4 app/controllers/api/v2/published_blurbs_controller.rb
@@ -2,9 +2,9 @@ class Api::V2::PublishedBlurbsController < Api::V2::BaseController
def index
if stale? :etag => current_project.etag
if params[:format] == "hierarchy"
- render :json => current_project.published_json(:hierarchy => true)
+ render :json => current_project.published_json(:hierarchy => true), :callback => params[:callback]
else
- render :json => current_project.published_json
+ render :json => current_project.published_json, :callback => params[:callback]
end
end
end
View
23 features/api_v2_download.feature
@@ -60,7 +60,7 @@ Feature: Download blurbs for a project through API
| en.test.one | expected one |
| en.test.two | expected two |
And I POST the v2 API URI for "Breakfast" deploys
- When I GET the v2 API URI for "Breakfast" published blurbs with a hierarchy param
+ When I GET the v2 API URI for "Breakfast" published blurbs with a "format=hierarchy" param
Then I should receive a HTTP 200
And I should receive the following JSON response:
"""
@@ -79,7 +79,7 @@ Feature: Download blurbs for a project through API
When I POST the v2 API URI for "Breakfast" draft blurbs:
| en.test.one | expected one |
| en.test.two | expected two |
- And I GET the v2 API URI for "Breakfast" draft blurbs with a hierarchy param
+ And I GET the v2 API URI for "Breakfast" draft blurbs with a "format=hierarchy" param
Then I should receive a HTTP 200
And I should receive the following JSON response:
"""
@@ -92,3 +92,22 @@ Feature: Download blurbs for a project through API
}
}
"""
+
+ Scenario: download published blurbs with a json hieratchy for a known project
+ Given a project exists with a name of "Breakfast"
+ When I POST the v2 API URI for "Breakfast" draft blurbs:
+ | en.test.one | expected one |
+ | en.test.two | expected two |
+ And I POST the v2 API URI for "Breakfast" deploys
+ When I GET the v2 API URI for "Breakfast" published blurbs with a "callback=jsonp" param
+ Then I should receive a HTTP 200
+ And the response should be wrapped in a "jsonp" callback function
+
+ Scenario: download draft blurbs with a json hieratchy for a known project
+ Given a project exists with a name of "Breakfast"
+ When I POST the v2 API URI for "Breakfast" draft blurbs:
+ | en.test.one | expected one |
+ | en.test.two | expected two |
+ When I GET the v2 API URI for "Breakfast" draft blurbs with a "callback=jsonp" param
+ Then I should receive a HTTP 200
+ And the response should be wrapped in a "jsonp" callback function
View
17 features/step_definitions/api_v2_steps.rb
@@ -1,16 +1,16 @@
-When /^I GET the v2 API URI for "([^"]*)" draft blurbs( with a hierarchy param)?$/ do |project_name, hierarchy|
+When /^I GET the v2 API URI for "([^"]*)" draft blurbs( with a "([^"]*)" param)?$/ do |project_name, skip, param|
project = Project.find_by_name!(project_name)
- if hierarchy
- get_with_etag "/api/v2/projects/#{project.api_key}/draft_blurbs?format=hierarchy"
+ if param
+ get_with_etag "/api/v2/projects/#{project.api_key}/draft_blurbs?#{param}"
else
get_with_etag "/api/v2/projects/#{project.api_key}/draft_blurbs"
end
end
-When /^I GET the v2 API URI for "([^"]*)" published blurbs( with a hierarchy param)?$/ do |project_name, hierarchy|
+When /^I GET the v2 API URI for "([^"]*)" published blurbs( with a "([^"]*)" param)?$/ do |project_name, skip, param|
project = Project.find_by_name!(project_name)
- if hierarchy
- get_with_etag "/api/v2/projects/#{project.api_key}/published_blurbs?format=hierarchy"
+ if param
+ get_with_etag "/api/v2/projects/#{project.api_key}/published_blurbs?#{param}"
else
get_with_etag "/api/v2/projects/#{project.api_key}/published_blurbs"
end
@@ -59,3 +59,8 @@
actual_result = JSON.parse(page.source)
actual_result.should == JSON.parse(string)
end
+
+Then /^the response should be wrapped in a "([^"]*)" callback function$/ do |callback_function|
+ page.source =~ /^#{callback_function}/
+end
+
Something went wrong with that request. Please try again.