ac 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +38 -26
- data/ac.gemspec +35 -0
- data/lib/ac/base.rb +2 -1
- data/lib/ac/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c0168d5bdf01a61dce4822daa18b9220e7206e054d8eb221e35f44960132a872
|
4
|
+
data.tar.gz: 55e1ff51ba10f2fcd774cec1076776d2e878892d64a61794e0d81864294754b8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a5ebe2c76798b8e089c1a9cd382f8a52d9517ba6d41c7fb1285b5ecf489d20c0cc60fc967afc4154cd676a79e4491fc15eca1d609ea8890aa503252eb5bb6d9e
|
7
|
+
data.tar.gz: 70b22d0c9746b6e85fb4d8bef1d15c7f75b00b8e226c449d8c8c28127bf71d7fd5ed629cfeb54ed137345af0dbb9c79cee937b9b7e9506bc89e9762789bc8977
|
data/README.md
CHANGED
@@ -1,39 +1,51 @@
|
|
1
1
|
# Ac
|
2
|
+
Api Client for Typhoeus
|
2
3
|
|
3
|
-
|
4
|
-
|
5
|
-
|
4
|
+
### Features
|
5
|
+
- defines convenience methods for get, post, put, patch, and delete
|
6
|
+
- allows passing a block to the convenience mehtods to handle retry logic
|
7
|
+
- prepends a module to Typhoeus::Response that provides a `.json` method that returns parsed JSON or `nil` if parsing fails.
|
6
8
|
|
7
9
|
## Installation
|
10
|
+
Add `gem "ac"` to your Gemfile or install it yourself with `gem install ac`.
|
8
11
|
|
9
|
-
TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
|
10
|
-
|
11
|
-
Install the gem and add to the application's Gemfile by executing:
|
12
|
-
|
13
|
-
$ bundle add UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
|
14
|
-
|
15
|
-
If bundler is not being used to manage dependencies, install the gem by executing:
|
16
|
-
|
17
|
-
$ gem install UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
|
18
12
|
|
19
13
|
## Usage
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
14
|
+
Subclass Ac::Base and define BASE_URL, then you can use `get(path, options)` (or put/patch/delete).
|
15
|
+
```ruby
|
16
|
+
class HttpbinClient < Ac::Base
|
17
|
+
BASE_URL = "https://httpbin.org"
|
18
|
+
|
19
|
+
def my_ip_address
|
20
|
+
get("/ip").json["origin"]
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
client = HttpbinClient.new
|
25
|
+
puts client.my_ip_address
|
26
|
+
# => 177.62.72.86
|
27
|
+
```
|
28
|
+
Implement retries by passing a block that blows up or retruns false if the resquest should be retried.
|
29
|
+
```ruby
|
30
|
+
class JsonPlaceholderClient < Ac::Base
|
31
|
+
BASE_URL = "https://jsonplaceholder.typicode.com"
|
32
|
+
|
33
|
+
def find_post id
|
34
|
+
res = get("posts/#{id}") do |response|
|
35
|
+
Integer(response.json["id"])
|
36
|
+
end
|
37
|
+
res.json
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
client = JsonPlaceholderClient.new
|
42
|
+
puts client.find_post 2
|
43
|
+
# => {"userId"=>1, "id"=>2, "title"=>"qui est esse", "body"=>"est rerum tempore vi...
|
44
|
+
```
|
29
45
|
## Contributing
|
30
46
|
|
31
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
47
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/felipedmesquita/ac.
|
32
48
|
|
33
49
|
## License
|
34
50
|
|
35
51
|
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
36
|
-
|
37
|
-
## Code of Conduct
|
38
|
-
|
39
|
-
Everyone interacting in the Ac project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/ac/blob/main/CODE_OF_CONDUCT.md).
|
data/ac.gemspec
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/ac/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "ac"
|
7
|
+
spec.version = Ac::VERSION
|
8
|
+
spec.authors = ["felipedmesquita"]
|
9
|
+
spec.email = ["16197684+felipedmesquita@users.noreply.github.com"]
|
10
|
+
|
11
|
+
spec.summary = "Api Client for Typhoeus"
|
12
|
+
spec.homepage = "https://github.com/felipedmesquita/ac"
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
16
|
+
spec.metadata["source_code_uri"] = "https://github.com/felipedmesquita/ac"
|
17
|
+
|
18
|
+
# Specify which files should be added to the gem when it is released.
|
19
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
20
|
+
spec.files = Dir.chdir(__dir__) do
|
21
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
22
|
+
(File.expand_path(f) == __FILE__) ||
|
23
|
+
f.start_with?(*%w[bin/ mini_mock/ test/ spec/ features/ .git .circleci appveyor Gemfile])
|
24
|
+
end
|
25
|
+
end
|
26
|
+
spec.bindir = "exe"
|
27
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
28
|
+
spec.require_paths = ["lib"]
|
29
|
+
|
30
|
+
# Uncomment to register a new dependency of your gem
|
31
|
+
spec.add_dependency "typhoeus"
|
32
|
+
|
33
|
+
# For more information and examples about making a new gem, check out our
|
34
|
+
# guide at: https://bundler.io/guides/creating_gem.html
|
35
|
+
end
|
data/lib/ac/base.rb
CHANGED
@@ -23,7 +23,7 @@ module Ac
|
|
23
23
|
|
24
24
|
define_method http_verb do |path, options = {}, &block|
|
25
25
|
retries_count ||= 0
|
26
|
-
raise "Too many retries" if retries_count > MAX_RETRIES
|
26
|
+
raise "Too many retries" if retries_count > self.class::MAX_RETRIES
|
27
27
|
# puts "Requesting #{path}, retry number #{retries_count}"
|
28
28
|
response = send("#{http_verb}_request", path, options).run
|
29
29
|
|
@@ -32,6 +32,7 @@ module Ac
|
|
32
32
|
raise unless block.call(response)
|
33
33
|
rescue
|
34
34
|
retries_count += 1 # standard:disable Lint/UselessAssignment
|
35
|
+
sleep(2**retries_count) # Exponential backoff
|
35
36
|
redo
|
36
37
|
end
|
37
38
|
end
|
data/lib/ac/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ac
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- felipedmesquita
|
@@ -35,6 +35,7 @@ files:
|
|
35
35
|
- LICENSE.txt
|
36
36
|
- README.md
|
37
37
|
- Rakefile
|
38
|
+
- ac.gemspec
|
38
39
|
- lib/ac.rb
|
39
40
|
- lib/ac/base.rb
|
40
41
|
- lib/ac/json_patch.rb
|
@@ -63,5 +64,5 @@ requirements: []
|
|
63
64
|
rubygems_version: 3.4.6
|
64
65
|
signing_key:
|
65
66
|
specification_version: 4
|
66
|
-
summary:
|
67
|
+
summary: Api Client for Typhoeus
|
67
68
|
test_files: []
|