plugzapi-gem 0.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: 0017b1d6c7794ad1e36a4a8bd78d5b5218012bdc797c783b18332333f4211a27
4
+ data.tar.gz: 9e3e286b3b4adad999b5c3a6d99362de46d275242470b6022144a3404ace4aea
5
+ SHA512:
6
+ metadata.gz: 8cb84f75ed446391edbf1330f0a1d0772e879af19cbb1f5f3bb5f5ba46afe5dbdad8dda50e519d9bd6bb495b1f6a9c914090fe0a2026a3c8b68bfb8b2195ba41
7
+ data.tar.gz: 668e1fde18ab764dec4a83186b418465412539d8101bafc46a6089a7cc064b9eb4c4eec2d6ca8eb97d66f05260b2db7074624e4c317a028266a8d3b0d90dbc6d
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,10 @@
1
+ AllCops:
2
+ TargetRubyVersion: 3.0
3
+
4
+ Style/StringLiterals:
5
+ EnforcedStyle: double_quotes
6
+
7
+ Style/StringLiteralsInInterpolation:
8
+ EnforcedStyle: double_quotes
9
+
10
+ Style/Documentation: false
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2024-09-11
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/README.md ADDED
@@ -0,0 +1,92 @@
1
+ # Plugzapi::Gem
2
+
3
+ TODO: Delete this and the text below, and describe your gem
4
+
5
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/plugzapi/gem`. To experiment with that code, run `bin/console` for an interactive prompt.
6
+
7
+ ## Installation
8
+
9
+ Para instalar a gem no projeto basta adicionar o seguinte trecho no Gemfile:
10
+
11
+ ```ruby
12
+ ...
13
+ gem 'pegar_o_path_que_vai_gerar_no_gitlab'
14
+ ```
15
+
16
+ Para testar localmente é possível instalar a gem executando o seguinte comando no terminal:
17
+
18
+ ```bash
19
+ gem install ./plugzapi-gem.gem
20
+ ```
21
+
22
+ instalando a gem é preciso criar um initializer para passar algumas variaveis para gem. Segue um exemplo:
23
+
24
+ ```ruby
25
+ Plugzapi.configure do |config|
26
+ config.first_value = "primeiro valor"
27
+ config.second_value = "segundo valor"
28
+ end
29
+ ```
30
+
31
+ ## Usage
32
+
33
+
34
+ ## Development
35
+
36
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
37
+
38
+ 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).
39
+
40
+ O desenvolvimento se concentra dentro da pasta lib/plugzapi. Seguindo a estrutura que temos de exemplo na classe Soma que fica dentro do Calculator.
41
+
42
+ ```ruby
43
+ module Plugzapi
44
+ module Calculator
45
+ class Soma
46
+ attr_reader :value1, :value2
47
+
48
+ def self.perform(value1, value2)
49
+ new(value1, value2).call
50
+ end
51
+
52
+ def initialize(value1, value2)
53
+ @value1 = value1
54
+ @value2 = value2
55
+ end
56
+
57
+ def call
58
+ puts value1 + value2
59
+ puts "---------------"
60
+ Plugzapi.configuration.valor_dos_parametros
61
+ end
62
+ end
63
+ end
64
+ end
65
+ ```
66
+
67
+ Segue um exemplo de como usar essa classe em uma aplicação que possui a gem instalada e configurada:
68
+
69
+ ```ruby
70
+ Plugzapi::Calculator::Soma.perform(4, 6)
71
+ ```
72
+
73
+ Isso vai retornar o seguinte:
74
+
75
+ ```bash
76
+ 10
77
+ ---------------
78
+ first_value = primeiro valor
79
+ second_value = segundo valor
80
+ ```
81
+
82
+ ## Contributing
83
+
84
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/plugzapi-gem. 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]/plugzapi-gem/blob/master/CODE_OF_CONDUCT.md).
85
+
86
+ ## Code of Conduct
87
+
88
+ Everyone interacting in the Plugzapi::Gem project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/plugzapi-gem/blob/master/CODE_OF_CONDUCT.md).
89
+
90
+ ## License
91
+
92
+ This gem is licensed under the MIT License. See the [LICENSE](./LICENSE) file for more information.
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Plugzapi
4
+ class Configuration
5
+ attr_accessor :client_token
6
+
7
+ def initialize
8
+ @client_token = nil
9
+ end
10
+ end
11
+
12
+ @configuration = Configuration.new
13
+
14
+ class << self
15
+ attr_accessor :configuration
16
+
17
+ def configure
18
+ yield(configuration)
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,66 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Plugzapi
4
+ # This main class is for connections with the PlugZapi API. The other classes that
5
+ # will integrate with endpoints need to inherit from Connections.
6
+ class Connections
7
+ attr_reader :instance_id, :token
8
+
9
+ def self.perform(instance_id:, token:)
10
+ new(instance_id, token).call
11
+ end
12
+
13
+ def initialize(instance_id, token)
14
+ @instance_id = instance_id
15
+ @token = token
16
+ end
17
+
18
+ # The call method will invoke response and return the API request's response.
19
+ def call
20
+ parsed_response = JSON.parse(response.body).transform_keys{ |key| key.to_sym }
21
+
22
+ parsed_response[:status] = response.status
23
+
24
+ parsed_response
25
+ end
26
+
27
+ private
28
+
29
+ def base_url
30
+ "#{Plugzapi::Constants::BASE_URL}/#{instance_id}/token/#{token}"
31
+ end
32
+
33
+ def get
34
+ Faraday.get(url) do |req|
35
+ req.headers['Client-Token'] = client_token
36
+ end
37
+ end
38
+
39
+ def post
40
+ Faraday.new(url: url).post do |req|
41
+ req.headers['content-type'] = 'application/json'
42
+ req.headers['Client-Token'] = client_token
43
+ req.body = {
44
+ message: message,
45
+ phone: phone
46
+ }.to_json
47
+ end
48
+ end
49
+
50
+ def client_token
51
+ Plugzapi.configuration.client_token
52
+ end
53
+
54
+ def response
55
+ raise NotImplementedError, "You must implement the response method"
56
+ end
57
+
58
+ def url
59
+ raise NotImplementedError, "You must implement the url method"
60
+ end
61
+
62
+ def client_token
63
+ Plugzapi.configuration.client_token
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Plugzapi
4
+ class Constants
5
+ BASE_URL = "https://api.plugzapi.com.br/instances/"
6
+ end
7
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Plugzapi
4
+ class Disconnect < Connections
5
+ private
6
+
7
+ def url
8
+ "#{base_url}/disconnect"
9
+ end
10
+
11
+ def response
12
+ @response ||= get
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Plugzapi
4
+ module Gem
5
+ VERSION = "0.1.0"
6
+ end
7
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "faraday"
4
+ require "pry"
5
+ require_relative "gem/version"
6
+ require_relative "configuration"
7
+ require_relative "constants"
8
+ require_relative "connections"
9
+ require_relative "get_qrcode"
10
+ require_relative "instance_status"
11
+ require_relative "validate_phone"
12
+ require_relative "send_message"
13
+ require_relative "disconnect"
14
+ require_relative "restore_session"
15
+ require_relative "restart"
16
+
17
+ module Plugzapi
18
+ module Gem
19
+ class Error < StandardError; end
20
+ # Your code goes here...
21
+ end
22
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Plugzapi
4
+ class GetQrcode < Connections
5
+ private
6
+
7
+ def url
8
+ "#{base_url}/qr-code/image"
9
+ end
10
+
11
+ def response
12
+ @response ||= get
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Plugzapi
4
+ class InstanceStatus < Connections
5
+ private
6
+
7
+ def url
8
+ "#{base_url}/status"
9
+ end
10
+
11
+ def response
12
+ @response ||= get
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Plugzapi
4
+ class Restart < Connections
5
+ private
6
+
7
+ def url
8
+ "#{base_url}/restart"
9
+ end
10
+
11
+ def response
12
+ @response ||= get
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Plugzapi
4
+ class RestoreSession < Connections
5
+ private
6
+
7
+ def url
8
+ "#{base_url}/restore-session"
9
+ end
10
+
11
+ def response
12
+ @response ||= get
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Plugzapi
4
+ class SendMessage < Connections
5
+ attr_reader :instance_id, :token, :phone, :message
6
+
7
+ def self.perform(instance_id:, token:, phone:, message:)
8
+ new(instance_id, token, phone, message).call
9
+ end
10
+
11
+ def initialize(instance_id, token, phone, message)
12
+ @instance_id = instance_id
13
+ @token = token
14
+ @phone = phone
15
+ @message = message
16
+ end
17
+
18
+ private
19
+
20
+ def url
21
+ "#{base_url}/send-text"
22
+ end
23
+
24
+ def response
25
+ @response ||= post
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Plugzapi
4
+ class ValidatePhone < Connections
5
+ attr_reader :instance_id, :token, :phone
6
+
7
+ def self.perform(instance_id:, token:, phone:)
8
+ new(instance_id, token, phone).call
9
+ end
10
+
11
+ def initialize(instance_id, token, phone)
12
+ @instance_id = instance_id
13
+ @token = token
14
+ @phone = phone
15
+ end
16
+
17
+ private
18
+
19
+ def url
20
+ "#{base_url}/phone-exists/#{phone}"
21
+ end
22
+
23
+ def response
24
+ @response ||= get
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,6 @@
1
+ module Plugzapi
2
+ module Gem
3
+ VERSION: String
4
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
5
+ end
6
+ end
metadata ADDED
@@ -0,0 +1,95 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: plugzapi-gem
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Keslley
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2024-09-25 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: '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'
27
+ - !ruby/object:Gem::Dependency
28
+ name: pry
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: " A plugzapi-gem facilita a integração com a API da Tecnospeed, permitindo
42
+ a automação do envio de mensagens via WhatsApp. \n Com uma interface simples
43
+ e intuitiva, desenvolvedores podem realizar chamadas à API da Plugzapi sem complicações,
44
+ \n otimizando o tempo de desenvolvimento para um integração com WhatsApp\n"
45
+ email:
46
+ - capelin.cvv@gmail.com
47
+ executables: []
48
+ extensions: []
49
+ extra_rdoc_files: []
50
+ files:
51
+ - ".rspec"
52
+ - ".rubocop.yml"
53
+ - CHANGELOG.md
54
+ - CODE_OF_CONDUCT.md
55
+ - README.md
56
+ - Rakefile
57
+ - lib/plugzapi/configuration.rb
58
+ - lib/plugzapi/connections.rb
59
+ - lib/plugzapi/constants.rb
60
+ - lib/plugzapi/disconnect.rb
61
+ - lib/plugzapi/gem.rb
62
+ - lib/plugzapi/gem/version.rb
63
+ - lib/plugzapi/get_qrcode.rb
64
+ - lib/plugzapi/instance_status.rb
65
+ - lib/plugzapi/restart.rb
66
+ - lib/plugzapi/restore_session.rb
67
+ - lib/plugzapi/send_message.rb
68
+ - lib/plugzapi/validate_phone.rb
69
+ - sig/plugzapi/gem.rbs
70
+ homepage: https://gitlab.limbersoftware.com.br/way-v/plugzapi-gem
71
+ licenses:
72
+ - MIT
73
+ metadata:
74
+ license: MIT
75
+ post_install_message:
76
+ rdoc_options: []
77
+ require_paths:
78
+ - lib
79
+ required_ruby_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: 3.0.0
84
+ required_rubygems_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ requirements: []
90
+ rubygems_version: 3.3.3
91
+ signing_key:
92
+ specification_version: 4
93
+ summary: Gem para integrar com a API Plugzapi da Tecnospeed para envio de mensagens
94
+ via WhatsApp
95
+ test_files: []