icalia-sdk-core 0.3.6
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 +7 -0
- data/lib/icalia-sdk-core.rb +6 -0
- data/lib/icalia-sdk-core/version.rb +7 -0
- data/lib/icalia/models.rb +34 -0
- data/lib/icalia/models/cloud_identity.rb +14 -0
- data/lib/icalia/models/code_commit.rb +9 -0
- data/lib/icalia/models/code_merge_request.rb +25 -0
- data/lib/icalia/models/code_repository.rb +15 -0
- data/lib/icalia/models/code_repository_reference.rb +12 -0
- data/lib/icalia/models/email_account.rb +10 -0
- data/lib/icalia/models/events/authorization_event.rb +9 -0
- data/lib/icalia/models/events/code_merge_request_event.rb +13 -0
- data/lib/icalia/models/events/code_repository_event.rb +15 -0
- data/lib/icalia/models/events/membership_event.rb +11 -0
- data/lib/icalia/models/events/organization_event.rb +14 -0
- data/lib/icalia/models/membership.rb +9 -0
- data/lib/icalia/models/model_base.rb +62 -0
- data/lib/icalia/models/model_collection_proxy.rb +13 -0
- data/lib/icalia/models/model_proxy.rb +15 -0
- data/lib/icalia/models/oauth_access_token.rb +9 -0
- data/lib/icalia/models/organization.rb +10 -0
- data/lib/icalia/models/person.rb +14 -0
- data/lib/icalia/models/resource_action.rb +12 -0
- data/lib/icalia/models/resource_identity.rb +15 -0
- data/lib/icalia/models/resource_timestamps.rb +11 -0
- data/lib/icalia/serialization.rb +76 -0
- data/lib/icalia/serialization/deserializable_authorization_event.rb +15 -0
- data/lib/icalia/serialization/deserializable_cloud_identity.rb +20 -0
- data/lib/icalia/serialization/deserializable_code_check_run.rb +39 -0
- data/lib/icalia/serialization/deserializable_code_check_run_event.rb +20 -0
- data/lib/icalia/serialization/deserializable_code_check_suite.rb +20 -0
- data/lib/icalia/serialization/deserializable_code_commit.rb +16 -0
- data/lib/icalia/serialization/deserializable_code_issue.rb +37 -0
- data/lib/icalia/serialization/deserializable_code_issue_occurrence.rb +14 -0
- data/lib/icalia/serialization/deserializable_code_merge_request.rb +41 -0
- data/lib/icalia/serialization/deserializable_code_merge_request_event.rb +17 -0
- data/lib/icalia/serialization/deserializable_code_repository.rb +26 -0
- data/lib/icalia/serialization/deserializable_code_repository_event.rb +17 -0
- data/lib/icalia/serialization/deserializable_code_repository_reference.rb +15 -0
- data/lib/icalia/serialization/deserializable_email_account.rb +18 -0
- data/lib/icalia/serialization/deserializable_membership.rb +19 -0
- data/lib/icalia/serialization/deserializable_membership_event.rb +16 -0
- data/lib/icalia/serialization/deserializable_oauth_access_token.rb +31 -0
- data/lib/icalia/serialization/deserializable_oauth_application.rb +13 -0
- data/lib/icalia/serialization/deserializable_organization.rb +14 -0
- data/lib/icalia/serialization/deserializable_organization_event.rb +16 -0
- data/lib/icalia/serialization/deserializable_person.rb +26 -0
- data/lib/icalia/serialization/deserializable_property_resource.rb +13 -0
- data/lib/icalia/serialization/deserializable_resource.rb +39 -0
- data/lib/icalia/serialization/deserializable_resource_action.rb +16 -0
- data/lib/icalia/serialization/deserializable_resource_creation_timestamp.rb +11 -0
- data/lib/icalia/serialization/deserializable_resource_timestamps.rb +12 -0
- data/lib/icalia/serialization/deserializable_user.rb +13 -0
- data/lib/icalia/serialization/deserializer.rb +108 -0
- metadata +171 -0
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Icalia
|
4
|
+
#= DeserializableOrganizationEvent
|
5
|
+
#
|
6
|
+
# This class is responsible for converting a JSONAPI.org representation of an
|
7
|
+
# Icalia Event's `OrganizationEvent` object
|
8
|
+
class DeserializableOrganizationEvent < DeserializableResource
|
9
|
+
include DeserializableResourceAction
|
10
|
+
include DeserializableResourceCreationTimestamp
|
11
|
+
|
12
|
+
has_one :organization do |_rel, id, type|
|
13
|
+
Hash[organization: get_stand_in(id: id, type: classify_type(type))]
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Icalia
|
4
|
+
#= DeserializablePerson
|
5
|
+
#
|
6
|
+
# This class is responsible for converting a JSONAPI.org representation of an
|
7
|
+
# Icalia Event's `Person` object
|
8
|
+
class DeserializablePerson < DeserializableResource
|
9
|
+
include DeserializableResourceTimestamps
|
10
|
+
|
11
|
+
attribute(:'full-name') { |value| Hash[full_name: value] }
|
12
|
+
attribute(:'given-name') { |value| Hash[given_name: value] }
|
13
|
+
attribute(:'family-name') { |value| Hash[family_name: value] }
|
14
|
+
attribute(:'gender-type') { |value| Hash[gender_type: value] }
|
15
|
+
attribute(:'custom-gender') { |value| Hash[custom_gender: value] }
|
16
|
+
attribute(:'date-of-birth') { |value| Hash[date_of_birth: value] }
|
17
|
+
|
18
|
+
has_many(:'email-accounts') do |rel, _ids, _types|
|
19
|
+
Hash[email_accounts: get_stand_ins(rel)]
|
20
|
+
end
|
21
|
+
|
22
|
+
has_many(:'cloud-identities') do |rel, _ids, _types|
|
23
|
+
Hash[cloud_identities: get_stand_ins(rel)]
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Icalia
|
4
|
+
module DeserializablePropertyResource
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
included do
|
8
|
+
has_one :owner do |_rel, id, type|
|
9
|
+
Hash[owner: get_stand_in(id: id, type: classify_type(type))]
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Icalia
|
4
|
+
class DeserializableResource < JSONAPI::Deserializable::Resource
|
5
|
+
|
6
|
+
delegate :classify_type,
|
7
|
+
:classify_data,
|
8
|
+
:get_stand_in,
|
9
|
+
:get_stand_ins,
|
10
|
+
to: :class
|
11
|
+
|
12
|
+
id { |value| Hash[id: value] }
|
13
|
+
type { |value| Hash[type: classify_type(value)] }
|
14
|
+
|
15
|
+
class << self
|
16
|
+
def classify_type(type)
|
17
|
+
type.underscore.camelize
|
18
|
+
end
|
19
|
+
|
20
|
+
def classify_data(data)
|
21
|
+
classify_type data['type']
|
22
|
+
end
|
23
|
+
|
24
|
+
def get_stand_in(id:, type:)
|
25
|
+
Icalia::ModelProxy.new id: id, type: type
|
26
|
+
end
|
27
|
+
|
28
|
+
def get_stand_ins(rel)
|
29
|
+
if rel['data'].nil?
|
30
|
+
Icalia::ModelCollectionProxy.new rel['links']
|
31
|
+
else
|
32
|
+
rel['data'].map do |data|
|
33
|
+
get_stand_in id: data['id'], type: classify_data(data)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Icalia
|
4
|
+
module DeserializableResourceAction
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
included do
|
8
|
+
attribute(:action) { |value| Hash[action: value] }
|
9
|
+
attribute(:timestamp) { |value| Hash[timestamp: Time.parse(value)] }
|
10
|
+
|
11
|
+
has_one :actor do |_rel, id, type|
|
12
|
+
Hash[actor: get_stand_in(id: id, type: classify_type(type))]
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Icalia
|
4
|
+
module DeserializableResourceTimestamps
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
included do
|
8
|
+
include DeserializableResourceCreationTimestamp
|
9
|
+
attribute(:'updated-at') { |value| Hash[updated_at: Time.parse(value)] }
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Icalia
|
4
|
+
#= DeserializableUser
|
5
|
+
#
|
6
|
+
# This class is responsible for converting a JSONAPI.org representation of an
|
7
|
+
# Icalia Event's `User` object
|
8
|
+
class DeserializableUser < DeserializableResource
|
9
|
+
include DeserializableResourceTimestamps
|
10
|
+
|
11
|
+
attributes :email
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,108 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'active_support/inflector'
|
4
|
+
|
5
|
+
module Icalia
|
6
|
+
class Deserializer
|
7
|
+
attr_reader :data
|
8
|
+
|
9
|
+
class StandInReplacement
|
10
|
+
attr_reader :model, :association, :stand_in, :index
|
11
|
+
|
12
|
+
def initialize(model:, association:, stand_in:, index: nil)
|
13
|
+
@model = model
|
14
|
+
@association = association
|
15
|
+
@stand_in = stand_in
|
16
|
+
@index = index
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def initialize(jsonapi_data)
|
21
|
+
@jsonapi_data = jsonapi_data
|
22
|
+
@objects = {}
|
23
|
+
@pending_stand_in_replacements = []
|
24
|
+
end
|
25
|
+
|
26
|
+
def perform
|
27
|
+
return @data if @data
|
28
|
+
deserialize_included
|
29
|
+
deserialize_data
|
30
|
+
replace_stand_ins
|
31
|
+
finalize
|
32
|
+
@data
|
33
|
+
end
|
34
|
+
|
35
|
+
def register_stand_in(model:, association:, stand_in:, index: nil)
|
36
|
+
@pending_stand_in_replacements << StandInReplacement.new(
|
37
|
+
model: model,
|
38
|
+
association: association,
|
39
|
+
stand_in: stand_in,
|
40
|
+
index: index
|
41
|
+
)
|
42
|
+
end
|
43
|
+
|
44
|
+
def to_s
|
45
|
+
'(...to_s...)'
|
46
|
+
end
|
47
|
+
|
48
|
+
def inspect
|
49
|
+
'(...inspect...)'
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
def replace_stand_ins
|
55
|
+
@pending_stand_in_replacements.each do |replacement|
|
56
|
+
next unless associated_object = @objects[replacement.stand_in.to_key]
|
57
|
+
|
58
|
+
model = replacement.model
|
59
|
+
index = replacement.index
|
60
|
+
variable = "@#{replacement.association}".to_sym
|
61
|
+
|
62
|
+
if index
|
63
|
+
model.instance_variable_get(variable)[index] = associated_object
|
64
|
+
else
|
65
|
+
model.instance_variable_set(variable, associated_object)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def finalize
|
71
|
+
# debugger
|
72
|
+
end
|
73
|
+
|
74
|
+
def deserialize_included
|
75
|
+
@jsonapi_data.fetch('included', []).each do |object_data|
|
76
|
+
if object = deserialize_object_data(object_data)
|
77
|
+
add_object_to_index object
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
def add_object_to_index(object)
|
83
|
+
@objects[object.to_key] = object
|
84
|
+
end
|
85
|
+
|
86
|
+
def deserialize_data
|
87
|
+
root_data = @jsonapi_data.fetch('data')
|
88
|
+
if @data = add_object_to_index(deserialize_object_data(root_data))
|
89
|
+
add_object_to_index @data
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def deserialize_object_data(object_data)
|
94
|
+
object_class_name = object_data['type'].underscore.classify.gsub(/Oauth/, 'OAuth')
|
95
|
+
object_class = "::Icalia::#{object_class_name}".safe_constantize
|
96
|
+
return unless object_class
|
97
|
+
|
98
|
+
deserializer_class = "::Icalia::Deserializable#{object_class_name}".safe_constantize
|
99
|
+
return unless deserializer_class
|
100
|
+
|
101
|
+
object_attributes = deserializer_class
|
102
|
+
.call(object_data)
|
103
|
+
.merge(serialization_context: self)
|
104
|
+
|
105
|
+
object_class.new object_attributes
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
metadata
ADDED
@@ -0,0 +1,171 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: icalia-sdk-core
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.3.6
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Roberto Quintanilla
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-03-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: jsonapi-deserializable
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.2.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.2.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: activemodel
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '5.2'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '5.2'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.17'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.17'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '13.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '13.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.0'
|
83
|
+
description: Official Icalia SDK for Icalia CoreThis gem is part of the Icalia SDK
|
84
|
+
for Ruby.
|
85
|
+
email:
|
86
|
+
- vov@icalialabs.com
|
87
|
+
executables: []
|
88
|
+
extensions: []
|
89
|
+
extra_rdoc_files: []
|
90
|
+
files:
|
91
|
+
- lib/icalia-sdk-core.rb
|
92
|
+
- lib/icalia-sdk-core/version.rb
|
93
|
+
- lib/icalia/models.rb
|
94
|
+
- lib/icalia/models/cloud_identity.rb
|
95
|
+
- lib/icalia/models/code_commit.rb
|
96
|
+
- lib/icalia/models/code_merge_request.rb
|
97
|
+
- lib/icalia/models/code_repository.rb
|
98
|
+
- lib/icalia/models/code_repository_reference.rb
|
99
|
+
- lib/icalia/models/email_account.rb
|
100
|
+
- lib/icalia/models/events/authorization_event.rb
|
101
|
+
- lib/icalia/models/events/code_merge_request_event.rb
|
102
|
+
- lib/icalia/models/events/code_repository_event.rb
|
103
|
+
- lib/icalia/models/events/membership_event.rb
|
104
|
+
- lib/icalia/models/events/organization_event.rb
|
105
|
+
- lib/icalia/models/membership.rb
|
106
|
+
- lib/icalia/models/model_base.rb
|
107
|
+
- lib/icalia/models/model_collection_proxy.rb
|
108
|
+
- lib/icalia/models/model_proxy.rb
|
109
|
+
- lib/icalia/models/oauth_access_token.rb
|
110
|
+
- lib/icalia/models/organization.rb
|
111
|
+
- lib/icalia/models/person.rb
|
112
|
+
- lib/icalia/models/resource_action.rb
|
113
|
+
- lib/icalia/models/resource_identity.rb
|
114
|
+
- lib/icalia/models/resource_timestamps.rb
|
115
|
+
- lib/icalia/serialization.rb
|
116
|
+
- lib/icalia/serialization/deserializable_authorization_event.rb
|
117
|
+
- lib/icalia/serialization/deserializable_cloud_identity.rb
|
118
|
+
- lib/icalia/serialization/deserializable_code_check_run.rb
|
119
|
+
- lib/icalia/serialization/deserializable_code_check_run_event.rb
|
120
|
+
- lib/icalia/serialization/deserializable_code_check_suite.rb
|
121
|
+
- lib/icalia/serialization/deserializable_code_commit.rb
|
122
|
+
- lib/icalia/serialization/deserializable_code_issue.rb
|
123
|
+
- lib/icalia/serialization/deserializable_code_issue_occurrence.rb
|
124
|
+
- lib/icalia/serialization/deserializable_code_merge_request.rb
|
125
|
+
- lib/icalia/serialization/deserializable_code_merge_request_event.rb
|
126
|
+
- lib/icalia/serialization/deserializable_code_repository.rb
|
127
|
+
- lib/icalia/serialization/deserializable_code_repository_event.rb
|
128
|
+
- lib/icalia/serialization/deserializable_code_repository_reference.rb
|
129
|
+
- lib/icalia/serialization/deserializable_email_account.rb
|
130
|
+
- lib/icalia/serialization/deserializable_membership.rb
|
131
|
+
- lib/icalia/serialization/deserializable_membership_event.rb
|
132
|
+
- lib/icalia/serialization/deserializable_oauth_access_token.rb
|
133
|
+
- lib/icalia/serialization/deserializable_oauth_application.rb
|
134
|
+
- lib/icalia/serialization/deserializable_organization.rb
|
135
|
+
- lib/icalia/serialization/deserializable_organization_event.rb
|
136
|
+
- lib/icalia/serialization/deserializable_person.rb
|
137
|
+
- lib/icalia/serialization/deserializable_property_resource.rb
|
138
|
+
- lib/icalia/serialization/deserializable_resource.rb
|
139
|
+
- lib/icalia/serialization/deserializable_resource_action.rb
|
140
|
+
- lib/icalia/serialization/deserializable_resource_creation_timestamp.rb
|
141
|
+
- lib/icalia/serialization/deserializable_resource_timestamps.rb
|
142
|
+
- lib/icalia/serialization/deserializable_user.rb
|
143
|
+
- lib/icalia/serialization/deserializer.rb
|
144
|
+
homepage: https://github.com/IcaliaLabs/icalia-sdk-ruby
|
145
|
+
licenses:
|
146
|
+
- MIT
|
147
|
+
metadata:
|
148
|
+
allowed_push_host: https://rubygems.org
|
149
|
+
homepage_uri: https://github.com/IcaliaLabs/icalia-sdk-ruby
|
150
|
+
source_code_uri: https://github.com/IcaliaLabs/icalia-sdk-ruby
|
151
|
+
changelog_uri: https://github.com/IcaliaLabs/icalia-sdk-ruby
|
152
|
+
post_install_message:
|
153
|
+
rdoc_options: []
|
154
|
+
require_paths:
|
155
|
+
- lib
|
156
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
157
|
+
requirements:
|
158
|
+
- - ">="
|
159
|
+
- !ruby/object:Gem::Version
|
160
|
+
version: '0'
|
161
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
162
|
+
requirements:
|
163
|
+
- - ">="
|
164
|
+
- !ruby/object:Gem::Version
|
165
|
+
version: '0'
|
166
|
+
requirements: []
|
167
|
+
rubygems_version: 3.0.3
|
168
|
+
signing_key:
|
169
|
+
specification_version: 4
|
170
|
+
summary: Icalia SDK for Ruby - Core Library
|
171
|
+
test_files: []
|