fault_tolerant_requests 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 0bdac0b98b5fdbd60b985024970c2f709b15ea92589857c93696c4fb9e888374
4
+ data.tar.gz: f8bd4a920c92ce5581b8a8a9584d3449bc5bef61fc97d35452f7e1c1554969c4
5
+ SHA512:
6
+ metadata.gz: 2a764731680c43ae63c15e9ca85cc86220517d127426e058ab7db1812a4090ad3650e5f8fa5e72261aa14c952166779d8d7bc62b83b6bf470c4886b9e3d1fafe
7
+ data.tar.gz: eb5ee3394d7a9c9d714fd4bc516c76f1d0ffbc746faba9a7150dfea5e15e54b6ecc4f4f42174fdc697b485fe81786b5b8652709a68982c70ee21995342109bdd
@@ -0,0 +1,45 @@
1
+ name: Ruby Gem
2
+
3
+ on:
4
+ workflow_dispatch:
5
+ release:
6
+ types: [published]
7
+
8
+ jobs:
9
+ build:
10
+ name: Build + Publish
11
+ runs-on: ubuntu-latest
12
+ permissions:
13
+ contents: read
14
+ packages: write
15
+
16
+ steps:
17
+ - uses: actions/checkout@v2
18
+ - name: Set up Ruby 2.7
19
+ uses: ruby/setup-ruby@v1
20
+ with:
21
+ ruby-version: '2.7'
22
+ bundler-cache: true
23
+
24
+ - name: Publish to GPR
25
+ run: |
26
+ mkdir -p $HOME/.gem
27
+ touch $HOME/.gem/credentials
28
+ chmod 0600 $HOME/.gem/credentials
29
+ printf -- "---\n:github: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
30
+ gem build *.gemspec
31
+ gem push --KEY github --host https://rubygems.pkg.github.com/${OWNER} *.gem
32
+ env:
33
+ GEM_HOST_API_KEY: "Bearer ${{secrets.GITHUB_TOKEN}}"
34
+ OWNER: ${{ github.repository_owner }}
35
+
36
+ - name: Publish to RubyGems
37
+ run: |
38
+ mkdir -p $HOME/.gem
39
+ touch $HOME/.gem/credentials
40
+ chmod 0600 $HOME/.gem/credentials
41
+ printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
42
+ gem build *.gemspec
43
+ gem push *.gem
44
+ env:
45
+ GEM_HOST_API_KEY: "${{secrets.RUBYGEMS_AUTH_TOKEN}}"
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2023-06-19
4
+
5
+ - Initial release
@@ -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 nick@flinkwise.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,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in fault_tolerant_requests.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2023 nicksterious
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,48 @@
1
+ # FaultTolerantRequests
2
+
3
+ Send GET requests, retry after incremental delays on failure.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'fault_tolerant_requests'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle install
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install fault_tolerant_requests
20
+
21
+ ## Usage
22
+
23
+ Set a proxy IP address and user agent, then fetch JSON @url
24
+
25
+ ```
26
+ json = ::TimeoutTolerantRequests::GetJsonRequest.new(
27
+ @proxy_ip,
28
+ @user_agent
29
+ ).do(@url)
30
+ ```
31
+
32
+ ## Development
33
+
34
+ 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.
35
+
36
+ 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).
37
+
38
+ ## Contributing
39
+
40
+ Bug reports and pull requests are welcome on GitHub at https://github.com/nicksterious/fault_tolerant_requests. 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]/fault_tolerant_requests/blob/master/CODE_OF_CONDUCT.md).
41
+
42
+ ## License
43
+
44
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
45
+
46
+ ## Code of Conduct
47
+
48
+ Everyone interacting in the FaultTolerantRequests project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/nicksterious/fault_tolerant_requests/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ task default: %i[]
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 "fault_tolerant_requests"
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
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/fault_tolerant_requests/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "fault_tolerant_requests"
7
+ spec.version = FaultTolerantRequests::VERSION
8
+ spec.authors = ["Nick"]
9
+ spec.email = ["spam@flinkwise.com"]
10
+
11
+ spec.summary = "Fault-tolerant GET requests"
12
+ spec.description = "Send GET requests, retry after incremental delays on failure."
13
+ spec.homepage = "https://github.com/nicksterious/fault_tolerant_requests"
14
+ spec.license = "MIT"
15
+ spec.required_ruby_version = ">= 2.6.0"
16
+
17
+ #spec.metadata["allowed_push_host"] = "TODO: Set to your gem server 'https://example.com'"
18
+
19
+ spec.metadata["homepage_uri"] = spec.homepage
20
+ spec.metadata["source_code_uri"] = "https://github.com/nicksterious/fault_tolerant_requests"
21
+ spec.metadata["changelog_uri"] = "https://github.com/nicksterious/fault_tolerant_requests/CHANGELOG.md"
22
+ # additional links
23
+ spec.metadata["bug_tracker_uri"] = "https://www.sportsbooksoft.com"
24
+ spec.metadata["mailing_list_uri"] = "https://www.sportsbook-provider.com"
25
+ spec.metadata["wiki_uri"] = "https://www.start-sportsbook.com"
26
+ spec.metadata["funding_uri"] = "https://www.sports-book-software.com"
27
+
28
+ # Specify which files should be added to the gem when it is released.
29
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
30
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
31
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
32
+ end
33
+ spec.bindir = "exe"
34
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
35
+ spec.require_paths = ["lib"]
36
+
37
+ # Uncomment to register a new dependency of your gem
38
+ spec.add_dependency "uri", "~> 0.12.1"
39
+
40
+ # For more information and examples about making a new gem, checkout our
41
+ # guide at: https://bundler.io/guides/creating_gem.html
42
+ end
@@ -0,0 +1,46 @@
1
+ require "uri"
2
+ require "open-uri"
3
+ class FaultTolerantRequests::GetJsonRequest
4
+ def initialize(proxy_ip = false, user_agent = false, debug = false)
5
+ @proxy_ip = proxy_ip
6
+ @debug = debug
7
+ @user_agent = user_agent
8
+ end
9
+
10
+ def do(url, attempts = 15, wait = 15)
11
+ request_count = 0
12
+ while request_count < attempts do
13
+ begin
14
+ options = {}
15
+ options[:proxy] = URI.parse("http://#{@proxy_ip}:3128") if @proxy_ip
16
+ options["User-Agent"] = @user_agent if @user_agent
17
+
18
+ requester = ::FaultTolerantRequests::GetRequest
19
+ .new(
20
+ @proxy_ip, @user_agent, @debug
21
+ )
22
+
23
+ content = requester.do(
24
+ url, attempts, wait
25
+ )
26
+
27
+ output = ActiveSupport::JSON.decode( content ).deep_symbolize_keys
28
+
29
+ return output
30
+
31
+ rescue JSON::ParserError => p
32
+ puts " --- Attempt #{request_count}: JSON parse error!"
33
+ puts "#{ p.inspect }"
34
+ request_count+= 1
35
+ sleep request_count * wait
36
+ end
37
+ end
38
+
39
+ # failed, raise an exception and exit, Rollbar will report
40
+ raise StandardError.new "Exceeded timeout/error count while sending API requests"
41
+
42
+ end
43
+
44
+ end
45
+
46
+
@@ -0,0 +1,56 @@
1
+ require "uri"
2
+ require "open-uri"
3
+ class FaultTolerantRequests::GetRequest
4
+ def initialize(proxy_ip = false, user_agent = false, debug = false)
5
+ @proxy_ip = proxy_ip
6
+ @debug = debug
7
+ @user_agent = user_agent
8
+ end
9
+
10
+ def do(url, attempts = 15, wait = 15)
11
+ request_count = 0
12
+ while request_count < attempts do
13
+ begin
14
+ options = {}
15
+ options[:proxy] = URI.parse("http://#{@proxy_ip}:3128") if @proxy_ip
16
+ options["User-Agent"] = @user_agent if @user_agent
17
+
18
+ puts options if @debug
19
+ puts " + #{url} (#{request_count})" if @debug
20
+
21
+ output = URI.open(url, options).read
22
+
23
+ puts output if @debug
24
+
25
+ # request went through fine
26
+ return output
27
+ rescue OpenURI::HTTPError => p
28
+ puts " --- Attempt #{request_count}: HTTP error!"
29
+ puts "#{ p.inspect }"
30
+ request_count+= 1
31
+ sleep request_count * wait * 2
32
+
33
+ rescue Net::ReadTimeout, Net::OpenTimeout, EOFError => e
34
+ # timeout/eof occured, log and sleep
35
+ puts " --- Attempt #{request_count}: timeout error!"
36
+ puts "#{e.inspect}"
37
+ request_count+= 1
38
+ sleep request_count * wait
39
+
40
+ rescue OpenSSL::SSL::SSLError => n
41
+ # SSL certificate error
42
+ puts " --- Attempt #{request_count}: SSL error!"
43
+ puts "#{e.inspect}"
44
+ request_count+= 1
45
+ sleep request_count * wait
46
+
47
+ end
48
+ end
49
+
50
+ # failed, raise an exception and exit, Rollbar will report
51
+ raise StandardError.new "Exceeded timeout/error count while sending API requests"
52
+
53
+ end
54
+
55
+ end
56
+
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module FaultTolerantRequests
4
+ VERSION = "0.1.0"
5
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "fault_tolerant_requests/version"
4
+
5
+ module FaultTolerantRequests
6
+ class Error < StandardError; end
7
+ require_relative "fault_tolerant_requests/get_request"
8
+ require_relative "fault_tolerant_requests/get_json_request"
9
+ end
metadata ADDED
@@ -0,0 +1,79 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fault_tolerant_requests
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Nick
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2023-06-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: uri
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.12.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.12.1
27
+ description: Send GET requests, retry after incremental delays on failure.
28
+ email:
29
+ - spam@flinkwise.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".github/workflows/main.yml"
35
+ - ".gitignore"
36
+ - CHANGELOG.md
37
+ - CODE_OF_CONDUCT.md
38
+ - Gemfile
39
+ - LICENSE.txt
40
+ - README.md
41
+ - Rakefile
42
+ - bin/console
43
+ - bin/setup
44
+ - fault_tolerant_requests.gemspec
45
+ - lib/fault_tolerant_requests.rb
46
+ - lib/fault_tolerant_requests/get_json_request.rb
47
+ - lib/fault_tolerant_requests/get_request.rb
48
+ - lib/fault_tolerant_requests/version.rb
49
+ homepage: https://github.com/nicksterious/fault_tolerant_requests
50
+ licenses:
51
+ - MIT
52
+ metadata:
53
+ homepage_uri: https://github.com/nicksterious/fault_tolerant_requests
54
+ source_code_uri: https://github.com/nicksterious/fault_tolerant_requests
55
+ changelog_uri: https://github.com/nicksterious/fault_tolerant_requests/CHANGELOG.md
56
+ bug_tracker_uri: https://www.sportsbooksoft.com
57
+ mailing_list_uri: https://www.sportsbook-provider.com
58
+ wiki_uri: https://www.start-sportsbook.com
59
+ funding_uri: https://www.sports-book-software.com
60
+ post_install_message:
61
+ rdoc_options: []
62
+ require_paths:
63
+ - lib
64
+ required_ruby_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: 2.6.0
69
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ requirements: []
75
+ rubygems_version: 3.1.6
76
+ signing_key:
77
+ specification_version: 4
78
+ summary: Fault-tolerant GET requests
79
+ test_files: []