Skip to content

Commit b578bd1

Browse files
author
julianfoo
committed
WIP: Add pagination to response object
1 parent 6b69875 commit b578bd1

3 files changed

Lines changed: 21 additions & 3 deletions

File tree

lib/tweetkit/connection.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ module Tweetkit
88
module Connection
99
include Tweetkit::Auth
1010

11+
attr_accessor :saved_params, :saved_url
12+
1113
BASE_URL = 'https://api.twitter.com/2/'
1214

1315
def get(endpoint, **options)
@@ -16,7 +18,8 @@ def get(endpoint, **options)
1618

1719
def request(method, endpoint, data, **options)
1820
auth_type = options.delete(:auth_type)
19-
url = URI.parse("#{BASE_URL}#{endpoint}")
21+
@saved_url = URI.parse("#{BASE_URL}#{endpoint}")
22+
@saved_params = data
2023

2124
if method == :get
2225
conn = Faraday.new(params: data) do |c|
@@ -26,7 +29,7 @@ def request(method, endpoint, data, **options)
2629
c.authorization :Bearer, @bearer_token
2730
end
2831
end
29-
response = conn.get(url)
32+
response = conn.get(saved_url)
3033
else
3134
conn = Faraday.new do |f|
3235
end

lib/tweetkit/pagination.rb

Whitespace-only changes.

lib/tweetkit/response.rb

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
require 'json'
2+
require 'pry'
3+
require 'tweetkit/connection'
24

35
module Tweetkit
46
class Response
@@ -9,8 +11,19 @@ def initialize(response)
911
parsed_response = JSON.parse(@original_response)
1012
@tweets = Tweetkit::Response::Tweets.new(parsed_response)
1113
@meta = Tweetkit::Response::Meta.new(@tweets.meta)
14+
@next_token = @meta.next_token
15+
@prev_token = @meta.prev_token
1216
@resources = Tweetkit::Response::Resources.new(@tweets.resources)
1317
end
18+
19+
def next
20+
binding.pry
21+
@meta.next_token
22+
end
23+
24+
def prev
25+
@meta.prev_token
26+
end
1427

1528
class Resources
1629
include Enumerable
@@ -82,10 +95,12 @@ def find(key)
8295
class Meta
8396
include Enumerable
8497

85-
attr_accessor :meta
98+
attr_accessor :meta, :next_token, :prev_token
8699

87100
def initialize(meta)
88101
@meta = meta
102+
@next_token = @meta['next_token']
103+
@prev_token = @meta['prev_token']
89104
end
90105

91106
def method_missing(attribute, **args)

0 commit comments

Comments
 (0)