Class: WCC::Contentful::SimpleClient::SyncResponse
- Inherits:
-
Response
- Object
- Response
- WCC::Contentful::SimpleClient::SyncResponse
show all
- Defined in:
- lib/wcc/contentful/simple_client/response.rb
Instance Attribute Summary
Attributes inherited from Response
#client, #raw_response, #request
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Response
#assert_ok!, #body, #error_message, #first, #items, #raw
Constructor Details
Returns a new instance of SyncResponse.
89
90
91
|
# File 'lib/wcc/contentful/simple_client/response.rb', line 89
def initialize(response)
super(response.client, response.request, response.raw_response)
end
|
Class Method Details
.parse_sync_token(url) ⇒ Object
133
134
135
136
137
|
# File 'lib/wcc/contentful/simple_client/response.rb', line 133
def self.parse_sync_token(url)
url = URI.parse(url)
q = CGI.parse(url.query)
q['sync_token']&.first
end
|
Instance Method Details
#count ⇒ Object
129
130
131
|
# File 'lib/wcc/contentful/simple_client/response.rb', line 129
def count
raw['items'].length
end
|
#each_page ⇒ Object
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
# File 'lib/wcc/contentful/simple_client/response.rb', line 97
def each_page
raise ArgumentError, 'Not a collection response' unless raw['items']
memoized_pages = (@memoized_pages ||= [self])
ret =
Enumerator.new do |y|
page_index = 0
current_page = self
loop do
y << current_page
break if current_page.raw['items'].empty?
page_index += 1
if page_index < memoized_pages.length
current_page = memoized_pages[page_index]
else
current_page = @client.get(raw['nextSyncUrl'])
current_page.assert_ok!
@next_sync_token = SyncResponse.parse_sync_token(current_page.raw['nextSyncUrl'])
memoized_pages.push(current_page)
end
end
end
if block_given?
ret.map(&block)
else
ret.lazy
end
end
|
#next_sync_token ⇒ Object
93
94
95
|
# File 'lib/wcc/contentful/simple_client/response.rb', line 93
def next_sync_token
@next_sync_token ||= SyncResponse.parse_sync_token(raw['nextSyncUrl'])
end
|