zaikio-hub 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -1
- data/README.md +11 -1
- data/lib/zaikio/hub.rb +4 -0
- data/lib/zaikio/hub/connection.rb +2 -0
- data/lib/zaikio/hub/pagination.rb +19 -0
- data/lib/zaikio/hub/pagination/header_parser.rb +25 -0
- data/lib/zaikio/hub/pagination/relation.rb +41 -0
- data/lib/zaikio/hub/pagination/scopes.rb +23 -0
- data/lib/zaikio/hub/subscription.rb +2 -0
- data/lib/zaikio/hub/version.rb +1 -1
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 71418bf55d46197710099e666b3db5b04fb9e08264b0c21f874f7ea9680dd9b0
|
4
|
+
data.tar.gz: cccda672c5c0149bc602605278b61e28ac2bef9b930e98bf0b17664562a62d2c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e0acec4f0cd530d9f4cb52b49eb53a86bf9aff30a576b02ab0ddd6573c3ef031b97a14ef3d13b451e61f9d7233e0232c4b50ad8bfd9afbeceaaf5d341df09256
|
7
|
+
data.tar.gz: '09c81fcb75e68d73e27ce8b69f2d0bc329b42e0fd7286b8fc0e825df50b40fbfabd1c4f1fd13a344126c79a99a1a52c4e77f70c27f6c26c9f13e40f0cbfcfa90'
|
data/CHANGELOG.md
CHANGED
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
7
7
|
|
8
8
|
## [Unreleased]
|
9
9
|
|
10
|
+
## [0.6.0] - 2020-04-12
|
11
|
+
|
12
|
+
* Added pagination features for `Subscription` and `Connection`
|
13
|
+
|
10
14
|
## [0.5.0] - 2020-04-08
|
11
15
|
|
12
16
|
* Added `granted_oauth_scopes`, `requested_oauth_scopes`, and `requested_oauth_scopes_waiting_for_approval` to Person and Organization
|
@@ -49,7 +53,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
49
53
|
### Added
|
50
54
|
- Added subscriptions (migration required)
|
51
55
|
|
52
|
-
[Unreleased]: https://github.com/zaikio/zaikio-hub-ruby/compare/v0.
|
56
|
+
[Unreleased]: https://github.com/zaikio/zaikio-hub-ruby/compare/v0.6.0..HEAD
|
57
|
+
[0.6.0]: https://github.com/zaikio/zaikio-hub-ruby/compare/v0.5.0..v0.6.0
|
53
58
|
[0.5.0]: https://github.com/zaikio/zaikio-hub-ruby/compare/v0.4.1..v0.5.0
|
54
59
|
[0.4.1]: https://github.com/zaikio/zaikio-hub-ruby/compare/v0.4.0...v0.4.1
|
55
60
|
[0.4.0]: https://github.com/zaikio/zaikio-hub-ruby/compare/v0.3.0...v0.4.0
|
data/README.md
CHANGED
@@ -122,7 +122,17 @@ client.test_accounts.create(
|
|
122
122
|
|
123
123
|
```rb
|
124
124
|
Zaikio::Hub.with_basic_auth(client_id, client_secret) do
|
125
|
-
|
125
|
+
# Iterate through pages
|
126
|
+
Zaikio::Hub::Connection.per_page(10).each_page do |connections|
|
127
|
+
connections.size # e.g. 10
|
128
|
+
connections.total_count
|
129
|
+
connections.total_pages
|
130
|
+
end
|
131
|
+
# Load 2nd page
|
132
|
+
Zaikio::Hub::Connection.per_page(10).page(2)
|
133
|
+
# All
|
134
|
+
all_connections = Zaikio::Hub::Connection.all.each_page.flat_map(&:to_a)
|
135
|
+
|
126
136
|
subscription = Zaikio::Hub::Subscription.find("Organization-b1475f65-236c-58b8-96e1-e1778b43beb7")
|
127
137
|
subscription.plan # => "advanced"
|
128
138
|
subscription.activate!
|
data/lib/zaikio/hub.rb
CHANGED
@@ -5,6 +5,9 @@ require "zaikio/hub/json_parser"
|
|
5
5
|
require "zaikio/hub/authorization_middleware"
|
6
6
|
require "zaikio/hub/basic_auth_middleware"
|
7
7
|
|
8
|
+
# Pagination
|
9
|
+
require "zaikio/hub/pagination"
|
10
|
+
|
8
11
|
# Models
|
9
12
|
require "zaikio/error"
|
10
13
|
require "zaikio/hub/client"
|
@@ -70,6 +73,7 @@ module Zaikio
|
|
70
73
|
ssl: { verify: configuration.environment != :test }) do |c|
|
71
74
|
c.request :json
|
72
75
|
c.response :logger, configuration&.logger, headers: false
|
76
|
+
c.use Zaikio::Hub::Pagination::HeaderParser
|
73
77
|
c.use JSONParser
|
74
78
|
c.use AuthorizationMiddleware
|
75
79
|
c.use BasicAuthMiddleware
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# adapted from https://github.com/balvig/spyke-kaminari
|
2
|
+
|
3
|
+
module Zaikio
|
4
|
+
module Hub
|
5
|
+
module Pagination
|
6
|
+
HEADERS = {
|
7
|
+
total_count: "Total-Count",
|
8
|
+
total_pages: "Total-Pages",
|
9
|
+
current_page: "Current-Page"
|
10
|
+
}.freeze
|
11
|
+
|
12
|
+
METADATA_KEY = :pagination
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
require "zaikio/hub/pagination/scopes"
|
18
|
+
require "zaikio/hub/pagination/relation"
|
19
|
+
require "zaikio/hub/pagination/header_parser"
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Zaikio
|
2
|
+
module Hub
|
3
|
+
module Pagination
|
4
|
+
class HeaderParser < Faraday::Response::Middleware
|
5
|
+
def on_complete(env)
|
6
|
+
@env = env
|
7
|
+
|
8
|
+
metadata = Zaikio::Hub::Pagination::HEADERS.transform_values do |key|
|
9
|
+
header(key)
|
10
|
+
end
|
11
|
+
|
12
|
+
@env.body[:metadata] ||= {}
|
13
|
+
@env.body[:metadata][Zaikio::Hub::Pagination::METADATA_KEY] = metadata
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def header(key)
|
19
|
+
value = @env.response_headers[key]
|
20
|
+
value.try(:to_i)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module Zaikio
|
2
|
+
module Hub
|
3
|
+
module Pagination
|
4
|
+
class Relation < Spyke::Relation
|
5
|
+
Zaikio::Hub::Pagination::HEADERS.each_key do |symbol|
|
6
|
+
define_method(symbol) do
|
7
|
+
find_some.metadata[Zaikio::Hub::Pagination::METADATA_KEY][symbol]
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def first_page?
|
12
|
+
current_page == 1
|
13
|
+
end
|
14
|
+
|
15
|
+
def next_page
|
16
|
+
current_page + 1
|
17
|
+
end
|
18
|
+
|
19
|
+
def last_page?
|
20
|
+
current_page == total_pages
|
21
|
+
end
|
22
|
+
|
23
|
+
def out_of_range?
|
24
|
+
current_page > total_pages
|
25
|
+
end
|
26
|
+
|
27
|
+
def each_page
|
28
|
+
return to_enum(:each_page) unless block_given?
|
29
|
+
|
30
|
+
relation = clone
|
31
|
+
yield relation
|
32
|
+
return if relation.last_page? || relation.out_of_range?
|
33
|
+
|
34
|
+
(relation.next_page..relation.total_pages).each do |number|
|
35
|
+
yield clone.page(number)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Zaikio
|
2
|
+
module Hub
|
3
|
+
module Pagination
|
4
|
+
module Scopes
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
included do
|
8
|
+
%i[page per_page].each do |symbol|
|
9
|
+
scope symbol, ->(value) { where(symbol => value) }
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
module ClassMethods
|
14
|
+
# Overrides the method included by Spyke::Scoping to return paginated
|
15
|
+
# relations.
|
16
|
+
def all
|
17
|
+
current_scope || Zaikio::Hub::Pagination::Relation.new(self, uri: uri)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/lib/zaikio/hub/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zaikio-hub
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- crispymtn
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2021-04-
|
13
|
+
date: 2021-04-12 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: concurrent-ruby
|
@@ -131,6 +131,10 @@ files:
|
|
131
131
|
- lib/zaikio/hub/membership.rb
|
132
132
|
- lib/zaikio/hub/organization.rb
|
133
133
|
- lib/zaikio/hub/organization_membership.rb
|
134
|
+
- lib/zaikio/hub/pagination.rb
|
135
|
+
- lib/zaikio/hub/pagination/header_parser.rb
|
136
|
+
- lib/zaikio/hub/pagination/relation.rb
|
137
|
+
- lib/zaikio/hub/pagination/scopes.rb
|
134
138
|
- lib/zaikio/hub/person.rb
|
135
139
|
- lib/zaikio/hub/revoked_access_token.rb
|
136
140
|
- lib/zaikio/hub/role.rb
|