zaikio-hub 0.4.0 → 0.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +27 -1
- data/README.md +11 -1
- data/lib/zaikio/hub.rb +4 -0
- data/lib/zaikio/hub/address.rb +8 -2
- data/lib/zaikio/hub/client.rb +7 -0
- data/lib/zaikio/hub/connection.rb +4 -1
- data/lib/zaikio/hub/current_organization.rb +4 -2
- data/lib/zaikio/hub/current_person.rb +3 -2
- data/lib/zaikio/hub/organization.rb +3 -1
- 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/person.rb +3 -1
- data/lib/zaikio/hub/subscription.rb +2 -0
- data/lib/zaikio/hub/version.rb +1 -1
- metadata +14 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 41182413d16f0e32529d683822ca39dfdd86e35186ba9197c936e00cb25b3a60
|
4
|
+
data.tar.gz: 975d3e33def4f1dbd77ddb3020ca2d072e142d2f32ba63cb524b8c86f852f3f6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 998198e1e90035fbe5bb2f25539d0b27b28f291de13b00784dc7ec4207af18145729284e5dc599839236e20c38c3d1d8b75b42e57ac2e170bbad558dcf212fb6
|
7
|
+
data.tar.gz: 80f7dbe3fe80a6d9699ba96d3794b43b7020d9e874f0d8c43002174f7e4032c0286ee135957eccac419f3867190e227885baa7d3f9a93eebe4df160ab0ae24c3
|
data/CHANGELOG.md
CHANGED
@@ -7,6 +7,27 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
7
7
|
|
8
8
|
## [Unreleased]
|
9
9
|
|
10
|
+
## [0.6.2] - 2021-04-27
|
11
|
+
|
12
|
+
* Include `id` property in `CurrentPerson#attributes` and `CurrentOrganization#attributes`
|
13
|
+
|
14
|
+
## [0.6.1] - 2020-04-12
|
15
|
+
|
16
|
+
* Fixed that `each_page` works correctly with client instance
|
17
|
+
|
18
|
+
## [0.6.0] - 2020-04-12
|
19
|
+
|
20
|
+
* Added pagination features for `Subscription` and `Connection`
|
21
|
+
|
22
|
+
## [0.5.0] - 2020-04-08
|
23
|
+
|
24
|
+
* Added `granted_oauth_scopes`, `requested_oauth_scopes`, and `requested_oauth_scopes_waiting_for_approval` to Person and Organization
|
25
|
+
* Added `requested_oauth_scopes`, and `requested_oauth_scopes_waiting_for_approval` to Connection
|
26
|
+
|
27
|
+
## [0.4.1] - 2020-03-04
|
28
|
+
|
29
|
+
* Add `state` property for `Zaikio::Hub::Address` model
|
30
|
+
|
10
31
|
## [0.4.0] - 2020-02-23
|
11
32
|
|
12
33
|
### Changed
|
@@ -40,7 +61,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
40
61
|
### Added
|
41
62
|
- Added subscriptions (migration required)
|
42
63
|
|
43
|
-
[Unreleased]: https://github.com/zaikio/zaikio-hub-ruby/compare/v0.
|
64
|
+
[Unreleased]: https://github.com/zaikio/zaikio-hub-ruby/compare/v0.6.2..HEAD
|
65
|
+
[0.6.2]: https://github.com/zaikio/zaikio-hub-ruby/compare/v0.6.1..v0.6.2
|
66
|
+
[0.6.1]: https://github.com/zaikio/zaikio-hub-ruby/compare/v0.6.0..v0.6.1
|
67
|
+
[0.6.0]: https://github.com/zaikio/zaikio-hub-ruby/compare/v0.5.0..v0.6.0
|
68
|
+
[0.5.0]: https://github.com/zaikio/zaikio-hub-ruby/compare/v0.4.1..v0.5.0
|
69
|
+
[0.4.1]: https://github.com/zaikio/zaikio-hub-ruby/compare/v0.4.0...v0.4.1
|
44
70
|
[0.4.0]: https://github.com/zaikio/zaikio-hub-ruby/compare/v0.3.0...v0.4.0
|
45
71
|
[0.3.0]: https://github.com/zaikio/zaikio-hub-ruby/compare/v0.2.0...v.0.3.0
|
46
72
|
[0.2.0]: https://github.com/zaikio/zaikio-hub-ruby/compare/v0.1.1...v.0.2.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
|
data/lib/zaikio/hub/address.rb
CHANGED
@@ -2,8 +2,14 @@ module Zaikio
|
|
2
2
|
module Hub
|
3
3
|
class Address < Base
|
4
4
|
# Attributes
|
5
|
-
attributes :addressee,
|
6
|
-
:
|
5
|
+
attributes :addressee,
|
6
|
+
:addition,
|
7
|
+
:country_code,
|
8
|
+
:state,
|
9
|
+
:street_and_number,
|
10
|
+
:text,
|
11
|
+
:town,
|
12
|
+
:zip_code
|
7
13
|
|
8
14
|
# Associations
|
9
15
|
belongs_to :site, uri: nil, class_name: "Zaikio::Hub::Site"
|
data/lib/zaikio/hub/client.rb
CHANGED
@@ -1,13 +1,16 @@
|
|
1
1
|
module Zaikio
|
2
2
|
module Hub
|
3
3
|
class Connection < Base
|
4
|
+
include Zaikio::Hub::Pagination::Scopes
|
5
|
+
|
4
6
|
uri "connections(/:id)"
|
5
7
|
|
6
8
|
include_root_in_json :connection
|
7
9
|
|
8
10
|
# Attributes
|
9
11
|
attributes :updated_at, :created_at, :connectable_type, :connectable_id,
|
10
|
-
:app_name, :granted_oauth_scopes
|
12
|
+
:app_name, :granted_oauth_scopes, :requested_oauth_scopes,
|
13
|
+
:requested_oauth_scopes_waiting_for_approval
|
11
14
|
|
12
15
|
def initialize(attributes = {})
|
13
16
|
if attributes["connectable_id"]
|
@@ -16,9 +16,11 @@ module Zaikio
|
|
16
16
|
include_root_in_json :organization
|
17
17
|
|
18
18
|
# Attributes
|
19
|
-
attributes :name, :slug, :logo_url, :connected, :subscription,
|
19
|
+
attributes :id, :name, :slug, :logo_url, :connected, :subscription,
|
20
20
|
:created_at, :updated_at, :country_code, :kinds,
|
21
|
-
:sections, :currency, :brand_color, :test_account_owner_id
|
21
|
+
:sections, :currency, :brand_color, :test_account_owner_id,
|
22
|
+
:granted_oauth_scopes, :requested_oauth_scopes,
|
23
|
+
:requested_oauth_scopes_waiting_for_approval
|
22
24
|
|
23
25
|
# Associations
|
24
26
|
has_many :memberships, class_name: "Zaikio::Hub::Membership",
|
@@ -6,11 +6,12 @@ module Zaikio
|
|
6
6
|
uri "person"
|
7
7
|
|
8
8
|
# Attributes
|
9
|
-
attributes :updated_at, :created_at, :first_name, :name, :full_name, :email,
|
9
|
+
attributes :id, :updated_at, :created_at, :first_name, :name, :full_name, :email,
|
10
10
|
:pronoun, :locale, :country_code, :currency, :unit_system, :connected,
|
11
11
|
:test_account_owner_id, :time_zone, :email_confirmed,
|
12
12
|
:two_factor_authentication_enabled, :avatar_url, :subscription,
|
13
|
-
:accessible_apps
|
13
|
+
:accessible_apps, :granted_oauth_scopes, :requested_oauth_scopes,
|
14
|
+
:requested_oauth_scopes_waiting_for_approval
|
14
15
|
|
15
16
|
def self.find
|
16
17
|
all.find_one
|
@@ -8,7 +8,9 @@ module Zaikio
|
|
8
8
|
# Attributes
|
9
9
|
attributes :name, :slug, :logo_url, :connected, :subscription,
|
10
10
|
:created_at, :updated_at, :country_code, :kinds,
|
11
|
-
:sections, :currency, :brand_color, :test_account_owner_id
|
11
|
+
:sections, :currency, :brand_color, :test_account_owner_id,
|
12
|
+
:granted_oauth_scopes, :requested_oauth_scopes,
|
13
|
+
:requested_oauth_scopes_waiting_for_approval
|
12
14
|
|
13
15
|
# Associations
|
14
16
|
has_many :memberships, class_name: "Zaikio::Hub::Membership",
|
@@ -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/person.rb
CHANGED
@@ -5,7 +5,9 @@ module Zaikio
|
|
5
5
|
attributes :updated_at, :created_at, :first_name, :name, :full_name, :email,
|
6
6
|
:pronoun, :locale, :country_code, :currency, :unit_system, :connected,
|
7
7
|
:test_account_owner_id, :time_zone, :email_confirmed,
|
8
|
-
:two_factor_authentication_enabled, :avatar_url, :subscription
|
8
|
+
:two_factor_authentication_enabled, :avatar_url, :subscription,
|
9
|
+
:granted_oauth_scopes, :requested_oauth_scopes,
|
10
|
+
:requested_oauth_scopes_waiting_for_approval
|
9
11
|
end
|
10
12
|
end
|
11
13
|
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.2
|
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-
|
13
|
+
date: 2021-04-27 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: concurrent-ruby
|
@@ -84,16 +84,22 @@ dependencies:
|
|
84
84
|
name: spyke
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- - "
|
87
|
+
- - ">="
|
88
88
|
- !ruby/object:Gem::Version
|
89
89
|
version: 5.3.4
|
90
|
+
- - "<"
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: 5.5.0
|
90
93
|
type: :runtime
|
91
94
|
prerelease: false
|
92
95
|
version_requirements: !ruby/object:Gem::Requirement
|
93
96
|
requirements:
|
94
|
-
- - "
|
97
|
+
- - ">="
|
95
98
|
- !ruby/object:Gem::Version
|
96
99
|
version: 5.3.4
|
100
|
+
- - "<"
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: 5.5.0
|
97
103
|
description: Ruby API Client for Zaikio's Hub
|
98
104
|
email:
|
99
105
|
- op@crispymtn.com
|
@@ -125,6 +131,10 @@ files:
|
|
125
131
|
- lib/zaikio/hub/membership.rb
|
126
132
|
- lib/zaikio/hub/organization.rb
|
127
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
|
128
138
|
- lib/zaikio/hub/person.rb
|
129
139
|
- lib/zaikio/hub/revoked_access_token.rb
|
130
140
|
- lib/zaikio/hub/role.rb
|