zaikio-hub 0.6.1 → 0.9.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: 76ec2ffbec46a39d7132335f3855db80abbe10eaf2c8aebcedb31c1785715f6b
4
- data.tar.gz: d69171f7abc873c12c766ddfdd188d7f0cd7be0df4c81ab0206cc9ef9cc255c4
3
+ metadata.gz: 18214a7030901b40e09a743798f3356cc2821588be5639360466d510425ecc1a
4
+ data.tar.gz: f1f691ed65c67d461bf4cc95ed0fdea6bf258ee7e8a7fb92778396c921df7bbe
5
5
  SHA512:
6
- metadata.gz: 5290f7d1e9edfb3f08522e1098b663fe7f10cde3978a3ae9c48680b9ff90bc6b599d356c5536277311398716088039eda6046cb234ae1d14f9813c1ad27fdc0d
7
- data.tar.gz: c88e8b7d077797ae90a843f42ceeb9e0c999ff69f1add278a70b5acd875ddd86934ab59f917af0547b1cf7031b8dc7847faf653a7f1476fdee7da8196f2402cb
6
+ metadata.gz: 7fb26a98cbf56f0cb9e4390d88af710b0452539b65d5f3b3dce474936e373bfaa77b6e98e1731560b9b44a2808ac96a958ac0b9a501961158084388cd94526e7
7
+ data.tar.gz: 79a2a1bcaf197e4eae88d31a8b87f0a3e127b1927f3e33f1437c9c52f5e1fd4e2fa42691974bee2c555c1eef6ec4f7a8aeb2263ec656ff2bd535267d0e3c8925
data/CHANGELOG.md CHANGED
@@ -7,6 +7,30 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.9.0] - 2021-08-31
11
+
12
+ * Added `.connections` and `.apps` for `CurrentOrganization`s that are vendors
13
+
14
+ ## [0.8.0] - 2021-08-25
15
+
16
+ * Added `CurrentOrganization#create_subscription`
17
+
18
+ ## [0.7.0] - 2021-06-18
19
+
20
+ * **BREAKING** `Relation#all` now fetches all following paginated resources by default
21
+ (endpoints which don't support pagination are unaffected).
22
+ * **BREAKING** Removed `Relation#each_page` method. You should just use the `all` method now
23
+ instead:
24
+
25
+ ```diff
26
+ -Model.all.each_page.flat_map(&:to_a)
27
+ +Model.all.to_a
28
+ ```
29
+
30
+ ## [0.6.2] - 2021-04-27
31
+
32
+ * Include `id` property in `CurrentPerson#attributes` and `CurrentOrganization#attributes`
33
+
10
34
  ## [0.6.1] - 2020-04-12
11
35
 
12
36
  * Fixed that `each_page` works correctly with client instance
@@ -57,7 +81,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
57
81
  ### Added
58
82
  - Added subscriptions (migration required)
59
83
 
60
- [Unreleased]: https://github.com/zaikio/zaikio-hub-ruby/compare/v0.6.1..HEAD
84
+ [Unreleased]: https://github.com/zaikio/zaikio-hub-ruby/compare/v0.9.0..HEAD
85
+ [0.9.0]: https://github.com/zaikio/zaikio-hub-ruby/compare/v0.8.0..v0.9.0
86
+ [0.8.0]: https://github.com/zaikio/zaikio-hub-ruby/compare/v0.7.0..v0.8.0
87
+ [0.7.0]: https://github.com/zaikio/zaikio-hub-ruby/compare/v0.6.2..v0.7.0
88
+ [0.6.2]: https://github.com/zaikio/zaikio-hub-ruby/compare/v0.6.1..v0.6.2
61
89
  [0.6.1]: https://github.com/zaikio/zaikio-hub-ruby/compare/v0.6.0..v0.6.1
62
90
  [0.6.0]: https://github.com/zaikio/zaikio-hub-ruby/compare/v0.5.0..v0.6.0
63
91
  [0.5.0]: https://github.com/zaikio/zaikio-hub-ruby/compare/v0.4.1..v0.5.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,16 +124,15 @@ client.test_accounts.create(
122
124
 
123
125
  ```rb
124
126
  Zaikio::Hub.with_basic_auth(client_id, client_secret) do
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)
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
+
133
134
  # All
134
- all_connections = Zaikio::Hub::Connection.all.each_page.flat_map(&:to_a)
135
+ all_connections = Zaikio::Hub::Connection.all.to_a
135
136
 
136
137
  subscription = Zaikio::Hub::Subscription.find("Organization-b1475f65-236c-58b8-96e1-e1778b43beb7")
137
138
  subscription.plan # => "advanced"
@@ -0,0 +1,12 @@
1
+ module Zaikio
2
+ module Hub
3
+ class App < Base
4
+ uri "apps(/:id)"
5
+
6
+ include_root_in_json :app
7
+
8
+ # Attributes
9
+ attributes :name, :category, :kind, :state, :configuration
10
+ end
11
+ end
12
+ end
@@ -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
@@ -1,8 +1,6 @@
1
1
  module Zaikio
2
2
  module Hub
3
3
  class Connection < Base
4
- include Zaikio::Hub::Pagination::Scopes
5
-
6
4
  uri "connections(/:id)"
7
5
 
8
6
  include_root_in_json :connection
@@ -16,7 +16,7 @@ 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
21
  :sections, :currency, :brand_color, :test_account_owner_id,
22
22
  :granted_oauth_scopes, :requested_oauth_scopes,
@@ -35,6 +35,11 @@ module Zaikio
35
35
  uri: "specialists(/:id)"
36
36
  has_many :sites, class_name: "Zaikio::Hub::Site",
37
37
  uri: "sites(/:id)"
38
+ # For vendors
39
+ has_many :connections, class_name: "Zaikio::Hub::Connection",
40
+ uri: "connections(/:id)"
41
+ has_many :apps, class_name: "Zaikio::Hub::App",
42
+ uri: "apps(/:id)"
38
43
 
39
44
  def fetch
40
45
  self.attributes = get
@@ -47,6 +52,14 @@ module Zaikio
47
52
  def members
48
53
  memberships.with_fallback.map(&:person)
49
54
  end
55
+
56
+ def create_subscription(status: "active", plan_name: nil)
57
+ if Zaikio::Hub.current_token_data.subject_type == "Organization"
58
+ result = self.class.request(:post, "organization/subscription",
59
+ subscription: { status: status, plan_name: plan_name })
60
+ Zaikio::Hub::Subscription.new(result.data)
61
+ end
62
+ end
50
63
  end
51
64
  end
52
65
  end
@@ -6,7 +6,7 @@ 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,
@@ -1,8 +1,6 @@
1
1
  module Zaikio
2
2
  module Hub
3
3
  class Subscription < Base
4
- include Zaikio::Hub::Pagination::Scopes
5
-
6
4
  uri "subscriptions(/:id)"
7
5
 
8
6
  include_root_in_json :subscription
@@ -10,7 +8,7 @@ module Zaikio
10
8
  # Attributes
11
9
  attributes :updated_at, :created_at, :subscriber_type, :subscriber_id,
12
10
  :status, :app_name, :activated_at, :last_billed_at,
13
- :last_paid_at, :trial_ended_at, :plan, :preceding_plan,
11
+ :last_paid_at, :trial_ended_at, :plan, :plan_name, :preceding_plan,
14
12
  :changed_plan_at, :usages_in_current_billing_period
15
13
 
16
14
  def initialize(attributes = {})
@@ -1,5 +1,5 @@
1
1
  module Zaikio
2
2
  module Hub
3
- VERSION = "0.6.1".freeze
3
+ VERSION = "0.9.0".freeze
4
4
  end
5
5
  end
data/lib/zaikio/hub.rb CHANGED
@@ -1,15 +1,12 @@
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
 
8
- # Pagination
9
- require "zaikio/hub/pagination"
10
-
11
9
  # Models
12
- require "zaikio/error"
13
10
  require "zaikio/hub/client"
14
11
  require "zaikio/hub/base"
15
12
  require "zaikio/hub/asset"
@@ -28,6 +25,7 @@ require "zaikio/hub/current_organization"
28
25
  require "zaikio/hub/role"
29
26
  require "zaikio/hub/revoked_access_token"
30
27
  require "zaikio/hub/connection"
28
+ require "zaikio/hub/app"
31
29
  require "zaikio/hub/subscription"
32
30
  require "zaikio/hub/test_account"
33
31
 
@@ -73,8 +71,8 @@ module Zaikio
73
71
  ssl: { verify: configuration.environment != :test }) do |c|
74
72
  c.request :json
75
73
  c.response :logger, configuration&.logger, headers: false
76
- c.use Zaikio::Hub::Pagination::HeaderParser
77
- c.use JSONParser
74
+ c.use Zaikio::Client::Helpers::Pagination::FaradayMiddleware
75
+ c.use Zaikio::Client::Helpers::JSONParser
78
76
  c.use AuthorizationMiddleware
79
77
  c.use BasicAuthMiddleware
80
78
  c.adapter Faraday.default_adapter
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.6.1
4
+ version: 0.9.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-12 00:00:00.000000000 Z
13
+ date: 2021-08-31 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: concurrent-ruby
@@ -69,7 +69,7 @@ dependencies:
69
69
  version: 3.10.5
70
70
  - - "<"
71
71
  - !ruby/object:Gem::Version
72
- version: 3.12.0
72
+ version: 3.14.0
73
73
  type: :runtime
74
74
  prerelease: false
75
75
  version_requirements: !ruby/object:Gem::Requirement
@@ -79,7 +79,7 @@ dependencies:
79
79
  version: 3.10.5
80
80
  - - "<"
81
81
  - !ruby/object:Gem::Version
82
- version: 3.12.0
82
+ version: 3.14.0
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: spyke
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -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.2'
110
+ type: :runtime
111
+ prerelease: false
112
+ version_requirements: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - "~>"
115
+ - !ruby/object:Gem::Version
116
+ version: '0.2'
103
117
  description: Ruby API Client for Zaikio's Hub
104
118
  email:
105
119
  - op@crispymtn.com
@@ -113,9 +127,9 @@ files:
113
127
  - MIT-LICENSE
114
128
  - README.md
115
129
  - Rakefile
116
- - lib/zaikio/error.rb
117
130
  - lib/zaikio/hub.rb
118
131
  - lib/zaikio/hub/address.rb
132
+ - lib/zaikio/hub/app.rb
119
133
  - lib/zaikio/hub/asset.rb
120
134
  - lib/zaikio/hub/authorization_middleware.rb
121
135
  - lib/zaikio/hub/base.rb
@@ -126,15 +140,10 @@ 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
133
146
  - 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
138
147
  - lib/zaikio/hub/person.rb
139
148
  - lib/zaikio/hub/revoked_access_token.rb
140
149
  - lib/zaikio/hub/role.rb
data/lib/zaikio/error.rb DELETED
@@ -1,18 +0,0 @@
1
- module Zaikio
2
- class Error < StandardError; end
3
-
4
- class ConnectionError < Zaikio::Error; end
5
-
6
- class ResourceNotFound < Zaikio::Error; end
7
- end
8
-
9
- module Spyke
10
- instance_eval do
11
- # avoid warning: already initialized constant
12
- remove_const("ConnectionError")
13
- remove_const("ResourceNotFound")
14
- end
15
-
16
- ConnectionError = Class.new Zaikio::ConnectionError
17
- ResourceNotFound = Class.new Zaikio::ResourceNotFound
18
- end
@@ -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
@@ -1,25 +0,0 @@
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
@@ -1,41 +0,0 @@
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
@@ -1,23 +0,0 @@
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
@@ -1,19 +0,0 @@
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"