sophia_service 1.1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: de923f29d0022525ca79e95b7858115a09f54483d2165e884943cde1c8dcd870
4
+ data.tar.gz: 77f0819faeaa3a6cb67bf526058719a81e0aee8077f69be09901b2d88bbf114c
5
+ SHA512:
6
+ metadata.gz: a9f4679ec7df13c35044bc643799ddef973d191024c61f79b75c629106389e4f0e2b43cbb6cb0a898ac00450b0f42f476798ca83860758e0fac88654c53695d9
7
+ data.tar.gz: 0c36b3615eab670eddaaffcc192e7ead58477201c28c95113ab8bc717f159eedd64f68d9f96410f64c2f1f3290d3cca20a325c0273bf80a607e889d07e1e31c9
data/.env.default ADDED
@@ -0,0 +1,4 @@
1
+ SOPHIA_USER=
2
+ SOPHIA_PASSWORD=
3
+ SOPHIA_URL=
4
+ IS_SOPHIA_PRODUCTION=true
data/.rubocop.yml ADDED
@@ -0,0 +1,11 @@
1
+ AllCops:
2
+ TargetRubyVersion: 3.0
3
+
4
+ Style/StringLiterals:
5
+ EnforcedStyle: double_quotes
6
+
7
+ Style/StringLiteralsInInterpolation:
8
+ EnforcedStyle: double_quotes
9
+
10
+ Metrics/ClassLength:
11
+ Enabled: false
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2024-12-16
4
+
5
+ - Initial release
@@ -0,0 +1,132 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our
6
+ community a harassment-free experience for everyone, regardless of age, body
7
+ size, visible or invisible disability, ethnicity, sex characteristics, gender
8
+ identity and expression, level of experience, education, socio-economic status,
9
+ nationality, personal appearance, race, caste, color, religion, or sexual
10
+ identity and orientation.
11
+
12
+ We pledge to act and interact in ways that contribute to an open, welcoming,
13
+ diverse, inclusive, and healthy community.
14
+
15
+ ## Our Standards
16
+
17
+ Examples of behavior that contributes to a positive environment for our
18
+ community include:
19
+
20
+ * Demonstrating empathy and kindness toward other people
21
+ * Being respectful of differing opinions, viewpoints, and experiences
22
+ * Giving and gracefully accepting constructive feedback
23
+ * Accepting responsibility and apologizing to those affected by our mistakes,
24
+ and learning from the experience
25
+ * Focusing on what is best not just for us as individuals, but for the overall
26
+ community
27
+
28
+ Examples of unacceptable behavior include:
29
+
30
+ * The use of sexualized language or imagery, and sexual attention or advances of
31
+ any kind
32
+ * Trolling, insulting or derogatory comments, and personal or political attacks
33
+ * Public or private harassment
34
+ * Publishing others' private information, such as a physical or email address,
35
+ without their explicit permission
36
+ * Other conduct which could reasonably be considered inappropriate in a
37
+ professional setting
38
+
39
+ ## Enforcement Responsibilities
40
+
41
+ Community leaders are responsible for clarifying and enforcing our standards of
42
+ acceptable behavior and will take appropriate and fair corrective action in
43
+ response to any behavior that they deem inappropriate, threatening, offensive,
44
+ or harmful.
45
+
46
+ Community leaders have the right and responsibility to remove, edit, or reject
47
+ comments, commits, code, wiki edits, issues, and other contributions that are
48
+ not aligned to this Code of Conduct, and will communicate reasons for moderation
49
+ decisions when appropriate.
50
+
51
+ ## Scope
52
+
53
+ This Code of Conduct applies within all community spaces, and also applies when
54
+ an individual is officially representing the community in public spaces.
55
+ Examples of representing our community include using an official email address,
56
+ posting via an official social media account, or acting as an appointed
57
+ representative at an online or offline event.
58
+
59
+ ## Enforcement
60
+
61
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
62
+ reported to the community leaders responsible for enforcement at
63
+ [INSERT CONTACT METHOD].
64
+ All complaints will be reviewed and investigated promptly and fairly.
65
+
66
+ All community leaders are obligated to respect the privacy and security of the
67
+ reporter of any incident.
68
+
69
+ ## Enforcement Guidelines
70
+
71
+ Community leaders will follow these Community Impact Guidelines in determining
72
+ the consequences for any action they deem in violation of this Code of Conduct:
73
+
74
+ ### 1. Correction
75
+
76
+ **Community Impact**: Use of inappropriate language or other behavior deemed
77
+ unprofessional or unwelcome in the community.
78
+
79
+ **Consequence**: A private, written warning from community leaders, providing
80
+ clarity around the nature of the violation and an explanation of why the
81
+ behavior was inappropriate. A public apology may be requested.
82
+
83
+ ### 2. Warning
84
+
85
+ **Community Impact**: A violation through a single incident or series of
86
+ actions.
87
+
88
+ **Consequence**: A warning with consequences for continued behavior. No
89
+ interaction with the people involved, including unsolicited interaction with
90
+ those enforcing the Code of Conduct, for a specified period of time. This
91
+ includes avoiding interactions in community spaces as well as external channels
92
+ like social media. Violating these terms may lead to a temporary or permanent
93
+ ban.
94
+
95
+ ### 3. Temporary Ban
96
+
97
+ **Community Impact**: A serious violation of community standards, including
98
+ sustained inappropriate behavior.
99
+
100
+ **Consequence**: A temporary ban from any sort of interaction or public
101
+ communication with the community for a specified period of time. No public or
102
+ private interaction with the people involved, including unsolicited interaction
103
+ with those enforcing the Code of Conduct, is allowed during this period.
104
+ Violating these terms may lead to a permanent ban.
105
+
106
+ ### 4. Permanent Ban
107
+
108
+ **Community Impact**: Demonstrating a pattern of violation of community
109
+ standards, including sustained inappropriate behavior, harassment of an
110
+ individual, or aggression toward or disparagement of classes of individuals.
111
+
112
+ **Consequence**: A permanent ban from any sort of public interaction within the
113
+ community.
114
+
115
+ ## Attribution
116
+
117
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
118
+ version 2.1, available at
119
+ [https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
120
+
121
+ Community Impact Guidelines were inspired by
122
+ [Mozilla's code of conduct enforcement ladder][Mozilla CoC].
123
+
124
+ For answers to common questions about this code of conduct, see the FAQ at
125
+ [https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
126
+ [https://www.contributor-covenant.org/translations][translations].
127
+
128
+ [homepage]: https://www.contributor-covenant.org
129
+ [v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
130
+ [Mozilla CoC]: https://github.com/mozilla/diversity
131
+ [FAQ]: https://www.contributor-covenant.org/faq
132
+ [translations]: https://www.contributor-covenant.org/translations
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2024 João Ferreira
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # SophiaApiService
2
+
3
+ This repository contains an implementation of a Ruby service which encapsulates the usage of the API of [Sophia ERP](https://sophia.com.br/).
4
+
5
+ It implements some of the main HTTP methods to the available endpoints.
6
+
7
+ ## Installation
8
+
9
+ TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
10
+
11
+ Install the gem and add to the application's Gemfile by executing:
12
+
13
+ $ bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
14
+
15
+ If bundler is not being used to manage dependencies, install the gem by executing:
16
+
17
+ $ gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
18
+
19
+ ## Usage
20
+
21
+ You should only import and use the SophiaApiService class defining the necessary environment variables.
22
+
23
+ ## Development
24
+
25
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
26
+
27
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
28
+
29
+ ## Contributing
30
+
31
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/sophia_api_service. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/sophia_api_service/blob/master/CODE_OF_CONDUCT.md).
32
+
33
+ ## License
34
+
35
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
36
+
37
+ ## Code of Conduct
38
+
39
+ Everyone interacting in the SophiaApiService project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/sophia_api_service/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rubocop/rake_task"
5
+
6
+ RuboCop::RakeTask.new
7
+
8
+ task default: :rubocop
@@ -0,0 +1,113 @@
1
+ require "uri"
2
+ require "net/http"
3
+ require "json"
4
+
5
+ module SophiaService
6
+ # Implement all Sophia API calls
7
+ class ApiClient
8
+ def initialize
9
+ # Initialize base configuration to retrieve information from Sophia's API
10
+ @sophia_routes = SophiaRoutes.new(base_url: SophiaService.configuration.base_url)
11
+ @sophia_user = SophiaService.configuration.sophia_user
12
+ @sophia_password = SophiaService.configuration.sophia_password
13
+ @should_use_ssl = SophiaService.configuration.is_sophia_production
14
+ @sophia_token = authenticate
15
+ return unless @sophia_user.nil? || @sophia_password.nil?
16
+
17
+ raise "It is mandatory to define the environment variables: 'SOPHIA_USER' and 'SOPHIA_PASSWORD'"
18
+ end
19
+
20
+ def get_students_by_units(units)
21
+ # Convert array of units to a String separated by comma, to send it to Sophia API
22
+ units_query = units.join(",")
23
+ url = URI("#{@sophia_routes.students_route}?Unidades=#{units_query}")
24
+ https = Net::HTTP.new(url.host, url.port)
25
+ https.use_ssl = @should_use_ssl
26
+ request = Net::HTTP::Get.new(url)
27
+ request["Token"] = @sophia_token
28
+ SophiaResponse.new(https.request(request))
29
+ end
30
+
31
+ def get_student_by_email(email)
32
+ url = URI("#{@sophia_routes.students_route}?Email=#{email}")
33
+ https = Net::HTTP.new(url.host, url.port)
34
+ https.use_ssl = @should_use_ssl
35
+ request = Net::HTTP::Get.new(url)
36
+ request["Token"] = @sophia_token
37
+ SophiaResponse.new(https.request(request))
38
+ end
39
+
40
+ def get_classes_by_codes(class_codes)
41
+ # Convert array of units to a String separated by comma, to send it to Sophia API
42
+ class_codes_query = class_codes.join(",")
43
+ url = URI("#{@sophia_routes.classes_route}?Codigos=#{class_codes_query}")
44
+ https = Net::HTTP.new(url.host, url.port)
45
+ https.use_ssl = @should_use_ssl
46
+ request = Net::HTTP::Get.new(url)
47
+ request["Accept"] = "application/json"
48
+ request["Content-Type"] = "application/json"
49
+ request["Token"] = @sophia_token
50
+ SophiaResponse.new(https.request(request))
51
+ end
52
+
53
+ def get_classes_by_units(class_units)
54
+ # Convert array of units to a String separated by comma, to send it to Sophia API
55
+ class_units_query = class_units.join(",")
56
+ url = URI("#{@sophia_routes.classes_route}?Unidades=#{class_units_query}")
57
+ https = Net::HTTP.new(url.host, url.port)
58
+ https.use_ssl = @should_use_ssl
59
+ request = Net::HTTP::Get.new(url)
60
+ request["Accept"] = "application/json"
61
+ request["Content-Type"] = "application/json"
62
+ request["Token"] = @sophia_token
63
+ SophiaResponse.new(https.request(request))
64
+ end
65
+
66
+ def get_collaborator_by_email(email)
67
+ url = URI("#{@sophia_routes.collaborators_route}?Email=#{email}")
68
+ https = Net::HTTP.new(url.host, url.port)
69
+ https.use_ssl = @should_use_ssl
70
+ request = Net::HTTP::Get.new(url)
71
+ request["Token"] = @sophia_token
72
+ SophiaResponse.new(https.request(request))
73
+ end
74
+
75
+ def get_sales_by_students(students_codes)
76
+ # Convert array of units to a String separated by comma, to send it to Sophia API
77
+ students_codes_query = students_codes.join(",")
78
+ url = URI("#{@sophia_routes.sales_route}?Alunos=#{students_codes_query}")
79
+ https = Net::HTTP.new(url.host, url.port)
80
+ https.use_ssl = @should_use_ssl
81
+ request = Net::HTTP::Get.new(url)
82
+ request["Token"] = @sophia_token
83
+ SophiaResponse.new(https.request(request))
84
+ end
85
+
86
+ def get_courses
87
+ url = URI(@sophia_routes.courses_route)
88
+ https = Net::HTTP.new(url.host, url.port)
89
+ https.use_ssl = @should_use_ssl
90
+ request = Net::HTTP::Get.new(url)
91
+ request["Token"] = @sophia_token
92
+ SophiaResponse.new(https.request(request))
93
+ end
94
+
95
+ def inspect
96
+ "#<SophiaService::ApiClient>"
97
+ end
98
+
99
+ private
100
+
101
+ def authenticate
102
+ auth_url = URI(@sophia_routes.authentication_route)
103
+ https = Net::HTTP.new(auth_url.host, auth_url.port)
104
+ https.use_ssl = @should_use_ssl
105
+ request = Net::HTTP::Post.new(auth_url)
106
+ request["Content-Type"] = "application/json"
107
+ request.body = JSON.dump({ usuario: @sophia_user, senha: @sophia_password })
108
+ http_response = https.request(request)
109
+ # The Sophia Auth method returns a string instead of a JSON, that why we not use the SophiaResponse object
110
+ http_response.read_body
111
+ end
112
+ end
113
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Encapsulates an HTTP base response
4
+ class SophiaResponse
5
+ attr_reader :body, :status_code
6
+
7
+ def initialize(http_response)
8
+ @status_code = http_response.code.to_i
9
+ @body = JSON.parse(http_response.read_body)
10
+ end
11
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Class encapsulating all available Sophia Routes
4
+ class SophiaRoutes
5
+ def initialize(base_url:)
6
+ @sophia_base_url = base_url
7
+ return unless @sophia_base_url.nil?
8
+
9
+ raise "The Sophia Base URL 'SOPHIA_URL' may be defined as an environment variable"
10
+ end
11
+
12
+ def students_route
13
+ "#{@sophia_base_url}/Alunos"
14
+ end
15
+
16
+ def authentication_route
17
+ "#{@sophia_base_url}/Autenticacao"
18
+ end
19
+
20
+ def classes_route
21
+ "#{@sophia_base_url}/Turmas"
22
+ end
23
+
24
+ def courses_route
25
+ "#{@sophia_base_url}/Cursos"
26
+ end
27
+
28
+ def collaborators_route
29
+ "#{@sophia_base_url}/Colaboradores"
30
+ end
31
+
32
+ def sales_route
33
+ "#{@sophia_base_url}/Vendas"
34
+ end
35
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SophiaService
4
+ VERSION = "1.1.0"
5
+ end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "sophia_service/version"
4
+
5
+ # Implement all Sophia API calls
6
+ module SophiaService
7
+ autoload :ApiClient, "sophia_service/api_client"
8
+ autoload :SophiaRoutes, "sophia_service/sophia_routes"
9
+ autoload :SophiaResponse, "sophia_service/sophia_response"
10
+
11
+ class << self
12
+ attr_accessor :configuration
13
+ end
14
+
15
+ def self.configure
16
+ self.configuration ||= Configuration.new
17
+ yield(configuration)
18
+ end
19
+
20
+ # Implement Sophia Service configuration
21
+ class Configuration
22
+ attr_reader :base_url, :sophia_user, :sophia_password, :is_sophia_production
23
+
24
+ def initialize
25
+ @base_url = ""
26
+ @sophia_user = ""
27
+ @sophia_password = ""
28
+ @is_sophia_production = true
29
+ end
30
+
31
+ def set_configuration(base_url:, sophia_user:, sophia_password:, is_sophia_production:)
32
+ @base_url = base_url
33
+ @sophia_user = sophia_user
34
+ @sophia_password = sophia_password
35
+ @is_sophia_production = is_sophia_production
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,45 @@
1
+ module SophiaService
2
+ VERSION: String
3
+
4
+ attr_accessor self.configuration: Configuration
5
+
6
+ def self.configure: -> Configuration
7
+
8
+ class ApiClient
9
+ @sophia_routes: SophiaRoutes
10
+ @sophia_user: (String | nil)
11
+ @sophia_password: (String | nil)
12
+ @sophia_token: (String | nil)
13
+ @should_use_ssl: (bool | nil)
14
+
15
+ def get_classes_by_codes: -> SophiaResponse
16
+
17
+ def get_classes_by_units: -> SophiaResponse
18
+
19
+ def get_collaborator_by_email: -> SophiaResponse
20
+
21
+ def get_courses: -> SophiaResponse
22
+
23
+ def get_sales_by_students: -> SophiaResponse
24
+
25
+ def get_student_by_email: -> SophiaResponse
26
+
27
+ def get_students_by_units: -> SophiaResponse
28
+
29
+ private
30
+
31
+ def authenticate: -> String
32
+ end
33
+
34
+ class Configuration
35
+ @base_url: String
36
+ @is_sophia_production: bool
37
+ @sophia_password: String
38
+ @sophia_user: String
39
+
40
+ attr_reader base_url: String
41
+ attr_reader is_sophia_production: bool
42
+ attr_reader sophia_password: String
43
+ attr_reader sophia_user: String
44
+ end
45
+ end
@@ -0,0 +1,4 @@
1
+ class SophiaResponse
2
+ attr_reader body: untyped
3
+ attr_reader status_code: int
4
+ end
@@ -0,0 +1,15 @@
1
+ class SophiaRoutes
2
+ @sophia_base_url: string
3
+
4
+ def authentication_route: -> string
5
+
6
+ def classes_route: -> string
7
+
8
+ def collaborators_route: -> string
9
+
10
+ def courses_route: -> string
11
+
12
+ def sales_route: -> string
13
+
14
+ def students_route: -> string
15
+ end
metadata ADDED
@@ -0,0 +1,62 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sophia_service
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.1.0
5
+ platform: ruby
6
+ authors:
7
+ - João F.
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2024-12-19 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Implements the main calls to the routes of the Sophia API ERP
14
+ email:
15
+ - jpedaf@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - ".env.default"
21
+ - ".rubocop.yml"
22
+ - CHANGELOG.md
23
+ - CODE_OF_CONDUCT.md
24
+ - LICENSE.txt
25
+ - README.md
26
+ - Rakefile
27
+ - lib/sophia_service.rb
28
+ - lib/sophia_service/api_client.rb
29
+ - lib/sophia_service/sophia_response.rb
30
+ - lib/sophia_service/sophia_routes.rb
31
+ - lib/sophia_service/version.rb
32
+ - sig/api_client.rbs
33
+ - sig/sophia_response.rbs
34
+ - sig/sophia_routes.rbs
35
+ homepage: https://github.com/jpedroantunes/sophia-api-service
36
+ licenses:
37
+ - MIT
38
+ metadata:
39
+ allowed_push_host: https://rubygems.org
40
+ homepage_uri: https://github.com/jpedroantunes/sophia-api-service
41
+ source_code_uri: https://github.com/jpedroantunes/sophia-api-service
42
+ changelog_uri: https://github.com/jpedroantunes/sophia-api-service
43
+ post_install_message:
44
+ rdoc_options: []
45
+ require_paths:
46
+ - lib
47
+ required_ruby_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ version: 3.0.0
52
+ required_rubygems_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ requirements: []
58
+ rubygems_version: 3.5.23
59
+ signing_key:
60
+ specification_version: 4
61
+ summary: Encapsulates the main Sophia Service API calls
62
+ test_files: []