Class: Tweetkit::Response::Tweets
- Inherits:
-
Object
- Object
- Tweetkit::Response::Tweets
- Includes:
- Enumerable
- Defined in:
- lib/tweetkit/response.rb
Defined Under Namespace
Classes: Expansions, Fields, Meta, Tweet
Instance Attribute Summary collapse
-
#annotations ⇒ Object
Returns the value of attribute annotations.
-
#connection ⇒ Object
Returns the value of attribute connection.
-
#context_annotations ⇒ Object
Returns the value of attribute context_annotations.
-
#entity_annotations ⇒ Object
Returns the value of attribute entity_annotations.
-
#expansions ⇒ Object
Returns the value of attribute expansions.
-
#fields ⇒ Object
Returns the value of attribute fields.
-
#meta ⇒ Object
Returns the value of attribute meta.
-
#options ⇒ Object
Returns the value of attribute options.
-
#original_response ⇒ Object
Returns the value of attribute original_response.
-
#response ⇒ Object
Returns the value of attribute response.
-
#tweets ⇒ Object
Returns the value of attribute tweets.
-
#twitter_request ⇒ Object
Returns the value of attribute twitter_request.
Instance Method Summary collapse
- #each(*args, &block) ⇒ Object
- #extract_and_save_expansions ⇒ Object
- #extract_and_save_meta ⇒ Object
- #extract_and_save_options(**options) ⇒ Object
- #extract_and_save_request ⇒ Object
- #extract_and_save_tweets ⇒ Object
-
#initialize(response, **options) ⇒ Tweets
constructor
A new instance of Tweets.
- #last ⇒ Object
- #next_page ⇒ Object
- #parse!(response, **options) ⇒ Object
- #parse_response(response) ⇒ Object
- #prev_page ⇒ Object
- #tweet ⇒ Object
Constructor Details
#initialize(response, **options) ⇒ Tweets
Returns a new instance of Tweets.
12 13 14 |
# File 'lib/tweetkit/response.rb', line 12 def initialize(response, **) parse! response, ** end |
Instance Attribute Details
#annotations ⇒ Object
Returns the value of attribute annotations.
10 11 12 |
# File 'lib/tweetkit/response.rb', line 10 def annotations @annotations end |
#connection ⇒ Object
Returns the value of attribute connection.
10 11 12 |
# File 'lib/tweetkit/response.rb', line 10 def connection @connection end |
#context_annotations ⇒ Object
Returns the value of attribute context_annotations.
10 11 12 |
# File 'lib/tweetkit/response.rb', line 10 def context_annotations @context_annotations end |
#entity_annotations ⇒ Object
Returns the value of attribute entity_annotations.
10 11 12 |
# File 'lib/tweetkit/response.rb', line 10 def entity_annotations @entity_annotations end |
#expansions ⇒ Object
Returns the value of attribute expansions.
10 11 12 |
# File 'lib/tweetkit/response.rb', line 10 def expansions @expansions end |
#fields ⇒ Object
Returns the value of attribute fields.
10 11 12 |
# File 'lib/tweetkit/response.rb', line 10 def fields @fields end |
#meta ⇒ Object
Returns the value of attribute meta.
10 11 12 |
# File 'lib/tweetkit/response.rb', line 10 def @meta end |
#options ⇒ Object
Returns the value of attribute options.
10 11 12 |
# File 'lib/tweetkit/response.rb', line 10 def @options end |
#original_response ⇒ Object
Returns the value of attribute original_response.
10 11 12 |
# File 'lib/tweetkit/response.rb', line 10 def original_response @original_response end |
#response ⇒ Object
Returns the value of attribute response.
10 11 12 |
# File 'lib/tweetkit/response.rb', line 10 def response @response end |
#tweets ⇒ Object
Returns the value of attribute tweets.
10 11 12 |
# File 'lib/tweetkit/response.rb', line 10 def tweets @tweets end |
#twitter_request ⇒ Object
Returns the value of attribute twitter_request.
10 11 12 |
# File 'lib/tweetkit/response.rb', line 10 def twitter_request @twitter_request end |
Instance Method Details
#each(*args, &block) ⇒ Object
61 62 63 |
# File 'lib/tweetkit/response.rb', line 61 def each(*args, &block) tweets.each(*args, &block) end |
#extract_and_save_expansions ⇒ Object
48 49 50 |
# File 'lib/tweetkit/response.rb', line 48 def extract_and_save_expansions @expansions = Expansions.new(@response['includes']) end |
#extract_and_save_meta ⇒ Object
44 45 46 |
# File 'lib/tweetkit/response.rb', line 44 def @meta = Meta.new(@response['meta']) end |
#extract_and_save_options(**options) ⇒ Object
52 53 54 |
# File 'lib/tweetkit/response.rb', line 52 def (**) @options = end |
#extract_and_save_request ⇒ Object
56 57 58 59 |
# File 'lib/tweetkit/response.rb', line 56 def extract_and_save_request @connection = @options[:connection] @twitter_request = @options[:twitter_request] end |
#extract_and_save_tweets ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/tweetkit/response.rb', line 32 def extract_and_save_tweets if (data = @response['data']) if data.is_a?(Array) @tweets = @response['data'].collect { |tweet| Tweet.new(tweet) } else @tweets = [Tweet.new(@response['data'])] end else @tweets = nil end end |
#last ⇒ Object
65 66 67 |
# File 'lib/tweetkit/response.rb', line 65 def last tweets.last end |
#next_page ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/tweetkit/response.rb', line 73 def next_page connection.params.merge!({ next_token: .next_token }) response = connection.get(twitter_request[:previous_url]) parse! response, connection: connection, twitter_request: { previous_url: twitter_request[:previous_url], previous_query: twitter_request[:previous_query] } self end |
#parse!(response, **options) ⇒ Object
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/tweetkit/response.rb', line 16 def parse!(response, **) parse_response response extract_and_save_tweets return unless @tweets extract_and_save_expansions (**) extract_and_save_request end |
#parse_response(response) ⇒ Object
27 28 29 30 |
# File 'lib/tweetkit/response.rb', line 27 def parse_response(response) @original_response = response.body @response = JSON.parse(@original_response) end |
#prev_page ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/tweetkit/response.rb', line 85 def prev_page connection.params.merge!({ previous: .previous_token }) response = connection.get(twitter_request[:previous_url]) parse! response, connection: connection, twitter_request: { previous_url: twitter_request[:previous_url], previous_query: twitter_request[:previous_query] } self end |
#tweet ⇒ Object
69 70 71 |
# File 'lib/tweetkit/response.rb', line 69 def tweet tweets.first end |