kaze_client 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +7 -0
  2. data/.github/workflows/main.yml +18 -0
  3. data/.gitignore +16 -0
  4. data/.rspec +3 -0
  5. data/.rubocop.yml +104 -0
  6. data/CHANGELOG.md +11 -0
  7. data/CODE_OF_CONDUCT.md +84 -0
  8. data/Gemfile +12 -0
  9. data/Gemfile.lock +63 -0
  10. data/LICENSE.txt +21 -0
  11. data/README.md +37 -0
  12. data/Rakefile +12 -0
  13. data/bin/console +15 -0
  14. data/bin/setup +8 -0
  15. data/kaze_client.gemspec +35 -0
  16. data/lib/activesupport/blank.rb +155 -0
  17. data/lib/activesupport/camelize.rb +32 -0
  18. data/lib/kaze_client/client.rb +99 -0
  19. data/lib/kaze_client/error/disabled_account.rb +13 -0
  20. data/lib/kaze_client/error/forbidden.rb +13 -0
  21. data/lib/kaze_client/error/generic.rb +29 -0
  22. data/lib/kaze_client/error/internal_server_error.rb +13 -0
  23. data/lib/kaze_client/error/invalid_credentials.rb +13 -0
  24. data/lib/kaze_client/error/no_endpoint.rb +19 -0
  25. data/lib/kaze_client/error/no_private_token.rb +13 -0
  26. data/lib/kaze_client/error/not_found.rb +13 -0
  27. data/lib/kaze_client/error/unauthorized.rb +13 -0
  28. data/lib/kaze_client/errors.rb +12 -0
  29. data/lib/kaze_client/request/request.rb +113 -0
  30. data/lib/kaze_client/request/requests/assign_performer_request.rb +23 -0
  31. data/lib/kaze_client/request/requests/companies_request.rb +19 -0
  32. data/lib/kaze_client/request/requests/create_job_request.rb +32 -0
  33. data/lib/kaze_client/request/requests/job_request.rb +17 -0
  34. data/lib/kaze_client/request/requests/job_workflow_request.rb +25 -0
  35. data/lib/kaze_client/request/requests/job_workflows_request.rb +19 -0
  36. data/lib/kaze_client/request/requests/jobs_request.rb +18 -0
  37. data/lib/kaze_client/request/requests/login_request.rb +28 -0
  38. data/lib/kaze_client/request/requests/profile_request.rb +17 -0
  39. data/lib/kaze_client/request/requests/update_template_request.rb +19 -0
  40. data/lib/kaze_client/request/requests/utils/authentified_request.rb +25 -0
  41. data/lib/kaze_client/request/requests/utils/final_request.rb +13 -0
  42. data/lib/kaze_client/request/requests/utils/list_request.rb +120 -0
  43. data/lib/kaze_client/requests.rb +23 -0
  44. data/lib/kaze_client/response.rb +34 -0
  45. data/lib/kaze_client/version.rb +5 -0
  46. data/lib/kaze_client.rb +17 -0
  47. metadata +114 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: e71be7a11e6eda6cc3c131cca7f758b86a899c7def80d9fe0c88e6856ef92eb0
4
+ data.tar.gz: '094490f87b08e879d00769788ca1213b84e3b49a5ac07a57a6b4e6b6ffeaa0c8'
5
+ SHA512:
6
+ metadata.gz: 717a355889796d246c24e0b1b9cb6db5ae688115417342fc103a490a3164b2fbce486ead122712b6f66ae5ab1c2286273bd8db4ac8bf0e73689650491ad21c3b
7
+ data.tar.gz: 7282041426db6859a0b911d220efb9cca946cca5d294447927ca0ccf13ecd01ce56be8246599ab22eb4967e6366ec93a0c7ca0ec95780de95e3ade431f29d19d
@@ -0,0 +1,18 @@
1
+ name: Ruby
2
+
3
+ on: [push,pull_request]
4
+
5
+ jobs:
6
+ build:
7
+ runs-on: ubuntu-latest
8
+ steps:
9
+ - uses: actions/checkout@v2
10
+ - name: Set up Ruby
11
+ uses: ruby/setup-ruby@v1
12
+ with:
13
+ ruby-version: 3.0.1
14
+ - name: Run the default task
15
+ run: |
16
+ gem install bundler -v 2.2.15
17
+ bundle install
18
+ bundle exec rake
data/.gitignore ADDED
@@ -0,0 +1,16 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+
13
+ # Ignore built gems
14
+ *.gem
15
+
16
+ .idea
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,104 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.5
3
+
4
+ Style/StringLiterals:
5
+ Enabled: true
6
+ EnforcedStyle: double_quotes
7
+
8
+ Style/StringLiteralsInInterpolation:
9
+ Enabled: true
10
+ EnforcedStyle: double_quotes
11
+
12
+ Layout/LineLength:
13
+ Max: 120
14
+
15
+ Gemspec/DateAssignment: # (new in 1.10)
16
+ Enabled: true
17
+
18
+ Layout/SpaceBeforeBrackets: # (new in 1.7)
19
+ Enabled: true
20
+
21
+ Lint/AmbiguousAssignment: # (new in 1.7)
22
+ Enabled: true
23
+
24
+ Lint/DeprecatedConstants: # (new in 1.8)
25
+ Enabled: true
26
+
27
+ Lint/DuplicateBranch: # (new in 1.3)
28
+ Enabled: true
29
+
30
+ Lint/DuplicateRegexpCharacterClassElement: # (new in 1.1)
31
+ Enabled: true
32
+
33
+ Lint/EmptyBlock: # (new in 1.1)
34
+ Enabled: true
35
+
36
+ Lint/EmptyClass: # (new in 1.3)
37
+ Enabled: true
38
+
39
+ Lint/LambdaWithoutLiteralBlock: # (new in 1.8)
40
+ Enabled: true
41
+
42
+ Lint/NoReturnInBeginEndBlocks: # (new in 1.2)
43
+ Enabled: true
44
+
45
+ Lint/NumberedParameterAssignment: # (new in 1.9)
46
+ Enabled: true
47
+
48
+ Lint/OrAssignmentToConstant: # (new in 1.9)
49
+ Enabled: true
50
+
51
+ Lint/RedundantDirGlobSort: # (new in 1.8)
52
+ Enabled: true
53
+
54
+ Lint/SymbolConversion: # (new in 1.9)
55
+ Enabled: true
56
+
57
+ Lint/ToEnumArguments: # (new in 1.1)
58
+ Enabled: true
59
+
60
+ Lint/TripleQuotes: # (new in 1.9)
61
+ Enabled: true
62
+
63
+ Lint/UnexpectedBlockArity: # (new in 1.5)
64
+ Enabled: true
65
+
66
+ Lint/UnmodifiedReduceAccumulator: # (new in 1.1)
67
+ Enabled: true
68
+
69
+ Style/ArgumentsForwarding: # (new in 1.1)
70
+ Enabled: true
71
+
72
+ Style/CollectionCompact: # (new in 1.2)
73
+ Enabled: true
74
+
75
+ Style/DocumentDynamicEvalDefinition: # (new in 1.1)
76
+ Enabled: true
77
+
78
+ Style/EndlessMethod: # (new in 1.8)
79
+ Enabled: true
80
+
81
+ Style/HashConversion: # (new in 1.10)
82
+ Enabled: true
83
+
84
+ Style/HashExcept: # (new in 1.7)
85
+ Enabled: true
86
+
87
+ Style/IfWithBooleanLiteralBranches: # (new in 1.9)
88
+ Enabled: true
89
+
90
+ Style/NegatedIfElseCondition: # (new in 1.2)
91
+ Enabled: true
92
+
93
+ Style/NilLambda: # (new in 1.3)
94
+ Enabled: true
95
+
96
+ Style/RedundantArgument: # (new in 1.4)
97
+ Enabled: true
98
+
99
+ Style/StringChars: # (new in 1.12)
100
+ Enabled: true
101
+
102
+ Style/SwapValues: # (new in 1.1)
103
+ Enabled: true
104
+
data/CHANGELOG.md ADDED
@@ -0,0 +1,11 @@
1
+ ## [0.1.1] - 2022-05-31
2
+
3
+ - Rename the gem to KazeClient to follow the rebranding of LastBill to Kaze.
4
+
5
+ ## [0.1.0] - 2021-05-20
6
+
7
+ - Initial release.
8
+ - Requests to:
9
+ - login,
10
+ - fetch data about logged in user,
11
+ - fetch and close jobs.
@@ -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 rails@modulotech.fr. 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,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in kaze_client.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "rspec", "~> 3.0"
11
+
12
+ gem "rubocop", "~> 1.7"
data/Gemfile.lock ADDED
@@ -0,0 +1,63 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ kaze_client (0.1.0)
5
+ httparty (~> 0.18, >= 0.18.1)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ ast (2.4.2)
11
+ diff-lcs (1.4.4)
12
+ httparty (0.18.1)
13
+ mime-types (~> 3.0)
14
+ multi_xml (>= 0.5.2)
15
+ mime-types (3.3.1)
16
+ mime-types-data (~> 3.2015)
17
+ mime-types-data (3.2021.0225)
18
+ multi_xml (0.6.0)
19
+ parallel (1.20.1)
20
+ parser (3.0.1.1)
21
+ ast (~> 2.4.1)
22
+ rainbow (3.0.0)
23
+ rake (13.0.3)
24
+ regexp_parser (2.1.1)
25
+ rexml (3.2.5)
26
+ rspec (3.10.0)
27
+ rspec-core (~> 3.10.0)
28
+ rspec-expectations (~> 3.10.0)
29
+ rspec-mocks (~> 3.10.0)
30
+ rspec-core (3.10.1)
31
+ rspec-support (~> 3.10.0)
32
+ rspec-expectations (3.10.1)
33
+ diff-lcs (>= 1.2.0, < 2.0)
34
+ rspec-support (~> 3.10.0)
35
+ rspec-mocks (3.10.2)
36
+ diff-lcs (>= 1.2.0, < 2.0)
37
+ rspec-support (~> 3.10.0)
38
+ rspec-support (3.10.2)
39
+ rubocop (1.15.0)
40
+ parallel (~> 1.10)
41
+ parser (>= 3.0.0.0)
42
+ rainbow (>= 2.2.2, < 4.0)
43
+ regexp_parser (>= 1.8, < 3.0)
44
+ rexml
45
+ rubocop-ast (>= 1.5.0, < 2.0)
46
+ ruby-progressbar (~> 1.7)
47
+ unicode-display_width (>= 1.4.0, < 3.0)
48
+ rubocop-ast (1.5.0)
49
+ parser (>= 3.0.1.1)
50
+ ruby-progressbar (1.11.0)
51
+ unicode-display_width (2.0.0)
52
+
53
+ PLATFORMS
54
+ x86_64-darwin-20
55
+
56
+ DEPENDENCIES
57
+ kaze_client!
58
+ rake (~> 13.0)
59
+ rspec (~> 3.0)
60
+ rubocop (~> 1.7)
61
+
62
+ BUNDLED WITH
63
+ 2.2.15
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2022 Modulotech
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,37 @@
1
+ # KazeClient
2
+
3
+ This is the official Ruby client library for Kaze API.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'kaze_client'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle install
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install kaze_client
20
+
21
+ ## Development
22
+
23
+ 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.
24
+
25
+ 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).
26
+
27
+ ## Contributing
28
+
29
+ Bug reports and pull requests are welcome on GitHub at https://github.com/moduloTech/kaze_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/moduloTech/kaze_client/blob/master/CODE_OF_CONDUCT.md).
30
+
31
+ ## License
32
+
33
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
34
+
35
+ ## Code of Conduct
36
+
37
+ Everyone interacting in the KazeClient project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/moduloTech/kaze_client/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
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 "kaze_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
@@ -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,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/kaze_client/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "kaze_client"
7
+ spec.version = KazeClient::VERSION
8
+ spec.authors = ["Matthieu Ciappara"]
9
+ spec.email = ["ciappa_m@modulotech.fr"]
10
+
11
+ spec.summary = "This is the official Ruby client library for Kaze API."
12
+ spec.description = <<~TEXT
13
+ This is the official Ruby client library for Kaze (https://www.kaze.so/) API.
14
+
15
+ The API documentation can be found at https://documenter.getpostman.com/view/15303175/U16nLQ7r.
16
+ TEXT
17
+ spec.homepage = "https://github.com/moduloTech/kaze_client"
18
+ spec.license = "MIT"
19
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.5.0")
20
+
21
+ spec.metadata["homepage_uri"] = spec.homepage
22
+ spec.metadata["source_code_uri"] = "https://github.com/moduloTech/kaze_client"
23
+ spec.metadata["changelog_uri"] = "https://github.com/moduloTech/kaze_client/blob/master/CHANGELOG.md"
24
+
25
+ # Specify which files should be added to the gem when it is released.
26
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
27
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
28
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
29
+ end
30
+ spec.bindir = "exe"
31
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
32
+ spec.require_paths = ["lib"]
33
+
34
+ spec.add_runtime_dependency "httparty", "~> 0.18", ">= 0.18.1"
35
+ end
@@ -0,0 +1,155 @@
1
+ # frozen_string_literal: true
2
+ # rubocop:disable all
3
+
4
+ # Downloaded from https://raw.githubusercontent.com/rails/rails/v6.1.3.1/activesupport/lib/active_support/core_ext/object/blank.rb
5
+ # Slight modification on +String#blank?+: encoding error means false for simplicity
6
+
7
+ class Object
8
+ # An object is blank if it's false, empty, or a whitespace string.
9
+ # For example, +nil+, '', ' ', [], {}, and +false+ are all blank.
10
+ #
11
+ # This simplifies
12
+ #
13
+ # !address || address.empty?
14
+ #
15
+ # to
16
+ #
17
+ # address.blank?
18
+ #
19
+ # @return [true, false]
20
+ def blank?
21
+ respond_to?(:empty?) ? !!empty? : !self
22
+ end
23
+
24
+ # An object is present if it's not blank.
25
+ #
26
+ # @return [true, false]
27
+ def present?
28
+ !blank?
29
+ end
30
+
31
+ # Returns the receiver if it's present otherwise returns +nil+.
32
+ # <tt>object.presence</tt> is equivalent to
33
+ #
34
+ # object.present? ? object : nil
35
+ #
36
+ # For example, something like
37
+ #
38
+ # state = params[:state] if params[:state].present?
39
+ # country = params[:country] if params[:country].present?
40
+ # region = state || country || 'US'
41
+ #
42
+ # becomes
43
+ #
44
+ # region = params[:state].presence || params[:country].presence || 'US'
45
+ #
46
+ # @return [Object]
47
+ def presence
48
+ self if present?
49
+ end
50
+ end
51
+
52
+ class NilClass
53
+ # +nil+ is blank:
54
+ #
55
+ # nil.blank? # => true
56
+ #
57
+ # @return [true]
58
+ def blank?
59
+ true
60
+ end
61
+ end
62
+
63
+ class FalseClass
64
+ # +false+ is blank:
65
+ #
66
+ # false.blank? # => true
67
+ #
68
+ # @return [true]
69
+ def blank?
70
+ true
71
+ end
72
+ end
73
+
74
+ class TrueClass
75
+ # +true+ is not blank:
76
+ #
77
+ # true.blank? # => false
78
+ #
79
+ # @return [false]
80
+ def blank?
81
+ false
82
+ end
83
+ end
84
+
85
+ class Array
86
+ # An array is blank if it's empty:
87
+ #
88
+ # [].blank? # => true
89
+ # [1,2,3].blank? # => false
90
+ #
91
+ # @return [true, false]
92
+ alias blank? empty?
93
+ end
94
+
95
+ class Hash
96
+ # A hash is blank if it's empty:
97
+ #
98
+ # {}.blank? # => true
99
+ # { key: 'value' }.blank? # => false
100
+ #
101
+ # @return [true, false]
102
+ alias blank? empty?
103
+ end
104
+
105
+ class String
106
+ BLANK_RE ||= /\A[[:space:]]*\z/.freeze
107
+
108
+ # A string is blank if it's empty or contains whitespaces only:
109
+ #
110
+ # ''.blank? # => true
111
+ # ' '.blank? # => true
112
+ # "\t\n\r".blank? # => true
113
+ # ' blah '.blank? # => false
114
+ #
115
+ # Unicode whitespace is supported:
116
+ #
117
+ # "\u00a0".blank? # => true
118
+ #
119
+ # @return [true, false]
120
+ def blank?
121
+ # The regexp that matches blank strings is expensive. For the case of empty
122
+ # strings we can speed up this method (~3.5x) with an empty? call. The
123
+ # penalty for the rest of strings is marginal.
124
+ empty? ||
125
+ begin
126
+ BLANK_RE.match?(self)
127
+ rescue Encoding::CompatibilityError
128
+ false
129
+ end
130
+ end
131
+ end
132
+
133
+ class Numeric #:nodoc:
134
+ # No number is blank:
135
+ #
136
+ # 1.blank? # => false
137
+ # 0.blank? # => false
138
+ #
139
+ # @return [false]
140
+ def blank?
141
+ false
142
+ end
143
+ end
144
+
145
+ class Time #:nodoc:
146
+ # No Time is blank:
147
+ #
148
+ # Time.now.blank? # => false
149
+ #
150
+ # @return [false]
151
+ def blank?
152
+ false
153
+ end
154
+ end
155
+ # rubocop:enable all
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+ # rubocop:disable all
3
+
4
+ class String
5
+ # Converts strings to UpperCamelCase.
6
+ #
7
+ # Also converts '/' to '::' which is useful for converting
8
+ # paths to namespaces.
9
+ #
10
+ # camelize('active_model') # => "ActiveModel"
11
+ # camelize('active_model/errors') # => "ActiveModel::Errors"
12
+ #
13
+ # Modified copy of +ActiveSupport::Inflector.camelize+.
14
+ # Since I did not need those features, I removed the handling of the +:lower+ parameter and the
15
+ # handling of acronyms.
16
+ # https://github.com/rails/rails/blob/v6.1.3.1/activesupport/lib/active_support/inflector/methods.rb
17
+ def camelize
18
+ string = to_s
19
+ string = string.sub(/^[a-z\d]*/) { |match| match.capitalize! || match }
20
+ string.gsub!(%r{(?:_|(/))([a-z\d]*)}i) do
21
+ word = Regexp.last_match(2)
22
+ substituted = word.capitalize! || word
23
+ Regexp.last_match(1) ? "::#{substituted}" : substituted
24
+ end
25
+ string
26
+ end
27
+
28
+ def constantize
29
+ Object.const_get(self)
30
+ end
31
+ end
32
+ # rubocop:enable all