github_api 0.8.11 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (146) hide show
  1. data/README.md +21 -14
  2. data/features/activity/notifications.feature +15 -0
  3. data/features/cassettes/activity/notifications/list_user.yml +54 -0
  4. data/features/step_definitions/common_steps.rb +8 -9
  5. data/lib/github_api.rb +3 -4
  6. data/lib/github_api/activity.rb +8 -13
  7. data/lib/github_api/activity/events.rb +0 -5
  8. data/lib/github_api/activity/notifications.rb +0 -5
  9. data/lib/github_api/api.rb +27 -22
  10. data/lib/github_api/api_factory.rb +13 -12
  11. data/lib/github_api/authorizations.rb +0 -5
  12. data/lib/github_api/client.rb +33 -33
  13. data/lib/github_api/configuration.rb +10 -2
  14. data/lib/github_api/connection.rb +2 -3
  15. data/lib/github_api/constants.rb +0 -3
  16. data/lib/github_api/gists.rb +2 -7
  17. data/lib/github_api/git_data.rb +10 -15
  18. data/lib/github_api/git_data/blobs.rb +0 -5
  19. data/lib/github_api/git_data/commits.rb +0 -5
  20. data/lib/github_api/git_data/references.rb +3 -7
  21. data/lib/github_api/git_data/tags.rb +0 -5
  22. data/lib/github_api/git_data/trees.rb +0 -5
  23. data/lib/github_api/gitignore.rb +0 -5
  24. data/lib/github_api/issues.rb +10 -15
  25. data/lib/github_api/issues/comments.rb +0 -5
  26. data/lib/github_api/issues/events.rb +0 -5
  27. data/lib/github_api/issues/labels.rb +0 -5
  28. data/lib/github_api/issues/milestones.rb +0 -5
  29. data/lib/github_api/markdown.rb +0 -5
  30. data/lib/github_api/meta.rb +0 -5
  31. data/lib/github_api/orgs.rb +4 -9
  32. data/lib/github_api/page_iterator.rb +44 -29
  33. data/lib/github_api/paged_request.rb +12 -12
  34. data/lib/github_api/{result.rb → pagination.rb} +19 -86
  35. data/lib/github_api/params_hash.rb +1 -1
  36. data/lib/github_api/pull_requests.rb +2 -7
  37. data/lib/github_api/repos.rb +22 -27
  38. data/lib/github_api/request.rb +7 -4
  39. data/lib/github_api/response/header.rb +76 -0
  40. data/lib/github_api/response_wrapper.rb +126 -0
  41. data/lib/github_api/scopes.rb +1 -1
  42. data/lib/github_api/search.rb +0 -5
  43. data/lib/github_api/users.rb +6 -11
  44. data/lib/github_api/version.rb +2 -2
  45. data/spec/github/activity/notifications/get_spec.rb +1 -1
  46. data/spec/github/activity/starring/starred_spec.rb +1 -1
  47. data/spec/github/activity/watching/watched_spec.rb +1 -1
  48. data/spec/github/api_factory_spec.rb +7 -8
  49. data/spec/github/api_spec.rb +0 -7
  50. data/spec/github/authorization_spec.rb +22 -32
  51. data/spec/github/authorizations/create_spec.rb +49 -0
  52. data/spec/github/authorizations/delete_spec.rb +39 -0
  53. data/spec/github/authorizations/get_spec.rb +49 -0
  54. data/spec/github/authorizations/list_spec.rb +55 -0
  55. data/spec/github/authorizations/update_spec.rb +50 -0
  56. data/spec/github/authorizations_spec.rb +2 -236
  57. data/spec/github/gists/comments/create_spec.rb +1 -1
  58. data/spec/github/gists/comments/edit_spec.rb +1 -1
  59. data/spec/github/gists/comments/get_spec.rb +1 -1
  60. data/spec/github/gists/create_spec.rb +1 -1
  61. data/spec/github/gists/edit_spec.rb +1 -1
  62. data/spec/github/gists/fork_spec.rb +1 -1
  63. data/spec/github/gists/get_spec.rb +1 -1
  64. data/spec/github/git_data/blobs/create_spec.rb +1 -1
  65. data/spec/github/git_data/blobs/get_spec.rb +1 -1
  66. data/spec/github/git_data/commits/create_spec.rb +1 -1
  67. data/spec/github/git_data/commits/get_spec.rb +1 -1
  68. data/spec/github/git_data/references/create_spec.rb +2 -2
  69. data/spec/github/git_data/references/get_spec.rb +1 -1
  70. data/spec/github/git_data/references/list_spec.rb +16 -6
  71. data/spec/github/git_data/tags/create_spec.rb +1 -1
  72. data/spec/github/git_data/tags/get_spec.rb +1 -1
  73. data/spec/github/git_data/trees/create_spec.rb +1 -1
  74. data/spec/github/git_data/trees/get_spec.rb +4 -4
  75. data/spec/github/issues/comments/create_spec.rb +1 -1
  76. data/spec/github/issues/comments/edit_spec.rb +1 -1
  77. data/spec/github/issues/comments/get_spec.rb +1 -1
  78. data/spec/github/issues/create_spec.rb +1 -1
  79. data/spec/github/issues/edit_spec.rb +1 -1
  80. data/spec/github/issues/events/get_spec.rb +1 -1
  81. data/spec/github/issues/get_spec.rb +1 -1
  82. data/spec/github/issues/labels/create_spec.rb +1 -1
  83. data/spec/github/issues/labels/get_spec.rb +1 -1
  84. data/spec/github/issues/labels/update_spec.rb +1 -1
  85. data/spec/github/issues/milestones/create_spec.rb +1 -1
  86. data/spec/github/issues/milestones/delete_spec.rb +1 -1
  87. data/spec/github/issues/milestones/get_spec.rb +1 -1
  88. data/spec/github/issues/milestones/update_spec.rb +1 -1
  89. data/spec/github/orgs/edit_spec.rb +1 -1
  90. data/spec/github/orgs/get_spec.rb +1 -1
  91. data/spec/github/orgs/teams/create_spec.rb +1 -1
  92. data/spec/github/orgs/teams/edit_spec.rb +1 -1
  93. data/spec/github/orgs/teams/get_spec.rb +1 -1
  94. data/spec/github/paged_request_spec.rb +34 -29
  95. data/spec/github/pagination/iterator/number_spec.rb +118 -0
  96. data/spec/github/pagination/iterator/sha_spec.rb +67 -0
  97. data/spec/github/pull_requests/comments/create_spec.rb +1 -1
  98. data/spec/github/pull_requests/comments/edit_spec.rb +1 -1
  99. data/spec/github/pull_requests/comments/get_spec.rb +1 -1
  100. data/spec/github/pull_requests/create_spec.rb +1 -1
  101. data/spec/github/pull_requests/get_spec.rb +1 -1
  102. data/spec/github/pull_requests/update_spec.rb +1 -1
  103. data/spec/github/repos/branch_spec.rb +1 -1
  104. data/spec/github/repos/comments/create_spec.rb +1 -1
  105. data/spec/github/repos/comments/get_spec.rb +1 -1
  106. data/spec/github/repos/comments/update_spec.rb +1 -1
  107. data/spec/github/repos/commits/get_spec.rb +1 -1
  108. data/spec/github/repos/create_spec.rb +1 -1
  109. data/spec/github/repos/downloads/create_spec.rb +1 -1
  110. data/spec/github/repos/downloads/get_spec.rb +1 -1
  111. data/spec/github/repos/edit_spec.rb +1 -1
  112. data/spec/github/repos/forks/create_spec.rb +1 -1
  113. data/spec/github/repos/get_spec.rb +1 -1
  114. data/spec/github/repos/hooks/create_spec.rb +1 -1
  115. data/spec/github/repos/hooks/edit_spec.rb +1 -1
  116. data/spec/github/repos/hooks/get_spec.rb +1 -1
  117. data/spec/github/repos/languages_spec.rb +1 -1
  118. data/spec/github/repos/merging/merge_spec.rb +1 -1
  119. data/spec/github/repos/statuses/create_spec.rb +1 -1
  120. data/spec/github/repos/tags_spec.rb +1 -1
  121. data/spec/github/repos/teams_spec.rb +1 -1
  122. data/spec/github/request/endpoint_spec.rb +24 -0
  123. data/spec/github/request/request_spec.rb +38 -0
  124. data/spec/github/{result_spec.rb → response_wrapper_spec.rb} +14 -13
  125. data/spec/github/users/emails/list_spec.rb +1 -1
  126. data/spec/github/users/get_spec.rb +2 -7
  127. data/spec/github/users/keys/create_spec.rb +1 -1
  128. data/spec/github/users/keys/get_spec.rb +1 -1
  129. data/spec/github/users/keys/update_spec.rb +1 -1
  130. data/spec/github/users/update_spec.rb +1 -1
  131. data/spec/github_spec.rb +1 -6
  132. data/spec/{github/activity → integration}/activity_spec.rb +0 -0
  133. data/spec/{github/gists → integration}/gists_spec.rb +2 -0
  134. data/spec/{github/git_data → integration}/git_data_spec.rb +0 -0
  135. data/spec/{github/issues → integration}/issues_spec.rb +2 -0
  136. data/spec/integration/options_spec.rb +103 -23
  137. data/spec/{github/orgs → integration}/orgs_spec.rb +0 -0
  138. data/spec/{github/pull_requests → integration}/pull_requests_spec.rb +0 -0
  139. data/spec/{github → integration}/repos_spec.rb +2 -0
  140. data/spec/{github/users → integration}/users_spec.rb +0 -0
  141. data/spec/shared/array_of_resources_behaviour.rb +1 -1
  142. metadata +55 -46
  143. data/lib/github_api/page_uri_processor.rb +0 -25
  144. data/lib/github_api/response/helpers.rb +0 -21
  145. data/spec/github/page_iterator_spec.rb +0 -260
  146. data/spec/github/response/helpers_spec.rb +0 -16
@@ -74,7 +74,13 @@ module Github
74
74
  end
75
75
 
76
76
  def self.extended(base)
77
- base.set_defaults
77
+ base.reset!
78
+ end
79
+
80
+ class << self
81
+ def keys
82
+ VALID_OPTIONS_KEYS
83
+ end
78
84
  end
79
85
 
80
86
  def options
@@ -83,7 +89,9 @@ module Github
83
89
  options
84
90
  end
85
91
 
86
- def set_defaults
92
+ # Reset configuration options to their defaults
93
+ #
94
+ def reset!
87
95
  self.adapter = DEFAULT_ADAPTER
88
96
  self.client_id = DEFAULT_CLIENT_ID
89
97
  self.client_secret = DEFAULT_CLIENT_SECRET
@@ -4,8 +4,8 @@ require 'faraday'
4
4
  require 'github_api/response'
5
5
  require 'github_api/response/mashify'
6
6
  require 'github_api/response/jsonize'
7
- require 'github_api/response/helpers'
8
7
  require 'github_api/response/raise_error'
8
+ require 'github_api/response/header'
9
9
  require 'github_api/request/oauth2'
10
10
  require 'github_api/request/basic_auth'
11
11
  require 'github_api/request/jsonize'
@@ -51,7 +51,6 @@ module Github
51
51
  builder.use Github::Request::BasicAuth, authentication if basic_authed?
52
52
 
53
53
  builder.use Faraday::Response::Logger if ENV['DEBUG']
54
- builder.use Github::Response::Helpers
55
54
  unless options[:raw]
56
55
  builder.use Github::Response::Mashify
57
56
  builder.use Github::Response::Jsonize
@@ -88,7 +87,7 @@ module Github
88
87
 
89
88
  # Returns a Fraday::Connection object
90
89
  #
91
- def connection(options = {})
90
+ def connection(options={})
92
91
  conn_options = default_options(options)
93
92
  clear_cache unless options.empty?
94
93
  puts "OPTIONS:#{conn_options.inspect}" if ENV['DEBUG']
@@ -54,9 +54,6 @@ module Github
54
54
 
55
55
  PARAM_START_PAGE = "start_page".freeze
56
56
 
57
- # URI parsing
58
- QUERY_STR_SEP = '?'.freeze
59
-
60
57
 
61
58
  end # Constants
62
59
  end # Github
@@ -14,14 +14,9 @@ module Github
14
14
  content
15
15
  ].freeze
16
16
 
17
- # Creates new Gists API
18
- def initialize(options = {})
19
- super(options)
20
- end
21
-
22
17
  # Access to Gists::Comments API
23
- def comments
24
- @comments ||= ApiFactory.new 'Gists::Comments'
18
+ def comments(options={}, &block)
19
+ @comments ||= ApiFactory.new('Gists::Comments', current_options.merge(options), &block)
25
20
  end
26
21
 
27
22
  # List a user's gists.
@@ -11,34 +11,29 @@ module Github
11
11
  :Tags => 'tags',
12
12
  :Trees => 'trees'
13
13
 
14
- # Creates new GitData API
15
- def initialize(options = {})
16
- super(options)
17
- end
18
-
19
14
  # Access to GitData::Blobs API
20
- def blobs
21
- @blobs ||= ApiFactory.new 'GitData::Blobs'
15
+ def blobs(options={}, &block)
16
+ @blobs ||= ApiFactory.new('GitData::Blobs', current_options.merge(options), &block)
22
17
  end
23
18
 
24
19
  # Access to GitData::Commits API
25
- def commits
26
- @commits ||= ApiFactory.new 'GitData::Commits'
20
+ def commits(options={}, &block)
21
+ @commits ||= ApiFactory.new('GitData::Commits', current_options.merge(options), &block)
27
22
  end
28
23
 
29
24
  # Access to GitData::References API
30
- def references
31
- @references ||= ApiFactory.new 'GitData::References'
25
+ def references(options={}, &block)
26
+ @references ||= ApiFactory.new('GitData::References', current_options.merge(options), &block)
32
27
  end
33
28
 
34
29
  # Access to GitData::Tags API
35
- def tags
36
- @tags ||= ApiFactory.new 'GitData::Tags'
30
+ def tags(options={}, &block)
31
+ @tags ||= ApiFactory.new('GitData::Tags', current_options.merge(options), &block)
37
32
  end
38
33
 
39
34
  # Access to GitData::Tags API
40
- def trees
41
- @trees ||= ApiFactory.new 'GitData::Trees'
35
+ def trees(options={}, &block)
36
+ @trees ||= ApiFactory.new('GitData::Trees', current_options.merge(options), &block)
42
37
  end
43
38
 
44
39
  end # GitData
@@ -8,11 +8,6 @@ module Github
8
8
 
9
9
  VALID_BLOB_PARAM_NAMES = %w[ content encoding ].freeze
10
10
 
11
- # Creates new GitData::Blobs API
12
- def initialize(options = {})
13
- super(options)
14
- end
15
-
16
11
  # Get a blob
17
12
  #
18
13
  # = Examples
@@ -20,11 +20,6 @@ module Github
20
20
  parents
21
21
  ].freeze
22
22
 
23
- # Creates new GitData::Commits API
24
- def initialize(options = {})
25
- super(options)
26
- end
27
-
28
23
  # Get a commit
29
24
  #
30
25
  # = Examples
@@ -9,11 +9,6 @@ module Github
9
9
  'ref' => %r{^refs\/\w+(\/\w+)*} # test fully qualified reference
10
10
  }
11
11
 
12
- # Creates new GitData::References API
13
- def initialize(options = {})
14
- super(options)
15
- end
16
-
17
12
  # Get all references
18
13
  #
19
14
  # This will return an array of all the references on the system,
@@ -130,8 +125,9 @@ module Github
130
125
 
131
126
  private
132
127
 
133
- def validate_reference ref
134
- refs = ref.start_with?('ref/') ? ref : "refs/#{ref}"
128
+ def validate_reference(ref)
129
+ refs = (ref =~ (/^(\/)?refs.*/) ? ref : "refs/#{ref}").gsub(/(\/)+/, '/')
130
+ refs.gsub!(/^\//, '')
135
131
  unless VALID_REF_PARAM_VALUES['ref'] =~ refs
136
132
  raise ArgumentError, "Provided 'reference' is invalid"
137
133
  end
@@ -22,11 +22,6 @@ module Github
22
22
  'type' => %w[ blob tree commit ]
23
23
  }
24
24
 
25
- # Creates new GitData::Tags API
26
- def initialize(options = {})
27
- super(options)
28
- end
29
-
30
25
  # Get a tag
31
26
  #
32
27
  # = Examples
@@ -19,11 +19,6 @@ module Github
19
19
  'type' => %w[ blob tree commit ]
20
20
  }
21
21
 
22
- # Creates new GitData::Trees API
23
- def initialize(options = {})
24
- super(options)
25
- end
26
-
27
22
  # Get a tree
28
23
  #
29
24
  # = Examples
@@ -6,11 +6,6 @@ module Github
6
6
  # .gitignore template to apply to the repository upon creation.
7
7
  class Gitignore < API
8
8
 
9
- # Creates new Gitignore API
10
- def initialize(options = {})
11
- super(options)
12
- end
13
-
14
9
  # List all templates available to pass as an option when creating a repository.
15
10
  #
16
11
  # = Examples
@@ -36,34 +36,29 @@ module Github
36
36
  'since' => %r{\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z}
37
37
  }
38
38
 
39
- # Creates new Issues API
40
- def initialize(options = {})
41
- super(options)
42
- end
43
-
44
39
  # Access to Issues::Assignees API
45
- def assignees
46
- @assignees ||= ApiFactory.new 'Issues::Assignees'
40
+ def assignees(options={}, &block)
41
+ @assignees ||= ApiFactory.new('Issues::Assignees', current_options.merge(options), &block)
47
42
  end
48
43
 
49
44
  # Access to Issues::Comments API
50
- def comments
51
- @comments ||= ApiFactory.new 'Issues::Comments'
45
+ def comments(options={}, &block)
46
+ @comments ||= ApiFactory.new('Issues::Comments', current_options.merge(options), &block)
52
47
  end
53
48
 
54
49
  # Access to Issues::Events API
55
- def events
56
- @events ||= ApiFactory.new 'Issues::Events'
50
+ def events(options={}, &block)
51
+ @events ||= ApiFactory.new('Issues::Events', current_options.merge(options), &block)
57
52
  end
58
53
 
59
54
  # Access to Issues::Comments API
60
- def labels
61
- @labels ||= ApiFactory.new 'Issues::Labels'
55
+ def labels(options={}, &block)
56
+ @labels ||= ApiFactory.new('Issues::Labels', current_options.merge(options), &block)
62
57
  end
63
58
 
64
59
  # Access to Issues::Comments API
65
- def milestones
66
- @milestones ||= ApiFactory.new 'Issues::Milestones'
60
+ def milestones(options={}, &block)
61
+ @milestones ||= ApiFactory.new('Issues::Milestones', current_options.merge(options), &block)
67
62
  end
68
63
 
69
64
  # List your issues
@@ -9,11 +9,6 @@ module Github
9
9
  mime_type
10
10
  ].freeze
11
11
 
12
- # Creates new Issues::Comments API
13
- def initialize(options = {})
14
- super(options)
15
- end
16
-
17
12
  # List comments on an issue
18
13
  #
19
14
  # = Examples
@@ -3,11 +3,6 @@
3
3
  module Github
4
4
  class Issues::Events < API
5
5
 
6
- # Creates new Issues::Events API
7
- def initialize(options = {})
8
- super(options)
9
- end
10
-
11
6
  # List events for an issue
12
7
  #
13
8
  # = Examples
@@ -5,11 +5,6 @@ module Github
5
5
 
6
6
  VALID_LABEL_INPUTS = %w[ name color ].freeze
7
7
 
8
- # Creates new Issues::Labels API
9
- def initialize(options = {})
10
- super(options)
11
- end
12
-
13
8
  # List all labels for a repository
14
9
  #
15
10
  # = Examples
@@ -16,11 +16,6 @@ module Github
16
16
  due_on
17
17
  ].freeze # :nodoc:
18
18
 
19
- # Creates new Issues::Milestones API
20
- def initialize(options = {})
21
- super(options)
22
- end
23
-
24
19
  # List milestones for a repository
25
20
  #
26
21
  # = Parameters
@@ -3,11 +3,6 @@
3
3
  module Github
4
4
  class Markdown < API
5
5
 
6
- # Creates new Markdown API
7
- def initialize(options = {})
8
- super(options)
9
- end
10
-
11
6
  # Render an arbritrary Markdown document
12
7
  #
13
8
  # = Parameters
@@ -3,11 +3,6 @@
3
3
  module Github
4
4
  class Meta < API
5
5
 
6
- # Creates new Search API
7
- def initialize(options = {})
8
- super(options)
9
- end
10
-
11
6
  # Get meta information about GitHub.com, the service.
12
7
  #
13
8
  # = Examples
@@ -16,19 +16,14 @@ module Github
16
16
  name
17
17
  ].freeze
18
18
 
19
- # Creates new Orgs API
20
- def initialize(options = {})
21
- super(options)
22
- end
23
-
24
19
  # Access to Orgs::Members API
25
- def members
26
- @members ||= ApiFactory.new 'Orgs::Members'
20
+ def members(options={}, &block)
21
+ @members ||= ApiFactory.new('Orgs::Members', current_options.merge(options), &block)
27
22
  end
28
23
 
29
24
  # Access to Orgs::Teams API
30
- def teams
31
- @teams ||= ApiFactory.new 'Orgs::Teams'
25
+ def teams(options={}, &block)
26
+ @teams ||= ApiFactory.new('Orgs::Teams', current_options.merge(options), &block)
32
27
  end
33
28
 
34
29
  # List all public organizations for a user.
@@ -1,6 +1,7 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  require 'github_api/utils/url'
4
+ require 'uri'
4
5
 
5
6
  module Github
6
7
  class PageIterator
@@ -15,8 +16,11 @@ module Github
15
16
  attr_accessor :"#{attr}_page_uri", :"#{attr}_page"
16
17
  end
17
18
 
18
- def initialize(env)
19
- @links = Github::PageLinks.new(env[:response_headers])
19
+ attr_reader :current_api
20
+
21
+ def initialize(links, current_api)
22
+ @links = links
23
+ @current_api = current_api
20
24
  update_page_links @links
21
25
  end
22
26
 
@@ -24,78 +28,89 @@ module Github
24
28
  next_page == 0 || !next_page_uri.nil?
25
29
  end
26
30
 
31
+ def count
32
+ return nil unless last_page_uri
33
+ parse_query(URI(last_page_uri).query)['page']
34
+ end
35
+
36
+ # Perform http get request for the first resource
37
+ #
27
38
  def first
28
39
  return nil unless first_page_uri
29
-
30
- response = if next_page < 1
31
- parsed_query = parse_query(first_page_uri.split(QUERY_STR_SEP).last)
32
- params = {}
33
- if parsed_query.keys.include?('sha')
34
- params['sha'] = 'master'
35
- end
40
+ page_uri = URI(first_page_uri)
41
+ params = parse_query(page_uri.query)
42
+ if next_page < 1
43
+ params['sha'] = 'master' if params.keys.include?('sha')
36
44
  params['per_page'] = parse_per_page_number(first_page_uri)
37
-
38
- page_request first_page_uri.split(QUERY_STR_SEP).first, params
39
45
  else
40
- page_request first_page_uri.split(QUERY_STR_SEP).first,
41
- 'per_page' => parse_per_page_number(first_page_uri)
46
+ params['page'] = parse_page_number(first_page_uri)
47
+ params['per_page'] = parse_per_page_number(first_page_uri)
42
48
  end
43
49
 
50
+ response = page_request(page_uri.path, params)
44
51
  update_page_links response.links
45
52
  response
46
53
  end
47
54
 
55
+ # Perform http get request for the next resource
56
+ #
48
57
  def next
49
58
  return nil unless has_next?
50
-
51
- response = if next_page < 1
52
- params = parse_query next_page_uri.split(QUERY_STR_SEP).last
59
+ page_uri = URI(next_page_uri)
60
+ params = parse_query(page_uri.query)
61
+ if next_page < 1
53
62
  params['sha'] = params['last_sha'] if params.keys.include?('last_sha')
54
63
  params['per_page'] = parse_per_page_number(next_page_uri)
55
- page_request next_page_uri.split(QUERY_STR_SEP).first, params
56
64
  else
57
- params = parse_query next_page_uri.split(QUERY_STR_SEP).last
58
- params['page'] = parse_page_number(next_page_uri)
65
+ params['page'] = parse_page_number(next_page_uri)
59
66
  params['per_page'] = parse_per_page_number(next_page_uri)
60
- page_request next_page_uri.split(QUERY_STR_SEP).first, params
61
67
  end
68
+
69
+ response = page_request(page_uri.path, params)
62
70
  update_page_links response.links
63
71
  response
64
72
  end
65
73
 
74
+ # Perform http get request for the previous resource
75
+ #
66
76
  def prev
67
77
  return nil unless prev_page_uri
68
- params = parse_query prev_page_uri.split(QUERY_STR_SEP).last
69
- params['page'] = parse_page_number(prev_page_uri)
78
+ page_uri = URI(prev_page_uri)
79
+ params = parse_query(page_uri.query)
80
+ params['page'] = parse_page_number(prev_page_uri)
70
81
  params['per_page'] = parse_per_page_number(prev_page_uri)
71
- response = page_request prev_page_uri.split(QUERY_STR_SEP).first, params
72
82
 
83
+ response = page_request(page_uri.path, params)
73
84
  update_page_links response.links
74
85
  response
75
86
  end
76
87
 
88
+ # Perform http get request for the last resource
89
+ #
77
90
  def last
78
91
  return nil unless last_page_uri
79
- params = parse_query last_page_uri.split(QUERY_STR_SEP).last
80
- params['page'] = parse_page_number(last_page_uri)
92
+ page_uri = URI(last_page_uri)
93
+ params = parse_query(page_uri.query)
94
+ params['page'] = parse_page_number(last_page_uri)
81
95
  params['per_page'] = parse_per_page_number(last_page_uri)
82
- response = page_request last_page_uri.split(QUERY_STR_SEP).first, params
83
96
 
97
+ response = page_request(page_uri.path, params)
84
98
  update_page_links response.links
85
99
  response
86
100
  end
87
101
 
88
102
  # Returns the result for a specific page.
103
+ #
89
104
  def get_page(page_number)
90
105
  # Find URI that we can work with, if we cannot get the first or the
91
106
  # last page URI then there is only one page.
92
107
  page_uri = first_page_uri || last_page_uri
93
108
  return nil unless page_uri
94
- params = parse_query page_uri.split(QUERY_STR_SEP).last
95
- params['page'] = page_number
109
+ params = parse_query URI(page_uri).query
110
+ params['page'] = page_number
96
111
  params['per_page'] = parse_per_page_number(page_uri)
97
- response = page_request page_uri.split(QUERY_STR_SEP).first, params
98
112
 
113
+ response = page_request URI(page_uri).path, params
99
114
  update_page_links response.links
100
115
  response
101
116
  end