Created
December 29, 2014 15:16
-
-
Save soeffing/32965d08d0838a8ee4a1 to your computer and use it in GitHub Desktop.
API interface
This file contains hidden or 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 AdsController < ApplicationController | |
before_action :require_auth, :default_params | |
# rubocop:disable Style/MethodLength | |
def index | |
@contest = Contest.find(@params[:contest_id], cookies, {}) | |
query_params = 'embed[resource]=[id,image.url(:detail_preview),url(:mp4),url(:ogg)]' \ | |
'&embed[nested][user][profile]=[email][last_name,first_name,avatar.url(:detail)]' \ | |
'&embed[votes]=[all,rate,user_id]' \ | |
'&embed[contest]=[id]' \ | |
'&embed[shortlists]=[all,id,ad_id]' \ | |
'&embed[my_favorites]=[all,id,ad_id,user_id]' \ | |
'&embed[ad_ratings]=[all,id,value,user_id,ad_rating_category_id]' | |
pager = Ad.all(cookies, query_params) | |
@current_page, @total_pages = pager.current_page, pager.total_pages | |
@ads = AdDecorator.decorate_collection(pager.data) | |
end | |
end | |
class Ad < Hashie::Mash | |
include Paginable | |
include Draper::Decoratable | |
def self.all(cookies, params) | |
response = ZOOPPA_API.do_request( | |
'ads', | |
method: :get, | |
authenticate: true, | |
cookies: cookies, | |
params: params | |
) | |
Pager.new(Ad, response) | |
end | |
def self.find(id, cookies, params) | |
response = ZOOPPA_API.do_request( | |
'ads', | |
method: :get, | |
id: id, | |
authenticate: true, | |
cookies: cookies, | |
params: params | |
) | |
Ad.new(response) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment