Module: Trubl::API::Touts
- Included in:
- Client
- Defined in:
- lib/trubl/api/touts.rb
Instance Method Summary collapse
-
#create_tout(params = {}) ⇒ Object
implements http://developer.tout.com/api/touts-api/apimethod/create-tout returns Trubl::Tout instance or nil.
-
#delete_tout(uid) ⇒ Object
implements http://developer.tout.com/api/touts-api/apimethod/delete-tout returns true or false.
-
#featured_touts(opts = {}) ⇒ Object
http://developer.tout.com/api/touts-api/apimethod/retrieve-list-featured-touts returns Array of Trubl::Tout instances or nil.
-
#latest_touts(per_page = nil, page = nil) ⇒ Object
implements http://developer.tout.com/api/touts-api/apimethod/retrieve-latest-touts returns Array of Trubl::Tout instances or nil.
-
#like_tout(uid) ⇒ Object
implements http://developer.tout.com/api/touts-api/apimethod/tout ToDo: could return an updated Tout object returns true or false.
- #retout_tout(uid) ⇒ Object
-
#retrieve_tout(uid) ⇒ Object
implements http://developer.tout.com/api/touts-api/apimethod/retrieve-tout returns Trubl::Tout instance or nil.
-
#retrieve_tout_conversation(uid) ⇒ Object
implements http://developer.tout.com/api/touts-api/apimethod/retrieve-touts-conversation returns Trubl::Conversation instance or nil.
- #retrieve_touts(uids = []) ⇒ Array<Trubl::Tout>
-
#retrieve_updates(order = nil, per_page = nil, page = nil) ⇒ Object
implements http://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.
-
#tout_liked_by(uid, order = nil, per_page = nil, page = nil) ⇒ Object
implements http://developer.tout.com/api/touts-api/apimethod/retrieve-list-users-who-have-liked-tout returns Array of Trubl::User instances or nil.
-
#unlike_tout(uid) ⇒ Object
implements http://developer.tout.com/api/touts-api/apimethod/unlike-tout ToDo: could return an updated Tout object returns true or false.
- #update_tout(uid, params = {}) ⇒ Object
Instance Method Details
#create_tout(params = {}) ⇒ Object
implements http://developer.tout.com/api/touts-api/apimethod/create-tout returns Trubl::Tout instance or nil
73 74 75 76 77 78 79 80 81 82 |
# 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) ⇒ Object
implements http://developer.tout.com/api/touts-api/apimethod/delete-tout returns true or false
96 97 98 |
# File 'lib/trubl/api/touts.rb', line 96 def delete_tout(uid) delete("touts/#{uid}").code == 200 end |
#featured_touts(opts = {}) ⇒ Object
http://developer.tout.com/api/touts-api/apimethod/retrieve-list-featured-touts returns Array of Trubl::Tout instances or nil
13 14 15 16 |
# File 'lib/trubl/api/touts.rb', line 13 def featured_touts(opts={}) response = get("featured", query: {per_page: opts[:per_page], page: opts[:page]}) Trubl::Touts.new.from_response(response) end |
#latest_touts(per_page = nil, page = nil) ⇒ Object
implements http://developer.tout.com/api/touts-api/apimethod/retrieve-latest-touts returns Array of Trubl::Tout instances or nil
58 59 60 61 |
# 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) ⇒ Object
implements http://developer.tout.com/api/touts-api/apimethod/tout ToDo: could return an updated Tout object returns true or false
103 104 105 106 107 |
# 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) ⇒ Object
118 119 120 121 122 123 124 125 |
# 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) ⇒ Object
implements http://developer.tout.com/api/touts-api/apimethod/retrieve-tout returns Trubl::Tout instance or nil
27 28 29 30 |
# 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) ⇒ Object
implements http://developer.tout.com/api/touts-api/apimethod/retrieve-touts-conversation returns Trubl::Conversation instance or nil
51 52 53 54 |
# 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 = []) ⇒ Array<Trubl::Tout>
35 36 37 38 39 40 41 42 43 44 45 46 47 |
# 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) ⇒ Object
implements http://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
66 67 68 69 |
# 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) ⇒ Object
implements http://developer.tout.com/api/touts-api/apimethod/retrieve-list-users-who-have-liked-tout returns Array of Trubl::User instances or nil
20 21 22 23 |
# 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) ⇒ Object
implements http://developer.tout.com/api/touts-api/apimethod/unlike-tout ToDo: could return an updated Tout object returns true or false
112 113 114 115 116 |
# 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 = {}) ⇒ Object
84 85 86 87 88 89 90 91 92 |
# 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 |