icalia-sdk-core 0.3.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +7 -0
  2. data/lib/icalia-sdk-core.rb +6 -0
  3. data/lib/icalia-sdk-core/version.rb +7 -0
  4. data/lib/icalia/models.rb +34 -0
  5. data/lib/icalia/models/cloud_identity.rb +14 -0
  6. data/lib/icalia/models/code_commit.rb +9 -0
  7. data/lib/icalia/models/code_merge_request.rb +25 -0
  8. data/lib/icalia/models/code_repository.rb +15 -0
  9. data/lib/icalia/models/code_repository_reference.rb +12 -0
  10. data/lib/icalia/models/email_account.rb +10 -0
  11. data/lib/icalia/models/events/authorization_event.rb +9 -0
  12. data/lib/icalia/models/events/code_merge_request_event.rb +13 -0
  13. data/lib/icalia/models/events/code_repository_event.rb +15 -0
  14. data/lib/icalia/models/events/membership_event.rb +11 -0
  15. data/lib/icalia/models/events/organization_event.rb +14 -0
  16. data/lib/icalia/models/membership.rb +9 -0
  17. data/lib/icalia/models/model_base.rb +62 -0
  18. data/lib/icalia/models/model_collection_proxy.rb +13 -0
  19. data/lib/icalia/models/model_proxy.rb +15 -0
  20. data/lib/icalia/models/oauth_access_token.rb +9 -0
  21. data/lib/icalia/models/organization.rb +10 -0
  22. data/lib/icalia/models/person.rb +14 -0
  23. data/lib/icalia/models/resource_action.rb +12 -0
  24. data/lib/icalia/models/resource_identity.rb +15 -0
  25. data/lib/icalia/models/resource_timestamps.rb +11 -0
  26. data/lib/icalia/serialization.rb +76 -0
  27. data/lib/icalia/serialization/deserializable_authorization_event.rb +15 -0
  28. data/lib/icalia/serialization/deserializable_cloud_identity.rb +20 -0
  29. data/lib/icalia/serialization/deserializable_code_check_run.rb +39 -0
  30. data/lib/icalia/serialization/deserializable_code_check_run_event.rb +20 -0
  31. data/lib/icalia/serialization/deserializable_code_check_suite.rb +20 -0
  32. data/lib/icalia/serialization/deserializable_code_commit.rb +16 -0
  33. data/lib/icalia/serialization/deserializable_code_issue.rb +37 -0
  34. data/lib/icalia/serialization/deserializable_code_issue_occurrence.rb +14 -0
  35. data/lib/icalia/serialization/deserializable_code_merge_request.rb +41 -0
  36. data/lib/icalia/serialization/deserializable_code_merge_request_event.rb +17 -0
  37. data/lib/icalia/serialization/deserializable_code_repository.rb +26 -0
  38. data/lib/icalia/serialization/deserializable_code_repository_event.rb +17 -0
  39. data/lib/icalia/serialization/deserializable_code_repository_reference.rb +15 -0
  40. data/lib/icalia/serialization/deserializable_email_account.rb +18 -0
  41. data/lib/icalia/serialization/deserializable_membership.rb +19 -0
  42. data/lib/icalia/serialization/deserializable_membership_event.rb +16 -0
  43. data/lib/icalia/serialization/deserializable_oauth_access_token.rb +31 -0
  44. data/lib/icalia/serialization/deserializable_oauth_application.rb +13 -0
  45. data/lib/icalia/serialization/deserializable_organization.rb +14 -0
  46. data/lib/icalia/serialization/deserializable_organization_event.rb +16 -0
  47. data/lib/icalia/serialization/deserializable_person.rb +26 -0
  48. data/lib/icalia/serialization/deserializable_property_resource.rb +13 -0
  49. data/lib/icalia/serialization/deserializable_resource.rb +39 -0
  50. data/lib/icalia/serialization/deserializable_resource_action.rb +16 -0
  51. data/lib/icalia/serialization/deserializable_resource_creation_timestamp.rb +11 -0
  52. data/lib/icalia/serialization/deserializable_resource_timestamps.rb +12 -0
  53. data/lib/icalia/serialization/deserializable_user.rb +13 -0
  54. data/lib/icalia/serialization/deserializer.rb +108 -0
  55. metadata +171 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: d2c6ba327f08a61953f9ce3f7d95c09ba037e2167daa384f385cb711f7b6ddc9
4
+ data.tar.gz: 8396528464a67afbbbf6c485626dace26d9be95a4789d1d75a614708c9900307
5
+ SHA512:
6
+ metadata.gz: 234af0f52008503f81f1032c9d54447d839e2c8e40e7304e780443f03dcf26584959a3164649a1b9896db72a52c4ce2f3d5639ef8e557ccbf69a0f5c909cea91
7
+ data.tar.gz: 5fe21de198dc7de1fc6f96cada4ed5c3482d6484c999d20d8a6db1f6a638f5e23960b642988d8970ed9144feaa2492a91ca27dfbf33bb2dc2fe8e8db3da35219
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'icalia-sdk-core/version'
4
+
5
+ require 'icalia/models'
6
+ require 'icalia/serialization'
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Icalia
4
+ module SDK
5
+ CORE_VERSION = '0.3.6'
6
+ end
7
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Icalia
4
+ autoload :ModelBase, 'icalia/models/model_base'
5
+ autoload :ModelProxy, 'icalia/models/model_proxy'
6
+ autoload :ModelCollectionProxy, 'icalia/models/model_collection_proxy'
7
+
8
+ autoload :ResourceAction, 'icalia/models/resource_action'
9
+ autoload :ResourceIdentity, 'icalia/models/resource_identity'
10
+ autoload :ResourceTimestamps, 'icalia/models/resource_timestamps'
11
+
12
+ # Core Models:
13
+ autoload :Person, 'icalia/models/person'
14
+ autoload :Organization, 'icalia/models/organization'
15
+
16
+ autoload :EmailAccount, 'icalia/models/email_account'
17
+ autoload :CloudIdentity, 'icalia/models/cloud_identity'
18
+
19
+ autoload :Membership, 'icalia/models/membership'
20
+
21
+ autoload :CodeCommit, 'icalia/models/code_commit'
22
+ autoload :CodeRepository, 'icalia/models/code_repository'
23
+ autoload :CodeRepositoryReference, 'icalia/models/code_repository_reference'
24
+
25
+ autoload :CodeMergeRequest, 'icalia/models/code_merge_request'
26
+ autoload :OAuthAccessToken, 'icalia/models/oauth_access_token'
27
+
28
+ # Event Models:
29
+ autoload :MembershipEvent, 'icalia/models/events/membership_event'
30
+ autoload :OrganizationEvent, 'icalia/models/events/organization_event'
31
+ autoload :AuthorizationEvent, 'icalia/models/events/authorization_event'
32
+ autoload :CodeRepositoryEvent, 'icalia/models/events/code_repository_event'
33
+ autoload :CodeMergeRequestEvent, 'icalia/models/events/code_merge_request_event'
34
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Icalia
4
+ class CloudIdentity < ModelBase
5
+ attr_reader :provider,
6
+ :id_at_provider,
7
+ :created_at,
8
+ :updated_at,
9
+ :name,
10
+ :identity_type
11
+
12
+ has_one :owner
13
+ end
14
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Icalia
4
+ class CodeCommit < ModelBase
5
+ attr_reader :sha
6
+
7
+ has_one :repository
8
+ end
9
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Icalia
4
+ class CodeMergeRequest < ModelBase
5
+ attr_reader :number,
6
+ :provider,
7
+ :id_at_provider,
8
+ :created_at,
9
+ :updated_at,
10
+ :number,
11
+ :body,
12
+ :state,
13
+ :title,
14
+ :url,
15
+ :additions,
16
+ :deletions,
17
+ :added_line_count,
18
+ :deleted_line_count,
19
+ :changed_file_count
20
+
21
+ has_one :base, :head, :author, :committer
22
+
23
+ def closed?; state == 'closed'; end
24
+ end
25
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Icalia
4
+ class CodeRepository < ModelBase
5
+ include ResourceIdentity
6
+
7
+ has_one :owner # DeserializablePropertyResource # has one owner
8
+
9
+ attr_reader :created_at, :updated_at
10
+
11
+ attr_reader :name, :private, :fork, :provider, :description, :url, :fork,
12
+ :exists, :archived, :html_url, :full_name, :id_at_provider,
13
+ :default_branch
14
+ end
15
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Icalia
4
+ class CodeRepositoryReference < ModelBase
5
+ include ResourceIdentity
6
+ attr_reader :name, :label
7
+
8
+ has_one :commit
9
+
10
+ delegate :sha, :repository, to: :commit, allow_nil: true
11
+ end
12
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Icalia
4
+ class EmailAccount < ModelBase
5
+ attr_reader :address,
6
+ :created_at
7
+
8
+ has_one :owner
9
+ end
10
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Icalia
4
+ class AuthorizationEvent < ModelBase
5
+ attr_reader :action, :timestamp
6
+
7
+ has_one :token
8
+ end
9
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Icalia
4
+ class CodeMergeRequestEvent < ModelBase
5
+ include ResourceAction
6
+ attr_reader :merge_request
7
+
8
+ def opened?; action == 'opened'; end
9
+ def updated?; action == 'updated'; end
10
+ def merged?; action == 'merged'; end
11
+ def declined?; action == 'declined'; end
12
+ end
13
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Icalia
4
+ class CodeRepositoryEvent < ModelBase
5
+ include ResourceAction
6
+ attr_reader :repository
7
+
8
+ %i[created deleted archived unarchived edited renamed transferred publicized
9
+ privatized].each do |action_name|
10
+ define_method "#{action_name}?".to_sym do
11
+ action == action_name
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Icalia
4
+ class MembershipEvent < ModelBase
5
+ include ResourceAction
6
+ has_one :membership
7
+
8
+ def added?; action == 'added'; end
9
+ def removed?; action == 'removed'; end
10
+ end
11
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Icalia
4
+ class OrganizationEvent < ModelBase
5
+ include ResourceAction
6
+
7
+ has_one :organization
8
+
9
+ def created?; action == 'created'; end
10
+ def deleted?; action == 'deleted'; end
11
+ def renamed?; action == 'renamed'; end
12
+ def updated?; action == 'updated'; end
13
+ end
14
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Icalia
4
+ class Membership < ModelBase
5
+ attr_reader :created_at
6
+
7
+ has_one :member, :group
8
+ end
9
+ end
@@ -0,0 +1,62 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'active_model'
4
+
5
+ module Icalia
6
+ class ModelBase
7
+ extend ActiveModel::Naming
8
+ include ResourceIdentity
9
+
10
+ attr_reader :serialization_context
11
+
12
+ cattr_reader(:associated_resources) { [] }
13
+ cattr_reader(:associated_resource_collections) { [] }
14
+
15
+ def initialize(object_attributes = {})
16
+ @serialization_context = object_attributes.delete :serialization_context
17
+
18
+ object_attributes.each do |key, value|
19
+ attribute_name = "#{key}".underscore
20
+ next register_stand_in(attribute_name, value) if value.is_a? ModelProxy
21
+ next register_collection(attribute_name, value) if value.is_a? Array
22
+ instance_variable_set("@#{attribute_name}", value)
23
+ end
24
+ end
25
+
26
+ class << self
27
+ def has_one(*associations)
28
+ associations.each do |association|
29
+ attr_reader association
30
+ associated_resources << association
31
+ end
32
+ end
33
+
34
+ def has_many(*associations)
35
+ associations.each do |association|
36
+ attr_reader association
37
+ associated_resource_collections << association
38
+ end
39
+ end
40
+ end
41
+
42
+ private
43
+
44
+ def register_collection(association, collection)
45
+ instance_variable_set("@#{association}", collection)
46
+ collection.each_with_index do |item, index|
47
+ next unless item.is_a? ModelProxy
48
+ serialization_context.register_stand_in model: self,
49
+ index: index,
50
+ stand_in: item,
51
+ association: association
52
+ end
53
+ end
54
+
55
+ def register_stand_in(association, stand_in)
56
+ instance_variable_set("@#{association}", stand_in)
57
+ serialization_context.register_stand_in model: self,
58
+ stand_in: stand_in,
59
+ association: association
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Icalia
4
+ # ModelCollectionProxy: Acts as a stand-in for an associated model collection,
5
+ # which may be awaiting for de-serialization at the time the parent object was
6
+ # being de-serialized
7
+ class ModelCollectionProxy
8
+
9
+ def initialize(links: {})
10
+ @links = links
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Icalia
4
+ # ModelProxy: Acts as a stand-in for an associated model, which may be
5
+ # awaiting for de-serialization at the time the parent object was being
6
+ # de-serialized
7
+ class ModelProxy
8
+ include ResourceIdentity
9
+
10
+ def initialize(id:, type:)
11
+ @id = id
12
+ @type = type
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Icalia
4
+ class OAuthAccessToken < ModelBase
5
+ attr_reader :scopes, :created_at, :expires_at
6
+
7
+ has_one :application, :resource_owner
8
+ end
9
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Icalia
4
+ class Organization < ModelBase
5
+ include ResourceTimestamps
6
+ attr_reader :name
7
+
8
+ has_many :email_accounts, :cloud_identities
9
+ end
10
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Icalia
4
+ class Person < ModelBase
5
+ include ResourceTimestamps
6
+ attr_reader :full_name, :given_name, :family_name,
7
+ :gender_type, :custom_gender,
8
+ :date_of_birth
9
+
10
+ alias name full_name
11
+
12
+ has_many :email_accounts, :cloud_identities
13
+ end
14
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Icalia
4
+ module ResourceAction
5
+ extend ActiveSupport::Concern
6
+
7
+ included do
8
+ attr_reader :action, :timestamp
9
+ has_one :actor
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Icalia
4
+ module ResourceIdentity
5
+ extend ActiveSupport::Concern
6
+
7
+ included do
8
+ attr_reader :id, :type
9
+ end
10
+
11
+ def to_key
12
+ { id: id, type: type }
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Icalia
4
+ module ResourceTimestamps
5
+ extend ActiveSupport::Concern
6
+
7
+ included do
8
+ attr_reader :created_at, :updated_at
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,76 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'jsonapi/deserializable'
4
+
5
+ module Icalia
6
+ autoload :Deserializer, 'icalia/serialization/deserializer'
7
+
8
+ # Deserialization Modules:
9
+ autoload :DeserializableResourceAction,
10
+ 'icalia/serialization/deserializable_resource_action'
11
+
12
+ autoload :DeserializableResourceCreationTimestamp,
13
+ 'icalia/serialization/deserializable_resource_creation_timestamp'
14
+
15
+ autoload :DeserializableResourceTimestamps,
16
+ 'icalia/serialization/deserializable_resource_timestamps'
17
+
18
+ autoload :DeserializablePropertyResource,
19
+ 'icalia/serialization/deserializable_property_resource'
20
+
21
+ # Event deserialization
22
+ autoload :DeserializableMembershipEvent,
23
+ 'icalia/serialization/deserializable_membership_event'
24
+
25
+ autoload :DeserializableOrganizationEvent,
26
+ 'icalia/serialization/deserializable_organization_event'
27
+
28
+ autoload :DeserializableAuthorizationEvent,
29
+ 'icalia/serialization/deserializable_authorization_event'
30
+
31
+ autoload :DeserializableCodeMergeRequestEvent,
32
+ 'icalia/serialization/deserializable_code_merge_request_event'
33
+
34
+ # Deserializable Objects
35
+ autoload :DeserializableResource,
36
+ 'icalia/serialization/deserializable_resource'
37
+
38
+ autoload :DeserializableEmailAccount,
39
+ 'icalia/serialization/deserializable_email_account'
40
+
41
+ autoload :DeserializableUser,
42
+ 'icalia/serialization/deserializable_user'
43
+
44
+ autoload :DeserializableMembership,
45
+ 'icalia/serialization/deserializable_membership'
46
+
47
+ autoload :DeserializablePerson,
48
+ 'icalia/serialization/deserializable_person'
49
+
50
+ autoload :DeserializableOAuthAccessToken,
51
+ 'icalia/serialization/deserializable_oauth_access_token'
52
+
53
+ autoload :DeserializableOauthApplication,
54
+ 'icalia/serialization/deserializable_oauth_application'
55
+
56
+ autoload :DeserializableOrganization,
57
+ 'icalia/serialization/deserializable_organization'
58
+
59
+ autoload :DeserializableCodeRepositoryEvent,
60
+ 'icalia/serialization/deserializable_code_repository_event'
61
+
62
+ autoload :DeserializableCodeMergeRequest,
63
+ 'icalia/serialization/deserializable_code_merge_request'
64
+
65
+ autoload :DeserializableCodeCommit,
66
+ 'icalia/serialization/deserializable_code_commit'
67
+
68
+ autoload :DeserializableCodeRepository,
69
+ 'icalia/serialization/deserializable_code_repository'
70
+
71
+ autoload :DeserializableCodeRepositoryReference,
72
+ 'icalia/serialization/deserializable_code_repository_reference'
73
+
74
+ autoload :DeserializableCloudIdentity,
75
+ 'icalia/serialization/deserializable_cloud_identity'
76
+ end