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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d2cc120a06ba1dff33147f685d63b31df8c04a7616b9e5877e3c88c94f176e10
4
- data.tar.gz: '0499e0f3109d6f84e8e2a0e2763733bd160ee643274060636db5de84a72adfc3'
3
+ metadata.gz: c0168d5bdf01a61dce4822daa18b9220e7206e054d8eb221e35f44960132a872
4
+ data.tar.gz: 55e1ff51ba10f2fcd774cec1076776d2e878892d64a61794e0d81864294754b8
5
5
  SHA512:
6
- metadata.gz: 77ffa28676c9caa0c35c8990d19a130d4232a165275e66eb93dee74899554779186a1aa9384bb8fe34a0f22da5c28e4e1b50e0a86fe4b37dd5ce3713c714928e
7
- data.tar.gz: fd089b550c29d87f8a68056d69f05518dc20dd6473a822fa03f6cdf14caba9e948ec29901321d73664b02f8ddddc928f6f6075fa13552916f9b05ce6e4929641
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
- TODO: Delete this and the text below, and describe your gem
4
-
5
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/ac`. To experiment with that code, run `bin/console` for an interactive prompt.
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
- TODO: Write usage instructions here
22
-
23
- ## Development
24
-
25
- After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
26
-
27
- 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).
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/[USERNAME]/ac. 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]/ac/blob/main/CODE_OF_CONDUCT.md).
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Ac
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.1"
5
5
  end
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.0
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: Simple Api Client for Typhoeus
67
+ summary: Api Client for Typhoeus
67
68
  test_files: []