bindup 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 143d81b94e654fd1e39be81a7fd352eb0ba8c2900fbf2dc9a41bd4b8aef774a2
4
+ data.tar.gz: 94928e94c65bf4a9be2161cba67c7ff46ea11831b7348ed8b475a62e83a6ebef
5
+ SHA512:
6
+ metadata.gz: e1df2aa1844165a3e47783a8ce5f6c6ba248d433c9ab69119a8d46a35ad5f195fd72f218aa58616af412180934ea398cd38e25c692d92bb45e6f083926a96ce9
7
+ data.tar.gz: f797c34d322e94e0bd5ef76e49d465bc97f2472886c1f6c0452bb35a04e358acfc1127487175a82e1377c88c59c18554df1458ecf14eae94b4d0aafb2f314280
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,13 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.6
3
+
4
+ Style/StringLiterals:
5
+ Enabled: true
6
+ EnforcedStyle: double_quotes
7
+
8
+ Style/StringLiteralsInInterpolation:
9
+ Enabled: true
10
+ EnforcedStyle: double_quotes
11
+
12
+ Layout/LineLength:
13
+ Max: 120
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.0.1] - 2022-06-19
4
+
5
+ - Initial release
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at TODO: Write your email address. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in bindup.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "rspec", "~> 3.0"
11
+
12
+ gem "rubocop", "~> 1.21"
data/Gemfile.lock ADDED
@@ -0,0 +1,73 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ bindup (0.0.1)
5
+ activesupport (~> 7.0, >= 7.0.3)
6
+ faraday (~> 2.3.0)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ activesupport (7.0.3)
12
+ concurrent-ruby (~> 1.0, >= 1.0.2)
13
+ i18n (>= 1.6, < 2)
14
+ minitest (>= 5.1)
15
+ tzinfo (~> 2.0)
16
+ ast (2.4.2)
17
+ concurrent-ruby (1.1.10)
18
+ diff-lcs (1.5.0)
19
+ faraday (2.3.0)
20
+ faraday-net_http (~> 2.0)
21
+ ruby2_keywords (>= 0.0.4)
22
+ faraday-net_http (2.0.3)
23
+ i18n (1.10.0)
24
+ concurrent-ruby (~> 1.0)
25
+ minitest (5.15.0)
26
+ parallel (1.22.1)
27
+ parser (3.1.2.0)
28
+ ast (~> 2.4.1)
29
+ rainbow (3.1.1)
30
+ rake (13.0.6)
31
+ regexp_parser (2.4.0)
32
+ rexml (3.2.5)
33
+ rspec (3.11.0)
34
+ rspec-core (~> 3.11.0)
35
+ rspec-expectations (~> 3.11.0)
36
+ rspec-mocks (~> 3.11.0)
37
+ rspec-core (3.11.0)
38
+ rspec-support (~> 3.11.0)
39
+ rspec-expectations (3.11.0)
40
+ diff-lcs (>= 1.2.0, < 2.0)
41
+ rspec-support (~> 3.11.0)
42
+ rspec-mocks (3.11.1)
43
+ diff-lcs (>= 1.2.0, < 2.0)
44
+ rspec-support (~> 3.11.0)
45
+ rspec-support (3.11.0)
46
+ rubocop (1.29.1)
47
+ parallel (~> 1.10)
48
+ parser (>= 3.1.0.0)
49
+ rainbow (>= 2.2.2, < 4.0)
50
+ regexp_parser (>= 1.8, < 3.0)
51
+ rexml (>= 3.2.5, < 4.0)
52
+ rubocop-ast (>= 1.17.0, < 2.0)
53
+ ruby-progressbar (~> 1.7)
54
+ unicode-display_width (>= 1.4.0, < 3.0)
55
+ rubocop-ast (1.18.0)
56
+ parser (>= 3.1.1.0)
57
+ ruby-progressbar (1.11.0)
58
+ ruby2_keywords (0.0.5)
59
+ tzinfo (2.0.4)
60
+ concurrent-ruby (~> 1.0)
61
+ unicode-display_width (2.1.0)
62
+
63
+ PLATFORMS
64
+ x86_64-linux
65
+
66
+ DEPENDENCIES
67
+ bindup!
68
+ rake (~> 13.0)
69
+ rspec (~> 3.0)
70
+ rubocop (~> 1.21)
71
+
72
+ BUNDLED WITH
73
+ 2.3.14
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2022 TODO: Write your name
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,83 @@
1
+ # Bindup (Customizable API Wrapper)
2
+
3
+ Bindup is able to wrap API from other services so the Ruby application
4
+ use those API with out having to implement a new module to deal with
5
+ every single API or having to create a gem. Bindup will be able to
6
+ setup multiple services at once so that integrating whole new service
7
+ is easy as changing the config
8
+
9
+ ## Installation
10
+
11
+ Install the gem and add to the application's Gemfile by executing:
12
+
13
+ $ bundle add bindup
14
+
15
+ If bundler is not being used to manage dependencies, install the gem by executing:
16
+
17
+ $ gem install bindup
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ### Basic config.yml
24
+
25
+ ```yaml
26
+ components:
27
+ bssmw:
28
+ name: 'BSSMW'
29
+ base_url: 'https://gorest.co.in'
30
+ version:
31
+ - name: 'V1'
32
+ base_url: 'https://gorest.co.in'
33
+ apis:
34
+ - name: "first_test_api"
35
+ url: "get"
36
+ base_url: "https://httpbin.org"
37
+ verb: "GET"
38
+ type: "json"
39
+ - name: "second_test_api"
40
+ base_url: "https://httpbin.org"
41
+ url: "post"
42
+ verb: "POST"
43
+ type: "json"
44
+ - name: "third_test_api"
45
+ base_url: "https://httpbin.org"
46
+ url: "post"
47
+ verb: "POST"
48
+ type: "urlencoded"
49
+ - name: "fourth_test_api"
50
+ base_url: "https://httpbin.org"
51
+ url: "put"
52
+ verb: "PUT"
53
+ type: "json"
54
+ ```
55
+
56
+ ## Do you like it? Star it!
57
+
58
+ If you use this component just star it. A developer is more motivated to improve a project when there is some interest.
59
+
60
+ ## Development
61
+
62
+ 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.
63
+
64
+ 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).
65
+
66
+ ## Contributing
67
+
68
+ Bug reports and pull requests are welcome on GitHub at https://github.com/randikabanura/bindup. 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/randikabanura/bindup/blob/master/CODE_OF_CONDUCT.md).
69
+
70
+ ## License
71
+
72
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT). You can review the licence [here](./LICENSE.txt).
73
+
74
+ ## Code of Conduct
75
+
76
+ Everyone interacting in the Bindup project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/bindup/blob/master/CODE_OF_CONDUCT.md).
77
+
78
+ ## Developer
79
+
80
+ Name: [Banura Randika Perera](https://github.com/randikabanura) <br/>
81
+ Linkedin: [randika-banura](https://www.linkedin.com/in/randika-banura/) <br/>
82
+ Email: [randika.banura@gamil.com](mailto:randika.banura@gamil.com) <br/>
83
+ Bsc (Hons) Information Technology specialized in Software Engineering (SLIIT) <br/>
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]
data/bindup.gemspec ADDED
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/bindup/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "bindup"
7
+ spec.version = Bindup::VERSION
8
+ spec.authors = ["Banura Randika Perera"]
9
+ spec.email = ["randika.banura@gmail.com"]
10
+
11
+ spec.summary = "Customizable API wrapper library"
12
+ spec.description = "Customizable API wrapper"
13
+ spec.homepage = "https://github.com/randikabanura"
14
+ spec.license = "MIT"
15
+ spec.required_ruby_version = ">= 2.6.0"
16
+
17
+ spec.metadata["homepage_uri"] = spec.homepage
18
+ spec.metadata["source_code_uri"] = "https://github.com/randikabanura/bindup"
19
+ spec.metadata["changelog_uri"] = "https://github.com/randikabanura/bindup/CHANGELOG.md"
20
+
21
+ # Specify which files should be added to the gem when it is released.
22
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
23
+ spec.files = Dir.chdir(__dir__) do
24
+ `git ls-files -z`.split("\x0").reject do |f|
25
+ (f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
26
+ end
27
+ end
28
+ spec.bindir = "exe"
29
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
30
+ spec.require_paths = ["lib"]
31
+
32
+ # Uncomment to register a new dependency of your gem
33
+ spec.add_dependency "activesupport", "~> 7.0", ">= 7.0.3"
34
+ spec.add_dependency "faraday", "~> 2.3.0"
35
+
36
+ # For more information and examples about making a new gem, check out our
37
+ # guide at: https://bundler.io/guides/creating_gem.html
38
+ end
@@ -0,0 +1,11 @@
1
+ require_relative "version"
2
+ require_relative "service_methods"
3
+ require_relative "service_creator"
4
+ require_relative "configuration"
5
+ require "yaml"
6
+ require "active_support/all"
7
+ require "faraday"
8
+
9
+ module Bindup
10
+ extend Bindup::Configuration
11
+ end
@@ -0,0 +1,29 @@
1
+
2
+
3
+ module Bindup
4
+ module Configuration
5
+ attr_accessor :configuration
6
+ attr_reader :component_setup
7
+
8
+ def configure
9
+ self.configuration ||= Configuration.new
10
+ yield(configuration)
11
+
12
+ @component_setup = YAML.load_file(configuration.config_path)
13
+
14
+ Bindup::ServiceCreator.execute
15
+ end
16
+
17
+ class Configuration
18
+ attr_accessor :config_path, :log_response, :log_response_params
19
+
20
+ def initialize
21
+ @config_path = "config/initializer/bindup.yml"
22
+ @log_response = true
23
+ # { headers: true, bodies: true }
24
+ @log_response_params = nil
25
+ end
26
+ end
27
+ end
28
+ end
29
+
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bindup
4
+ module ServiceCreator
5
+ extend Bindup::ServiceMethods
6
+
7
+ class << self
8
+ def execute
9
+ services = component_setup_keys
10
+ components = component_setup
11
+
12
+ services.each do |service|
13
+ versions = components[service]["version"]
14
+ service_module = create_service_module(components, service)
15
+
16
+ versions.each do |version|
17
+ version_class = create_version_class(service_module, version)
18
+
19
+ api_endpoint(version_class, service, version)
20
+ faraday_client(version_class)
21
+ request(version_class)
22
+ log_response_params(version_class)
23
+ request_method_build(version_class)
24
+
25
+ version_class.send(:set_api_endpoint_by_service)
26
+ version_class.send(:set_api_endpoint_by_version)
27
+
28
+ build_options(version_class)
29
+ build_client(version_class)
30
+ build_params(version_class)
31
+ build_headers(version_class)
32
+ api_methods(version_class, version)
33
+ methods_as_alias(version_class)
34
+ methods_as_private(version_class)
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
41
+
@@ -0,0 +1,161 @@
1
+ module Bindup
2
+ module ServiceMethods
3
+ METHODS_WITH_QUERY = %w[get head delete trace].freeze
4
+ METHODS_WITH_BODY = %w[post put patch].freeze
5
+
6
+ private
7
+
8
+ def component_setup_keys
9
+ Bindup.component_setup["components"].keys || []
10
+ end
11
+
12
+ def component_setup
13
+ Bindup.component_setup["components"]
14
+ end
15
+
16
+ def create_service_module(components, service)
17
+ Bindup.const_set(components[service]["name"], Module.new)
18
+ end
19
+
20
+ def create_version_class(service_module, version)
21
+ service_module.const_set(version["name"], Class.new)
22
+ end
23
+
24
+ def api_endpoint(version_class, service, version)
25
+ version_class.define_singleton_method(:set_api_endpoint_by_service) do
26
+ version_class.define_singleton_method("API_ENDPOINT") { service["base_url"] } if service["base_url"].present?
27
+ end
28
+
29
+ version_class.define_singleton_method(:set_api_endpoint_by_version) do
30
+ version_class.define_singleton_method("API_ENDPOINT") { version["base_url"] } if version["base_url"].present?
31
+ end
32
+ end
33
+
34
+ def faraday_client(version_class)
35
+ version_class.define_singleton_method(:client) do |options:|
36
+ return version_class.send(:build_client, options: options) if options.present?
37
+
38
+ @client ||= version_class.send(:build_client)
39
+ end
40
+ end
41
+
42
+ def request(version_class)
43
+ version_class.define_singleton_method(:request) do |http_method:, endpoint:, params: nil, headers: nil, options: nil|
44
+ params = version_class.send(:build_params, options, params)
45
+ headers = version_class.send(:build_headers, options, headers)
46
+ extra_params = if METHODS_WITH_QUERY.include?(http_method.to_s)
47
+ version_class.send(:build_body, options, options["extra_params"], force_build: true)
48
+ else
49
+ options["extra_params"]
50
+ end
51
+
52
+ if extra_params.present? && METHODS_WITH_QUERY.include?(http_method.to_s)
53
+ response = version_class.send(:client, options: options).send(http_method, endpoint, params, headers) { |req| req.body = extra_params }
54
+ elsif extra_params.present? && METHODS_WITH_BODY.include?(http_method.to_s)
55
+ response = version_class.send(:client, options: options).send(http_method, endpoint, params, headers) do |req|
56
+ extra_params.each { |extra_params_key, extra_params_value| req.params[extra_params_key.to_s] = extra_params_value }
57
+ end
58
+ else
59
+ response = version_class.send(:client, options: options).send(http_method, endpoint, params, headers)
60
+ end
61
+ [response&.body, response&.headers]
62
+ end
63
+ end
64
+
65
+ def log_response_params(version_class)
66
+ version_class.define_singleton_method(:log_response_params) do
67
+ if Bindup.configuration.log_response_params.present?
68
+ Bindup.configuration.log_response_params
69
+ else
70
+ { headers: true, bodies: true }
71
+ end
72
+ end
73
+ end
74
+
75
+ def request_method_build(version_class)
76
+ version_class.define_singleton_method(:request_method_build) do |api:, params: nil, headers: nil, extra_params: nil|
77
+ options = version_class.send(:build_options, api, extra_params)
78
+
79
+ version_class.send(:request, http_method: api["verb"].downcase.to_sym, endpoint: api["url"],
80
+ params: params, headers: headers, options: options)
81
+ end
82
+ end
83
+
84
+ def api_methods(version_class, version)
85
+ version["apis"].each do |api|
86
+ version_class.define_singleton_method(api["name"].to_sym) do |params = nil, headers = nil, extra_params: nil|
87
+ version_class.send(:request_method_build, api: api, params: params&.stringify_keys, headers: headers&.stringify_keys, extra_params: extra_params&.stringify_keys)
88
+ end
89
+ end
90
+ end
91
+
92
+ def build_client(version_class)
93
+ version_class.define_singleton_method(:build_client) do |options:|
94
+ url = options.present? && options["base_url"].present? ? options["base_url"] : version_class.API_ENDPOINT
95
+
96
+ Faraday.new(url) do |client|
97
+ client.response :logger, nil, version_class.send(:log_response_params) if Bindup.configuration.log_response
98
+ client.adapter Faraday.default_adapter
99
+ end
100
+ end
101
+ end
102
+
103
+ def build_options(version_class)
104
+ version_class.define_singleton_method(:build_options) do |api, extra_params|
105
+ { "base_url" => api["base_url"], "type" => api["type"], "http_method" => api["verb"].downcase, "extra_params" => extra_params }
106
+ end
107
+ end
108
+
109
+ def build_params(version_class)
110
+ version_class.define_singleton_method(:build_params) do |options, params, force_build: false|
111
+ return params if params.blank? || options.blank? || options["type"].blank?
112
+ if !force_build && options["http_method"].present? && METHODS_WITH_QUERY.include?(options["http_method"])
113
+ return params
114
+ end
115
+
116
+ case options["type"].downcase
117
+ when "json"
118
+ params = params.to_json
119
+ when "urlencoded"
120
+ params = URI.encode_www_form(params)
121
+ else
122
+ params
123
+ end
124
+
125
+ params
126
+ end
127
+ end
128
+
129
+ def build_headers(version_class)
130
+ version_class.define_singleton_method(:build_headers) do |options, headers|
131
+ return headers if options.blank? || options["type"].blank?
132
+
133
+ headers = {} if headers.blank?
134
+
135
+ case options["type"].downcase
136
+ when "json"
137
+ headers.merge!({ "Content-Type" => "application/json" }) unless headers.key?("Content-Type")
138
+ when "urlencoded"
139
+ headers.merge!({ "Content-Type" => "application/x-www-form-urlencoded" }) unless headers.key?("Content-Type")
140
+ else
141
+ headers
142
+ end
143
+
144
+ headers
145
+ end
146
+ end
147
+
148
+ def methods_as_alias(version_class)
149
+ version_class.define_singleton_method(:build_body) do |options, params, force_build: false|
150
+ version_class.send(:build_params, options, params, force_build: force_build)
151
+ end
152
+ end
153
+
154
+ def methods_as_private(version_class)
155
+ version_class.private_class_method :log_response_params, :request, :client, :request_method_build,
156
+ :set_api_endpoint_by_service, :set_api_endpoint_by_version, :build_client,
157
+ :build_options, :build_params, :build_headers
158
+ end
159
+ end
160
+ end
161
+
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bindup
4
+ VERSION = "0.0.1"
5
+ end
data/lib/bindup.rb ADDED
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "bindup/bindup"
4
+
5
+ # Bindup is customizable API wrapper
6
+ #
7
+ # It is able to wrap API from other services so the Ruby application
8
+ # use those API with out having to implement a new module to deal with
9
+ # every single API or having to create a gem. Bindup will be able to
10
+ # setup multiple services at once so that integrating whole new service
11
+ # is easy as changing the config
12
+ module Bindup
13
+ end
data/sig/bindup.rbs ADDED
@@ -0,0 +1,4 @@
1
+ module Bindup
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bindup
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Banura Randika Perera
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-06-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '7.0'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 7.0.3
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '7.0'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 7.0.3
33
+ - !ruby/object:Gem::Dependency
34
+ name: faraday
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: 2.3.0
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: 2.3.0
47
+ description: Customizable API wrapper
48
+ email:
49
+ - randika.banura@gmail.com
50
+ executables: []
51
+ extensions: []
52
+ extra_rdoc_files: []
53
+ files:
54
+ - ".rspec"
55
+ - ".rubocop.yml"
56
+ - CHANGELOG.md
57
+ - CODE_OF_CONDUCT.md
58
+ - Gemfile
59
+ - Gemfile.lock
60
+ - LICENSE.txt
61
+ - README.md
62
+ - Rakefile
63
+ - bindup.gemspec
64
+ - lib/bindup.rb
65
+ - lib/bindup/bindup.rb
66
+ - lib/bindup/configuration.rb
67
+ - lib/bindup/service_creator.rb
68
+ - lib/bindup/service_methods.rb
69
+ - lib/bindup/version.rb
70
+ - sig/bindup.rbs
71
+ homepage: https://github.com/randikabanura
72
+ licenses:
73
+ - MIT
74
+ metadata:
75
+ homepage_uri: https://github.com/randikabanura
76
+ source_code_uri: https://github.com/randikabanura/bindup
77
+ changelog_uri: https://github.com/randikabanura/bindup/CHANGELOG.md
78
+ post_install_message:
79
+ rdoc_options: []
80
+ require_paths:
81
+ - lib
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: 2.6.0
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ requirements: []
93
+ rubygems_version: 3.2.15
94
+ signing_key:
95
+ specification_version: 4
96
+ summary: Customizable API wrapper library
97
+ test_files: []