module Trubl::API::Touts

Public Instance Methods

create_tout(params={}) click to toggle source

implements developer.tout.com/api/touts-api/apimethod/create-tout returns Trubl::Tout instance or nil

# File lib/trubl/api/touts.rb, line 73
def create_tout(params={})
  response = if params[:url].nil?
    params[:data] = params[:tout].delete(:data)
    multipart_post("touts", params)
  else
    post("touts", params)
  end

  Trubl::Tout.new.from_response(response)
end
delete_tout(uid) click to toggle source

implements developer.tout.com/api/touts-api/apimethod/delete-tout returns true or false

# File lib/trubl/api/touts.rb, line 96
def delete_tout(uid)
  delete("touts/#{uid}").code == 200
end
latest_touts(per_page=nil, page=nil) click to toggle source

implements developer.tout.com/api/touts-api/apimethod/retrieve-latest-touts returns Array of Trubl::Tout instances or nil

# File lib/trubl/api/touts.rb, line 58
def latest_touts(per_page=nil, page=nil)
  response = get("latest", query: {per_page: per_page, page: page})
  Trubl::Touts.new.from_response(response)
end
like_tout(uid) click to toggle source

implements developer.tout.com/api/touts-api/apimethod/tout ToDo: could return an updated Tout object returns true or false

# File lib/trubl/api/touts.rb, line 103
def like_tout(uid)
  response = post("touts/#{uid}/likes")
  
  JSON.parse(response.body)["like"]["status"] == "liked"
end
retout_tout(uid) click to toggle source
# File lib/trubl/api/touts.rb, line 118
def retout_tout(uid)
  response = post("touts/#{uid}/retouts")
  if response.code == 200
    Trubl::Tout.new.from_response(response)
  else
    nil
  end
end
retrieve_tout(uid) click to toggle source

implements developer.tout.com/api/touts-api/apimethod/retrieve-tout returns Trubl::Tout instance or nil

# File lib/trubl/api/touts.rb, line 27
def retrieve_tout(uid)
  response = get("touts/#{uid}")
  Trubl::Tout.new.from_response(response)
end
retrieve_tout_conversation(uid) click to toggle source

implements developer.tout.com/api/touts-api/apimethod/retrieve-touts-conversation returns Trubl::Conversation instance or nil

# File lib/trubl/api/touts.rb, line 51
def retrieve_tout_conversation(uid)
  response = get("touts/#{uid}/conversation")
  Trubl::Conversation.new.from_response(response)
end
retrieve_touts(uids=[]) click to toggle source

implements developer.tout.com/api/users-api/apimethod/retrieve-touts @param uids [Array<String>] of tout uids @return [Array<Trubl::Tout>]

# File lib/trubl/api/touts.rb, line 35
def retrieve_touts(uids=[])
  uids = (uids.is_a?(Array) ? uids : [uids]).compact.uniq.sort
  return [] if uids.blank?

  requests = uids.in_groups_of(100, false).collect do |uid_group|
    {path: "touts", query: {uids: uid_group.join(',')} }
  end

  multi_request(:get, requests).
    collect { |response| Trubl::Touts.new.from_response(response) }.
    flatten.
    compact
end
retrieve_updates(order=nil, per_page=nil, page=nil) click to toggle source

implements developer.tout.com/api/touts-api/apimethod/retrieve-touts-hashtags-and-users-followed-given-user ToDo: is this api call documented in the right place? returns Array of Trubl::Tout instances or nil

# File lib/trubl/api/touts.rb, line 66
def retrieve_updates(order=nil, per_page=nil, page=nil)
  response = get("me/updates",query: {order: order, per_page: per_page, page: page})
  Trubl::Touts.new.from_response(response)
end
tout_liked_by(uid, order=nil, per_page=nil, page=nil) click to toggle source

implements developer.tout.com/api/touts-api/apimethod/retrieve-list-users-who-have-liked-tout returns Array of Trubl::User instances or nil

# File lib/trubl/api/touts.rb, line 20
def tout_liked_by(uid, order=nil, per_page=nil, page=nil)
  response = get("touts/#{uid}/liked_by", query: {order: order, per_page: per_page, page: page})
  Trubl::Users.new.from_response(response)
end
unlike_tout(uid) click to toggle source

implements developer.tout.com/api/touts-api/apimethod/unlike-tout ToDo: could return an updated Tout object returns true or false

# File lib/trubl/api/touts.rb, line 112
def unlike_tout(uid)
  response = delete("touts/#{uid}/likes")

  JSON.parse(response.body)["like"]["status"] == "not_liked"
end
update_tout(uid, params={}) click to toggle source
# File lib/trubl/api/touts.rb, line 84
def update_tout(uid, params={})
  return nil if params.blank? or params[:tout].blank?

  raise "Not implemented" if params[:tout].keys.map(&:to_sym) != [:text]

  response = put("touts/#{uid}", {body: params})

  Trubl::Tout.new.from_response(response)
end