api_wrapper 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +7 -0
  2. data/.rubocop.yml +7 -0
  3. data/CHANGELOG.md +18 -0
  4. data/CODE_OF_CONDUCT.md +84 -0
  5. data/Gemfile +22 -0
  6. data/LICENSE.txt +21 -0
  7. data/README.md +153 -0
  8. data/Rakefile +31 -0
  9. data/api_wrapper.gemspec +34 -0
  10. data/doc/ApiWrapper/ApiManager.html +807 -0
  11. data/doc/ApiWrapper/Cache/CachePolicy.html +907 -0
  12. data/doc/ApiWrapper/Cache/CacheStore.html +674 -0
  13. data/doc/ApiWrapper/Cache.html +117 -0
  14. data/doc/ApiWrapper/Configuration.html +366 -0
  15. data/doc/ApiWrapper/HttpClient/BaseClient.html +349 -0
  16. data/doc/ApiWrapper/HttpClient/FaradayClient.html +299 -0
  17. data/doc/ApiWrapper/HttpClient.html +117 -0
  18. data/doc/ApiWrapper.html +543 -0
  19. data/doc/_index.html +195 -0
  20. data/doc/class_list.html +54 -0
  21. data/doc/css/common.css +1 -0
  22. data/doc/css/full_list.css +58 -0
  23. data/doc/css/style.css +503 -0
  24. data/doc/file.README.html +248 -0
  25. data/doc/file_list.html +59 -0
  26. data/doc/frames.html +22 -0
  27. data/doc/index.html +248 -0
  28. data/doc/js/app.js +344 -0
  29. data/doc/js/full_list.js +242 -0
  30. data/doc/js/jquery.js +4 -0
  31. data/doc/method_list.html +286 -0
  32. data/doc/top-level-namespace.html +110 -0
  33. data/lib/api_wrapper/api_manager.rb +86 -0
  34. data/lib/api_wrapper/cache/README.md +78 -0
  35. data/lib/api_wrapper/cache/cache_policy.rb +115 -0
  36. data/lib/api_wrapper/cache/cache_store.rb +84 -0
  37. data/lib/api_wrapper/cache/redis_cache_store.rb +3 -0
  38. data/lib/api_wrapper/http_client/base_client.rb +26 -0
  39. data/lib/api_wrapper/http_client/faraday_client.rb +81 -0
  40. data/lib/api_wrapper/version.rb +5 -0
  41. data/lib/api_wrapper.rb +83 -0
  42. metadata +121 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: a1fb3f8095d43a989fe1af85ad5929fc4831d5f8aa04d4fa0218318857510d0d
4
+ data.tar.gz: 9367ad54c68420f3a679d36329ce47fda8adfa72a903913834ed548762bdd21b
5
+ SHA512:
6
+ metadata.gz: c8b4e19a62d31217c911541e4bec026120934ca914fe4240361d1dec27eada9f8adfd69fd8a5185a1455ff5d16a3c5d65c927d8f021bee857aa5587cea906244
7
+ data.tar.gz: 998d488e50643a75d6b9222c02add188dc380eef709096963e1fdb221b124fba0944b63c0aadb8ba244099e0c539e8c1e4c9c75dba836df5aebd3abd2b038ecd
data/.rubocop.yml ADDED
@@ -0,0 +1,7 @@
1
+ Metrics/BlockLength:
2
+ Exclude:
3
+ - 'Rakefile'
4
+ - '**/*.rake'
5
+ - 'spec/**/*.rb'
6
+ AllCops:
7
+ SuggestExtensions: false
data/CHANGELOG.md ADDED
@@ -0,0 +1,18 @@
1
+ # Changelog
2
+
3
+ ## [0.1.6] - 2024-09-16
4
+ ### CI
5
+ - Configure GitHub Actions to run tests on PR creation by @ahasunos in [#1](https://github.com/ahasunos/api_wrapper/pull/1)
6
+ - Fix version bumper failure due to missing semantic gem by @ahasunos in [#2](https://github.com/ahasunos/api_wrapper/pull/2)
7
+
8
+ ### Fixes
9
+ - Rename old commit files from nse_gem project by @ahasunos in [#3](https://github.com/ahasunos/api_wrapper/pull/3)
10
+
11
+ ### Features
12
+ - Implement caching mechanism in the library by @ahasunos in [#5](https://github.com/ahasunos/api_wrapper/pull/5)
13
+ - Implement client to handle HTTP requests by @ahasunos in [#6](https://github.com/ahasunos/api_wrapper/pull/6)
14
+ - Implement API manager with API configuration & caching support by @ahasunos in [#8](https://github.com/ahasunos/api_wrapper/pull/8)
15
+ - Implement ApiWrapper interface for end users by @ahasunos in [#9](https://github.com/ahasunos/api_wrapper/pull/9)
16
+
17
+ ### Documentation
18
+ - Update documentation for ApiWrapper by @ahasunos in [#11](https://github.com/ahasunos/api_wrapper/pull/11)
@@ -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 ahasunos@gmail.com. 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,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in api_wrapper.gemspec
6
+ gemspec
7
+
8
+ group :development do
9
+ gem 'bundler-audit', require: false
10
+ gem 'byebug'
11
+ gem 'rake', '~> 13.0'
12
+ gem 'rspec', '~> 3.0'
13
+ gem 'rubocop', '~> 1.21'
14
+ gem 'semantic'
15
+ gem 'yard', '~> 0.9.37'
16
+ end
17
+
18
+ group :test do
19
+ gem 'simplecov'
20
+ gem 'timecop'
21
+ gem 'webmock', '~> 3.0'
22
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2024 Sonu Saha
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,153 @@
1
+ `ApiWrapper` is a Ruby gem that offers an easy and flexible way to handle API interactions.
2
+
3
+ ## Table of Contents
4
+
5
+ - [Installation](#installation)
6
+ - [Usage](#usage)
7
+ - [Basic Usage](#basic-usage)
8
+ - [Custom Configuration](#custom-configuration)
9
+ - [Resetting the API Manager](#resetting-the-api-manager)
10
+ - [Configuration](#configuration)
11
+ - [API Configuration File](#api-configuration-file)
12
+ - [Key Methods](#key-methods)
13
+ - [Development](#development)
14
+ - [Running Tests](#running-tests)
15
+ - [Code Style and Linting](#code-style-and-linting)
16
+ - [Contributing](#contributing)
17
+ - [License](#license)
18
+ - [Code of Conduct](#code-of-conduct)
19
+
20
+ ## Installation
21
+
22
+ Add this to your Gemfile:
23
+
24
+
25
+ ```ruby
26
+ gem 'api_wrapper'
27
+ ```
28
+
29
+ Then run
30
+
31
+ ```ruby
32
+ bundle install
33
+ ```
34
+
35
+ ## Usage
36
+
37
+ ### Basic Usage
38
+ By default, ApiWrapper looks for an API configuration file at `config/api_endpoints.yml` (see [API Configuration File](#api-configuration-file)) in your root directory of your application and uses in-memory caching. You can fetch data from an API endpoint like this:
39
+
40
+ ```ruby
41
+ require 'api_wrapper'
42
+
43
+ # Fetch data from an API endpoint using the default settings
44
+ response = ApiWrapper.fetch_data('endpoint_key')
45
+ puts response.body
46
+ ```
47
+
48
+ ### Custom Configuration
49
+ You can customize the API configuration path and cache store by configuring ApiWrapper:
50
+
51
+ ```ruby
52
+ require 'api_wrapper'
53
+
54
+ # Configure ApiWrapper with custom settings
55
+ ApiWrapper.configure do |config|
56
+ config.api_configuration_path = 'custom/path/to/api_configuration.yml'
57
+ config.cache_store = CustomCacheStore.new # TODO: Update details on CustomCacheStore later
58
+ end
59
+
60
+ # Fetch data with the custom configuration
61
+ response = ApiWrapper.fetch_data('endpoint_key')
62
+ puts response.body
63
+ ```
64
+
65
+ ### Resetting the API Manager
66
+ If you change the configuration and want to reset the API manager, call:
67
+ ```ruby
68
+ ApiWrapper.reset_api_manager!
69
+ ```
70
+ This will create a new instance of ApiManager with the updated settings.
71
+
72
+ ## Configuration
73
+ You can adjust two main settings:
74
+
75
+ 1. **API Configuration Path**: This is the path to the YAML file that defines your API endpoints. By default, it’s set to config/api_endpoints.yml. You can also set it through the environment variable ENV['API_CONFIGURATION_PATH'].
76
+
77
+ 2. **Cache Store**: This is where API responses are stored. By default, ApiWrapper uses an in-memory cache. You can customize this to use a different cache store, such as Redis. You can also set the cache type through ENV['CACHE_STORE_TYPE'].
78
+
79
+ ### API Configuration File
80
+ Your configuration file (api_endpoints.yml) defines the base URL for the API and the available endpoints. Here’s an example:
81
+
82
+ ```yaml
83
+ base_url: https://api.example.com/
84
+ apis:
85
+ endpoint1:
86
+ path: 'path/to/endpoint1'
87
+ description: 'Endpoint 1 description'
88
+ no_cache: true
89
+ endpoint2:
90
+ path: 'path/to/endpoint2'
91
+ description: 'Endpoint 2 description'
92
+ ttl: 600
93
+ ```
94
+
95
+ - base_url: The base URL for all API requests.
96
+ - apis: A list of API endpoints.
97
+ - path: The path to the API endpoint.
98
+ - description: (Optional) The description about the endpoint
99
+ - ttl: (Optional) The time (in seconds) that data should be cached.
100
+ - no_cache: (Optional) Whether to bypass caching for this endpoint.
101
+
102
+ ## Key Methods
103
+ - `ApiWrapper.fetch_data(endpoint_key, force_refresh: false)`: Fetches data from the specified API endpoint.
104
+ - `ApiWrapper.configure { |config| ... }`: Allows you to configure the gem with custom settings.
105
+ - `ApiWrapper.reset_api_manager!`: Resets the ApiManager instance, which will use any new settings.
106
+
107
+ ## Development
108
+
109
+ To get started with contributing to **ApiWrapper**, follow these steps:
110
+
111
+ 1. **Clone the repository**:
112
+
113
+ First, clone the repository to your local machine and navigate to the project directory:
114
+
115
+ ```bash
116
+ git clone https://github.com/ahasunos/api_wrapper.git
117
+ cd api_wrapper
118
+
119
+ 2. **Install dependencies**:
120
+
121
+ After navigating to the project directory, install the required gems using Bundler:
122
+
123
+ ```bash
124
+ bundle install
125
+ ```
126
+
127
+ ### Running Tests
128
+ The project uses RSpec for testing. Before submitting any changes, make sure to run the test suite to ensure that everything works as expected:
129
+
130
+ ```bash
131
+ bundle exec rspec
132
+ ```
133
+
134
+ ### Code Style and Linting
135
+ To maintain consistent code quality and style, the project uses RuboCop for linting. Before submitting a pull request, ensure that your code adheres to the project's style guidelines by running RuboCop:
136
+
137
+ ```bash
138
+ bundle exec rubocop
139
+ ```
140
+
141
+ If RuboCop identifies any issues, it will provide suggestions for how to fix them.
142
+
143
+ ## Contributing
144
+
145
+ Bug reports and pull requests are welcome on GitHub at https://github.com/ahasunos/api_wrapper. For major changes, please open an issue first to discuss what you would like to change.
146
+
147
+ ## License
148
+
149
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
150
+
151
+ ## Code of Conduct
152
+
153
+ Everyone interacting in the NseData project's codebases, issue trackers, chat rooms, and mailing lists is expected to follow the [code of conduct](https://github.com/ahasunos/api_wrapper/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Load Bundler's gem tasks (e.g., `rake build`, `rake install`, etc.)
4
+ require 'bundler/gem_tasks'
5
+
6
+ # Load RSpec's rake task to run the test suite using `rake spec`
7
+ require 'rspec/core/rake_task'
8
+
9
+ # Define the `spec` task to run RSpec tests
10
+ RSpec::Core::RakeTask.new(:spec)
11
+
12
+ # Load RuboCop's rake task to check for style guide violations using `rake rubocop`
13
+ require 'rubocop/rake_task'
14
+
15
+ # Define the `rubocop` task to run RuboCop linter
16
+ RuboCop::RakeTask.new
17
+
18
+ # Load Yard's rake task for generating documentation using `rake yard`
19
+ require 'yard'
20
+
21
+ # Define the `yard` task to generate documentation
22
+ YARD::Rake::YardocTask.new
23
+
24
+ # By default, run both the `spec` (tests) and `rubocop` (linter) tasks
25
+ task default: %i[spec rubocop]
26
+
27
+ # Usage:
28
+ # 1. `rake spec` - Runs the RSpec tests
29
+ # 2. `rake rubocop` - Runs RuboCop linter for code quality checks
30
+ # 3. `rake yard` - Generates Yard documentation (output in the `doc/` folder)
31
+ # 4. `rake` - Runs both the tests and RuboCop checks (default task)
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/api_wrapper/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'api_wrapper'
7
+ spec.version = ApiWrapper::VERSION
8
+ spec.authors = ['Sonu Saha']
9
+ spec.email = ['ahasunos@gmail.com']
10
+
11
+ spec.summary = 'A Ruby gem to simplify API interactions'
12
+ spec.description = 'ApiWrapper provides an easy-to-use interface for interacting with APIs in a configurable way'
13
+ spec.homepage = 'https://github.com/ahasunos/api_wrapper'
14
+ spec.license = 'MIT'
15
+ spec.required_ruby_version = '>= 3.1.0'
16
+
17
+ spec.metadata['homepage_uri'] = spec.homepage
18
+ spec.metadata['source_code_uri'] = 'https://github.com/ahasunos/api_wrapper'
19
+ spec.metadata['changelog_uri'] = 'https://github.com/ahasunos/api_wrapper'
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
+ (File.expand_path(f) == __FILE__) || f.start_with?(*%w[bin/ test/ spec/ features/ .git .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
+ spec.add_dependency 'faraday', '~> 2.11'
33
+ spec.add_dependency 'faraday-http-cache', '~> 2.5', '>= 2.5.1'
34
+ end