zaikio-hub 0.6.2 → 0.9.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 41182413d16f0e32529d683822ca39dfdd86e35186ba9197c936e00cb25b3a60
4
- data.tar.gz: 975d3e33def4f1dbd77ddb3020ca2d072e142d2f32ba63cb524b8c86f852f3f6
3
+ metadata.gz: 3cb7e370ad9b9dbb15d7e6637293d95f33cefc3d48b255aafd1d88f9607f77fc
4
+ data.tar.gz: 995f65525b2baf40b34c2cc8d7eaf1685e201a7fbca67fc3834189140b822ca2
5
5
  SHA512:
6
- metadata.gz: 998198e1e90035fbe5bb2f25539d0b27b28f291de13b00784dc7ec4207af18145729284e5dc599839236e20c38c3d1d8b75b42e57ac2e170bbad558dcf212fb6
7
- data.tar.gz: 80f7dbe3fe80a6d9699ba96d3794b43b7020d9e874f0d8c43002174f7e4032c0286ee135957eccac419f3867190e227885baa7d3f9a93eebe4df160ab0ae24c3
6
+ metadata.gz: ca9c4d829d55480f69cfa5b619d8d471486ac15ad1b5a8bc4aa9c4b2ada5508948be81b82ef0ce309c21d09d427d604c0352add0309d2f08f5ea5fd09a268fc0
7
+ data.tar.gz: 0a5f4048cdf0b65e5f42cae0e4da1c18ed5fe7d73232b098956de8cbad736f4fde4998abce70d14e54992213d9a3dd5a54a5dcf3d60835b40f76cdcc313e766a
data/CHANGELOG.md CHANGED
@@ -7,6 +7,31 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.9.1] - 2022-01-05
11
+
12
+ * Fix warning about redefined methods in BasicAuthMiddleware
13
+ * Permit newer versions of Spyke & JWT gems
14
+
15
+ ## [0.9.0] - 2021-08-31
16
+
17
+ * Added `.connections` and `.apps` for `CurrentOrganization`s that are vendors
18
+
19
+ ## [0.8.0] - 2021-08-25
20
+
21
+ * Added `CurrentOrganization#create_subscription`
22
+
23
+ ## [0.7.0] - 2021-06-18
24
+
25
+ * **BREAKING** `Relation#all` now fetches all following paginated resources by default
26
+ (endpoints which don't support pagination are unaffected).
27
+ * **BREAKING** Removed `Relation#each_page` method. You should just use the `all` method now
28
+ instead:
29
+
30
+ ```diff
31
+ -Model.all.each_page.flat_map(&:to_a)
32
+ +Model.all.to_a
33
+ ```
34
+
10
35
  ## [0.6.2] - 2021-04-27
11
36
 
12
37
  * Include `id` property in `CurrentPerson#attributes` and `CurrentOrganization#attributes`
@@ -61,7 +86,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
61
86
  ### Added
62
87
  - Added subscriptions (migration required)
63
88
 
64
- [Unreleased]: https://github.com/zaikio/zaikio-hub-ruby/compare/v0.6.2..HEAD
89
+ [Unreleased]: https://github.com/zaikio/zaikio-hub-ruby/compare/v0.9.0..HEAD
90
+ [0.9.0]: https://github.com/zaikio/zaikio-hub-ruby/compare/v0.8.0..v0.9.0
91
+ [0.8.0]: https://github.com/zaikio/zaikio-hub-ruby/compare/v0.7.0..v0.8.0
92
+ [0.7.0]: https://github.com/zaikio/zaikio-hub-ruby/compare/v0.6.2..v0.7.0
65
93
  [0.6.2]: https://github.com/zaikio/zaikio-hub-ruby/compare/v0.6.1..v0.6.2
66
94
  [0.6.1]: https://github.com/zaikio/zaikio-hub-ruby/compare/v0.6.0..v0.6.1
67
95
  [0.6.0]: https://github.com/zaikio/zaikio-hub-ruby/compare/v0.5.0..v0.6.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"
data/Rakefile CHANGED
@@ -29,9 +29,7 @@ task default: :test
29
29
 
30
30
  namespace :test do
31
31
  desc 'Runs RuboCop on specified directories'
32
- RuboCop::RakeTask.new(:rubocop) do |task|
33
- task.fail_on_error = false
34
- end
32
+ RuboCop::RakeTask.new(:rubocop)
35
33
  end
36
34
 
37
35
  Rake::Task[:test].enhance ['test:rubocop']
@@ -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
@@ -4,8 +4,6 @@ require "base64"
4
4
  module Zaikio
5
5
  module Hub
6
6
  class BasicAuthMiddleware < Faraday::Middleware
7
- class_attribute :credentials
8
-
9
7
  def self.credentials
10
8
  @credentials ||= Concurrent::ThreadLocalVar.new { nil }
11
9
  @credentials.value
@@ -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
@@ -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
+ return unless Zaikio::Hub.current_token_data.subject_type == "Organization"
58
+
59
+ result = self.class.request(:post, "organization/subscription",
60
+ subscription: { status: status, plan_name: plan_name })
61
+ Zaikio::Hub::Subscription.new(result.data)
62
+ end
50
63
  end
51
64
  end
52
65
  end
@@ -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.2".freeze
3
+ VERSION = "0.9.1".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.2
4
+ version: 0.9.1
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-27 00:00:00.000000000 Z
13
+ date: 2022-01-05 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: concurrent-ruby
@@ -30,16 +30,22 @@ dependencies:
30
30
  name: jwt
31
31
  requirement: !ruby/object:Gem::Requirement
32
32
  requirements:
33
- - - "~>"
33
+ - - ">="
34
34
  - !ruby/object:Gem::Version
35
35
  version: 2.2.1
36
+ - - "<"
37
+ - !ruby/object:Gem::Version
38
+ version: 2.4.0
36
39
  type: :runtime
37
40
  prerelease: false
38
41
  version_requirements: !ruby/object:Gem::Requirement
39
42
  requirements:
40
- - - "~>"
43
+ - - ">="
41
44
  - !ruby/object:Gem::Version
42
45
  version: 2.2.1
46
+ - - "<"
47
+ - !ruby/object:Gem::Version
48
+ version: 2.4.0
43
49
  - !ruby/object:Gem::Dependency
44
50
  name: multi_json
45
51
  requirement: !ruby/object:Gem::Requirement
@@ -69,7 +75,7 @@ dependencies:
69
75
  version: 3.10.5
70
76
  - - "<"
71
77
  - !ruby/object:Gem::Version
72
- version: 3.12.0
78
+ version: 3.14.0
73
79
  type: :runtime
74
80
  prerelease: false
75
81
  version_requirements: !ruby/object:Gem::Requirement
@@ -79,7 +85,7 @@ dependencies:
79
85
  version: 3.10.5
80
86
  - - "<"
81
87
  - !ruby/object:Gem::Version
82
- version: 3.12.0
88
+ version: 3.14.0
83
89
  - !ruby/object:Gem::Dependency
84
90
  name: spyke
85
91
  requirement: !ruby/object:Gem::Requirement
@@ -89,7 +95,7 @@ dependencies:
89
95
  version: 5.3.4
90
96
  - - "<"
91
97
  - !ruby/object:Gem::Version
92
- version: 5.5.0
98
+ version: 6.2.0
93
99
  type: :runtime
94
100
  prerelease: false
95
101
  version_requirements: !ruby/object:Gem::Requirement
@@ -99,7 +105,21 @@ dependencies:
99
105
  version: 5.3.4
100
106
  - - "<"
101
107
  - !ruby/object:Gem::Version
102
- version: 5.5.0
108
+ version: 6.2.0
109
+ - !ruby/object:Gem::Dependency
110
+ name: zaikio-client-helpers
111
+ requirement: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - "~>"
114
+ - !ruby/object:Gem::Version
115
+ version: '0.2'
116
+ type: :runtime
117
+ prerelease: false
118
+ version_requirements: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - "~>"
121
+ - !ruby/object:Gem::Version
122
+ version: '0.2'
103
123
  description: Ruby API Client for Zaikio's Hub
104
124
  email:
105
125
  - op@crispymtn.com
@@ -113,9 +133,9 @@ files:
113
133
  - MIT-LICENSE
114
134
  - README.md
115
135
  - Rakefile
116
- - lib/zaikio/error.rb
117
136
  - lib/zaikio/hub.rb
118
137
  - lib/zaikio/hub/address.rb
138
+ - lib/zaikio/hub/app.rb
119
139
  - lib/zaikio/hub/asset.rb
120
140
  - lib/zaikio/hub/authorization_middleware.rb
121
141
  - lib/zaikio/hub/base.rb
@@ -126,15 +146,10 @@ files:
126
146
  - lib/zaikio/hub/connection.rb
127
147
  - lib/zaikio/hub/current_organization.rb
128
148
  - lib/zaikio/hub/current_person.rb
129
- - lib/zaikio/hub/json_parser.rb
130
149
  - lib/zaikio/hub/machine.rb
131
150
  - lib/zaikio/hub/membership.rb
132
151
  - lib/zaikio/hub/organization.rb
133
152
  - 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
153
  - lib/zaikio/hub/person.rb
139
154
  - lib/zaikio/hub/revoked_access_token.rb
140
155
  - 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"