trubl 1.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (105) hide show
  1. data/.yardopts +8 -0
  2. data/LICENSE.md +20 -0
  3. data/README.md +72 -0
  4. data/Rakefile +11 -0
  5. data/lib/trubl.rb +30 -0
  6. data/lib/trubl/api/category.rb +33 -0
  7. data/lib/trubl/api/channel.rb +32 -0
  8. data/lib/trubl/api/conversation.rb +31 -0
  9. data/lib/trubl/api/hashtags.rb +45 -0
  10. data/lib/trubl/api/me.rb +68 -0
  11. data/lib/trubl/api/search.rb +35 -0
  12. data/lib/trubl/api/streams.rb +14 -0
  13. data/lib/trubl/api/suggested_users.rb +16 -0
  14. data/lib/trubl/api/touts.rb +143 -0
  15. data/lib/trubl/api/users.rb +79 -0
  16. data/lib/trubl/authorization.rb +7 -0
  17. data/lib/trubl/authorizations.rb +8 -0
  18. data/lib/trubl/base.rb +37 -0
  19. data/lib/trubl/category.rb +7 -0
  20. data/lib/trubl/channel.rb +7 -0
  21. data/lib/trubl/client.rb +252 -0
  22. data/lib/trubl/collection.rb +43 -0
  23. data/lib/trubl/conversation.rb +7 -0
  24. data/lib/trubl/hashtag.rb +7 -0
  25. data/lib/trubl/hashtags.rb +8 -0
  26. data/lib/trubl/oauth.rb +56 -0
  27. data/lib/trubl/pagination.rb +17 -0
  28. data/lib/trubl/tout.rb +29 -0
  29. data/lib/trubl/touts.rb +8 -0
  30. data/lib/trubl/user.rb +29 -0
  31. data/lib/trubl/users.rb +8 -0
  32. data/lib/trubl/version.rb +16 -0
  33. data/lib/trubl/widget.rb +15 -0
  34. data/lib/trubl/widgets.rb +8 -0
  35. data/spec/fixtures/category_response.json +1 -0
  36. data/spec/fixtures/category_touts_response.json +689 -0
  37. data/spec/fixtures/category_users_response.json +1709 -0
  38. data/spec/fixtures/channel_response.json +1 -0
  39. data/spec/fixtures/channel_touts_response.json +1 -0
  40. data/spec/fixtures/channel_users_response.json +1 -0
  41. data/spec/fixtures/client1_auth_resp.json +1 -0
  42. data/spec/fixtures/client2_auth_resp.json +1 -0
  43. data/spec/fixtures/conversation_authors_response.json +37 -0
  44. data/spec/fixtures/conversation_response.json +41 -0
  45. data/spec/fixtures/conversation_touts_response.json +107 -0
  46. data/spec/fixtures/featured_touts_response.json +4249 -0
  47. data/spec/fixtures/hashtag_response.json +1 -0
  48. data/spec/fixtures/hashtags_touts_response.json +304 -0
  49. data/spec/fixtures/latest_touts_response.json +3600 -0
  50. data/spec/fixtures/like_tout_response.json +109 -0
  51. data/spec/fixtures/me_authorizations_response.json +14 -0
  52. data/spec/fixtures/me_fb_sharing_response.json +21 -0
  53. data/spec/fixtures/me_friends_response.json +121 -0
  54. data/spec/fixtures/me_retrieve_user_friends_response.json +174 -0
  55. data/spec/fixtures/me_retrieve_user_liked_touts_response.json +1255 -0
  56. data/spec/fixtures/me_retrieve_user_touts_response.json +479 -0
  57. data/spec/fixtures/retout_tout_response.json +99 -0
  58. data/spec/fixtures/retrieve_me_response.json +35 -0
  59. data/spec/fixtures/retrieve_tout.json +98 -0
  60. data/spec/fixtures/retrieve_tout_response.json +98 -0
  61. data/spec/fixtures/search_hashtags_response.json +100 -0
  62. data/spec/fixtures/search_touts_response.json +304 -0
  63. data/spec/fixtures/search_users_response.json +37 -0
  64. data/spec/fixtures/suggested_hashtags_response.json +137 -0
  65. data/spec/fixtures/suggested_users_response.json +1 -0
  66. data/spec/fixtures/test.mp4 +0 -0
  67. data/spec/fixtures/tout.json +98 -0
  68. data/spec/fixtures/tout_conversation_response.json +41 -0
  69. data/spec/fixtures/touts_liked_by_response.json +65 -0
  70. data/spec/fixtures/touts_liked_by_user_response.json +106 -0
  71. data/spec/fixtures/touts_me_updates_response.json +357 -0
  72. data/spec/fixtures/touts_search_results.json +304 -0
  73. data/spec/fixtures/trending_hashtags_response.json +149 -0
  74. data/spec/fixtures/unlike_tout_response.json +109 -0
  75. data/spec/fixtures/update_me_response.json +35 -0
  76. data/spec/fixtures/user.json +28 -0
  77. data/spec/fixtures/user_followers.json +1409 -0
  78. data/spec/fixtures/user_touts_response.json +479 -0
  79. data/spec/fixtures/user_with_utf8.json +29 -0
  80. data/spec/fixtures/users.json +58 -0
  81. data/spec/fixtures/users_search_results.json +37 -0
  82. data/spec/fixtures/widgets.json +142 -0
  83. data/spec/spec_helper.rb +61 -0
  84. data/spec/trubl/api/category_spec.rb +39 -0
  85. data/spec/trubl/api/channel_spec.rb +39 -0
  86. data/spec/trubl/api/conversation_spec.rb +38 -0
  87. data/spec/trubl/api/hashtags_spec.rb +60 -0
  88. data/spec/trubl/api/me_spec.rb +98 -0
  89. data/spec/trubl/api/search_spec.rb +40 -0
  90. data/spec/trubl/api/streams_spec.rb +18 -0
  91. data/spec/trubl/api/suggested_users_spec.rb +17 -0
  92. data/spec/trubl/api/touts_spec.rb +215 -0
  93. data/spec/trubl/api/users_spec.rb +122 -0
  94. data/spec/trubl/base_spec.rb +88 -0
  95. data/spec/trubl/category_spec.rb +15 -0
  96. data/spec/trubl/channel_spec.rb +16 -0
  97. data/spec/trubl/client_spec.rb +141 -0
  98. data/spec/trubl/conversation_spec.rb +13 -0
  99. data/spec/trubl/hashtag_spec.rb +11 -0
  100. data/spec/trubl/oauth_spec.rb +27 -0
  101. data/spec/trubl/tout_spec.rb +41 -0
  102. data/spec/trubl/user_spec.rb +65 -0
  103. data/spec/trubl_spec.rb +23 -0
  104. data/trubl.gemspec +41 -0
  105. metadata +494 -0
@@ -0,0 +1,8 @@
1
+ --no-private
2
+ --protected
3
+ --tag rate_limited:"Rate Limited?"
4
+ --tag authentication_required:"Authentication Required?"
5
+ --markup markdown
6
+ -
7
+ LICENSE.md
8
+ README.md
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 Aaron Terrell
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,72 @@
1
+ # Trubl
2
+
3
+ A Ruby 1.9 interface for the Tout API. Right now, the read only API calls have been implemented,
4
+ but given proper user auth implementation, the infrastructure is ready for writing back as well.
5
+
6
+ [![Build Status](https://api.travis-ci.org/Tout/trubl.png)](https://travis-ci.org/Tout/trubl)
7
+
8
+ Intended as sample code initially, help take it to greatness!
9
+
10
+ See http://developer.tout.com/ and https://github.com/Tout/trubl for details.
11
+
12
+ # Using Trubl
13
+
14
+ ## Requirements
15
+
16
+ * Ruby
17
+ * Battle tested with MRI 1.9.3
18
+ * Specs pass for JRuby 1.7.3
19
+ * Unkown for Rbx 2.0.0rc1
20
+ * On Debian or Ubuntu you should run `sudo apt-get install libcurl4-gnutls-dev`
21
+
22
+ ## Installation
23
+ ```sh
24
+ bundle install
25
+ ```
26
+
27
+ ## Run unit tests
28
+ ```sh
29
+ bundle exec rspec -d -f d
30
+ ```
31
+
32
+ ## Run sample script with valid app credentials
33
+ ```sh
34
+ export CLIENT_ID=#{your client id}
35
+ export CLIENT_SECRET=#{your client secret}
36
+ export CALLBACK_URL=#{your callback url}
37
+ bundle exec ruby bin/trubl_sample
38
+ ```
39
+
40
+ ## Use a client instance
41
+ Get a client instance, and authenticate with tout.com:
42
+ ```rb
43
+ client = Trubl.client('client_id', 'client_secret')
44
+ client.auth()
45
+ # or
46
+ client = Trubl::Client.new('client_id', 'client_secret')
47
+ client.auth()
48
+ ```
49
+
50
+ Search for users matching a keyword
51
+ ```rb
52
+ collection = client.search_users('aaron', 2, 4)
53
+ collection.pagination
54
+ # => hash of pagination data
55
+ collection.users
56
+ # => get an array of Trubl::User instances
57
+ ```
58
+
59
+ etc, etc
60
+
61
+ ## Contributing to trubl
62
+
63
+ * Fork the project.
64
+ * Start a feature/bugfix branch.
65
+ * Commit and push until you are happy with your contribution.
66
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
67
+
68
+ ## Copyright
69
+
70
+ Copyright (c) 2013 Aaron Terrell, Tout. See LICENSE.txt for
71
+ further details.
72
+
@@ -0,0 +1,11 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ require 'rspec/core/rake_task'
5
+ RSpec::Core::RakeTask.new(:spec)
6
+
7
+ task :test => :spec
8
+ task :default => :spec
9
+
10
+ require 'yard'
11
+ YARD::Rake::YardocTask.new
@@ -0,0 +1,30 @@
1
+ if RUBY_ENGINE == 'ruby'
2
+ require 'yajl'
3
+ require 'yajl/json_gem'
4
+ end
5
+
6
+ require 'logger'
7
+ require 'trubl/client'
8
+
9
+ module Trubl
10
+ class << self
11
+
12
+ # Returns a Trubl::Client instance
13
+ #
14
+ # @param [String] client_id
15
+ # @param [String] client_secret
16
+ # @param [String] access_token
17
+ # @return [Trubl::Client]
18
+ def client(client_id='', client_secret='', callback_url='', access_token=nil)
19
+ @client = Trubl::Client.new(client_id, client_secret, callback_url, access_token) unless defined?(@client) && @client.access_token == access_token && @client.access_token != nil
20
+ @client
21
+ end
22
+
23
+ def logger(level=Logger::INFO)
24
+ @logger = Logger.new(STDOUT) unless defined?(@logger) and @logger.level != level
25
+ @logger.level = level
26
+ @logger
27
+ end
28
+
29
+ end
30
+ end
@@ -0,0 +1,33 @@
1
+ require_relative '../category'
2
+ require_relative '../channel'
3
+ require_relative '../users'
4
+ require_relative '../touts'
5
+
6
+ module Trubl
7
+ module API
8
+ module Category
9
+
10
+ # implements categories/:uid
11
+ # returns Trubl::Category instance or nil
12
+ def retrieve_category(uid)
13
+ response = get("categories/#{uid}")
14
+ Trubl::Category.new(JSON.parse(response.body)["category"])
15
+ end
16
+
17
+ # implements categories/:uid/users
18
+ # returns Array of Trubl::User instances or nil
19
+ def retrieve_category_users(uid, order=nil, per_page=nil, page=nil)
20
+ response = get("categories/#{uid}/users", query: {order: order, per_page: per_page, page: page})
21
+ Trubl::Users.new.from_response(response)
22
+ end
23
+
24
+ # implements categories/:uid/touts
25
+ # returns Array of Trubl::Tout instances or nil
26
+ def retrieve_category_touts(uid, order=nil, per_page=nil, page=nil)
27
+ response = get("categories/#{uid}/touts", query: {order: order, per_page: per_page, page: page})
28
+ Trubl::Touts.new.from_response(response)
29
+ end
30
+
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,32 @@
1
+ require_relative '../channel'
2
+ require_relative '../users'
3
+ require_relative '../touts'
4
+
5
+ module Trubl
6
+ module API
7
+ module Channel
8
+
9
+ # implements http://developer.tout.com/api/channel-api/apimethod/retrieve-channel
10
+ # returns Trubl::Channel instance or nil
11
+ def retrieve_channel(uid)
12
+ response = get("/api/v1/channels/#{uid}")
13
+ Trubl::Channel.new(JSON.parse(response.body)["channel"])
14
+ end
15
+
16
+ # implements http://developer.tout.com/api/channel-api/apimethod/retrieve-channel-users
17
+ # returns Array of Trubl::User instances or nil
18
+ def retrieve_channel_users(uid, order=nil, per_page=nil, page=nil)
19
+ response = get("/api/v1/channels/#{uid}/users", query: {order: order, per_page: per_page, page: page})
20
+ Trubl::Users.new.from_response(response)
21
+ end
22
+
23
+ # implements http://developer.tout.com/api/channel-api/apimethod/retrieve-channel-touts
24
+ # returns Array of Trubl::Tout instances or nil
25
+ def retrieve_channel_touts(uid, order=nil, per_page=nil, page=nil)
26
+ response = get("/api/v1/channels/#{uid}/touts", query: {order: order, per_page: per_page, page: page})
27
+ Trubl::Touts.new.from_response(response)
28
+ end
29
+
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,31 @@
1
+ require_relative '../conversation'
2
+ require_relative '../touts'
3
+
4
+ module Trubl
5
+ module API
6
+ module Conversation
7
+
8
+ # implements http://developer.tout.com/api/conversation-api/apimethod/retrieve-conversation
9
+ # returns Trubl::Conversation instance or nil
10
+ def retrieve_conversation(uid)
11
+ response = get("conversations/#{uid}")
12
+ Trubl::Conversation.new.from_response(response)
13
+ end
14
+
15
+ # implements http://developer.tout.com/api/conversation-api/apimethod/retrieve-conversation-participants
16
+ # returns Array of Trubl::User instances or nil
17
+ def retrieve_conversation_participants(uid, order=nil, per_page=nil, page=nil)
18
+ response = get("conversations/#{uid}/authors", query: {order: order, per_page: per_page, page: page})
19
+ Trubl::Users.new.from_response(response)
20
+ end
21
+
22
+ # implements http://developer.tout.com/api/conversation-api/apimethod/retrieve-conversation-touts
23
+ # returns Array of Trubl::Tout instances or nil
24
+ def retrieve_conversation_touts(uid, order=nil, per_page=nil, page=nil)
25
+ response = get("conversations/#{uid}/touts", query: {order: order, per_page: per_page, page: page})
26
+ Trubl::Touts.new.from_response(response)
27
+ end
28
+
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,45 @@
1
+ require_relative '../hashtags'
2
+ require_relative '../touts'
3
+
4
+ module Trubl
5
+ module API
6
+ module Hashtags
7
+
8
+ # returns Trubl::Hashtag instance or nil
9
+ def retrieve_hashtag(uid)
10
+ response = get("hashtags/#{uid}")
11
+ Trubl::Hashtag.new.from_response(response)
12
+ end
13
+
14
+ # implements http://developer.tout.com/api/hashtags-api/apimethod/retrieve-hashtags-touts
15
+ # returns Array of Trubl::Hastag instances or nil
16
+ def retrieve_hashtag_touts(uid, order=nil, per_page=nil, page=nil)
17
+ response = get("hashtags/#{uid}/touts", query: {order: order, per_page: per_page, page: page})
18
+ Trubl::Touts.new.from_response(response)
19
+ end
20
+
21
+ # http://developer.tout.com/api/hashtags-api/apimethod/retrieve-list-trending-hashtags
22
+ # returns Array of Trubl::Hastag instances or nil
23
+ def retrieve_trending_hashtags(per_page=nil, page=nil)
24
+ response = get("trending_hashtags", query: {per_page: per_page, page: page})
25
+ Trubl::Hashtags.new.from_response(response)
26
+ end
27
+
28
+ # implements http://developer.tout.com/api/conversation-api/apimethod/retrieve-conversation
29
+ # returns Array of Trubl::Hastag instances or nil
30
+ def retrieve_suggested_hashtags(q, limit=nil)
31
+ response = get("suggested_hashtags", query: {q: q, limit: limit})
32
+ Trubl::Hashtags.new.from_response(response)
33
+ end
34
+
35
+ def follow_hashtag(uid)
36
+ post("/api/v1/hashtags/#{uid}/subscribes")
37
+ end
38
+
39
+ def unfollow_hashtag(uid)
40
+ delete("/api/v1/hashtags/#{uid}/subscribes")
41
+ end
42
+
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,68 @@
1
+ require_relative '../user'
2
+ require_relative '../authorizations'
3
+
4
+ module Trubl
5
+ module API
6
+ module Me
7
+ # implements http://developer.tout.com/api-overview/me-api
8
+
9
+ # implements http://developer.tout.com/api/me-api/apimethod/retrieve-authenticated-user
10
+ # returns Trubl::User instance or nil
11
+ def get_me
12
+ Trubl::User.new.from_response(get("me"))
13
+ end
14
+
15
+ # TODO update_me should return meaningful exceptions instead of nil
16
+ def update_me(params={})
17
+ return nil if params.blank? or params[:user].blank?
18
+
19
+ allowed_properties = [:email, :password, :password_confirmation, :username, :avatar, :fullname, :location, :bio, :headline]
20
+ unallowed_properties = params[:user].keys.map(&:to_sym) - allowed_properties
21
+
22
+ raise "#{unallowed_properties.join(', ')} are not supported" if unallowed_properties.present?
23
+
24
+ response = put("me", {body: params})
25
+
26
+ Trubl::User.new.from_response(response)
27
+ end
28
+
29
+ # implements me/authorizations
30
+ def get_my_authorizations
31
+ response = get("me/authorizations")
32
+ Trubl::Authorizations.new.from_response(response)
33
+ end
34
+
35
+ # implements http://developer.tout.com/api/me-api/apimethod/retrieve-sharing-settings
36
+ def get_my_fb_sharing_settings
37
+ response = get("me/sharing/facebook")
38
+ JSON.parse(response.body)
39
+ end
40
+
41
+ # implements http://developer.tout.com/api/me-api/apimethod/retrieve-list-touts-authenticated-user
42
+ # returns Array of Trubl::Tout instances or nil
43
+ def get_my_touts(order="most_recent_first", per_page=nil, page=nil)
44
+ response = get("me/touts", query: {order: order, per_page: per_page, page: page})
45
+ Trubl::Touts.new.from_response(response)
46
+ end
47
+
48
+ # returns Array of Trubl::Tout instances or nil
49
+ def get_my_liked_touts(order="most_recent_first", per_page=nil, page=nil)
50
+ response = get("me/likes", query: {order: order, per_page: per_page, page: page})
51
+ Trubl::Touts.new.from_response(response)
52
+ end
53
+
54
+ # returns Array of Trubl::User instances or nil
55
+ def friends(order=nil, per_page=nil, page=nil)
56
+ response = get("me/friends", query: {order: order, per_page: per_page, page: page})
57
+ Trubl::Users.new.from_response(response)
58
+ end
59
+
60
+ # order, per_page, page arent supported at the moment
61
+ def widgets(order=nil, per_page=nil, page=nil)
62
+ response = get("me/widgets")
63
+ Trubl::Widgets.new.from_response(response)
64
+ end
65
+
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,35 @@
1
+ require_relative '../hashtags'
2
+ require_relative '../touts'
3
+ require_relative '../users'
4
+
5
+ module Trubl
6
+ module API
7
+ module Search
8
+ # implements http://developer.tout.com/api-overview/search-api
9
+
10
+ def search_hashtags(query, per_page=nil, page=nil)
11
+ response = search('hashtags', query, per_page, page)
12
+ Trubl::Hashtags.new.from_response(response)
13
+ end
14
+
15
+ def search_users(query, per_page=nil, page=nil)
16
+ response = search('users', query, per_page, page)
17
+ Trubl::Users.new.from_response(response)
18
+ end
19
+
20
+ # implements http://developer.tout.com/api/search-api/apimethod/search-touts
21
+ def search_touts(query, per_page=nil, page=nil)
22
+ response = search('touts', query, per_page, page)
23
+ Trubl::Touts.new.from_response(response)
24
+ end
25
+
26
+ private
27
+
28
+ def search(type, query, per_page=nil, page=nil)
29
+ response = get("search/#{type}", query: {q: query, per_page: per_page, page: page})
30
+ response
31
+ end
32
+
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,14 @@
1
+ require_relative '../touts'
2
+
3
+ module Trubl
4
+ module API
5
+ module Streams
6
+
7
+ def retrieve_stream_touts(uid, order=nil, per_page=nil, page=nil)
8
+ response = get("streams/#{uid}/touts", query: {order: order, per_page: per_page, page: page})
9
+ Trubl::Touts.new.from_response(response)
10
+ end
11
+
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,16 @@
1
+ require_relative '../users'
2
+
3
+ module Trubl
4
+ module API
5
+ module Suggested_Users
6
+
7
+ # http://localhost:3000/api/v1/suggested_users.json?access_token=aa054fba7f546a2cafc1f6b960c0742cd45eabb8e188044704efb36ce8d1d5ae&q=puiyee
8
+ # returns Array of Trubl::User instances or nil
9
+ def suggested_users(query, per_page=nil, page=nil)
10
+ response = get("suggested_users.json", query: {q: query, per_page: per_page, page: page})
11
+ Trubl::Users.new.from_response(response)
12
+ end
13
+
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,143 @@
1
+ require_relative '../touts'
2
+ require_relative '../users'
3
+
4
+ # todo: all api modules should simply return responses
5
+
6
+ module Trubl
7
+ module API
8
+ module Touts
9
+ # implements http://developer.tout.com/api-overview/touts-api
10
+
11
+ # http://developer.tout.com/api/touts-api/apimethod/retrieve-list-featured-touts
12
+ # returns Array of Trubl::Tout instances or nil
13
+ def featured_touts(opts={})
14
+ response = get("featured", query: {per_page: opts[:per_page], page: opts[:page]})
15
+ Trubl::Touts.new.from_response(response)
16
+ end
17
+
18
+ # implements http://developer.tout.com/api/touts-api/apimethod/retrieve-list-users-who-have-liked-tout
19
+ # returns Array of Trubl::User instances or nil
20
+ def tout_liked_by(uid, order=nil, per_page=nil, page=nil)
21
+ response = get("touts/#{uid}/liked_by", query: {order: order, per_page: per_page, page: page})
22
+ Trubl::Users.new.from_response(response)
23
+ end
24
+
25
+ # implements http://developer.tout.com/api/touts-api/apimethod/retrieve-tout
26
+ # returns Trubl::Tout instance or nil
27
+ def retrieve_tout(uid)
28
+ response = get("touts/#{uid}")
29
+ Trubl::Tout.new.from_response(response)
30
+ end
31
+
32
+ # implements http://developer.tout.com/api/users-api/apimethod/retrieve-touts
33
+ # @param uids [Array<String>] of tout uids
34
+ # @return [Array<Trubl::Tout>]
35
+ def retrieve_touts(uids=[])
36
+ uids = (uids.is_a?(Array) ? uids : [uids]).compact.uniq.sort
37
+ return [] if uids.blank?
38
+
39
+ requests = uids.in_groups_of(100, false).collect do |uid_group|
40
+ {path: "touts", query: {uids: uid_group.join(',')} }
41
+ end
42
+
43
+ multi_request(:get, requests).
44
+ collect { |response| Trubl::Touts.new.from_response(response) }.
45
+ flatten.
46
+ compact
47
+ end
48
+
49
+ # implements http://developer.tout.com/api/touts-api/apimethod/retrieve-touts-conversation
50
+ # returns Trubl::Conversation instance or nil
51
+ def retrieve_tout_conversation(uid)
52
+ response = get("touts/#{uid}/conversation")
53
+ Trubl::Conversation.new.from_response(response)
54
+ end
55
+
56
+ # implements http://developer.tout.com/api/touts-api/apimethod/retrieve-latest-touts
57
+ # returns Array of Trubl::Tout instances or nil
58
+ def latest_touts(per_page=nil, page=nil)
59
+ response = get("latest", query: {per_page: per_page, page: page})
60
+ Trubl::Touts.new.from_response(response)
61
+ end
62
+
63
+ # implements http://developer.tout.com/api/touts-api/apimethod/retrieve-touts-hashtags-and-users-followed-given-user
64
+ # ToDo: is this api call documented in the right place?
65
+ # returns Array of Trubl::Tout instances or nil
66
+ def retrieve_updates(order=nil, per_page=nil, page=nil)
67
+ response = get("me/updates",query: {order: order, per_page: per_page, page: page})
68
+ Trubl::Touts.new.from_response(response)
69
+ end
70
+
71
+ # implements http://developer.tout.com/api/touts-api/apimethod/create-tout
72
+ # returns Trubl::Tout instance or nil
73
+ def create_tout(params={})
74
+ response = if params[:url].nil?
75
+ params[:data] = params[:tout].delete(:data)
76
+ multipart_post("touts", params)
77
+ else
78
+ post("touts", params)
79
+ end
80
+
81
+ Trubl::Tout.new.from_response(response)
82
+ end
83
+
84
+ def update_tout(uid, params={})
85
+ return nil if params.blank? or params[:tout].blank?
86
+
87
+ raise "Not implemented" if params[:tout].keys.map(&:to_sym) != [:text]
88
+
89
+ response = put("touts/#{uid}", {body: params})
90
+
91
+ Trubl::Tout.new.from_response(response)
92
+ end
93
+
94
+ # implements http://developer.tout.com/api/touts-api/apimethod/delete-tout
95
+ # returns true or false
96
+ def delete_tout(uid)
97
+ delete("touts/#{uid}").code == 200
98
+ end
99
+
100
+ # implements http://developer.tout.com/api/touts-api/apimethod/tout
101
+ # ToDo: could return an updated Tout object
102
+ # returns true or false
103
+ def like_tout(uid)
104
+ response = post("touts/#{uid}/likes")
105
+
106
+ JSON.parse(response.body)["like"]["status"] == "liked"
107
+ end
108
+
109
+ # implements http://developer.tout.com/api/touts-api/apimethod/unlike-tout
110
+ # ToDo: could return an updated Tout object
111
+ # returns true or false
112
+ def unlike_tout(uid)
113
+ response = delete("touts/#{uid}/likes")
114
+
115
+ JSON.parse(response.body)["like"]["status"] == "not_liked"
116
+ end
117
+
118
+ def retout_tout(uid)
119
+ response = post("touts/#{uid}/retouts")
120
+ if response.code == 200
121
+ Trubl::Tout.new.from_response(response)
122
+ else
123
+ nil
124
+ end
125
+ end
126
+
127
+
128
+ =begin
129
+ # implements http://developer.tout.com/api/touts-api/apimethod/share-tout
130
+ def share_tout(uid)
131
+ response = post("touts/#{uid}/share")
132
+ raise "Not implemented"
133
+ end
134
+
135
+ # implements http://developer.tout.com/api/touts-api/apimethod/update-touts-text
136
+ def update_tout_text(uid)
137
+ response = put("touts/#{uid}.json?")
138
+ raise "Not implemented; see update_tout"
139
+ end
140
+ =end
141
+ end
142
+ end
143
+ end