nexo 0.1.3 → 0.1.5

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: bf53f0b9f6a1041943a11b96d6688fc0506528d29d855615fb651f56d7dfdb81
4
- data.tar.gz: 1b707625c9f1f621daf84912c2bb2de01e008f4b7d7024c31dae0c7fa6019448
3
+ metadata.gz: ba5c579264ba2dddff0d51feddf0f28a92947c507852131030f958bc3b4911a5
4
+ data.tar.gz: 2f1e9ef346625a560dbc98ee357684422b5d9170ae123f82130d2e5ced7e01bb
5
5
  SHA512:
6
- metadata.gz: 536a191c758d2ac7ccab8a5780a1d568820723571b9682382b71b5324de83109179882a1777b2a7380061e8289efec8c9c0e470c8f758ba2ec26a1c57117e575
7
- data.tar.gz: 2f5509307f988bcf11bd57e7582713f7d2dd187f53a6e915ca43050c476363ea427c43cd811ce7a968c90422bf560e79f530aec7f4d4a4fcb001856a2e448514
6
+ metadata.gz: abdd4355a1dab11e798acca2c37bda4c4b0c133fd8e6a36e6ae8eadbb79ea1c6522d325333ba2f54461e37383a042632fb3599bfb5fcfc0526c46b661b2d1ffc
7
+ data.tar.gz: 073eed8eac35693101915193ee7493581ca483c37cf297a6d7adbb9313bc13005184a697002d6a4fede2876d8e487b6b50fa6e971d386571f7ae338fe3077307
data/README.md CHANGED
@@ -21,6 +21,11 @@ Or install it yourself as:
21
21
  $ gem install nexo
22
22
  ```
23
23
 
24
+ Install good_job
25
+ Configure good_job
26
+ max_threads:
27
+ queues:
28
+
24
29
  ## Contributing
25
30
  Contribution directions go here.
26
31
 
@@ -4,6 +4,8 @@ module Nexo
4
4
  if folder.external_identifier.present?
5
5
  protocol_service = ServiceBuilder.instance.build_protocol_service(folder)
6
6
  response = protocol_service.remove_calendar(folder)
7
+ else
8
+ Rails.logger.info("Folder doesn't have external_identifier: #{folder.to_gid}")
7
9
  end
8
10
  end
9
11
  end
@@ -1,10 +1,12 @@
1
1
  module Nexo
2
2
  class FolderSyncJob < BaseJob
3
3
  def perform(folder)
4
+ protocol_service = ServiceBuilder.instance.build_protocol_service(folder)
4
5
  if folder.external_identifier.blank?
5
- protocol_service = ServiceBuilder.instance.build_protocol_service(folder)
6
6
  response = protocol_service.insert_calendar(folder)
7
7
  folder.update(external_identifier: response.id)
8
+ else
9
+ protocol_service.update_calendar(folder)
8
10
  end
9
11
 
10
12
  policies = PolicyService.instance.policies_for(folder)
@@ -17,7 +17,7 @@ module Nexo
17
17
  def store(integration, token)
18
18
  ActiveRecord::Base.transaction do
19
19
  # Maybe these should be destroyed
20
- integration.tokens.active.update_all(tpt_status: :expired)
20
+ integration.tokens.active.update_all(nt_status: :expired)
21
21
 
22
22
  Token.create!(integration:, secret: token)
23
23
  end
@@ -28,7 +28,7 @@ module Nexo
28
28
  token = find_by_id(id)
29
29
 
30
30
  if token.present?
31
- token.update!(tpt_status: :revoked)
31
+ token.update!(nt_status: :revoked)
32
32
  else
33
33
  # TODO: pg_warn("Couldn't find token for revocation: #{id}")
34
34
  end
@@ -37,7 +37,7 @@ module Nexo
37
37
  private
38
38
 
39
39
  def find_by_id(id)
40
- Token.where(environment: Rails.env, integration: id, tpt_status: :active).last
40
+ Token.where(environment: Rails.env, integration: id, nt_status: :active).last
41
41
  end
42
42
  end
43
43
  end
@@ -53,9 +53,13 @@ module Nexo
53
53
  # Guarda el Token
54
54
  # Si el client tiene más permisos que los que el user solicitó
55
55
  def get_credentials(request = nil)
56
- if request.present? && request.session["code_verifier"].present?
56
+ if request.present?
57
57
  # :nocov: tricky
58
- authorizer.code_verifier = request.session["code_verifier"]
58
+ if request.session["code_verifier"].present?
59
+ authorizer.code_verifier = request.session["code_verifier"]
60
+ else
61
+ Rails.logger.warn("Request has no code_verifier")
62
+ end
59
63
  # :nocov:
60
64
  end
61
65
  authorizer.get_credentials @integration, request
@@ -63,11 +67,11 @@ module Nexo
63
67
  # TODO: log
64
68
  end
65
69
 
66
- def get_authorization_url(request)
70
+ def get_authorization_url(request, login_hint: nil)
67
71
  request.session["code_verifier"] ||= Google::Auth::WebUserAuthorizer.generate_code_verifier
68
72
  authorizer.code_verifier = request.session["code_verifier"]
69
- authorizer.get_authorization_url(request:)
70
- # authorizer.get_authorization_url(request:, login_hint: "bla@gmail.com")
73
+ # authorizer.get_authorization_url(request:)
74
+ authorizer.get_authorization_url(request:, login_hint:)
71
75
  end
72
76
 
73
77
  private
@@ -3,8 +3,10 @@ module Nexo
3
3
  #
4
4
  # @raise [Google::Apis::ClientError] possible messages:
5
5
  # - duplicate: The requested identifier already exists.
6
- # - notFound: Not Found
7
- # - forbidden: Forbidden (cuando se intenta updatear un evento que ya fue borrado)
6
+ # - notFound: Not Found (calendar not exists or was deleted)
7
+ # - forbidden: Forbidden (event to update was deleted)
8
+ #
9
+ # TODO! when event to update was deleted, create a new one and warn
8
10
  class GoogleCalendarService < CalendarService
9
11
  # Create an event in a Google Calendar
10
12
  #
@@ -39,11 +41,26 @@ module Nexo
39
41
 
40
42
  # Create a Google calendar
41
43
  def insert_calendar(folder)
44
+ unless folder.integration.token?
45
+ raise Errors::Error, "folder has no token"
46
+ end
47
+
42
48
  cal = build_calendar(folder)
43
49
  response = client.insert_calendar(cal)
44
50
  ApiResponse.new(payload: response.to_json, status: :ok, etag: response.etag, id: response.id)
45
51
  end
46
52
 
53
+ # Create a Google calendar
54
+ def update_calendar(folder)
55
+ unless folder.integration.token?
56
+ raise Errors::Error, "folder has no token"
57
+ end
58
+
59
+ cal = build_calendar(folder)
60
+ response = client.update_calendar(folder.external_identifier, cal)
61
+ ApiResponse.new(payload: response.to_json, status: :ok, etag: response.etag, id: response.id)
62
+ end
63
+
47
64
  def remove_calendar(folder)
48
65
  client.delete_calendar(folder.external_identifier)
49
66
  ApiResponse.new(status: :ok)
@@ -65,6 +82,10 @@ module Nexo
65
82
  private
66
83
 
67
84
  def validate_folder_state!(folder)
85
+ unless folder.integration.token?
86
+ raise Errors::Error, "folder has no token"
87
+ end
88
+
68
89
  if folder.external_identifier.blank?
69
90
  raise Errors::InvalidFolderState, folder
70
91
  end
@@ -10,7 +10,7 @@ module Nexo
10
10
  end
11
11
 
12
12
  def build_protocol_service(folder)
13
- service_klass_name = "#{folder.integration.client.service}_#{folder.protocol}_service".camelcase
13
+ service_klass_name = "#{folder.integration.client.service}_#{folder.nexo_protocol}_service".camelcase
14
14
  build_service(service_klass_name, folder.integration)
15
15
  end
16
16
 
@@ -62,7 +62,7 @@ module Nexo
62
62
  def update_from!(element_version)
63
63
  transaction do
64
64
  # TODO: parse the element_version.payload
65
- # and set the Synchronizable fields according to the Folder#protocol
65
+ # and set the Synchronizable fields according to the Folder#nexo_protocol
66
66
 
67
67
  new_sequence = increment_sequence!
68
68
  element_version.update_sequence!(new_sequence)
@@ -2,14 +2,13 @@
2
2
  #
3
3
  # Table name: nexo_clients
4
4
  #
5
- # id :bigint not null, primary key
6
- # service :integer
7
- # secret :string
8
- # tcp_status :integer
9
- # brand_name :integer
10
- # user_integrations_allowed :boolean
11
- # created_at :datetime not null
12
- # updated_at :datetime not null
5
+ # id :bigint not null, primary key
6
+ # service :integer
7
+ # secret :string
8
+ # nc_status :integer
9
+ # brand_name :integer
10
+ # created_at :datetime not null
11
+ # updated_at :datetime not null
13
12
  #
14
13
  require "google-apis-calendar_v3"
15
14
  require "google-apis-oauth2_v2"
@@ -27,9 +26,9 @@ module Nexo
27
26
  encrypts :secret
28
27
 
29
28
  enum :service, google: 0
30
- enum :tcp_status, authorized: 0, disabled: 1, expired: 2
29
+ enum :nc_status, authorized: 0, disabled: 1, expired: 2
31
30
 
32
- validates :service, :tcp_status, :secret, presence: true
31
+ validates :service, :nc_status, :secret, presence: true
33
32
 
34
33
  serialize :secret, coder: JSON
35
34
 
@@ -7,8 +7,8 @@
7
7
  # synchronizable_id :integer not null
8
8
  # synchronizable_type :string not null
9
9
  # uuid :string
10
- # flag_deletion :boolean not null
11
- # deletion_reason :integer
10
+ # flagged_for_removal :boolean not null
11
+ # removal_reason :integer
12
12
  # conflicted :boolean default(FALSE), not null
13
13
  # discarded_at :datetime
14
14
  # created_at :datetime not null
@@ -22,12 +22,12 @@ module Nexo
22
22
 
23
23
  after_initialize do
24
24
  # TODO: https://api.rubyonrails.org/classes/ActiveRecord/Attributes/ClassMethods.html#method-i-attribute
25
- self.flag_deletion = false if flag_deletion.nil?
25
+ self.flagged_for_removal = false if flagged_for_removal.nil?
26
26
  end
27
27
 
28
28
  scope :kept, -> { where(discarded_at: nil) }
29
29
 
30
- enum :deletion_reason, no_longer_included_in_folder: 0, synchronizable_destroyed: 1
30
+ enum :removal_reason, no_longer_included_in_folder: 0, synchronizable_destroyed: 1
31
31
 
32
32
  scope :conflicted, -> { where(conflicted: true) }
33
33
 
@@ -47,12 +47,12 @@ module Nexo
47
47
  element_versions.where(sequence: nil).order(created_at: :desc).first
48
48
  end
49
49
 
50
- def flag_for_deletion!(deletion_reason)
51
- update!(flag_deletion: true, deletion_reason:)
50
+ def flag_for_deletion!(removal_reason)
51
+ update!(flagged_for_removal: true, removal_reason:)
52
52
  end
53
53
 
54
54
  def flagged_for_deletion?
55
- flag_deletion?
55
+ flagged_for_removal?
56
56
  end
57
57
 
58
58
  # :nocov: TODO, not yet being called
@@ -4,7 +4,7 @@
4
4
  #
5
5
  # id :bigint not null, primary key
6
6
  # integration_id :bigint not null
7
- # protocol :integer not null
7
+ # nexo_protocol :integer not null
8
8
  # external_identifier :string
9
9
  # name :string
10
10
  # description :string
@@ -18,14 +18,14 @@ module Nexo
18
18
  has_many :elements, class_name: "Nexo::Element"
19
19
 
20
20
  if respond_to?(:enumerize)
21
- enumerize :protocol, in: { calendar: 0, dummy_calendar: 1 }
21
+ enumerize :nexo_protocol, in: { calendar: 0, dummy_calendar: 1 }
22
22
  else
23
- enum :protocol, calendar: 0, dummy_calendar: 1
23
+ enum :nexo_protocol, calendar: 0, dummy_calendar: 1
24
24
  end
25
25
 
26
26
  scope :kept, -> { where(discarded_at: nil) }
27
27
 
28
- validates :protocol, :name, presence: true
28
+ validates :nexo_protocol, :name, presence: true
29
29
 
30
30
  # TODO!: find better name
31
31
  # maybe policy_applies?
@@ -21,6 +21,11 @@ module Nexo
21
21
  belongs_to :user
22
22
  belongs_to :client, class_name: "Nexo::Client"
23
23
  has_many :tokens, class_name: "Nexo::Token"
24
+ has_many :folders, class_name: "Nexo::Folder"
25
+
26
+ before_validation do
27
+ self.scope = scope.select(&:present?)
28
+ end
24
29
 
25
30
  validates :scope, presence: true
26
31
 
@@ -52,6 +57,10 @@ module Nexo
52
57
  end
53
58
  end
54
59
 
60
+ def token?
61
+ token_status.in? [ :active_token, :expired_token ]
62
+ end
63
+
55
64
  def credentials
56
65
  service = ServiceBuilder.instance.build_auth_service(self)
57
66
  @credentials ||= service.get_credentials
@@ -5,7 +5,7 @@
5
5
  # id :bigint not null, primary key
6
6
  # integration_id :bigint not null
7
7
  # secret :string
8
- # tpt_status :integer not null
8
+ # nt_status :integer not null
9
9
  # environment :string not null
10
10
  # created_at :datetime not null
11
11
  # updated_at :datetime not null
@@ -16,14 +16,14 @@ module Nexo
16
16
 
17
17
  after_initialize do
18
18
  # TODO: https://api.rubyonrails.org/classes/ActiveRecord/Attributes/ClassMethods.html#method-i-attribute
19
- self.tpt_status = :active if tpt_status.nil?
19
+ self.nt_status = :active if nt_status.nil?
20
20
  self.environment = Rails.env if environment.nil?
21
21
  end
22
22
 
23
23
  encrypts :secret
24
24
 
25
- enum :tpt_status, active: 0, revoked: 1, expired: 2
25
+ enum :nt_status, active: 0, revoked: 1, expired: 2
26
26
 
27
- validates :secret, :tpt_status, :environment, presence: true
27
+ validates :secret, :nt_status, :environment, presence: true
28
28
  end
29
29
  end
@@ -3,7 +3,7 @@ class CreateNexoClients < ActiveRecord::Migration[7.2]
3
3
  create_table :nexo_clients do |t|
4
4
  t.integer :service
5
5
  t.string :secret
6
- t.integer :tcp_status
6
+ t.integer :nc_status
7
7
  t.integer :brand_name
8
8
 
9
9
  t.timestamps
@@ -3,7 +3,7 @@ class CreateNexoTokens < ActiveRecord::Migration[7.2]
3
3
  create_table :nexo_tokens do |t|
4
4
  t.references :integration, null: false, foreign_key: { to_table: :nexo_integrations }
5
5
  t.string :secret
6
- t.integer :tpt_status, null: false
6
+ t.integer :nt_status, null: false
7
7
  t.string :environment, null: false
8
8
 
9
9
  t.timestamps
@@ -2,7 +2,7 @@ class CreateNexoFolders < ActiveRecord::Migration[7.2]
2
2
  def change
3
3
  create_table :nexo_folders do |t|
4
4
  t.references :integration, null: false, foreign_key: { to_table: :nexo_integrations }
5
- t.integer :protocol, null: false
5
+ t.integer :nexo_protocol, null: false
6
6
  t.string :external_identifier
7
7
  t.string :name
8
8
  t.string :description
@@ -5,8 +5,8 @@ class CreateNexoElements < ActiveRecord::Migration[7.2]
5
5
  t.integer :synchronizable_id, null: false, index: true
6
6
  t.string :synchronizable_type, null: false, index: true
7
7
  t.string :uuid
8
- t.boolean :flag_deletion, null: false
9
- t.integer :deletion_reason
8
+ t.boolean :flagged_for_removal, null: false
9
+ t.integer :removal_reason
10
10
  t.boolean :conflicted, null: false, default: false
11
11
  t.datetime :discarded_at, index: true
12
12
 
data/db/seeds.rb CHANGED
@@ -4,7 +4,7 @@ module Nexo
4
4
 
5
5
  if ENV.fetch('SEED_GOOGLE_APIS_CLIENT_SECRET', nil)
6
6
  client = Client.create!(
7
- tcp_status: 0,
7
+ nc_status: 0,
8
8
  service: "google",
9
9
  secret: JSON.parse(ENV.fetch('SEED_GOOGLE_APIS_CLIENT_SECRET'))
10
10
  )
@@ -20,7 +20,7 @@ module Nexo
20
20
  Nexo::Token.create!(
21
21
  integration:,
22
22
  secret: ENV.fetch('SEED_GOOGLE_APIS_TOKEN'),
23
- tpt_status: :active,
23
+ nt_status: :active,
24
24
  environment: "development"
25
25
  )
26
26
  end
data/lib/nexo/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # :nocov: non-viable
2
2
  module Nexo
3
- VERSION = "0.1.3"
3
+ VERSION = "0.1.5"
4
4
  end
5
5
  # :nocov:
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nexo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Martín Rosso
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-05-21 00:00:00.000000000 Z
11
+ date: 2025-05-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails