my_data 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +14 -0
  3. data/.rspec +3 -0
  4. data/.rubocop.yml +32 -0
  5. data/Gemfile +15 -0
  6. data/LICENSE.txt +21 -0
  7. data/README.md +39 -0
  8. data/Rakefile +12 -0
  9. data/bin/console +15 -0
  10. data/bin/setup +8 -0
  11. data/lib/my_data.rb +24 -0
  12. data/lib/my_data/client.rb +42 -0
  13. data/lib/my_data/resource.rb +191 -0
  14. data/lib/my_data/resources.rb +10 -0
  15. data/lib/my_data/resources/ecls.rb +7 -0
  16. data/lib/my_data/resources/ecls/expenses_classification_type.rb +7 -0
  17. data/lib/my_data/resources/ecls/invoice_expenses_classification_type.rb +7 -0
  18. data/lib/my_data/resources/ecls/invoices_expenses_classification_detail_type.rb +7 -0
  19. data/lib/my_data/resources/error_type.rb +8 -0
  20. data/lib/my_data/resources/icls.rb +7 -0
  21. data/lib/my_data/resources/icls/income_classification_type.rb +7 -0
  22. data/lib/my_data/resources/icls/invoice_income_classification_type.rb +7 -0
  23. data/lib/my_data/resources/icls/invoices_income_classification_detail_type.rb +7 -0
  24. data/lib/my_data/resources/inv.rb +14 -0
  25. data/lib/my_data/resources/inv/aade_book_invoice_type.rb +7 -0
  26. data/lib/my_data/resources/inv/address_type.rb +7 -0
  27. data/lib/my_data/resources/inv/invoice_header_type.rb +7 -0
  28. data/lib/my_data/resources/inv/invoice_row_type.rb +7 -0
  29. data/lib/my_data/resources/inv/invoice_summary_type.rb +7 -0
  30. data/lib/my_data/resources/inv/invoices_doc.rb +17 -0
  31. data/lib/my_data/resources/inv/party_type.rb +7 -0
  32. data/lib/my_data/resources/inv/payment_method_detail_type.rb +7 -0
  33. data/lib/my_data/resources/inv/ship_type.rb +7 -0
  34. data/lib/my_data/resources/inv/tax_totals_type.rb +7 -0
  35. data/lib/my_data/resources/response_type.rb +19 -0
  36. data/lib/my_data/resources/responses_doc.rb +8 -0
  37. data/lib/my_data/type_caster.rb +58 -0
  38. data/lib/my_data/version.rb +5 -0
  39. data/lib/my_data/xml_generator.rb +80 -0
  40. data/lib/my_data/xml_parser.rb +96 -0
  41. data/lib/my_data/xsd.rb +7 -0
  42. data/lib/my_data/xsd/complex_type.rb +24 -0
  43. data/lib/my_data/xsd/docs/InvoicesDoc-v1.0.2.xsd +1088 -0
  44. data/lib/my_data/xsd/docs/RequestedProviderDoc-v1.0.2.xsd +44 -0
  45. data/lib/my_data/xsd/docs/expensesClassification-v1.0.2.xsd +193 -0
  46. data/lib/my_data/xsd/docs/incomeClassification-v1.0.2.xsd +141 -0
  47. data/lib/my_data/xsd/docs/requestDoc-v1.0.2.xsd +66 -0
  48. data/lib/my_data/xsd/docs/requestedInvoicesDoc-v1.0.2.xsd +66 -0
  49. data/lib/my_data/xsd/docs/response-v1.0.2.xsd +80 -0
  50. data/lib/my_data/xsd/element.rb +49 -0
  51. data/lib/my_data/xsd/resource_generator.rb +37 -0
  52. data/lib/my_data/xsd/structure.rb +80 -0
  53. data/my_data.gemspec +36 -0
  54. metadata +153 -0
@@ -0,0 +1,80 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified" version="1.0.2">
3
+ <xs:element name="ResponseDoc">
4
+ <xs:annotation>
5
+ <xs:documentation>Comment describing your root element</xs:documentation>
6
+ </xs:annotation>
7
+ <xs:complexType>
8
+ <xs:sequence maxOccurs="unbounded">
9
+ <xs:element name="response" type="ResponseType"/>
10
+ </xs:sequence>
11
+ </xs:complexType>
12
+ </xs:element>
13
+ <xs:complexType name="ResponseType">
14
+ <xs:sequence>
15
+ <xs:element name="index" type="xs:int" minOccurs="0">
16
+ <xs:annotation>
17
+ <xs:documentation>ΑΑ γραμμής οντότητας</xs:documentation>
18
+ </xs:annotation>
19
+ </xs:element>
20
+ <xs:choice>
21
+ <xs:sequence>
22
+ <xs:element name="invoiceUid" type="xs:string" minOccurs="0">
23
+ <xs:annotation>
24
+ <xs:documentation>Αναγνωριστικό οντότητας</xs:documentation>
25
+ </xs:annotation>
26
+ </xs:element>
27
+ <xs:element name="invoiceMark" type="xs:long" minOccurs="0">
28
+ <xs:annotation>
29
+ <xs:documentation>Μοναδικός Αριθμός Καταχώρησης παραστατικού</xs:documentation>
30
+ </xs:annotation>
31
+ </xs:element>
32
+ <xs:element name="classificationMark" type="xs:long" minOccurs="0">
33
+ <xs:annotation>
34
+ <xs:documentation>Μοναδικός Αριθμός Παραλαβής Χαρακτηρισμού</xs:documentation>
35
+ </xs:annotation>
36
+ </xs:element>
37
+ <xs:element name="cancellationMark" type="xs:long" minOccurs="0">
38
+ <xs:annotation>
39
+ <xs:documentation>Μοναδικός Αριθμός Ακύρωσης</xs:documentation>
40
+ </xs:annotation>
41
+ </xs:element>
42
+ <xs:element name="authenticationCode" type="xs:string" minOccurs="0">
43
+ <xs:annotation>
44
+ <xs:documentation>Συμβολοσειρά Αυθεντικοποίησης Παρόχου</xs:documentation>
45
+ </xs:annotation>
46
+ </xs:element>
47
+ </xs:sequence>
48
+ <xs:element name="errors">
49
+ <xs:annotation>
50
+ <xs:documentation>Λίστα Σφαλμάτων</xs:documentation>
51
+ </xs:annotation>
52
+ <xs:complexType>
53
+ <xs:sequence>
54
+ <xs:element name="error" type="ErrorType" maxOccurs="unbounded"/>
55
+ </xs:sequence>
56
+ </xs:complexType>
57
+ </xs:element>
58
+ </xs:choice>
59
+ <xs:element name="statusCode" type="xs:string">
60
+ <xs:annotation>
61
+ <xs:documentation>Κωδικός αποτελέσματος</xs:documentation>
62
+ </xs:annotation>
63
+ </xs:element>
64
+ </xs:sequence>
65
+ </xs:complexType>
66
+ <xs:complexType name="ErrorType">
67
+ <xs:sequence>
68
+ <xs:element name="message" type="xs:string">
69
+ <xs:annotation>
70
+ <xs:documentation>Μήνυμα Σφάλματος</xs:documentation>
71
+ </xs:annotation>
72
+ </xs:element>
73
+ <xs:element name="code" type="xs:int">
74
+ <xs:annotation>
75
+ <xs:documentation>Κωδικός Σφάλαματος</xs:documentation>
76
+ </xs:annotation>
77
+ </xs:element>
78
+ </xs:sequence>
79
+ </xs:complexType>
80
+ </xs:schema>
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ class MyData::Xsd::Element
4
+ attr_reader :element, :namespace
5
+
6
+ def initialize(element, namespace: nil)
7
+ @element = element
8
+ @namespace = namespace
9
+ end
10
+
11
+ def name
12
+ @name ||= element.attributes["name"].value
13
+ end
14
+
15
+ def type
16
+ @type =
17
+ if element.attributes["type"].present?
18
+ element.attributes["type"]
19
+ elsif element.xpath(".//xs:restriction[@base]").any?
20
+ element.xpath(".//xs:restriction[@base]").first.attributes["base"]
21
+ elsif element.xpath(".//xs:element[@type]").any?
22
+ element.xpath(".//xs:element[@type]").first.attributes["type"]
23
+ end.value
24
+ end
25
+
26
+ def collection?
27
+ return @collection if defined? @collection
28
+
29
+ @collection = element.to_s.include? "maxOccurs"
30
+ end
31
+
32
+ def collection_element_name
33
+ return @collection_element_name if defined? @collection_element_name
34
+
35
+ @collection_element_name =
36
+ if collection?
37
+ nested_element = element.at_xpath(".//xs:element")
38
+ nested_element ? nested_element.attributes["name"].value : nil
39
+ end
40
+ end
41
+
42
+ def required?
43
+ element.attributes["minOccurs"]&.value != "0"
44
+ end
45
+
46
+ def inspect
47
+ "Element: { name: #{name.to_json}, type: #{type.to_json}, collection: #{collection?} }"
48
+ end
49
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "fileutils"
4
+
5
+ # This class is for development reason only, to generate resources
6
+ module MyData::Xsd::ResourceGenerator
7
+ module_function
8
+
9
+ def generate
10
+ MyData::Xsd::Structure.complex_types.each do |_, type|
11
+ folder_name = File.join(MyData.root, "lib/my_data/resources", type.namespace.to_s)
12
+ FileUtils.mkdir_p(folder_name)
13
+
14
+ class_name = "#{type.namespace.capitalize}::#{type.name}"
15
+
16
+ puts "Create file: #{folder_name} #{type.name}"
17
+
18
+ file = File.new(File.join(folder_name, "#{type.name.underscore}.rb"), "w")
19
+ file.write(class_string(class_name))
20
+ file.close
21
+ end
22
+
23
+ "done"
24
+ end
25
+
26
+ def class_string(class_name)
27
+ string = "# frozen_string_literal: true\n"
28
+ string += "\n"
29
+ string += "class MyData::Resources::#{class_name}\n"
30
+ string += " include MyData::Resource\n"
31
+ string += "\n"
32
+ string += " xsd_structure\n"
33
+ string += "end\n"
34
+
35
+ string
36
+ end
37
+ end
@@ -0,0 +1,80 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MyData::Xsd::Structure
4
+ extend self
5
+
6
+ PATH = File.join(MyData.root, "lib/my_data/xsd/docs")
7
+
8
+ def resource_attributes(class_name)
9
+ namespace, name = class_name.split("::").last(2)
10
+
11
+ complex_types["#{namespace.downcase}:#{name}"].elements.map do |element|
12
+ type = type_mapping(element.type)
13
+
14
+ [
15
+ element.name.underscore,
16
+ type,
17
+ {
18
+ collection: element.collection?,
19
+ collection_element_name: element.collection_element_name,
20
+ class_name: type == :resource ? classify(element.type) : nil,
21
+ required: element.required?
22
+ }
23
+ ]
24
+ end
25
+ end
26
+
27
+ def complex_types
28
+ @complex_types ||= docs.each_with_object({}) do |(namespace, doc), types|
29
+ doc.xpath("//xs:schema/xs:complexType").each do |node|
30
+ type = MyData::Xsd::ComplexType.new(node, namespace: namespace)
31
+
32
+ types["#{type.namespace}:#{type.name}"] = type
33
+ end
34
+ end
35
+ end
36
+
37
+ def simple_types
38
+ @simple_types ||= docs.each_with_object({}) do |(namespace, doc), types|
39
+ doc.xpath("//xs:schema/xs:simpleType").each do |node|
40
+ type = MyData::Xsd::Element.new(node, namespace: namespace)
41
+
42
+ types["#{type.namespace}:#{type.name}"] = type
43
+ end
44
+ end
45
+ end
46
+
47
+ private
48
+
49
+ def classify(type)
50
+ namespace, name = type.split(":")
51
+
52
+ "#{namespace.capitalize}::#{name}"
53
+ end
54
+
55
+ def type_mapping(type)
56
+ if ["xs:byte", "xs:long", "xs:int"].include?(type)
57
+ :integer
58
+ elsif type == "xs:decimal"
59
+ :float
60
+ elsif complex_types.key?(type)
61
+ :resource
62
+ elsif simple_types.key?(type)
63
+ type_mapping(simple_types[type].type)
64
+ else
65
+ type.split(":").last.to_sym
66
+ end
67
+ end
68
+
69
+ def docs
70
+ @docs ||= {
71
+ inv: read_xsd("InvoicesDoc-v1.0.2.xsd"),
72
+ icls: read_xsd("incomeClassification-v1.0.2.xsd"),
73
+ ecls: read_xsd("expensesClassification-v1.0.2.xsd")
74
+ }
75
+ end
76
+
77
+ def read_xsd(name)
78
+ Nokogiri::XML(File.read(File.join(PATH, name)))
79
+ end
80
+ end
data/my_data.gemspec ADDED
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/my_data/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "my_data"
7
+ spec.version = MyData::VERSION
8
+ spec.authors = ["Michalis Zamparas"]
9
+ spec.email = ["mikezaby@gmail.com"]
10
+
11
+ spec.summary = "Api client for AADE myData"
12
+ spec.description = "Api client for AADE myData"
13
+ spec.homepage = "https://github.com/mikezaby/my_data"
14
+ spec.license = "MIT"
15
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
16
+
17
+ spec.metadata["homepage_uri"] = spec.homepage
18
+ spec.metadata["source_code_uri"] = spec.homepage
19
+
20
+ # Specify which files should be added to the gem when it is released.
21
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
22
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
23
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
24
+ end
25
+ spec.bindir = "exe"
26
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
27
+ spec.require_paths = ["lib"]
28
+
29
+ spec.add_dependency "faraday", "~> 1.0"
30
+ spec.add_dependency "activesupport", ">= 3.2"
31
+ spec.add_dependency "activemodel", ">= 3.2"
32
+ spec.add_dependency "nokogiri", ">= 1.10"
33
+
34
+ # For more information and examples about making a new gem, checkout our
35
+ # guide at: https://bundler.io/guides/creating_gem.html
36
+ end
metadata ADDED
@@ -0,0 +1,153 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: my_data
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Michalis Zamparas
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2021-03-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: activesupport
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '3.2'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '3.2'
41
+ - !ruby/object:Gem::Dependency
42
+ name: activemodel
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '3.2'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '3.2'
55
+ - !ruby/object:Gem::Dependency
56
+ name: nokogiri
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '1.10'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '1.10'
69
+ description: Api client for AADE myData
70
+ email:
71
+ - mikezaby@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - ".rubocop.yml"
79
+ - Gemfile
80
+ - LICENSE.txt
81
+ - README.md
82
+ - Rakefile
83
+ - bin/console
84
+ - bin/setup
85
+ - lib/my_data.rb
86
+ - lib/my_data/client.rb
87
+ - lib/my_data/resource.rb
88
+ - lib/my_data/resources.rb
89
+ - lib/my_data/resources/ecls.rb
90
+ - lib/my_data/resources/ecls/expenses_classification_type.rb
91
+ - lib/my_data/resources/ecls/invoice_expenses_classification_type.rb
92
+ - lib/my_data/resources/ecls/invoices_expenses_classification_detail_type.rb
93
+ - lib/my_data/resources/error_type.rb
94
+ - lib/my_data/resources/icls.rb
95
+ - lib/my_data/resources/icls/income_classification_type.rb
96
+ - lib/my_data/resources/icls/invoice_income_classification_type.rb
97
+ - lib/my_data/resources/icls/invoices_income_classification_detail_type.rb
98
+ - lib/my_data/resources/inv.rb
99
+ - lib/my_data/resources/inv/aade_book_invoice_type.rb
100
+ - lib/my_data/resources/inv/address_type.rb
101
+ - lib/my_data/resources/inv/invoice_header_type.rb
102
+ - lib/my_data/resources/inv/invoice_row_type.rb
103
+ - lib/my_data/resources/inv/invoice_summary_type.rb
104
+ - lib/my_data/resources/inv/invoices_doc.rb
105
+ - lib/my_data/resources/inv/party_type.rb
106
+ - lib/my_data/resources/inv/payment_method_detail_type.rb
107
+ - lib/my_data/resources/inv/ship_type.rb
108
+ - lib/my_data/resources/inv/tax_totals_type.rb
109
+ - lib/my_data/resources/response_type.rb
110
+ - lib/my_data/resources/responses_doc.rb
111
+ - lib/my_data/type_caster.rb
112
+ - lib/my_data/version.rb
113
+ - lib/my_data/xml_generator.rb
114
+ - lib/my_data/xml_parser.rb
115
+ - lib/my_data/xsd.rb
116
+ - lib/my_data/xsd/complex_type.rb
117
+ - lib/my_data/xsd/docs/InvoicesDoc-v1.0.2.xsd
118
+ - lib/my_data/xsd/docs/RequestedProviderDoc-v1.0.2.xsd
119
+ - lib/my_data/xsd/docs/expensesClassification-v1.0.2.xsd
120
+ - lib/my_data/xsd/docs/incomeClassification-v1.0.2.xsd
121
+ - lib/my_data/xsd/docs/requestDoc-v1.0.2.xsd
122
+ - lib/my_data/xsd/docs/requestedInvoicesDoc-v1.0.2.xsd
123
+ - lib/my_data/xsd/docs/response-v1.0.2.xsd
124
+ - lib/my_data/xsd/element.rb
125
+ - lib/my_data/xsd/resource_generator.rb
126
+ - lib/my_data/xsd/structure.rb
127
+ - my_data.gemspec
128
+ homepage: https://github.com/mikezaby/my_data
129
+ licenses:
130
+ - MIT
131
+ metadata:
132
+ homepage_uri: https://github.com/mikezaby/my_data
133
+ source_code_uri: https://github.com/mikezaby/my_data
134
+ post_install_message:
135
+ rdoc_options: []
136
+ require_paths:
137
+ - lib
138
+ required_ruby_version: !ruby/object:Gem::Requirement
139
+ requirements:
140
+ - - ">="
141
+ - !ruby/object:Gem::Version
142
+ version: 2.3.0
143
+ required_rubygems_version: !ruby/object:Gem::Requirement
144
+ requirements:
145
+ - - ">="
146
+ - !ruby/object:Gem::Version
147
+ version: '0'
148
+ requirements: []
149
+ rubygems_version: 3.1.4
150
+ signing_key:
151
+ specification_version: 4
152
+ summary: Api client for AADE myData
153
+ test_files: []