zaikio-hub 0.4.1 → 0.7.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4f6bfd7e6c71ab7f1e36f7e636b0669dcf412df73af3a4ea50e9b0ff65b70bd7
4
- data.tar.gz: f5aa4039ff6e0a9d0474948445d8a41ac8219d607e5127f4a415b6b547908ceb
3
+ metadata.gz: 0e562039d2b3f9feb71cd94761df5ee9beb0bb3152d6e87bcf4ee0385a6357a7
4
+ data.tar.gz: 4302ba8ecdb9493280abf4402e69f9750bb2b3ecd0294d23977bbd748a73082e
5
5
  SHA512:
6
- metadata.gz: ae95dd113b81078b5d8ebaec510682a1a0c256de6586f46a3cf4ca904128c94bcbe45ad14ffca2deed71b4a911ef5afe9944a83a2299a6fb352b63ac0eb52d55
7
- data.tar.gz: d443851cf63f8829dfed8528c7cb4ba3fd2bc4e12492f6e530e4657a9c99d037c3402b66fb12add551d273ebe22882d8d50d5aab731f417cfb83ee40c322b1fb
6
+ metadata.gz: d75dfed1d42bbffdecffcf1543ecf9d9f98e2ccef507e6f2f56bfe847553e17921619273be2e7eac610f82091ef5eb586db5626d287e0877e531461db01c44e1
7
+ data.tar.gz: 23babf7a088b8aca679f11241448a8f2d468488cbe6f213dfe7280f186320d739dc6a539411bd3feaac52979d2ed458479cf1138ebe4a3e7ba21525619e60ca4
data/CHANGELOG.md CHANGED
@@ -7,6 +7,35 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.7.0] - 2021-06-18
11
+
12
+ * **BREAKING** `Relation#all` now fetches all following paginated resources by default
13
+ (endpoints which don't support pagination are unaffected).
14
+ * **BREAKING** Removed `Relation#each_page` method. You should just use the `all` method now
15
+ instead:
16
+
17
+ ```diff
18
+ -Model.all.each_page.flat_map(&:to_a)
19
+ +Model.all.to_a
20
+ ```
21
+
22
+ ## [0.6.2] - 2021-04-27
23
+
24
+ * Include `id` property in `CurrentPerson#attributes` and `CurrentOrganization#attributes`
25
+
26
+ ## [0.6.1] - 2020-04-12
27
+
28
+ * Fixed that `each_page` works correctly with client instance
29
+
30
+ ## [0.6.0] - 2020-04-12
31
+
32
+ * Added pagination features for `Subscription` and `Connection`
33
+
34
+ ## [0.5.0] - 2020-04-08
35
+
36
+ * Added `granted_oauth_scopes`, `requested_oauth_scopes`, and `requested_oauth_scopes_waiting_for_approval` to Person and Organization
37
+ * Added `requested_oauth_scopes`, and `requested_oauth_scopes_waiting_for_approval` to Connection
38
+
10
39
  ## [0.4.1] - 2020-03-04
11
40
 
12
41
  * Add `state` property for `Zaikio::Hub::Address` model
@@ -44,7 +73,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
44
73
  ### Added
45
74
  - Added subscriptions (migration required)
46
75
 
47
- [Unreleased]: https://github.com/zaikio/zaikio-hub-ruby/compare/v0.4.1...HEAD
76
+ [Unreleased]: https://github.com/zaikio/zaikio-hub-ruby/compare/v0.7.0..HEAD
77
+ [0.7.0]: https://github.com/zaikio/zaikio-hub-ruby/compare/v0.6.2..v0.7.0
78
+ [0.6.2]: https://github.com/zaikio/zaikio-hub-ruby/compare/v0.6.1..v0.6.2
79
+ [0.6.1]: https://github.com/zaikio/zaikio-hub-ruby/compare/v0.6.0..v0.6.1
80
+ [0.6.0]: https://github.com/zaikio/zaikio-hub-ruby/compare/v0.5.0..v0.6.0
81
+ [0.5.0]: https://github.com/zaikio/zaikio-hub-ruby/compare/v0.4.1..v0.5.0
48
82
  [0.4.1]: https://github.com/zaikio/zaikio-hub-ruby/compare/v0.4.0...v0.4.1
49
83
  [0.4.0]: https://github.com/zaikio/zaikio-hub-ruby/compare/v0.3.0...v0.4.0
50
84
  [0.3.0]: https://github.com/zaikio/zaikio-hub-ruby/compare/v0.2.0...v.0.3.0
data/README.md CHANGED
@@ -46,8 +46,10 @@ token = "..." # Your valid JWT for an organization
46
46
  Zaikio::Hub.with_token(token) do
47
47
  organization = Zaikio::Hub::CurrentOrganization.new
48
48
 
49
- # Fetch Data
49
+ # Fetch data
50
50
  organization.memberships.find('abc')
51
+
52
+ # Note that .all understands pagination headers and will fetch all pages
51
53
  organization.members.all
52
54
  organization.machines.all
53
55
  organization.software.all
@@ -122,7 +124,16 @@ client.test_accounts.create(
122
124
 
123
125
  ```rb
124
126
  Zaikio::Hub.with_basic_auth(client_id, client_secret) do
125
- connections = Zaikio::Hub::Connection.all
127
+ # Get total number of records
128
+ Zaikio::Hub::Connection.per_page(10).total_count
129
+ #=> 20
130
+
131
+ # Fetch just the second page
132
+ Zaikio::Hub::Connection.per_page(10).page(2).find_some
133
+
134
+ # All
135
+ all_connections = Zaikio::Hub::Connection.all.to_a
136
+
126
137
  subscription = Zaikio::Hub::Subscription.find("Organization-b1475f65-236c-58b8-96e1-e1778b43beb7")
127
138
  subscription.plan # => "advanced"
128
139
  subscription.activate!
data/lib/zaikio/hub.rb CHANGED
@@ -1,7 +1,8 @@
1
1
  require "faraday"
2
2
  require "spyke"
3
+ require "zaikio-client-helpers"
4
+
3
5
  require "zaikio/hub/configuration"
4
- require "zaikio/hub/json_parser"
5
6
  require "zaikio/hub/authorization_middleware"
6
7
  require "zaikio/hub/basic_auth_middleware"
7
8
 
@@ -70,7 +71,8 @@ module Zaikio
70
71
  ssl: { verify: configuration.environment != :test }) do |c|
71
72
  c.request :json
72
73
  c.response :logger, configuration&.logger, headers: false
73
- c.use JSONParser
74
+ c.use Zaikio::Client::Helpers::Pagination::FaradayMiddleware
75
+ c.use Zaikio::Client::Helpers::JSONParser
74
76
  c.use AuthorizationMiddleware
75
77
  c.use BasicAuthMiddleware
76
78
  c.adapter Faraday.default_adapter
@@ -1,6 +1,8 @@
1
+ require "zaikio/client/model"
2
+
1
3
  module Zaikio
2
4
  module Hub
3
- class Base < Spyke::Base
5
+ class Base < Zaikio::Client::Model
4
6
  self.callback_methods = { create: :post, update: :patch }.freeze
5
7
  end
6
8
  end
@@ -19,6 +19,13 @@ module Zaikio
19
19
  result
20
20
  end
21
21
  end
22
+
23
+ def each_page
24
+ super() do |page|
25
+ page = RequestWrapper.new(page, @client)
26
+ yield(page)
27
+ end
28
+ end
22
29
  end
23
30
 
24
31
  class Client
@@ -7,7 +7,8 @@ module Zaikio
7
7
 
8
8
  # Attributes
9
9
  attributes :updated_at, :created_at, :connectable_type, :connectable_id,
10
- :app_name, :granted_oauth_scopes
10
+ :app_name, :granted_oauth_scopes, :requested_oauth_scopes,
11
+ :requested_oauth_scopes_waiting_for_approval
11
12
 
12
13
  def initialize(attributes = {})
13
14
  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",
@@ -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
@@ -1,5 +1,5 @@
1
1
  module Zaikio
2
2
  module Hub
3
- VERSION = "0.4.1".freeze
3
+ VERSION = "0.7.0".freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,16 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zaikio-hub
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - crispymtn
8
8
  - Jalyna Schröder
9
9
  - Martin Spickermann
10
- autorequire:
10
+ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2021-03-04 00:00:00.000000000 Z
13
+ date: 2021-06-18 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: concurrent-ruby
@@ -89,7 +89,7 @@ dependencies:
89
89
  version: 5.3.4
90
90
  - - "<"
91
91
  - !ruby/object:Gem::Version
92
- version: 5.5.0
92
+ version: 6.1.0
93
93
  type: :runtime
94
94
  prerelease: false
95
95
  version_requirements: !ruby/object:Gem::Requirement
@@ -99,7 +99,21 @@ dependencies:
99
99
  version: 5.3.4
100
100
  - - "<"
101
101
  - !ruby/object:Gem::Version
102
- version: 5.5.0
102
+ version: 6.1.0
103
+ - !ruby/object:Gem::Dependency
104
+ name: zaikio-client-helpers
105
+ requirement: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ type: :runtime
111
+ prerelease: false
112
+ version_requirements: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
103
117
  description: Ruby API Client for Zaikio's Hub
104
118
  email:
105
119
  - op@crispymtn.com
@@ -126,7 +140,6 @@ files:
126
140
  - lib/zaikio/hub/connection.rb
127
141
  - lib/zaikio/hub/current_organization.rb
128
142
  - lib/zaikio/hub/current_person.rb
129
- - lib/zaikio/hub/json_parser.rb
130
143
  - lib/zaikio/hub/machine.rb
131
144
  - lib/zaikio/hub/membership.rb
132
145
  - lib/zaikio/hub/organization.rb
@@ -145,7 +158,7 @@ licenses:
145
158
  - MIT
146
159
  metadata:
147
160
  changelog_uri: https://github.com/zaikio/zaikio-hub-ruby/blob/master/CHANGELOG.md
148
- post_install_message:
161
+ post_install_message:
149
162
  rdoc_options: []
150
163
  require_paths:
151
164
  - lib
@@ -160,8 +173,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
160
173
  - !ruby/object:Gem::Version
161
174
  version: '0'
162
175
  requirements: []
163
- rubygems_version: 3.1.2
164
- signing_key:
176
+ rubygems_version: 3.1.4
177
+ signing_key:
165
178
  specification_version: 4
166
179
  summary: Ruby API Client for Zaikio's Hub
167
180
  test_files: []
@@ -1,36 +0,0 @@
1
- require "multi_json"
2
-
3
- module Zaikio
4
- module Hub
5
- class JSONParser < Faraday::Response::Middleware
6
- def on_complete(env)
7
- connection_error(env) unless /^(2\d\d)|422|404$/.match?(env.status.to_s)
8
-
9
- raise Spyke::ResourceNotFound if env.status.to_s == "404"
10
-
11
- env.body = parse_body(env.body)
12
- end
13
-
14
- def connection_error(env)
15
- Zaikio::Hub.configuration.logger
16
- .error("Zaikio::Hub Status Code #{env.status}, #{env.body}")
17
- raise Spyke::ConnectionError, "Status Code #{env.status}, #{env.body}"
18
- end
19
-
20
- def parse_body(body)
21
- json = MultiJson.load(body, symbolize_keys: true)
22
- {
23
- data: json,
24
- metadata: {},
25
- errors: json.is_a?(Hash) ? json[:errors] : {}
26
- }
27
- rescue MultiJson::ParseError
28
- {
29
- data: {},
30
- metadata: {},
31
- errors: {}
32
- }
33
- end
34
- end
35
- end
36
- end