Skip to content
Merged
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ clients/ruby/git_push.sh
clients/ruby/openapitools.json
clients/ruby/*.gemspec
clients/ruby/spec/*.rb
!clients/ruby/spec/response_spec.rb
clients/ruby/spec/api/*
clients/ruby/spec/models/
clients/ruby/docs
Expand Down
4 changes: 2 additions & 2 deletions clients/ruby/lib/phrase/response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ def initialize(data, headers)
link_headers = headers["link"]
if link_headers
@paginated = true
parsed_links = LinkHeaderParser.parse(link_headers, base: 'https://api.phrase.com').group_by_relation_type
next_page_link = parsed_links[:next]&.first
parsed_links = LinkHeaderParser.parse(link_headers, base_uri: 'https://api.phrase.com').group_by_relation_type
next_page_link = parsed_links["next"]&.first
if next_page_link
@next_page = CGI.parse(URI.parse(next_page_link.target_uri).query)["page"]&.first&.to_i
end
Expand Down
53 changes: 53 additions & 0 deletions clients/ruby/spec/response_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
require 'spec_helper'

describe Phrase::Response do
context 'without a link header' do
it 'is not paginated' do
response = Phrase::Response.new({ 'foo' => 'bar' }, {})

expect(response.paginated?).to eq(false)
expect(response.next_page?).to eq(false)
expect(response.next_page).to be_nil
end
end

context 'with a link header that has a next page' do
let(:headers) do
{
'link' => '<https://api.phrase.com/v2/projects/project_id/keys?page=2>; rel="next", ' \
'<https://api.phrase.com/v2/projects/project_id/keys?page=5>; rel="last"'
}
end

it 'parses the next page number without raising' do
response = Phrase::Response.new({ 'foo' => 'bar' }, headers)

expect(response.paginated?).to eq(true)
expect(response.next_page?).to eq(true)
expect(response.next_page).to eq(2)
end
end

context 'with a link header that has no next page' do
let(:headers) do
{
'link' => '<https://api.phrase.com/v2/projects/project_id/keys?page=1>; rel="first", ' \
'<https://api.phrase.com/v2/projects/project_id/keys?page=1>; rel="last"'
}
end

it 'is paginated but has no next page' do
response = Phrase::Response.new({ 'foo' => 'bar' }, headers)

expect(response.paginated?).to eq(true)
expect(response.next_page?).to eq(false)
expect(response.next_page).to be_nil
end
end

it 'delegates missing methods to the underlying data' do
response = Phrase::Response.new({ 'foo' => 'bar' }, {})

expect(response['foo']).to eq('bar')
end
end
2 changes: 1 addition & 1 deletion openapi-generator/templates/ruby-client/gemspec.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Gem::Specification.new do |s|
s.add_runtime_dependency 'typhoeus', '>= 1.0.1'
{{/isFaraday}}
s.add_runtime_dependency 'json', '>= 2.1.0'
s.add_runtime_dependency 'link-header-parser'
s.add_runtime_dependency 'link-header-parser', '>= 7.0'

s.add_development_dependency 'rspec', '>= 3.6.0'

Expand Down
Loading