Skip to content

Commit

Permalink
Merge 5629ec8 into 60eb256
Browse files Browse the repository at this point in the history
  • Loading branch information
robertIngrum committed Jun 21, 2016
2 parents 60eb256 + 5629ec8 commit 4fc163f
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Expand Up @@ -9,3 +9,7 @@ doc/*
log/*
measurement/*
pkg/*

# Ignore IntelliJ specific files
*.iml
.idea
2 changes: 2 additions & 0 deletions lib/twitter/rest/api.rb
@@ -1,3 +1,4 @@
require 'twitter/rest/collections'
require 'twitter/rest/direct_messages'
require 'twitter/rest/favorites'
require 'twitter/rest/friends_and_followers'
Expand All @@ -20,6 +21,7 @@ module REST
# @note All methods have been separated into modules and follow the same grouping used in {http://dev.twitter.com/doc the Twitter API Documentation}.
# @see https://dev.twitter.com/overview/general/things-every-developer-should-know
module API
include Twitter::REST::Collections
include Twitter::REST::DirectMessages
include Twitter::REST::Favorites
include Twitter::REST::FriendsAndFollowers
Expand Down
29 changes: 29 additions & 0 deletions lib/twitter/rest/collections.rb
@@ -0,0 +1,29 @@
require 'twitter/rest/utils'
require 'twitter/tweet'

module Twitter
module REST
module Collections
include Twitter::REST::Utils
DEFAULT_TWEETS_PER_REQUEST = 20
MAX_TWEETS_PER_REQUEST = 200

# Returns the 20 most recent tweets in the given collection
#
# @see https://dev.twitter.com/rest/reference/get/collections/list
# @rate_limited Yes
# @authentication Requires user context
# @raise [Twitter::Error::Unauthorized] Error raised when supplied use credentials are not valid.
# @return [Array<Twitter::Tweet>]
# @overload user_timeline(collection_id, options = {})
# @param collection_id [String] A twitter collection id
# @param options [Hash] A customizable set of options.
# @option options [Integer] :count Specifies the maximum number of results to include in the response. Between 1 and 200.
# @option options [Integer] :max_position Returns results with a position value less than or equal to the specified position.
# @option options [Integer] :min_position Returns results with a position greater than the specified position.
def collection_entries(*args)
objects_from_response_with_collection(Twitter::Tweet, :get, '/1.1/collections/entries.json', args)
end
end
end
end
14 changes: 14 additions & 0 deletions lib/twitter/rest/utils.rb
Expand Up @@ -6,6 +6,8 @@
require 'twitter/utils'
require 'uri'

require 'pp'

module Twitter
module REST
module Utils
Expand Down Expand Up @@ -97,6 +99,12 @@ def perform_request_with_objects(request_method, path, options, klass)
end
end

def perform_request_with_collections(request_method, path, options, klass)
perform_request(request_method, path, options)[:objects][:tweets].values.collect do |element|
klass.new(element)
end
end

# @param path [String]
# @param options [Hash]
# @param collection_name [Symbol]
Expand Down Expand Up @@ -139,6 +147,12 @@ def objects_from_response_with_user(klass, request_method, path, args)
perform_request_with_objects(request_method, path, arguments.options, klass)
end

def objects_from_response_with_collection(klass, request_method, path, args)
arguments = Twitter::Arguments.new(args)
set_compound_key('id', arguments.pop, arguments.options)
perform_request_with_collections(request_method, path, arguments.options, klass)
end

# @param klass [Class]
# @param request_method [Symbol]
# @param path [String]
Expand Down

0 comments on commit 4fc163f

Please sign in to comment.