Skip to content

Commit

Permalink
Merge f8e46fe into 844818c
Browse files Browse the repository at this point in the history
  • Loading branch information
renatolond committed Jan 16, 2020
2 parents 844818c + f8e46fe commit 8d01f3f
Show file tree
Hide file tree
Showing 15 changed files with 29 additions and 9 deletions.
3 changes: 3 additions & 0 deletions .travis.yml
Expand Up @@ -18,6 +18,9 @@ env:
global:
- JRUBY_OPTS="$JRUBY_OPTS --debug"

before_install:
- gem uninstall -a bundler || true
- gem install bundler -v '< 2'
matrix:
allow_failures:
- rvm: jruby-head
Expand Down
1 change: 1 addition & 0 deletions lib/twitter/creatable.rb
Expand Up @@ -11,6 +11,7 @@ module Creatable
def created_at
time = @attrs[:created_at]
return if time.nil?

time = Time.parse(time) unless time.is_a?(Time)
time.utc
end
Expand Down
1 change: 1 addition & 0 deletions lib/twitter/cursor.rb
Expand Up @@ -42,6 +42,7 @@ def next_cursor
def last?
return false if next_cursor.is_a?(String)
return true if next_cursor.nil?

next_cursor.zero?
end

Expand Down
1 change: 1 addition & 0 deletions lib/twitter/enumerable.rb
Expand Up @@ -5,6 +5,7 @@ module Enumerable
# @return [Enumerator]
def each(start = 0)
return to_enum(:each, start) unless block_given?

Array(@collection[start..-1]).each do |element|
yield(element)
end
Expand Down
2 changes: 2 additions & 0 deletions lib/twitter/null_object.rb
Expand Up @@ -19,11 +19,13 @@ def respond_to?(*)

def instance_of?(klass)
raise(TypeError, 'class or module required') unless klass.is_a?(Class)

self.class == klass
end

def kind_of?(mod)
raise(TypeError, 'class or module required') unless mod.is_a?(Module)

self.class.ancestors.include?(mod)
end

Expand Down
4 changes: 2 additions & 2 deletions lib/twitter/profile.rb
Expand Up @@ -4,8 +4,8 @@

module Twitter
module Profile
PROFILE_IMAGE_SUFFIX_REGEX = /_normal(\.gif|\.jpe?g|\.png)$/i
PREDICATE_URI_METHOD_REGEX = /_uri\?$/
PROFILE_IMAGE_SUFFIX_REGEX = /_normal(\.gif|\.jpe?g|\.png)$/i # rubocop:disable Style/MutableConstant
PREDICATE_URI_METHOD_REGEX = /_uri\?$/ # rubocop:disable Style/MutableConstant
include Memoizable

class << self
Expand Down
4 changes: 1 addition & 3 deletions lib/twitter/rest/direct_messages.rb
Expand Up @@ -187,9 +187,7 @@ def create_direct_message(user_id, text, options = {})
def create_direct_message_event(*args)
arguments = Twitter::Arguments.new(args)
options = arguments.options.dup
if arguments.length >= 2
options[:event] = {type: 'message_create', message_create: {target: {recipient_id: extract_id(arguments[0])}, message_data: {text: arguments[1]}}}
end
options[:event] = {type: 'message_create', message_create: {target: {recipient_id: extract_id(arguments[0])}, message_data: {text: arguments[1]}}} if arguments.length >= 2
response = Twitter::REST::Request.new(self, :json_post, '/1.1/direct_messages/events/new.json', options).perform
Twitter::DirectMessageEvent.new(response[:event])
end
Expand Down
1 change: 1 addition & 0 deletions lib/twitter/rest/lists.rb
Expand Up @@ -484,6 +484,7 @@ def merge_list_and_owner!(hash, list)
# @return [Hash]
def merge_owner!(hash, user)
return hash if hash[:owner_id] || hash[:owner_screen_name]

if user
merge_user!(hash, user, 'owner')
hash[:owner_id] = hash.delete(:owner_user_id) unless hash[:owner_user_id].nil?
Expand Down
7 changes: 6 additions & 1 deletion lib/twitter/rest/request.rb
Expand Up @@ -79,6 +79,7 @@ def content_type(basename)
def fail_or_return_response_body(code, body, headers)
error = error(code, body, headers)
raise(error) if error

@rate_limit = Twitter::RateLimit.new(headers)
body
end
Expand Down Expand Up @@ -115,15 +116,19 @@ def symbolize_keys!(object)
object
end

# Returns an HTTP client, using configuration set up in the client
#
# @api private
# @return [HTTP::Client, HTTP]
def http_client
client = @client.proxy ? HTTP.via(*proxy) : HTTP
client = client.timeout(:per_operation, connect: @client.timeouts[:connect], read: @client.timeouts[:read], write: @client.timeouts[:write]) if @client.timeouts
client = client.timeout(connect: @client.timeouts[:connect], read: @client.timeouts[:read], write: @client.timeouts[:write]) if @client.timeouts
client
end

# Return proxy values as a compacted array
#
# @api private
# @return [Array]
def proxy
@client.proxy.values_at(:host, :port, :username, :password).compact
Expand Down
1 change: 1 addition & 0 deletions lib/twitter/rest/timelines.rb
Expand Up @@ -188,6 +188,7 @@ def collect_with_count(count)
def collect_with_max_id(collection = [], max_id = nil, &block)
tweets = yield(max_id)
return collection if tweets.nil?

collection += tweets
tweets.empty? ? collection.flatten : collect_with_max_id(collection, tweets.last.id - 1, &block)
end
Expand Down
4 changes: 4 additions & 0 deletions lib/twitter/rest/utils.rb
Expand Up @@ -17,6 +17,7 @@ module Utils
# Take a URI string or Twitter::Identity object and return its ID
#
# @param object [Integer, String, URI, Twitter::Identity] An ID, URI, or object.
# @api private
# @return [Integer]
def extract_id(object)
case object
Expand All @@ -31,18 +32,21 @@ def extract_id(object)
end
end

# @api private
# @param path [String]
# @param options [Hash]
def perform_get(path, options = {})
perform_request(:get, path, options)
end

# @api private
# @param path [String]
# @param options [Hash]
def perform_post(path, options = {})
perform_request(:post, path, options)
end

# @api private
# @param request_method [Symbol]
# @param path [String]
# @param options [Hash]
Expand Down
1 change: 1 addition & 0 deletions lib/twitter/streaming/response.rb
Expand Up @@ -27,6 +27,7 @@ def on_headers_complete(_headers)
def on_body(data)
@tokenizer.extract(data).each do |line|
next if line.empty?

@block.call(JSON.parse(line, symbolize_names: true))
end
end
Expand Down
2 changes: 2 additions & 0 deletions lib/twitter/utils.rb
Expand Up @@ -9,6 +9,7 @@ module Utils
# @return [Array, Enumerator]
def flat_pmap(enumerable)
return to_enum(:flat_pmap, enumerable) unless block_given?

pmap(enumerable, &Proc.new).flatten(1)
end

Expand All @@ -19,6 +20,7 @@ def flat_pmap(enumerable)
# @return [Array, Enumerator]
def pmap(enumerable)
return to_enum(:pmap, enumerable) unless block_given?

if enumerable.count == 1
enumerable.collect { |object| yield(object) }
else
Expand Down
4 changes: 2 additions & 2 deletions spec/twitter/rest/request_spec.rb
Expand Up @@ -41,7 +41,7 @@
end
it 'requests with given timeout settings' do
stub_post('/1.1/statuses/update.json').with(body: {status: 'Update'}).to_return(body: fixture('status.json'), headers: {content_type: 'application/json; charset=utf-8'})
expect_any_instance_of(HTTP::Client).to receive(:timeout).with(:per_operation, connect: 2, read: 2, write: 3).and_call_original
expect_any_instance_of(HTTP::Client).to receive(:timeout).with(connect: 2, read: 2, write: 3).and_call_original
@client.update('Update')
end
end
Expand All @@ -53,7 +53,7 @@
end
it 'requests with given timeout settings' do
stub_post('/1.1/statuses/update.json').with(body: {status: 'Update'}).to_return(body: fixture('status.json'), headers: {content_type: 'application/json; charset=utf-8'})
expect(HTTP).to receive(:timeout).with(:per_operation, connect: 2, read: 2, write: 3).and_call_original
expect(HTTP).to receive(:timeout).with(connect: 2, read: 2, write: 3).and_call_original
@client.update('Update')
end
end
Expand Down
2 changes: 1 addition & 1 deletion twitter.gemspec
Expand Up @@ -6,7 +6,7 @@ Gem::Specification.new do |spec|
spec.add_dependency 'addressable', '~> 2.3'
spec.add_dependency 'buftok', '~> 0.2.0'
spec.add_dependency 'equalizer', '~> 0.0.11'
spec.add_dependency 'http', '~> 3.0'
spec.add_dependency 'http', '~> 4.0'
spec.add_dependency 'http-form_data', '~> 2.0'
spec.add_dependency 'http_parser.rb', '~> 0.6.0'
spec.add_dependency 'memoizable', '~> 0.4.0'
Expand Down

0 comments on commit 8d01f3f

Please sign in to comment.