Skip to content
This repository has been archived by the owner on Jun 27, 2020. It is now read-only.

RE: Issue #21 #22

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
Binary file added lib/.DS_Store
Binary file not shown.
Binary file added lib/redditkit/.DS_Store
Binary file not shown.
31 changes: 19 additions & 12 deletions lib/redditkit/client/search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,26 @@ module Search
# @option options [hour, day, week, month, year, all] time Show results with a specific time period.
# @return [RedditKit::PaginatedResponse]
def search(query, options = {})
path = "%s/search.json" % ('r/' + options[:subreddit] if options[:subreddit])
parameters = { :q => query,
:restrict_sr => options[:restrict_to_subreddit],
:limit => options[:limit],
:count => options[:count],
:sort => options[:sort],
:before => options[:before],
:after => options[:after],
:syntax => options[:syntax],
:t => options[:time]
}

objects_from_response(:get, path, parameters)
if query =~ URI::regexp
path = "/submit.json"
parameters = { :url => URI.escape(query) }
objects_from_response(:get, path, parameters)
else
path = "%s/search.json" % ('r/' + options[:subreddit] if options[:subreddit])
parameters = { :q => query,
:restrict_sr => options[:restrict_to_subreddit],
:limit => options[:limit],
:count => options[:count],
:sort => options[:sort],
:before => options[:before],
:after => options[:after],
:syntax => options[:syntax],
:t => options[:time]
}

objects_from_response(:get, path, parameters)
end
end

end
Expand Down
2 changes: 1 addition & 1 deletion lib/redditkit/comment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def deleted?
# The replies to a comment.
def replies
replies_listing = @attributes[:replies]
return [] if replies_listing.empty?
return [] if replies_listing.nil?

replies_array = replies_listing[:data][:children]

Expand Down
2 changes: 1 addition & 1 deletion lib/redditkit/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module RedditKit
class Version
MAJOR = 1
MINOR = 0
PATCH = 1
PATCH = 2

class << self

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions spec/redditkit/client/search_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
results = RedditKit.search 'ruby', :subreddit => 'ruby', :restrict_to_subreddit => true, :limit => 3
expect(results.length).to eq 3
end

it "returns search results from the 'seen it' page" do
results = RedditKit.search 'http://i.imgur.com/ypLqggl.png'
expect(results).to_not be_empty
end
end

end