Add checkins
This commit is contained in:
@@ -5,12 +5,18 @@ module Adamantium
|
||||
|
||||
cont_type = content_type(params)
|
||||
req_type = request_type(params)
|
||||
req_params = parse_params(req_type, cont_type, params)
|
||||
|
||||
if cont_type == :bookmark
|
||||
req_params = parse_post_params(req_type, cont_type, params)
|
||||
return Entities::BookmarkRequest.new(req_params)
|
||||
end
|
||||
|
||||
if cont_type == :checkin
|
||||
checkin_params = parse_checkin_params(params)
|
||||
return Entities::CheckinRequest.new(checkin_params)
|
||||
end
|
||||
|
||||
req_params = parse_post_params(req_type, cont_type, params)
|
||||
Entities::PostRequest.new(req_params)
|
||||
end
|
||||
|
||||
@@ -18,6 +24,7 @@ module Adamantium
|
||||
|
||||
def content_type(params)
|
||||
return :bookmark if params[:"bookmark-of"]
|
||||
return :checkin if params.dig(:properties, :checkin)
|
||||
:post
|
||||
end
|
||||
|
||||
@@ -33,7 +40,7 @@ module Adamantium
|
||||
nil
|
||||
end
|
||||
|
||||
def parse_params(req_type, post_type, params)
|
||||
def parse_post_params(req_type, post_type, params)
|
||||
new_params = {}
|
||||
new_params[:h] = "entry"
|
||||
new_params[:post_type] = post_type
|
||||
@@ -56,7 +63,13 @@ module Adamantium
|
||||
new_params[:slug] = params[:slug] || params["mp-slug"]
|
||||
new_params[:published_at] = (params[:"post-status"] == "draft") ? nil : publish_time
|
||||
new_params[:category] = params[:category] || []
|
||||
new_params[:photos] = params[:photo] || []
|
||||
new_params[:photos] = if params[:photo].is_a?(String)
|
||||
{value: params[:photo], alt: ""}
|
||||
elsif params[:photo].nil?
|
||||
[]
|
||||
else
|
||||
params[:photo]
|
||||
end
|
||||
new_params[:location] = params[:location]
|
||||
|
||||
content = if params[:content]
|
||||
@@ -74,5 +87,24 @@ module Adamantium
|
||||
|
||||
new_params
|
||||
end
|
||||
|
||||
def parse_checkin_params(params)
|
||||
new_params = {}
|
||||
|
||||
checkin = params.dig(:properties, :checkin).first
|
||||
new_params[:h] = "entry"
|
||||
new_params[:syndication_sources] = params.dig(:properties, :syndication)
|
||||
new_params[:name] = checkin.dig(:properties, :name).first
|
||||
new_params[:content] = params.dig(:properties, :content)&.first
|
||||
new_params[:url] = checkin.dig(:properties, :url)&.first
|
||||
new_params[:slug] = SecureRandom.uuid
|
||||
new_params[:category] = params.dig(:properties, :category)
|
||||
new_params[:published_at] = params.dig(:properties, :published)&.first
|
||||
new_params[:post_type] = :checkin
|
||||
location = params.dig(:properties, :location).first[:properties]
|
||||
new_params[:photos] = []
|
||||
new_params[:location] = "geo:#{location.dig(:latitude).first},#{location.dig(:longitude).first};u=0"
|
||||
new_params
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user