-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes #418.
- Loading branch information
Showing
9 changed files
with
124 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
require 'twitter/creatable' | ||
require 'twitter/null_object' | ||
|
||
module Twitter | ||
class GeoResults | ||
include Enumerable | ||
include Twitter::Creatable | ||
attr_reader :attrs | ||
alias to_h attrs | ||
alias to_hash attrs | ||
alias to_hsh attrs | ||
|
||
# Construct a new SearchResults object from a response hash | ||
# | ||
# @param response [Hash] | ||
# @return [Twitter::Base] | ||
def self.from_response(response={}) | ||
new(response[:body]) | ||
end | ||
|
||
# Initializes a new SearchResults object | ||
# | ||
# @param attrs [Hash] | ||
# @return [Twitter::GeoResults] | ||
def initialize(attrs={}) | ||
@attrs = attrs | ||
@collection = Array(@attrs[:result][:places]).map do |place| | ||
Twitter::Place.new(place) | ||
end | ||
end | ||
|
||
# @return [Enumerator] | ||
def each(start = 0, &block) | ||
return to_enum(:each) unless block_given? | ||
Array(@collection[start..-1]).each do |element| | ||
yield element | ||
end | ||
self | ||
end | ||
|
||
# @return [String] | ||
def token | ||
@attrs[:token] | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
require 'helper' | ||
|
||
describe Twitter::GeoResults do | ||
|
||
describe "#each" do | ||
before do | ||
@geo_results = Twitter::GeoResults.new(:result => {:places => [{:id => 1}, {:id => 2}, {:id => 3}, {:id => 4}, {:id => 5}, {:id => 6}]}) | ||
end | ||
it "iterates" do | ||
count = 0 | ||
@geo_results.each{count += 1} | ||
expect(count).to eq 6 | ||
end | ||
context "with start" do | ||
it "iterates" do | ||
count = 0 | ||
@geo_results.each(5){count += 1} | ||
expect(count).to eq 1 | ||
end | ||
end | ||
end | ||
|
||
describe "#token" do | ||
it "returns a String when token is set" do | ||
geo_results = Twitter::GeoResults.new(:result => {}, :token => "abc123") | ||
expect(geo_results.token).to be_a String | ||
expect(geo_results.token).to eq "abc123" | ||
end | ||
it "returns nil when token is not set" do | ||
geo_results = Twitter::GeoResults.new(:result => {}) | ||
expect(geo_results.token).to be_nil | ||
end | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters