act_as_api_client 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.github/workflows/main.yml +49 -0
- data/.gitignore +15 -0
- data/.rspec +4 -0
- data/.rubocop.yml +18 -0
- data/.rubocop_todo.yml +96 -0
- data/CODE_OF_CONDUCT.md +84 -0
- data/Gemfile +14 -0
- data/Gemfile.lock +82 -0
- data/LICENSE.txt +21 -0
- data/README.md +71 -0
- data/Rakefile +12 -0
- data/act_as_api_client.gemspec +32 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/demo.rb +12 -0
- data/lib/act_as_api_client/base_api_methods.rb +29 -0
- data/lib/act_as_api_client/clients/github_client.rb +50 -0
- data/lib/act_as_api_client/clients/http_client.rb +29 -0
- data/lib/act_as_api_client/version.rb +5 -0
- data/lib/act_as_api_client.rb +29 -0
- metadata +80 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 7f1c7c6c3d7211351b1bd796c0f246656d4cf5e860c586d88a52da0c133b8622
|
4
|
+
data.tar.gz: 525403634a6f733f4ef1729b8bbc7dc4d30087029eefb8aecfe025642ed518d1
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: '028bb21fa8d582e88781684576b07878a00bdef6b556de591bd23a3c3fbf43be12a71f673a55d189f49ca45accb94bfbc86ff2d90a31a9b84bb35c354f0ffb59'
|
7
|
+
data.tar.gz: b5769d9b5db7fafb4cf7b4cf2ee9a98278154ad1536ddb83be48634f81085c4ee84de16daa1172e6000bf7602710519012efd9ebf115e46094687e39b813318a
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# This workflow uses actions that are not certified by GitHub.
|
2
|
+
# They are provided by a third-party and are governed by
|
3
|
+
# separate terms of service, privacy policy, and support
|
4
|
+
# documentation.
|
5
|
+
# This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
|
6
|
+
# For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
|
7
|
+
|
8
|
+
name: Ruby
|
9
|
+
|
10
|
+
on:
|
11
|
+
push:
|
12
|
+
branches: [ main ]
|
13
|
+
pull_request:
|
14
|
+
branches: [ main ]
|
15
|
+
|
16
|
+
permissions:
|
17
|
+
contents: read
|
18
|
+
|
19
|
+
jobs:
|
20
|
+
linters:
|
21
|
+
runs-on: ubuntu-latest
|
22
|
+
strategy:
|
23
|
+
matrix:
|
24
|
+
ruby-version: ['3.0']
|
25
|
+
steps:
|
26
|
+
- uses: actions/checkout@v3
|
27
|
+
- name: Set up Ruby
|
28
|
+
uses: ruby/setup-ruby@2b019609e2b0f1ea1a2bc8ca11cb82ab46ada124
|
29
|
+
with:
|
30
|
+
ruby-version: ${{ matrix.ruby-version }}
|
31
|
+
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
32
|
+
- name: Run tests
|
33
|
+
run: bundle exec rubocop
|
34
|
+
test:
|
35
|
+
runs-on: ubuntu-latest
|
36
|
+
strategy:
|
37
|
+
matrix:
|
38
|
+
ruby-version: ['2.6', '2.7', '3.0']
|
39
|
+
steps:
|
40
|
+
- uses: actions/checkout@v3
|
41
|
+
- name: Set up Ruby
|
42
|
+
uses: ruby/setup-ruby@2b019609e2b0f1ea1a2bc8ca11cb82ab46ada124
|
43
|
+
with:
|
44
|
+
ruby-version: ${{ matrix.ruby-version }}
|
45
|
+
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
46
|
+
- name: Copy credentials file for CI
|
47
|
+
run: mv spec/credentials.example.yml spec/credentials.yml
|
48
|
+
- name: Run tests
|
49
|
+
run: bundle exec rspec
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
inherit_from: .rubocop_todo.yml
|
2
|
+
|
3
|
+
require:
|
4
|
+
- rubocop-rspec
|
5
|
+
|
6
|
+
Style/StringLiterals:
|
7
|
+
Enabled: true
|
8
|
+
EnforcedStyle: double_quotes
|
9
|
+
|
10
|
+
Style/StringLiteralsInInterpolation:
|
11
|
+
Enabled: true
|
12
|
+
EnforcedStyle: double_quotes
|
13
|
+
|
14
|
+
Layout/LineLength:
|
15
|
+
Max: 120
|
16
|
+
|
17
|
+
AllCops:
|
18
|
+
NewCops: enable
|
data/.rubocop_todo.yml
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
# This configuration was generated by
|
2
|
+
# `rubocop --auto-gen-config --auto-gen-only-exclude`
|
3
|
+
# on 2022-07-04 14:26:01 UTC using RuboCop version 0.93.1.
|
4
|
+
# The point is for the user to remove these configuration records
|
5
|
+
# one by one as the offenses are removed from the code base.
|
6
|
+
# Note that changes in the inspected code, or installation of new
|
7
|
+
# versions of RuboCop, may require this file to be generated again.
|
8
|
+
|
9
|
+
# Offense count: 1
|
10
|
+
# Configuration parameters: Include.
|
11
|
+
# Include: **/*.gemspec
|
12
|
+
Gemspec/RequiredRubyVersion:
|
13
|
+
Exclude:
|
14
|
+
- 'act_as_api_client.gemspec'
|
15
|
+
|
16
|
+
# Offense count: 7
|
17
|
+
Lint/ConstantDefinitionInBlock:
|
18
|
+
Exclude:
|
19
|
+
- 'spec/act_as_api_client_spec.rb'
|
20
|
+
- 'spec/clients/github_client_spec.rb'
|
21
|
+
|
22
|
+
# Offense count: 1
|
23
|
+
# Cop supports --auto-correct.
|
24
|
+
# Configuration parameters: AllowUnusedKeywordArguments, IgnoreEmptyMethods, IgnoreNotImplementedMethods.
|
25
|
+
Lint/UnusedMethodArgument:
|
26
|
+
Exclude:
|
27
|
+
- 'lib/act_as_api_client/clients/github_client.rb'
|
28
|
+
|
29
|
+
# Offense count: 1
|
30
|
+
# Configuration parameters: CountComments, Max, CountAsOne, ExcludedMethods.
|
31
|
+
# ExcludedMethods: refine
|
32
|
+
Metrics/BlockLength:
|
33
|
+
Exclude:
|
34
|
+
- '**/*.gemspec'
|
35
|
+
- 'spec/act_as_api_client_spec.rb'
|
36
|
+
|
37
|
+
# Offense count: 1
|
38
|
+
# Configuration parameters: CountComments, Max, CountAsOne, ExcludedMethods.
|
39
|
+
Metrics/MethodLength:
|
40
|
+
Exclude:
|
41
|
+
- 'lib/act_as_api_client/clients/github_client.rb'
|
42
|
+
|
43
|
+
# Offense count: 2
|
44
|
+
Naming/AccessorMethodName:
|
45
|
+
Exclude:
|
46
|
+
- 'lib/act_as_api_client.rb'
|
47
|
+
|
48
|
+
# Offense count: 1
|
49
|
+
# Configuration parameters: Prefixes.
|
50
|
+
# Prefixes: when, with, without
|
51
|
+
RSpec/ContextWording:
|
52
|
+
Exclude:
|
53
|
+
- 'spec/act_as_api_client_spec.rb'
|
54
|
+
|
55
|
+
# Offense count: 1
|
56
|
+
# Configuration parameters: Max.
|
57
|
+
RSpec/ExampleLength:
|
58
|
+
Exclude:
|
59
|
+
- 'spec/act_as_api_client_spec.rb'
|
60
|
+
|
61
|
+
# Offense count: 1
|
62
|
+
# Configuration parameters: CustomTransform, IgnoreMethods, SpecSuffixOnly.
|
63
|
+
RSpec/FilePath:
|
64
|
+
Exclude:
|
65
|
+
- 'spec/clients/github_client_spec.rb'
|
66
|
+
|
67
|
+
# Offense count: 7
|
68
|
+
RSpec/LeakyConstantDeclaration:
|
69
|
+
Exclude:
|
70
|
+
- 'spec/act_as_api_client_spec.rb'
|
71
|
+
- 'spec/clients/github_client_spec.rb'
|
72
|
+
|
73
|
+
# Offense count: 5
|
74
|
+
Style/Documentation:
|
75
|
+
Exclude:
|
76
|
+
- 'spec/**/*'
|
77
|
+
- 'test/**/*'
|
78
|
+
- 'demo.rb'
|
79
|
+
- 'lib/act_as_api_client.rb'
|
80
|
+
- 'lib/act_as_api_client/base_api_methods.rb'
|
81
|
+
- 'lib/act_as_api_client/clients/github_client.rb'
|
82
|
+
- 'lib/act_as_api_client/clients/http_client.rb'
|
83
|
+
|
84
|
+
# Offense count: 1
|
85
|
+
# Configuration parameters: MinBodyLength.
|
86
|
+
Style/GuardClause:
|
87
|
+
Exclude:
|
88
|
+
- 'lib/act_as_api_client.rb'
|
89
|
+
|
90
|
+
# Offense count: 1
|
91
|
+
# Cop supports --auto-correct.
|
92
|
+
# Configuration parameters: AutoCorrect, Max, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
|
93
|
+
# URISchemes: http, https
|
94
|
+
Layout/LineLength:
|
95
|
+
Exclude:
|
96
|
+
- 'act_as_api_client.gemspec'
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -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 max@apply4.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,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
# Specify your gem's dependencies in act_as_api_client.gemspec
|
6
|
+
gemspec
|
7
|
+
|
8
|
+
gem "byebug", "~> 11.1"
|
9
|
+
gem "rake", "~> 13.0"
|
10
|
+
gem "rspec", "~> 3.0"
|
11
|
+
gem "rubocop", "~> 0.80"
|
12
|
+
gem "rubocop-rspec", require: false
|
13
|
+
gem "vcr", "~> 6.1"
|
14
|
+
gem "webmock", "~> 3.14"
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
act_as_api_client (0.1.0)
|
5
|
+
httparty (~> 0.20)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
addressable (2.8.0)
|
11
|
+
public_suffix (>= 2.0.2, < 5.0)
|
12
|
+
ast (2.4.2)
|
13
|
+
byebug (11.1.3)
|
14
|
+
crack (0.4.5)
|
15
|
+
rexml
|
16
|
+
diff-lcs (1.5.0)
|
17
|
+
hashdiff (1.0.1)
|
18
|
+
httparty (0.20.0)
|
19
|
+
mime-types (~> 3.0)
|
20
|
+
multi_xml (>= 0.5.2)
|
21
|
+
mime-types (3.4.1)
|
22
|
+
mime-types-data (~> 3.2015)
|
23
|
+
mime-types-data (3.2022.0105)
|
24
|
+
multi_xml (0.6.0)
|
25
|
+
parallel (1.22.1)
|
26
|
+
parser (3.1.2.0)
|
27
|
+
ast (~> 2.4.1)
|
28
|
+
public_suffix (4.0.7)
|
29
|
+
rainbow (3.1.1)
|
30
|
+
rake (13.0.6)
|
31
|
+
regexp_parser (2.5.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 (0.93.1)
|
47
|
+
parallel (~> 1.10)
|
48
|
+
parser (>= 2.7.1.5)
|
49
|
+
rainbow (>= 2.2.2, < 4.0)
|
50
|
+
regexp_parser (>= 1.8)
|
51
|
+
rexml
|
52
|
+
rubocop-ast (>= 0.6.0)
|
53
|
+
ruby-progressbar (~> 1.7)
|
54
|
+
unicode-display_width (>= 1.4.0, < 2.0)
|
55
|
+
rubocop-ast (1.18.0)
|
56
|
+
parser (>= 3.1.1.0)
|
57
|
+
rubocop-rspec (1.44.1)
|
58
|
+
rubocop (~> 0.87)
|
59
|
+
rubocop-ast (>= 0.7.1)
|
60
|
+
ruby-progressbar (1.11.0)
|
61
|
+
unicode-display_width (1.8.0)
|
62
|
+
vcr (6.1.0)
|
63
|
+
webmock (3.14.0)
|
64
|
+
addressable (>= 2.8.0)
|
65
|
+
crack (>= 0.3.2)
|
66
|
+
hashdiff (>= 0.4.0, < 2.0.0)
|
67
|
+
|
68
|
+
PLATFORMS
|
69
|
+
ruby
|
70
|
+
|
71
|
+
DEPENDENCIES
|
72
|
+
act_as_api_client!
|
73
|
+
byebug (~> 11.1)
|
74
|
+
rake (~> 13.0)
|
75
|
+
rspec (~> 3.0)
|
76
|
+
rubocop (~> 0.80)
|
77
|
+
rubocop-rspec
|
78
|
+
vcr (~> 6.1)
|
79
|
+
webmock (~> 3.14)
|
80
|
+
|
81
|
+
BUNDLED WITH
|
82
|
+
2.2.3
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2022 Max Rukomoynikov
|
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,71 @@
|
|
1
|
+
# act_as_api_client
|
2
|
+
|
3
|
+
How to create api clients for your application? What is a better way to encapsualte interactions with third APIs? My answer is `act_as_api_client`.
|
4
|
+
|
5
|
+
Let's assume you have a typical Rails or any ruby application and want to play around with an API, Github for example. See the [Usage](#usage) section to find how to use existing preconfigured API's and encapsulate all logic inside `APIClient` classes.
|
6
|
+
|
7
|
+
_At the moment i experiment in order to make api clients behavior very similiar to `ActiveRecord` models, so out of the box most of the clients support these methods: find, where, delete, update, find_by, create, update_
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
gem 'act_as_api_client'
|
15
|
+
```
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
|
19
|
+
$ bundle install
|
20
|
+
|
21
|
+
Or install it yourself as:
|
22
|
+
|
23
|
+
$ gem install act_as_api_client
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
**1. Folder for clients:**
|
28
|
+
Create a folder for examples api_clients inside your `lib` directory.
|
29
|
+
|
30
|
+
**2. Create API client class:**
|
31
|
+
For example you want to fetch and update Github repositoties, then you class may have a form like this:
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
class GithubClient < ApiClient
|
35
|
+
act_as_api_client for: :github
|
36
|
+
end
|
37
|
+
```
|
38
|
+
|
39
|
+
In case you want to provide and use auth token for Github:
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
class GithubClient < ApiClient
|
43
|
+
act_as_api_client for: :github,
|
44
|
+
with: {
|
45
|
+
token: <your_token>
|
46
|
+
}
|
47
|
+
end
|
48
|
+
```
|
49
|
+
|
50
|
+
btw, all values from `with` hash will be availabe in tour clients as instance variable `@options`
|
51
|
+
|
52
|
+
## List of supported api clients
|
53
|
+
1. [Github Repositories](https://docs.github.com/en/rest/repos/repos)
|
54
|
+
|
55
|
+
## Development
|
56
|
+
|
57
|
+
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.
|
58
|
+
|
59
|
+
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).
|
60
|
+
|
61
|
+
## Contributing
|
62
|
+
|
63
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/act_as_api_client. 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]/act_as_api_client/blob/master/CODE_OF_CONDUCT.md).
|
64
|
+
|
65
|
+
## License
|
66
|
+
|
67
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
68
|
+
|
69
|
+
## Code of Conduct
|
70
|
+
|
71
|
+
Everyone interacting in the ActAsApiClient project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/act_as_api_client/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/act_as_api_client/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "act_as_api_client"
|
7
|
+
spec.version = ActAsApiClient::VERSION
|
8
|
+
spec.authors = ["Max Rukomoynikov"]
|
9
|
+
spec.email = ["rukomoynikov@gmail.com"]
|
10
|
+
|
11
|
+
spec.summary = "Collection of predefined API clients"
|
12
|
+
spec.description = "Helps you to build reliable API clients in a minute. Just add act_as_api_client to your classes."
|
13
|
+
spec.homepage = "https://rubygems.org/gems/act_as_api_client"
|
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"] = "https://github.com/Rukomoynikov/act_as_api_client"
|
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.require_paths = ["lib"]
|
26
|
+
|
27
|
+
# Uncomment to register a new dependency of your gem
|
28
|
+
spec.add_dependency "httparty", "~> 0.20"
|
29
|
+
|
30
|
+
# For more information and examples about making a new gem, checkout our
|
31
|
+
# guide at: https://bundler.io/guides/creating_gem.html
|
32
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require "bundler/setup"
|
5
|
+
require "act_as_api_client"
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require "irb"
|
15
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/demo.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/act_as_api_client"
|
4
|
+
|
5
|
+
class GithubClient < ApiClient
|
6
|
+
act_as_api_client for: :github
|
7
|
+
end
|
8
|
+
|
9
|
+
p GithubClient.ancestors
|
10
|
+
p GithubClient.new.method(:find).source_location
|
11
|
+
|
12
|
+
GithubClient.new.find
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ActAsApiClient
|
4
|
+
module BaseApiMethods
|
5
|
+
def find
|
6
|
+
raise StandardError, "Should be defined in inherited class"
|
7
|
+
end
|
8
|
+
|
9
|
+
def where
|
10
|
+
raise StandardError, "Should be defined in inherited class"
|
11
|
+
end
|
12
|
+
|
13
|
+
def find_by
|
14
|
+
raise StandardError, "Should be defined in inherited class"
|
15
|
+
end
|
16
|
+
|
17
|
+
def delete
|
18
|
+
raise StandardError, "Should be defined in inherited class"
|
19
|
+
end
|
20
|
+
|
21
|
+
def create
|
22
|
+
raise StandardError, "Should be defined in inherited class"
|
23
|
+
end
|
24
|
+
|
25
|
+
def update
|
26
|
+
raise StandardError, "Should be defined in inherited class"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "http_client"
|
4
|
+
require "httparty"
|
5
|
+
|
6
|
+
module ActAsApiClient
|
7
|
+
module Clients
|
8
|
+
module GithubClient
|
9
|
+
include HttpClient
|
10
|
+
def find(repository_name)
|
11
|
+
unless repository_name.match?(%r{[a-zA-Z]/[a-zA-Z]})
|
12
|
+
raise StandardError, "repository_name parameter is not valid"
|
13
|
+
end
|
14
|
+
|
15
|
+
HTTParty
|
16
|
+
.get(
|
17
|
+
"https://api.github.com/repos/#{repository_name}",
|
18
|
+
headers: { "Content-Type" => "application/json",
|
19
|
+
"Accept" => "application/vnd.github.v3+json",
|
20
|
+
"Authorization" => (options[:token] ? "token #{options[:token]}" : nil) }
|
21
|
+
)
|
22
|
+
.parsed_response
|
23
|
+
end
|
24
|
+
|
25
|
+
def where
|
26
|
+
"where"
|
27
|
+
end
|
28
|
+
|
29
|
+
def find_by(options = {})
|
30
|
+
# by_organization https://docs.github.com/en/rest/repos/repos#list-organization-repositories
|
31
|
+
# by_user https://docs.github.com/en/rest/repos/repos#list-repositories-for-a-user
|
32
|
+
# by_authenticated_user https://docs.github.com/en/rest/repos/repos#list-repositories-for-the-authenticated-user
|
33
|
+
"find_by"
|
34
|
+
end
|
35
|
+
|
36
|
+
def delete
|
37
|
+
# Call only on queried before repository and repository is not 404/400 and has right to delete (write)
|
38
|
+
"delete"
|
39
|
+
end
|
40
|
+
|
41
|
+
def create
|
42
|
+
"create"
|
43
|
+
end
|
44
|
+
|
45
|
+
def update
|
46
|
+
"update"
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "httparty"
|
4
|
+
|
5
|
+
module ActAsApiClient
|
6
|
+
module Clients
|
7
|
+
module HttpClient
|
8
|
+
def get(url, options = {})
|
9
|
+
HTTParty.get(url, options).parsed_response
|
10
|
+
end
|
11
|
+
|
12
|
+
def post
|
13
|
+
HTTParty.post
|
14
|
+
end
|
15
|
+
|
16
|
+
def put
|
17
|
+
HTTParty.put
|
18
|
+
end
|
19
|
+
|
20
|
+
def update
|
21
|
+
HTTParty.update
|
22
|
+
end
|
23
|
+
|
24
|
+
def delete
|
25
|
+
HTTParty.delete
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "act_as_api_client/version"
|
4
|
+
require_relative "act_as_api_client/base_api_methods"
|
5
|
+
|
6
|
+
class ApiClient
|
7
|
+
include ActAsApiClient::BaseApiMethods
|
8
|
+
|
9
|
+
class << self
|
10
|
+
def act_as_api_client(**args)
|
11
|
+
set_general_client(client_for: args.fetch(:for, nil))
|
12
|
+
set_options(options: args.fetch(:with, {}))
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def set_general_client(client_for:)
|
18
|
+
unless client_for.nil?
|
19
|
+
require(File.expand_path("act_as_api_client/clients/#{client_for}_client",
|
20
|
+
File.dirname(__FILE__)))
|
21
|
+
include const_get("ActAsApiClient::Clients::#{client_for.capitalize}Client")
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def set_options(options:)
|
26
|
+
define_method("options") { options }
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
metadata
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: act_as_api_client
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Max Rukomoynikov
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2022-07-04 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: httparty
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.20'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.20'
|
27
|
+
description: Helps you to build reliable API clients in a minute. Just add act_as_api_client
|
28
|
+
to your classes.
|
29
|
+
email:
|
30
|
+
- rukomoynikov@gmail.com
|
31
|
+
executables: []
|
32
|
+
extensions: []
|
33
|
+
extra_rdoc_files: []
|
34
|
+
files:
|
35
|
+
- ".github/workflows/main.yml"
|
36
|
+
- ".gitignore"
|
37
|
+
- ".rspec"
|
38
|
+
- ".rubocop.yml"
|
39
|
+
- ".rubocop_todo.yml"
|
40
|
+
- CODE_OF_CONDUCT.md
|
41
|
+
- Gemfile
|
42
|
+
- Gemfile.lock
|
43
|
+
- LICENSE.txt
|
44
|
+
- README.md
|
45
|
+
- Rakefile
|
46
|
+
- act_as_api_client.gemspec
|
47
|
+
- bin/console
|
48
|
+
- bin/setup
|
49
|
+
- demo.rb
|
50
|
+
- lib/act_as_api_client.rb
|
51
|
+
- lib/act_as_api_client/base_api_methods.rb
|
52
|
+
- lib/act_as_api_client/clients/github_client.rb
|
53
|
+
- lib/act_as_api_client/clients/http_client.rb
|
54
|
+
- lib/act_as_api_client/version.rb
|
55
|
+
homepage: https://rubygems.org/gems/act_as_api_client
|
56
|
+
licenses:
|
57
|
+
- MIT
|
58
|
+
metadata:
|
59
|
+
homepage_uri: https://rubygems.org/gems/act_as_api_client
|
60
|
+
source_code_uri: https://github.com/Rukomoynikov/act_as_api_client
|
61
|
+
post_install_message:
|
62
|
+
rdoc_options: []
|
63
|
+
require_paths:
|
64
|
+
- lib
|
65
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 2.3.0
|
70
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
requirements: []
|
76
|
+
rubygems_version: 3.2.3
|
77
|
+
signing_key:
|
78
|
+
specification_version: 4
|
79
|
+
summary: Collection of predefined API clients
|
80
|
+
test_files: []
|