act_as_api_client 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -1
- data/.rubocop.yml +5 -1
- data/.rubocop_todo.yml +27 -47
- data/Gemfile.lock +2 -10
- data/README.md +20 -16
- data/act_as_api_client.gemspec +8 -5
- data/lib/act_as_api_client/clients/authorize_net_notifications_client.rb +30 -0
- data/lib/act_as_api_client/clients/authorize_net_webhooks_client.rb +42 -0
- data/lib/act_as_api_client/clients/github_client.rb +69 -25
- data/lib/act_as_api_client/clients/http_client.rb +31 -6
- data/lib/act_as_api_client/version.rb +1 -1
- data/lib/act_as_api_client.rb +18 -5
- metadata +10 -20
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 585bfe652e889c7eaebcd2dfefd0a0c295ae87a390f9522de24fc2126e9011b3
|
4
|
+
data.tar.gz: 5d61e33b3f9702b1bbcc2bac97913278dcbcfc6e7db780e0ea4b1a1efdfb14cb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e2cc7b10a33b1d6955b6aad98709aa58ddba78e38e7804ab6f8b4b8be49ce4ac4b93077cdfa0a9f81e6ea5501784ce02d0ff278228affb4a33a23d71ed52adbe
|
7
|
+
data.tar.gz: c3926de463c5fef33ce98c7158165cffe8fb19d5eef4a94b72fc14fbc51b9a0966134845d899a23310e26b786326a1fe9ee1f058390f7c19809efefa43f7b822
|
data/.gitignore
CHANGED
data/.rubocop.yml
CHANGED
data/.rubocop_todo.yml
CHANGED
@@ -1,96 +1,76 @@
|
|
1
1
|
# This configuration was generated by
|
2
2
|
# `rubocop --auto-gen-config --auto-gen-only-exclude`
|
3
|
-
# on 2022-07-
|
3
|
+
# on 2022-07-28 12:30:04 UTC using RuboCop version 0.93.1.
|
4
4
|
# The point is for the user to remove these configuration records
|
5
5
|
# one by one as the offenses are removed from the code base.
|
6
6
|
# Note that changes in the inspected code, or installation of new
|
7
7
|
# versions of RuboCop, may require this file to be generated again.
|
8
8
|
|
9
9
|
# Offense count: 1
|
10
|
-
# Configuration parameters:
|
11
|
-
|
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:
|
10
|
+
# Configuration parameters: IgnoredMethods, Max.
|
11
|
+
Metrics/AbcSize:
|
26
12
|
Exclude:
|
27
13
|
- 'lib/act_as_api_client/clients/github_client.rb'
|
28
14
|
|
29
|
-
# Offense count:
|
15
|
+
# Offense count: 5
|
30
16
|
# Configuration parameters: CountComments, Max, CountAsOne, ExcludedMethods.
|
31
17
|
# ExcludedMethods: refine
|
32
18
|
Metrics/BlockLength:
|
33
19
|
Exclude:
|
34
20
|
- '**/*.gemspec'
|
35
|
-
- 'spec/
|
21
|
+
- 'spec/act_as_api_client/clients/authorize_net/authorize_net_notifications_client_spec.rb'
|
22
|
+
- 'spec/act_as_api_client/clients/github_client/find_by_spec.rb'
|
23
|
+
- 'spec/act_as_api_client/clients/github_client/find_spec.rb'
|
24
|
+
- 'spec/act_as_api_client/clients/github_client/where_spec.rb'
|
36
25
|
|
37
26
|
# Offense count: 1
|
27
|
+
# Configuration parameters: IgnoredMethods, Max.
|
28
|
+
Metrics/CyclomaticComplexity:
|
29
|
+
Exclude:
|
30
|
+
- 'lib/act_as_api_client/clients/github_client.rb'
|
31
|
+
|
32
|
+
# Offense count: 2
|
38
33
|
# Configuration parameters: CountComments, Max, CountAsOne, ExcludedMethods.
|
39
34
|
Metrics/MethodLength:
|
40
35
|
Exclude:
|
41
36
|
- 'lib/act_as_api_client/clients/github_client.rb'
|
37
|
+
- 'lib/act_as_api_client/clients/http_client.rb'
|
42
38
|
|
43
39
|
# Offense count: 2
|
44
40
|
Naming/AccessorMethodName:
|
45
41
|
Exclude:
|
46
42
|
- 'lib/act_as_api_client.rb'
|
47
43
|
|
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
44
|
# Offense count: 1
|
56
45
|
# Configuration parameters: Max.
|
57
46
|
RSpec/ExampleLength:
|
58
47
|
Exclude:
|
59
|
-
- 'spec/
|
48
|
+
- 'spec/act_as_api_client/clients/http_client_spec.rb'
|
60
49
|
|
61
|
-
# Offense count:
|
50
|
+
# Offense count: 2
|
62
51
|
# Configuration parameters: CustomTransform, IgnoreMethods, SpecSuffixOnly.
|
63
52
|
RSpec/FilePath:
|
64
53
|
Exclude:
|
65
|
-
- 'spec/clients/
|
54
|
+
- 'spec/act_as_api_client/clients/authorize_net/authorize_net_notifications_client_spec.rb'
|
55
|
+
- 'spec/act_as_api_client/clients/authorize_net/authorize_net_webhooks_client_spec.rb'
|
66
56
|
|
67
|
-
# Offense count:
|
68
|
-
|
69
|
-
|
70
|
-
- 'spec/act_as_api_client_spec.rb'
|
71
|
-
- 'spec/clients/github_client_spec.rb'
|
72
|
-
|
73
|
-
# Offense count: 5
|
74
|
-
Style/Documentation:
|
57
|
+
# Offense count: 3
|
58
|
+
# Configuration parameters: Max.
|
59
|
+
RSpec/NestedGroups:
|
75
60
|
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'
|
61
|
+
- 'spec/act_as_api_client/clients/github_client/find_by_spec.rb'
|
83
62
|
|
84
63
|
# Offense count: 1
|
85
64
|
# Configuration parameters: MinBodyLength.
|
86
65
|
Style/GuardClause:
|
87
66
|
Exclude:
|
88
|
-
- 'lib/act_as_api_client.rb'
|
67
|
+
- 'lib/act_as_api_client/clients/authorize_net_webhooks_client.rb'
|
89
68
|
|
90
|
-
# Offense count:
|
69
|
+
# Offense count: 4
|
91
70
|
# Cop supports --auto-correct.
|
92
71
|
# Configuration parameters: AutoCorrect, Max, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
|
93
72
|
# URISchemes: http, https
|
94
73
|
Layout/LineLength:
|
95
74
|
Exclude:
|
96
|
-
- 'act_as_api_client.
|
75
|
+
- 'lib/act_as_api_client/clients/github_client.rb'
|
76
|
+
- 'spec/support/vcr_setup.rb'
|
data/Gemfile.lock
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
act_as_api_client (0.
|
5
|
-
httparty (~> 0.20)
|
4
|
+
act_as_api_client (0.2.0)
|
6
5
|
|
7
6
|
GEM
|
8
7
|
remote: https://rubygems.org/
|
@@ -15,13 +14,6 @@ GEM
|
|
15
14
|
rexml
|
16
15
|
diff-lcs (1.5.0)
|
17
16
|
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
17
|
parallel (1.22.1)
|
26
18
|
parser (3.1.2.0)
|
27
19
|
ast (~> 2.4.1)
|
@@ -52,7 +44,7 @@ GEM
|
|
52
44
|
rubocop-ast (>= 0.6.0)
|
53
45
|
ruby-progressbar (~> 1.7)
|
54
46
|
unicode-display_width (>= 1.4.0, < 2.0)
|
55
|
-
rubocop-ast (1.
|
47
|
+
rubocop-ast (1.19.1)
|
56
48
|
parser (>= 3.1.1.0)
|
57
49
|
rubocop-rspec (1.44.1)
|
58
50
|
rubocop (~> 0.87)
|
data/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
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
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.
|
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](https://github.com/Rukomoynikov/act_as_api_client#usage) section to find how to use existing preconfigured API's and encapsulate all logic inside `APIClient` classes.
|
6
6
|
|
7
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
8
|
|
@@ -24,10 +24,10 @@ Or install it yourself as:
|
|
24
24
|
|
25
25
|
## Usage
|
26
26
|
|
27
|
-
|
28
|
-
Create a folder for examples api_clients inside your `lib` directory.
|
27
|
+
### Folder for clients:
|
28
|
+
Create a folder in your app for examples `api_clients` inside your `lib` directory. This will be the place where you will keep all... api clients.
|
29
29
|
|
30
|
-
|
30
|
+
### Create API client class:
|
31
31
|
For example you want to fetch and update Github repositoties, then you class may have a form like this:
|
32
32
|
|
33
33
|
```ruby
|
@@ -36,7 +36,7 @@ class GithubClient < ApiClient
|
|
36
36
|
end
|
37
37
|
```
|
38
38
|
|
39
|
-
In case you want to provide and use
|
39
|
+
In case you want to provide and use authorization token for Github:
|
40
40
|
|
41
41
|
```ruby
|
42
42
|
class GithubClient < ApiClient
|
@@ -46,11 +46,23 @@ class GithubClient < ApiClient
|
|
46
46
|
}
|
47
47
|
end
|
48
48
|
```
|
49
|
+
btw, all values from `with` hash will be availabe in tour clients as instance variable `@options`
|
49
50
|
|
50
|
-
|
51
|
+
### Use it:
|
52
|
+
Let's fetch all repositories from Rails organization:
|
51
53
|
|
52
|
-
|
53
|
-
|
54
|
+
```ruby
|
55
|
+
github_client = GithubClient.new()
|
56
|
+
|
57
|
+
github_client.find('Rukomoynikov/tabled')
|
58
|
+
github_client.find_by(organization: 'rails')
|
59
|
+
github_client.where('rails', per_page: 100)
|
60
|
+
```
|
61
|
+
|
62
|
+
Voila.
|
63
|
+
|
64
|
+
## List of supported API clients
|
65
|
+
1. [Github Repositories](https://rubydoc.info/github/Rukomoynikov/act_as_api_client/ActAsApiClient/Clients/GithubClient)
|
54
66
|
|
55
67
|
## Development
|
56
68
|
|
@@ -58,14 +70,6 @@ After checking out the repo, run `bin/setup` to install dependencies. Then, run
|
|
58
70
|
|
59
71
|
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
72
|
|
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
73
|
## License
|
66
74
|
|
67
75
|
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/act_as_api_client.gemspec
CHANGED
@@ -9,13 +9,17 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.email = ["rukomoynikov@gmail.com"]
|
10
10
|
|
11
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
|
12
|
+
spec.description = "Helps you to build reliable API clients in a minute. Just add act_as_api_client to your classes"
|
13
13
|
spec.homepage = "https://rubygems.org/gems/act_as_api_client"
|
14
14
|
spec.license = "MIT"
|
15
|
-
spec.required_ruby_version = Gem::Requirement.new(">= 2.
|
15
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.4.0")
|
16
16
|
|
17
|
-
spec.metadata
|
18
|
-
|
17
|
+
spec.metadata = {
|
18
|
+
"source_code_uri" => "https://github.com/Rukomoynikov/act_as_api_client",
|
19
|
+
"homepage_uri" => spec.homepage,
|
20
|
+
"documentation_uri" => "https://rubydoc.info/github/Rukomoynikov/act_as_api_client/main",
|
21
|
+
"bug_tracker_uri" => "https://github.com/Rukomoynikov/act_as_api_client/issues"
|
22
|
+
}
|
19
23
|
|
20
24
|
# Specify which files should be added to the gem when it is released.
|
21
25
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
@@ -25,7 +29,6 @@ Gem::Specification.new do |spec|
|
|
25
29
|
spec.require_paths = ["lib"]
|
26
30
|
|
27
31
|
# Uncomment to register a new dependency of your gem
|
28
|
-
spec.add_dependency "httparty", "~> 0.20"
|
29
32
|
|
30
33
|
# For more information and examples about making a new gem, checkout our
|
31
34
|
# guide at: https://bundler.io/guides/creating_gem.html
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "http_client"
|
4
|
+
require_relative "./authorize_net_webhooks_client"
|
5
|
+
require "base64"
|
6
|
+
|
7
|
+
module ActAsApiClient
|
8
|
+
module Clients
|
9
|
+
module AuthorizeNetNotificationsClient
|
10
|
+
include AuthorizeNetWebhooksClient
|
11
|
+
|
12
|
+
def where(parameters = {})
|
13
|
+
# GET https://apitest.authorize.net/rest/v1/notifications?from_date=2017-03-01&to_date=2017-03-13&offset=0&limit=100
|
14
|
+
# GET https://apitest.authorize.net/rest/v1/notifications?deliveryStatus=Failed
|
15
|
+
# [:from_date, :to_date, :offset, :limit, :deliveryStatus]
|
16
|
+
|
17
|
+
get("https://#{base_uri}/rest/v1/notifications/",
|
18
|
+
headers: { "Authorization" => auth },
|
19
|
+
params: parameters)
|
20
|
+
end
|
21
|
+
|
22
|
+
def find(uuid)
|
23
|
+
raise StandardError, "uuid is not provided" if uuid.empty?
|
24
|
+
|
25
|
+
get("https://#{base_uri}/rest/v1/notifications/#{uuid}",
|
26
|
+
headers: { "Authorization" => auth })
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "http_client"
|
4
|
+
require "base64"
|
5
|
+
|
6
|
+
module ActAsApiClient
|
7
|
+
module Clients
|
8
|
+
module AuthorizeNetWebhooksClient
|
9
|
+
include HttpClient
|
10
|
+
DEFAULT_OPTIONS = {
|
11
|
+
mode: :production
|
12
|
+
}.freeze
|
13
|
+
|
14
|
+
def initialize
|
15
|
+
@options = DEFAULT_OPTIONS.merge(options)
|
16
|
+
end
|
17
|
+
|
18
|
+
def find(uuid)
|
19
|
+
raise StandardError, "uuid is not provided" if uuid.empty?
|
20
|
+
|
21
|
+
get("https://#{base_uri}/rest/v1/webhooks/#{uuid}",
|
22
|
+
headers: { "Authorization" => auth })
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def base_uri
|
28
|
+
if @options[:mode] == :test
|
29
|
+
"apitest.authorize.net"
|
30
|
+
else
|
31
|
+
"authorize.net"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def auth
|
36
|
+
if options[:payment_user]
|
37
|
+
"Basic #{Base64.strict_encode64("#{options[:payment_user]}:#{options[:payment_pass]}")}"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -1,50 +1,94 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require_relative "http_client"
|
4
|
-
require "httparty"
|
5
4
|
|
6
5
|
module ActAsApiClient
|
7
6
|
module Clients
|
8
7
|
module GithubClient
|
9
8
|
include HttpClient
|
9
|
+
|
10
|
+
# Searches Github for one repository by it's owner and repository names.
|
11
|
+
# More details look at the corresponding {https://docs.github.com/en/rest/repos/repos#get-a-repository Github Docs page}
|
12
|
+
#
|
13
|
+
# @param repository_name [String] owner and repository name, 'Rukomoynikov/tabled'
|
14
|
+
#
|
15
|
+
# @return [Hash] detailed info about the repository.
|
10
16
|
def find(repository_name)
|
11
17
|
unless repository_name.match?(%r{[a-zA-Z]/[a-zA-Z]})
|
12
18
|
raise StandardError, "repository_name parameter is not valid"
|
13
19
|
end
|
14
20
|
|
15
|
-
|
16
|
-
|
17
|
-
|
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
|
21
|
+
get("https://api.github.com/repos/#{repository_name}",
|
22
|
+
headers: { "Accept" => "application/vnd.github.v3+json",
|
23
|
+
"Authorization" => (options[:token] ? "token #{options[:token]}" : nil) })
|
23
24
|
end
|
24
25
|
|
25
|
-
|
26
|
-
|
26
|
+
# Search through Github repositories using query string and additional parameters explained on the {https://docs.github.com/en/rest/search#search-repositories Github Docs page}
|
27
|
+
#
|
28
|
+
# @param query_string [String] query string to search github repositories
|
29
|
+
# @param parameters [Hash] paramaters like per_page, page, sort and order
|
30
|
+
#
|
31
|
+
# @example Reverse a string
|
32
|
+
# class GithubClient < ApiClient
|
33
|
+
# act_as_api_client for: :github
|
34
|
+
# end
|
35
|
+
#
|
36
|
+
# GithubClient.new.where('rails')
|
37
|
+
# GithubClient.new.where('rails', per_page: 100)
|
38
|
+
#
|
39
|
+
# @return [Array] list of repositories
|
40
|
+
def where(query_string, parameters = {})
|
41
|
+
get("https://api.github.com/search/repositories",
|
42
|
+
headers: { "Accept" => "application/vnd.github.v3+json",
|
43
|
+
"Authorization" => (options[:token] ? "token #{options[:token]}" : nil) },
|
44
|
+
params: { q: query_string }.merge(parameters))
|
27
45
|
end
|
28
46
|
|
47
|
+
# Use this method if you need to get list of repositories selected by one of this conditions: user, authenticated_user, organization
|
48
|
+
#
|
49
|
+
# @param options [Hash] has to have one of these keys: user, authenticated_user, organization
|
50
|
+
#
|
51
|
+
# @example Reverse a string
|
52
|
+
# class GithubClient < ApiClient
|
53
|
+
# act_as_api_client for: :github
|
54
|
+
# end
|
55
|
+
#
|
56
|
+
# GithubClient.new.find_by(organization: 'rails')
|
57
|
+
#
|
58
|
+
# @return [Array] list of repositories
|
29
59
|
def find_by(options = {})
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
"
|
34
|
-
|
60
|
+
unless options.is_a?(Hash)
|
61
|
+
raise StandardError, "provide a hash as an argument not #{options.class.to_s.downcase}"
|
62
|
+
end
|
63
|
+
raise StandardError, "provide at least one parameter" if options.keys.length.zero?
|
64
|
+
raise StandardError, "method 'find_by' supports only one parameter" if options.keys.length > 1
|
35
65
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
66
|
+
url = case options.keys.first
|
67
|
+
when :organization
|
68
|
+
"https://api.github.com/orgs/#{options[:organization]}/repos"
|
69
|
+
when :user
|
70
|
+
"https://api.github.com/users/#{options[:user]}/repos"
|
71
|
+
when :authenticated_user
|
72
|
+
"https://api.github.com/repositories"
|
73
|
+
end
|
40
74
|
|
41
|
-
|
42
|
-
|
75
|
+
get(url,
|
76
|
+
headers: { "Accept" => "application/vnd.github.v3+json",
|
77
|
+
"Authorization" => (options[:token] ? "token #{options[:token]}" : nil) })
|
43
78
|
end
|
44
79
|
|
45
|
-
def
|
46
|
-
|
47
|
-
|
80
|
+
# def delete
|
81
|
+
# # Call only on queried before repository and repository is not 404/400 and has right to delete (write)
|
82
|
+
# "delete"
|
83
|
+
# end
|
84
|
+
#
|
85
|
+
# def create
|
86
|
+
# "create"
|
87
|
+
# end
|
88
|
+
#
|
89
|
+
# def update
|
90
|
+
# "update"
|
91
|
+
# end
|
48
92
|
end
|
49
93
|
end
|
50
94
|
end
|
@@ -1,28 +1,53 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "
|
3
|
+
require "net/http"
|
4
|
+
require "json"
|
4
5
|
|
5
6
|
module ActAsApiClient
|
6
7
|
module Clients
|
7
8
|
module HttpClient
|
9
|
+
private
|
10
|
+
|
8
11
|
def get(url, options = {})
|
9
|
-
|
12
|
+
# Request part
|
13
|
+
uri = URI(url)
|
14
|
+
uri.query = URI.encode_www_form(options.fetch(:params, {}))
|
15
|
+
|
16
|
+
request = Net::HTTP::Get.new(uri)
|
17
|
+
request_headers(headers: options.fetch(:headers, {}),
|
18
|
+
request: request)
|
19
|
+
|
20
|
+
# Response part
|
21
|
+
response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
|
22
|
+
http.request(request)
|
23
|
+
end
|
24
|
+
|
25
|
+
case response
|
26
|
+
when Net::HTTPNotFound, Net::HTTPSuccess, Net::HTTPUnprocessableEntity, Net::HTTPUnauthorized
|
27
|
+
::JSON.parse(response.body)
|
28
|
+
end
|
10
29
|
end
|
11
30
|
|
12
31
|
def post
|
13
|
-
HTTParty.post
|
32
|
+
# HTTParty.post
|
14
33
|
end
|
15
34
|
|
16
35
|
def put
|
17
|
-
HTTParty.put
|
36
|
+
# HTTParty.put
|
18
37
|
end
|
19
38
|
|
20
39
|
def update
|
21
|
-
HTTParty.update
|
40
|
+
# HTTParty.update
|
22
41
|
end
|
23
42
|
|
24
43
|
def delete
|
25
|
-
HTTParty.delete
|
44
|
+
# HTTParty.delete
|
45
|
+
end
|
46
|
+
|
47
|
+
def request_headers(headers:, request:)
|
48
|
+
headers.each do |key, value|
|
49
|
+
request[key] = value
|
50
|
+
end
|
26
51
|
end
|
27
52
|
end
|
28
53
|
end
|
data/lib/act_as_api_client.rb
CHANGED
@@ -15,15 +15,28 @@ class ApiClient
|
|
15
15
|
private
|
16
16
|
|
17
17
|
def set_general_client(client_for:)
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
18
|
+
return if client_for.nil?
|
19
|
+
|
20
|
+
class_name = convert_underscore_to_camelcase(client_for)
|
21
|
+
|
22
|
+
require(File.expand_path("act_as_api_client/clients/#{client_for}_client",
|
23
|
+
File.dirname(__FILE__)))
|
24
|
+
include const_get("ActAsApiClient::Clients::#{class_name}Client")
|
23
25
|
end
|
24
26
|
|
25
27
|
def set_options(options:)
|
26
28
|
define_method("options") { options }
|
27
29
|
end
|
30
|
+
|
31
|
+
# Converting from authorize_net_webhooks_client to AuthorizeNetWebhooksClient
|
32
|
+
#
|
33
|
+
# @param value [String] string with underscores
|
34
|
+
#
|
35
|
+
# @return [String] transformed in camel case format string
|
36
|
+
def convert_underscore_to_camelcase(value)
|
37
|
+
value.to_s.capitalize.gsub(/_(.)/) do |s|
|
38
|
+
s.upcase.gsub("_", "")
|
39
|
+
end
|
40
|
+
end
|
28
41
|
end
|
29
42
|
end
|
metadata
CHANGED
@@ -1,31 +1,17 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: act_as_api_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Max Rukomoynikov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-07-
|
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'
|
11
|
+
date: 2022-07-29 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
27
13
|
description: Helps you to build reliable API clients in a minute. Just add act_as_api_client
|
28
|
-
to your classes
|
14
|
+
to your classes
|
29
15
|
email:
|
30
16
|
- rukomoynikov@gmail.com
|
31
17
|
executables: []
|
@@ -49,6 +35,8 @@ files:
|
|
49
35
|
- demo.rb
|
50
36
|
- lib/act_as_api_client.rb
|
51
37
|
- lib/act_as_api_client/base_api_methods.rb
|
38
|
+
- lib/act_as_api_client/clients/authorize_net_notifications_client.rb
|
39
|
+
- lib/act_as_api_client/clients/authorize_net_webhooks_client.rb
|
52
40
|
- lib/act_as_api_client/clients/github_client.rb
|
53
41
|
- lib/act_as_api_client/clients/http_client.rb
|
54
42
|
- lib/act_as_api_client/version.rb
|
@@ -56,8 +44,10 @@ homepage: https://rubygems.org/gems/act_as_api_client
|
|
56
44
|
licenses:
|
57
45
|
- MIT
|
58
46
|
metadata:
|
59
|
-
homepage_uri: https://rubygems.org/gems/act_as_api_client
|
60
47
|
source_code_uri: https://github.com/Rukomoynikov/act_as_api_client
|
48
|
+
homepage_uri: https://rubygems.org/gems/act_as_api_client
|
49
|
+
documentation_uri: https://rubydoc.info/github/Rukomoynikov/act_as_api_client/main
|
50
|
+
bug_tracker_uri: https://github.com/Rukomoynikov/act_as_api_client/issues
|
61
51
|
post_install_message:
|
62
52
|
rdoc_options: []
|
63
53
|
require_paths:
|
@@ -66,7 +56,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
66
56
|
requirements:
|
67
57
|
- - ">="
|
68
58
|
- !ruby/object:Gem::Version
|
69
|
-
version: 2.
|
59
|
+
version: 2.4.0
|
70
60
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
71
61
|
requirements:
|
72
62
|
- - ">="
|