From f600f81ef5a2bb661df40557d68821170004d453 Mon Sep 17 00:00:00 2001 From: alvinkatojr Date: Wed, 24 Jun 2020 06:46:26 +0300 Subject: [PATCH 01/14] Sets up rubocop, adds yaml config files --- .rubocop.yml | 1 + .rubocop_todo.yml | 351 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 352 insertions(+) create mode 100644 .rubocop.yml create mode 100644 .rubocop_todo.yml diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 0000000..cc32da4 --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1 @@ +inherit_from: .rubocop_todo.yml diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml new file mode 100644 index 0000000..b912301 --- /dev/null +++ b/.rubocop_todo.yml @@ -0,0 +1,351 @@ +# This configuration was generated by +# `rubocop --auto-gen-config` +# on 2020-06-24 06:31:38 +0300 using RuboCop version 0.85.1. +# The point is for the user to remove these configuration records +# one by one as the offenses are removed from the code base. +# Note that changes in the inspected code, or installation of new +# versions of RuboCop, may require this file to be generated again. + +# Offense count: 3 +# Cop supports --auto-correct. +# Configuration parameters: TreatCommentsAsGroupSeparators, Include. +# Include: **/*.gemspec +Gemspec/OrderedDependencies: + Exclude: + - 'beyonic.gemspec' + +# Offense count: 1 +# Cop supports --auto-correct. +Layout/EmptyLineAfterMagicComment: + Exclude: + - 'beyonic.gemspec' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: AllowAdjacentOneLineDefs, NumberOfEmptyLines. +Layout/EmptyLineBetweenDefs: + Exclude: + - 'lib/beyonic/abstract_api.rb' + +# Offense count: 3 +# Cop supports --auto-correct. +Layout/EmptyLines: + Exclude: + - 'lib/beyonic/abstract_api.rb' + - 'spec/beyonic/metadata_spec.rb' + - 'spec/spec_helper.rb' + +# Offense count: 6 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: empty_lines, no_empty_lines +Layout/EmptyLinesAroundBlockBody: + Exclude: + - 'spec/beyonic/collection_request_spec.rb' + - 'spec/beyonic/metadata_spec.rb' + - 'spec/beyonic/payment_spec.rb' + - 'spec/beyonic/webhook_spec.rb' + +# Offense count: 7 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: empty_lines, empty_lines_except_namespace, empty_lines_special, no_empty_lines +Layout/EmptyLinesAroundModuleBody: + Exclude: + - 'lib/beyonic.rb' + - 'lib/beyonic/abstract_api.rb' + +# Offense count: 18 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, IndentationWidth. +# SupportedStyles: consistent, consistent_relative_to_receiver, special_for_inner_method_call, special_for_inner_method_call_in_parentheses +Layout/FirstArgumentIndentation: + Exclude: + - 'spec/beyonic/accounts_spec.rb' + - 'spec/beyonic/collection_request_spec.rb' + - 'spec/beyonic/collection_spec.rb' + - 'spec/beyonic/metadata_spec.rb' + - 'spec/beyonic/payment_spec.rb' + - 'spec/beyonic/webhook_spec.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: Width, IgnoredPatterns. +Layout/IndentationWidth: + Exclude: + - 'spec/beyonic/webhook_spec.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: AllowDoxygenCommentStyle, AllowGemfileRubyComment. +Layout/LeadingCommentSpace: + Exclude: + - 'lib/beyonic/abstract_api.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +Layout/RescueEnsureAlignment: + Exclude: + - 'lib/beyonic/abstract_api.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +Layout/SpaceAfterComma: + Exclude: + - 'lib/beyonic/abstract_api.rb' + +# Offense count: 4 +# Cop supports --auto-correct. +# Configuration parameters: AllowForAlignment, EnforcedStyleForExponentOperator. +# SupportedStylesForExponentOperator: space, no_space +Layout/SpaceAroundOperators: + Exclude: + - 'lib/beyonic/abstract_api.rb' + - 'spec/beyonic/webhook_spec.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces. +# SupportedStyles: space, no_space +# SupportedStylesForEmptyBraces: space, no_space +Layout/SpaceBeforeBlockBraces: + Exclude: + - 'spec/beyonic/webhook_spec.rb' + +# Offense count: 2 +# Cop supports --auto-correct. +# Configuration parameters: AllowForAlignment. +Layout/SpaceBeforeFirstArg: + Exclude: + - 'lib/beyonic/abstract_api.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces, SpaceBeforeBlockParameters. +# SupportedStyles: space, no_space +# SupportedStylesForEmptyBraces: space, no_space +Layout/SpaceInsideBlockBraces: + Exclude: + - 'lib/beyonic/abstract_api.rb' + +# Offense count: 46 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces. +# SupportedStyles: space, no_space, compact +# SupportedStylesForEmptyBraces: space, no_space +Layout/SpaceInsideHashLiteralBraces: + Exclude: + - 'lib/beyonic/abstract_api.rb' + - 'spec/beyonic/accounts_spec.rb' + - 'spec/beyonic/collection_request_spec.rb' + - 'spec/beyonic/collection_spec.rb' + - 'spec/beyonic/metadata_spec.rb' + - 'spec/beyonic/payment_spec.rb' + - 'spec/beyonic/webhook_spec.rb' + +# Offense count: 7 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: final_newline, final_blank_line +Layout/TrailingEmptyLines: + Exclude: + - 'Gemfile' + - 'Rakefile' + - 'lib/beyonic/collection_request.rb' + - 'lib/beyonic/contact.rb' + - 'lib/beyonic/payment.rb' + - 'lib/beyonic/webhook.rb' + - 'spec/beyonic/webhook_spec.rb' + +# Offense count: 60 +# Cop supports --auto-correct. +# Configuration parameters: AllowInHeredoc. +Layout/TrailingWhitespace: + Exclude: + - 'spec/beyonic/collection_request_spec.rb' + - 'spec/beyonic/collection_spec.rb' + - 'spec/beyonic/payment_spec.rb' + - 'spec/beyonic/webhook_spec.rb' + - 'spec/spec_helper.rb' + +# Offense count: 2 +# Cop supports --auto-correct. +# Configuration parameters: IgnoreEmptyBlocks, AllowUnusedKeywordArguments. +Lint/UnusedBlockArgument: + Exclude: + - 'lib/beyonic/abstract_api.rb' + - 'spec/spec_helper.rb' + +# Offense count: 1 +# Configuration parameters: IgnoredMethods. +Metrics/AbcSize: + Max: 17 + +# Offense count: 21 +# Configuration parameters: CountComments, ExcludedMethods. +# ExcludedMethods: refine +Metrics/BlockLength: + Max: 272 + +# Offense count: 1 +Naming/AccessorMethodName: + Exclude: + - 'lib/beyonic/abstract_api.rb' + +# Offense count: 82 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, ProceduralMethods, FunctionalMethods, IgnoredMethods, AllowBracesOnProceduralOneLiners, BracesRequiredMethods. +# SupportedStyles: line_count_based, semantic, braces_for_chaining, always_braces +# ProceduralMethods: benchmark, bm, bmbm, create, each_with_object, measure, new, realtime, tap, with_object +# FunctionalMethods: let, let!, subject, watch +# IgnoredMethods: lambda, proc, it +Style/BlockDelimiters: + Exclude: + - 'spec/beyonic/accounts_spec.rb' + - 'spec/beyonic/collection_request_spec.rb' + - 'spec/beyonic/collection_spec.rb' + - 'spec/beyonic/metadata_spec.rb' + - 'spec/beyonic/payment_spec.rb' + - 'spec/beyonic/webhook_spec.rb' + +# Offense count: 10 +# Cop supports --auto-correct. +# Configuration parameters: AutoCorrect, EnforcedStyle. +# SupportedStyles: nested, compact +Style/ClassAndModuleChildren: + Exclude: + - 'lib/beyonic/abstract_api.rb' + - 'lib/beyonic/account.rb' + - 'lib/beyonic/collection.rb' + - 'lib/beyonic/collection_request.rb' + - 'lib/beyonic/contact.rb' + - 'lib/beyonic/currency.rb' + - 'lib/beyonic/network.rb' + - 'lib/beyonic/payment.rb' + - 'lib/beyonic/transaction.rb' + - 'lib/beyonic/webhook.rb' + +# Offense count: 14 +Style/Documentation: + Exclude: + - 'spec/**/*' + - 'test/**/*' + - 'lib/beyonic.rb' + - 'lib/beyonic/abstract_api.rb' + - 'lib/beyonic/account.rb' + - 'lib/beyonic/collection.rb' + - 'lib/beyonic/collection_request.rb' + - 'lib/beyonic/contact.rb' + - 'lib/beyonic/currency.rb' + - 'lib/beyonic/network.rb' + - 'lib/beyonic/payment.rb' + - 'lib/beyonic/transaction.rb' + - 'lib/beyonic/webhook.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +Style/Encoding: + Exclude: + - 'beyonic.gemspec' + +# Offense count: 1 +# Cop supports --auto-correct. +Style/ExpandPathArguments: + Exclude: + - 'beyonic.gemspec' + +# Offense count: 22 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: always, always_true, never +Style/FrozenStringLiteralComment: + Enabled: false + +# Offense count: 25 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: line_count_dependent, lambda, literal +Style/Lambda: + Exclude: + - 'spec/beyonic/accounts_spec.rb' + - 'spec/beyonic/collection_request_spec.rb' + - 'spec/beyonic/collection_spec.rb' + - 'spec/beyonic/payment_spec.rb' + - 'spec/beyonic/webhook_spec.rb' + +# Offense count: 2 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: literals, strict +Style/MutableConstant: + Exclude: + - 'lib/beyonic/version.rb' + - 'spec/beyonic/accounts_spec.rb' + +# Offense count: 2 +# Cop supports --auto-correct. +# Configuration parameters: PreferredDelimiters. +Style/PercentLiteralDelimiters: + Exclude: + - 'beyonic.gemspec' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: short, verbose +Style/PreferredHashMethods: + Exclude: + - 'lib/beyonic/abstract_api.rb' + +# Offense count: 2 +# Cop supports --auto-correct. +# Configuration parameters: . +# SupportedStyles: compact, exploded +Style/RaiseArgs: + EnforcedStyle: compact + +# Offense count: 1 +# Cop supports --auto-correct. +Style/RedundantInterpolation: + Exclude: + - 'spec/beyonic/accounts_spec.rb' + +# Offense count: 4 +# Cop supports --auto-correct. +Style/RedundantParentheses: + Exclude: + - 'lib/beyonic/abstract_api.rb' + - 'spec/beyonic/webhook_spec.rb' + +# Offense count: 2 +# Cop supports --auto-correct. +Style/RedundantPercentQ: + Exclude: + - 'beyonic.gemspec' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: AllowMultipleReturnValues. +Style/RedundantReturn: + Exclude: + - 'lib/beyonic/abstract_api.rb' + +# Offense count: 5 +# Cop supports --auto-correct. +Style/RedundantSelf: + Exclude: + - 'lib/beyonic/abstract_api.rb' + +# Offense count: 213 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, ConsistentQuotesInMultiline. +# SupportedStyles: single_quotes, double_quotes +Style/StringLiterals: + Enabled: false + +# Offense count: 5 +# Cop supports --auto-correct. +# Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns. +# URISchemes: http, https +Layout/LineLength: + Max: 168 From c969b1f67653abf11b6006662264ef77535a5963 Mon Sep 17 00:00:00 2001 From: alvinkatojr Date: Wed, 24 Jun 2020 06:53:03 +0300 Subject: [PATCH 02/14] Rubocop fix: enforces single quotes for string --- .rubocop.yml | 4 ++ .rubocop_todo.yml | 7 --- Rakefile | 2 +- beyonic.gemspec | 30 ++++++------ lib/beyonic.rb | 28 +++++------ lib/beyonic/abstract_api.rb | 12 ++--- lib/beyonic/account.rb | 2 +- lib/beyonic/collection.rb | 2 +- lib/beyonic/collection_request.rb | 2 +- lib/beyonic/contact.rb | 2 +- lib/beyonic/currency.rb | 2 +- lib/beyonic/network.rb | 2 +- lib/beyonic/payment.rb | 2 +- lib/beyonic/transaction.rb | 2 +- lib/beyonic/version.rb | 2 +- lib/beyonic/webhook.rb | 2 +- spec/beyonic/accounts_spec.rb | 12 ++--- spec/beyonic/collection_request_spec.rb | 32 ++++++------- spec/beyonic/collection_spec.rb | 34 ++++++------- spec/beyonic/metadata_spec.rb | 26 +++++----- spec/beyonic/payment_spec.rb | 46 +++++++++--------- spec/beyonic/webhook_spec.rb | 64 ++++++++++++------------- spec/spec_helper.rb | 2 +- 23 files changed, 158 insertions(+), 161 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index cc32da4..414cdc1 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1 +1,5 @@ inherit_from: .rubocop_todo.yml + +Style/StringLiterals: + EnforcedStyle: single_quotes + Enabled: true diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index b912301..a6360b8 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -336,13 +336,6 @@ Style/RedundantSelf: Exclude: - 'lib/beyonic/abstract_api.rb' -# Offense count: 213 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, ConsistentQuotesInMultiline. -# SupportedStyles: single_quotes, double_quotes -Style/StringLiterals: - Enabled: false - # Offense count: 5 # Cop supports --auto-correct. # Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns. diff --git a/Rakefile b/Rakefile index 809eb56..33eb07c 100644 --- a/Rakefile +++ b/Rakefile @@ -1,2 +1,2 @@ -require "bundler/gem_tasks" +require 'bundler/gem_tasks' diff --git a/beyonic.gemspec b/beyonic.gemspec index b1c689b..4016a7c 100644 --- a/beyonic.gemspec +++ b/beyonic.gemspec @@ -4,29 +4,29 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require 'beyonic/version' Gem::Specification.new do |spec| - spec.name = "beyonic" + spec.name = 'beyonic' spec.version = Beyonic::VERSION spec.authors = ['Oleg German', 'Luke Kyohere'] spec.email = ['oleg.german@gmail.com', 'luke@beyonic.com'] spec.summary = %q{Ruby library for the beyonic.com api} spec.description = %q{Beyonic.com makes enterprise payments to mobile easy. Details: http://beyonic.com} - spec.homepage = "http://support.beyonic.com/api/" - spec.license = "MIT" + spec.homepage = 'http://support.beyonic.com/api/' + spec.license = 'MIT' - spec.files = Dir["{lib}/**/*.rb", "bin/*", "LICENSE", "*.md"] + spec.files = Dir['{lib}/**/*.rb', 'bin/*', 'LICENSE', '*.md'] spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) } spec.test_files = spec.files.grep(%r{^(test|spec|features)/}) - spec.require_paths = ["lib"] + spec.require_paths = ['lib'] - spec.add_runtime_dependency "rest-client" - spec.add_runtime_dependency "oj", "~> 2.11" - spec.add_runtime_dependency "addressable" + spec.add_runtime_dependency 'rest-client' + spec.add_runtime_dependency 'oj', '~> 2.11' + spec.add_runtime_dependency 'addressable' - spec.add_development_dependency "bundler", "~> 1.7" - spec.add_development_dependency "rake", "~> 12.3.3" - spec.add_development_dependency "rspec" - spec.add_development_dependency "rspec-collection_matchers" - spec.add_development_dependency "webmock" - spec.add_development_dependency "simplecov" - spec.add_development_dependency "vcr" + spec.add_development_dependency 'bundler', '~> 1.7' + spec.add_development_dependency 'rake', '~> 12.3.3' + spec.add_development_dependency 'rspec' + spec.add_development_dependency 'rspec-collection_matchers' + spec.add_development_dependency 'webmock' + spec.add_development_dependency 'simplecov' + spec.add_development_dependency 'vcr' end diff --git a/lib/beyonic.rb b/lib/beyonic.rb index 07f10f4..f542a91 100644 --- a/lib/beyonic.rb +++ b/lib/beyonic.rb @@ -1,7 +1,7 @@ module Beyonic - require "rest-client" - require "oj" + require 'rest-client' + require 'oj' # Uncomment this if you are testing on your server and you want to bypass SSL checks. # OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE @@ -23,19 +23,19 @@ def self.api_version end def self.endpoint_base - "https://app.beyonic.us/api/" + 'https://app.beyonic.us/api/' end end -require "beyonic/version" -require "beyonic/abstract_api" -require "beyonic/payment" -require "beyonic/webhook" -require "beyonic/collection" -require "beyonic/collection_request" -require "beyonic/account" -require "beyonic/contact" -require "beyonic/transaction" -require "beyonic/currency" -require "beyonic/network" +require 'beyonic/version' +require 'beyonic/abstract_api' +require 'beyonic/payment' +require 'beyonic/webhook' +require 'beyonic/collection' +require 'beyonic/collection_request' +require 'beyonic/account' +require 'beyonic/contact' +require 'beyonic/transaction' +require 'beyonic/currency' +require 'beyonic/network' diff --git a/lib/beyonic/abstract_api.rb b/lib/beyonic/abstract_api.rb index f4eaa24..ef278b8 100644 --- a/lib/beyonic/abstract_api.rb +++ b/lib/beyonic/abstract_api.rb @@ -24,7 +24,7 @@ def create(payload = {}, header_overrides = {}) def list(payload = {}) # Turn payload into query parameters - require "addressable/uri" + require 'addressable/uri' uri = Addressable::URI.new uri.query_values = payload @@ -48,17 +48,17 @@ def update(id, payload, header_overrides = {}) def delete(id) resp = RestClient.delete("#{@endpoint_url}/#{id}", headers) - return true if resp == "" + return true if resp == '' end private def headers(header_overrides = {}) headers_hash = {} - headers_hash.merge!({"Authorization" => "Token #{Beyonic.api_key}"}) if Beyonic.api_key - headers_hash.merge!({"Beyonic-Version" => Beyonic.api_version}) if Beyonic.api_version - headers_hash.merge!({"Beyonic-Client" => "Ruby"}) - headers_hash.merge!({"Beyonic-Client-Version" => Beyonic::VERSION}) + headers_hash.merge!({'Authorization' => "Token #{Beyonic.api_key}"}) if Beyonic.api_key + headers_hash.merge!({'Beyonic-Version' => Beyonic.api_version}) if Beyonic.api_version + headers_hash.merge!({'Beyonic-Client' => 'Ruby'}) + headers_hash.merge!({'Beyonic-Client-Version' => Beyonic::VERSION}) headers_hash.merge!(header_overrides) headers_hash end diff --git a/lib/beyonic/account.rb b/lib/beyonic/account.rb index 4511e15..ec9d9bc 100644 --- a/lib/beyonic/account.rb +++ b/lib/beyonic/account.rb @@ -1,5 +1,5 @@ require 'ostruct' class Beyonic::Account < OpenStruct include Beyonic::AbstractApi - set_endpoint_resource "accounts" + set_endpoint_resource 'accounts' end diff --git a/lib/beyonic/collection.rb b/lib/beyonic/collection.rb index a7d8d53..55f8992 100644 --- a/lib/beyonic/collection.rb +++ b/lib/beyonic/collection.rb @@ -1,5 +1,5 @@ require 'ostruct' class Beyonic::Collection < OpenStruct include Beyonic::AbstractApi - set_endpoint_resource "collections" + set_endpoint_resource 'collections' end diff --git a/lib/beyonic/collection_request.rb b/lib/beyonic/collection_request.rb index 73e9ea9..a3f5a4c 100644 --- a/lib/beyonic/collection_request.rb +++ b/lib/beyonic/collection_request.rb @@ -1,5 +1,5 @@ require 'ostruct' class Beyonic::CollectionRequest < OpenStruct include Beyonic::AbstractApi - set_endpoint_resource "collectionrequests" + set_endpoint_resource 'collectionrequests' end \ No newline at end of file diff --git a/lib/beyonic/contact.rb b/lib/beyonic/contact.rb index 99a06e0..1e78584 100644 --- a/lib/beyonic/contact.rb +++ b/lib/beyonic/contact.rb @@ -1,5 +1,5 @@ require 'ostruct' class Beyonic::Contact < OpenStruct include Beyonic::AbstractApi - set_endpoint_resource "contacts" + set_endpoint_resource 'contacts' end \ No newline at end of file diff --git a/lib/beyonic/currency.rb b/lib/beyonic/currency.rb index 6ca359b..d8396cc 100644 --- a/lib/beyonic/currency.rb +++ b/lib/beyonic/currency.rb @@ -1,5 +1,5 @@ require 'ostruct' class Beyonic::Currency < OpenStruct include Beyonic::AbstractApi - set_endpoint_resource "currencies" + set_endpoint_resource 'currencies' end diff --git a/lib/beyonic/network.rb b/lib/beyonic/network.rb index 56b5a3a..5a8d6d6 100644 --- a/lib/beyonic/network.rb +++ b/lib/beyonic/network.rb @@ -1,5 +1,5 @@ require 'ostruct' class Beyonic::Network < OpenStruct include Beyonic::AbstractApi - set_endpoint_resource "networks" + set_endpoint_resource 'networks' end diff --git a/lib/beyonic/payment.rb b/lib/beyonic/payment.rb index 580475f..96155e2 100644 --- a/lib/beyonic/payment.rb +++ b/lib/beyonic/payment.rb @@ -1,5 +1,5 @@ require 'ostruct' class Beyonic::Payment < OpenStruct include Beyonic::AbstractApi - set_endpoint_resource "payments" + set_endpoint_resource 'payments' end \ No newline at end of file diff --git a/lib/beyonic/transaction.rb b/lib/beyonic/transaction.rb index bed5873..3f056fa 100644 --- a/lib/beyonic/transaction.rb +++ b/lib/beyonic/transaction.rb @@ -1,5 +1,5 @@ require 'ostruct' class Beyonic::Transaction < OpenStruct include Beyonic::AbstractApi - set_endpoint_resource "transactions" + set_endpoint_resource 'transactions' end diff --git a/lib/beyonic/version.rb b/lib/beyonic/version.rb index d210918..021e919 100644 --- a/lib/beyonic/version.rb +++ b/lib/beyonic/version.rb @@ -1,3 +1,3 @@ module Beyonic - VERSION = "0.0.15" + VERSION = '0.0.15' end diff --git a/lib/beyonic/webhook.rb b/lib/beyonic/webhook.rb index 5c71481..e6bd704 100644 --- a/lib/beyonic/webhook.rb +++ b/lib/beyonic/webhook.rb @@ -1,5 +1,5 @@ require 'ostruct' class Beyonic::Webhook < OpenStruct include Beyonic::AbstractApi - set_endpoint_resource "webhooks" + set_endpoint_resource 'webhooks' end \ No newline at end of file diff --git a/spec/beyonic/accounts_spec.rb b/spec/beyonic/accounts_spec.rb index d7c9d75..dc788d2 100644 --- a/spec/beyonic/accounts_spec.rb +++ b/spec/beyonic/accounts_spec.rb @@ -2,13 +2,13 @@ describe Beyonic::Account do before { - Beyonic.api_key = "d349087313cc7a6627d77ab61163d4dab6449b4c" - Beyonic.api_version = "v1" - API_ENDPOINT = "https://staging.beyonic.com/api/accounts" + Beyonic.api_key = 'd349087313cc7a6627d77ab61163d4dab6449b4c' + Beyonic.api_version = 'v1' + API_ENDPOINT = 'https://staging.beyonic.com/api/accounts' Beyonic::Account.instance_variable_set(:@endpoint_url, API_ENDPOINT) } - describe ".list" do + describe '.list' do context 'Success response' do subject { VCR.use_cassette('accounts_list') do @@ -18,7 +18,7 @@ it { is_expected.to have_requested(:get, "#{API_ENDPOINT}").with( - headers: {"Authorization" => "Token #{Beyonic.api_key}", "Beyonic-Version" => Beyonic.api_version} + headers: {'Authorization' => "Token #{Beyonic.api_key}", 'Beyonic-Version' => Beyonic.api_version} ) } it { is_expected.to be_an(Array) } @@ -28,7 +28,7 @@ context 'Unauthorized' do before { - Beyonic.api_key = "invalid_key" + Beyonic.api_key = 'invalid_key' } subject { diff --git a/spec/beyonic/collection_request_spec.rb b/spec/beyonic/collection_request_spec.rb index f6983c1..e54066f 100644 --- a/spec/beyonic/collection_request_spec.rb +++ b/spec/beyonic/collection_request_spec.rb @@ -1,8 +1,8 @@ describe Beyonic::CollectionRequest do before { - Beyonic.api_key = "d349087313cc7a6627d77ab61163d4dab6449b4c" - Beyonic.api_version = "v1" - Beyonic::CollectionRequest.instance_variable_set(:@endpoint_url, "https://staging.beyonic.com/api/collectionrequests") + Beyonic.api_key = 'd349087313cc7a6627d77ab61163d4dab6449b4c' + Beyonic.api_version = 'v1' + Beyonic::CollectionRequest.instance_variable_set(:@endpoint_url, 'https://staging.beyonic.com/api/collectionrequests') } let(:payload) { @@ -19,20 +19,20 @@ end } - describe ".crate" do + describe '.crate' do context 'Success response' do subject { create_collection_requests } it { - is_expected.to have_requested(:post, "https://staging.beyonic.com/api/collectionrequests").with( - headers: {"Authorization" => "Token d349087313cc7a6627d77ab61163d4dab6449b4c", "Beyonic-Version" => "v1"} + is_expected.to have_requested(:post, 'https://staging.beyonic.com/api/collectionrequests').with( + headers: {'Authorization' => 'Token d349087313cc7a6627d77ab61163d4dab6449b4c', 'Beyonic-Version' => 'v1'} ) } it { is_expected.to be_an(Beyonic::CollectionRequest) } - it { is_expected.to have_attributes(id: create_collection_requests.id, currency: "UGX") } + it { is_expected.to have_attributes(id: create_collection_requests.id, currency: 'UGX') } end context 'Bad request' do @@ -50,7 +50,7 @@ context 'Unauthorized' do before { - Beyonic.api_key = "invalid_key" + Beyonic.api_key = 'invalid_key' } subject { @@ -67,7 +67,7 @@ end - describe ".list" do + describe '.list' do context 'Success response' do subject { VCR.use_cassette('collection_requests_list') do @@ -76,8 +76,8 @@ } it { - is_expected.to have_requested(:get, "https://staging.beyonic.com/api/collectionrequests").with( - headers: {"Authorization" => "Token d349087313cc7a6627d77ab61163d4dab6449b4c", "Beyonic-Version" => "v1"} + is_expected.to have_requested(:get, 'https://staging.beyonic.com/api/collectionrequests').with( + headers: {'Authorization' => 'Token d349087313cc7a6627d77ab61163d4dab6449b4c', 'Beyonic-Version' => 'v1'} ) } it { is_expected.to be_an(Array) } @@ -87,7 +87,7 @@ context 'Unauthorized' do before { - Beyonic.api_key = "invalid_key" + Beyonic.api_key = 'invalid_key' } subject { @@ -104,7 +104,7 @@ end end - describe ".get" do + describe '.get' do context 'Success response' do subject { VCR.use_cassette('collection_requests_get') do @@ -114,17 +114,17 @@ it { is_expected.to have_requested(:get, "https://staging.beyonic.com/api/collectionrequests/#{create_collection_requests.id}").with( - headers: {"Authorization" => "Token d349087313cc7a6627d77ab61163d4dab6449b4c", "Beyonic-Version" => "v1"} + headers: {'Authorization' => 'Token d349087313cc7a6627d77ab61163d4dab6449b4c', 'Beyonic-Version' => 'v1'} ) } it { is_expected.to be_an(Beyonic::CollectionRequest) } - it { is_expected.to have_attributes(id: create_collection_requests.id, currency: "UGX") } + it { is_expected.to have_attributes(id: create_collection_requests.id, currency: 'UGX') } end context 'Unauthorized' do before { - Beyonic.api_key = "invalid_key" + Beyonic.api_key = 'invalid_key' } subject { diff --git a/spec/beyonic/collection_spec.rb b/spec/beyonic/collection_spec.rb index 65418ec..5bd5786 100644 --- a/spec/beyonic/collection_spec.rb +++ b/spec/beyonic/collection_spec.rb @@ -2,13 +2,13 @@ describe Beyonic::Collection do before { - Beyonic.api_key = "d349087313cc7a6627d77ab61163d4dab6449b4c" - Beyonic.api_version = "v1" - Beyonic::Collection.instance_variable_set(:@endpoint_url, "https://staging.beyonic.com/api/collections") + Beyonic.api_key = 'd349087313cc7a6627d77ab61163d4dab6449b4c' + Beyonic.api_version = 'v1' + Beyonic::Collection.instance_variable_set(:@endpoint_url, 'https://staging.beyonic.com/api/collections') } - describe ".list" do + describe '.list' do context 'Success response' do subject { VCR.use_cassette('collections_list') do @@ -17,8 +17,8 @@ } it { - is_expected.to have_requested(:get, "https://staging.beyonic.com/api/collections").with( - headers: {"Authorization" => "Token d349087313cc7a6627d77ab61163d4dab6449b4c", "Beyonic-Version" => "v1"} + is_expected.to have_requested(:get, 'https://staging.beyonic.com/api/collections').with( + headers: {'Authorization' => 'Token d349087313cc7a6627d77ab61163d4dab6449b4c', 'Beyonic-Version' => 'v1'} ) } it { is_expected.to be_an(Array) } @@ -35,8 +35,8 @@ } it { - is_expected.to have_requested(:get, "https://staging.beyonic.com/api/collections?phonenumber=%2B254727843600").with( - headers: {"Authorization" => "Token d349087313cc7a6627d77ab61163d4dab6449b4c", "Beyonic-Version" => "v1"} + is_expected.to have_requested(:get, 'https://staging.beyonic.com/api/collections?phonenumber=%2B254727843600').with( + headers: {'Authorization' => 'Token d349087313cc7a6627d77ab61163d4dab6449b4c', 'Beyonic-Version' => 'v1'} ) } it { is_expected.to be_an(Array) } @@ -48,7 +48,7 @@ context 'Unauthorized' do before { - Beyonic.api_key = "invalid_key" + Beyonic.api_key = 'invalid_key' } subject { @@ -65,7 +65,7 @@ end end - describe ".get" do + describe '.get' do context 'Success response' do subject { VCR.use_cassette('collections_get') do @@ -74,8 +74,8 @@ } it { - is_expected.to have_requested(:get, "https://staging.beyonic.com/api/collections/1").with( - headers: {"Authorization" => "Token d349087313cc7a6627d77ab61163d4dab6449b4c", "Beyonic-Version" => "v1"} + is_expected.to have_requested(:get, 'https://staging.beyonic.com/api/collections/1').with( + headers: {'Authorization' => 'Token d349087313cc7a6627d77ab61163d4dab6449b4c', 'Beyonic-Version' => 'v1'} ) } it { is_expected.to be_an(Beyonic::Collection) } @@ -85,7 +85,7 @@ context 'Unauthorized' do before { - Beyonic.api_key = "invalid_key" + Beyonic.api_key = 'invalid_key' } subject { @@ -115,7 +115,7 @@ end end - describe ".claim" do + describe '.claim' do context 'by Phonenumber' do subject { @@ -125,8 +125,8 @@ } it { - is_expected.to have_requested(:get, "https://staging.beyonic.com/api/collections?amount=200&claim=true&phonenumber=%2B254727843600&remote_transaction_id").with( - headers: {"Authorization" => "Token d349087313cc7a6627d77ab61163d4dab6449b4c", "Beyonic-Version" => "v1"} + is_expected.to have_requested(:get, 'https://staging.beyonic.com/api/collections?amount=200&claim=true&phonenumber=%2B254727843600&remote_transaction_id').with( + headers: {'Authorization' => 'Token d349087313cc7a6627d77ab61163d4dab6449b4c', 'Beyonic-Version' => 'v1'} ) } it { is_expected.to be_an(Array) } @@ -138,7 +138,7 @@ context 'Unauthorized' do before { - Beyonic.api_key = "invalid_key" + Beyonic.api_key = 'invalid_key' } subject { diff --git a/spec/beyonic/metadata_spec.rb b/spec/beyonic/metadata_spec.rb index 02ac126..b92729c 100644 --- a/spec/beyonic/metadata_spec.rb +++ b/spec/beyonic/metadata_spec.rb @@ -2,9 +2,9 @@ describe Beyonic::CollectionRequest do before { - Beyonic.api_key = "c4269a8029e8a7c5659d3cb7829ce1d7319b4689" - Beyonic.api_version = "v1" - Beyonic::CollectionRequest.instance_variable_set(:@endpoint_url, "https://staging.beyonic.com/api/collectionrequests") + Beyonic.api_key = 'c4269a8029e8a7c5659d3cb7829ce1d7319b4689' + Beyonic.api_version = 'v1' + Beyonic::CollectionRequest.instance_variable_set(:@endpoint_url, 'https://staging.beyonic.com/api/collectionrequests') } let(:array_notation_payload) { @@ -12,7 +12,7 @@ phonenumber: '+40715441309', currency: 'BXC', amount: 3000, - metadata: {"my_id": "123ASDAsd123"} + metadata: {"my_id": '123ASDAsd123'} } } @@ -21,11 +21,11 @@ phonenumber: '+40715441309', currency: 'BXC', amount: 3000, - 'metadata.my_id': "123ASDAsd123" + 'metadata.my_id': '123ASDAsd123' } } - describe ".create_array_notation" do + describe '.create_array_notation' do let!(:metadata_array_notation_request) { VCR.use_cassette('metadata_create_requests_array_notation') do Beyonic::CollectionRequest.create(array_notation_payload) @@ -37,16 +37,16 @@ } it { - is_expected.to have_requested(:post, "https://staging.beyonic.com/api/collectionrequests").with( - headers: {"Authorization" => "Token c4269a8029e8a7c5659d3cb7829ce1d7319b4689", "Beyonic-Version" => "v1"} + is_expected.to have_requested(:post, 'https://staging.beyonic.com/api/collectionrequests').with( + headers: {'Authorization' => 'Token c4269a8029e8a7c5659d3cb7829ce1d7319b4689', 'Beyonic-Version' => 'v1'} ) } it { is_expected.to be_an(Beyonic::CollectionRequest) } - it { is_expected.to have_attributes('metadata': metadata_array_notation_request.metadata, currency: "BXC") } + it { is_expected.to have_attributes('metadata': metadata_array_notation_request.metadata, currency: 'BXC') } end end - describe ".create_dot_notation" do + describe '.create_dot_notation' do let!(:metadata_dot_notation_request) { VCR.use_cassette('metadata_create_requests_dot_notation') do Beyonic::CollectionRequest.create(dot_notation_payload) @@ -58,12 +58,12 @@ } it { - is_expected.to have_requested(:post, "https://staging.beyonic.com/api/collectionrequests").with( - headers: {"Authorization" => "Token c4269a8029e8a7c5659d3cb7829ce1d7319b4689", "Beyonic-Version" => "v1"} + is_expected.to have_requested(:post, 'https://staging.beyonic.com/api/collectionrequests').with( + headers: {'Authorization' => 'Token c4269a8029e8a7c5659d3cb7829ce1d7319b4689', 'Beyonic-Version' => 'v1'} ) } it { is_expected.to be_an(Beyonic::CollectionRequest) } - it { is_expected.to have_attributes('metadata': metadata_dot_notation_request.metadata, currency: "BXC") } + it { is_expected.to have_attributes('metadata': metadata_dot_notation_request.metadata, currency: 'BXC') } end end diff --git a/spec/beyonic/payment_spec.rb b/spec/beyonic/payment_spec.rb index b2a31d8..a77fd91 100644 --- a/spec/beyonic/payment_spec.rb +++ b/spec/beyonic/payment_spec.rb @@ -2,19 +2,19 @@ describe Beyonic::Payment do before { - Beyonic.api_key = "d349087313cc7a6627d77ab61163d4dab6449b4c" - Beyonic.api_version = "v1" - Beyonic::Payment.instance_variable_set(:@endpoint_url, "https://staging.beyonic.com/api/payments") + Beyonic.api_key = 'd349087313cc7a6627d77ab61163d4dab6449b4c' + Beyonic.api_version = 'v1' + Beyonic::Payment.instance_variable_set(:@endpoint_url, 'https://staging.beyonic.com/api/payments') } let(:payload) { { - phonenumber: "+256773712831", - amount: "100.2", - currency: "UGX", - description: "Per diem payment", - payment_type: "money", - callback_url: "https://my.website/payments/callback", + phonenumber: '+256773712831', + amount: '100.2', + currency: 'UGX', + description: 'Per diem payment', + payment_type: 'money', + callback_url: 'https://my.website/payments/callback', metadata: "{'id': '1234', 'name': 'Lucy'}" } } @@ -25,15 +25,15 @@ end } - describe ".crate" do + describe '.crate' do context 'Success response' do subject { create_payment } it { - is_expected.to have_requested(:post, "https://staging.beyonic.com/api/payments").with( - headers: {"Authorization" => "Token d349087313cc7a6627d77ab61163d4dab6449b4c", "Beyonic-Version" => "v1"} + is_expected.to have_requested(:post, 'https://staging.beyonic.com/api/payments').with( + headers: {'Authorization' => 'Token d349087313cc7a6627d77ab61163d4dab6449b4c', 'Beyonic-Version' => 'v1'} ) } it { is_expected.to be_an(Beyonic::Payment) } @@ -56,7 +56,7 @@ context 'Unauthorized' do before { - Beyonic.api_key = "invalid_key" + Beyonic.api_key = 'invalid_key' } subject { @@ -73,7 +73,7 @@ end - describe ".list" do + describe '.list' do context 'Success response' do subject { VCR.use_cassette('payments_list') do @@ -82,8 +82,8 @@ } it { - is_expected.to have_requested(:get, "https://staging.beyonic.com/api/payments").with( - headers: {"Authorization" => "Token d349087313cc7a6627d77ab61163d4dab6449b4c", "Beyonic-Version" => "v1"} + is_expected.to have_requested(:get, 'https://staging.beyonic.com/api/payments').with( + headers: {'Authorization' => 'Token d349087313cc7a6627d77ab61163d4dab6449b4c', 'Beyonic-Version' => 'v1'} ) } it { is_expected.to be_an(Array) } @@ -93,7 +93,7 @@ context 'Unauthorized' do before { - Beyonic.api_key = "invalid_key" + Beyonic.api_key = 'invalid_key' } subject { @@ -110,7 +110,7 @@ end end - describe ".get" do + describe '.get' do context 'Success response' do subject { VCR.use_cassette('payments_get') do @@ -120,7 +120,7 @@ it { is_expected.to have_requested(:get, "https://staging.beyonic.com/api/payments/#{create_payment.id}").with( - headers: {"Authorization" => "Token d349087313cc7a6627d77ab61163d4dab6449b4c", "Beyonic-Version" => "v1"} + headers: {'Authorization' => 'Token d349087313cc7a6627d77ab61163d4dab6449b4c', 'Beyonic-Version' => 'v1'} ) } it { is_expected.to be_an(Beyonic::Payment) } @@ -130,7 +130,7 @@ context 'Unauthorized' do before { - Beyonic.api_key = "invalid_key" + Beyonic.api_key = 'invalid_key' } subject { @@ -160,7 +160,7 @@ end end - describe "#save" do + describe '#save' do context 'new object' do subject { Beyonic::Payment } @@ -180,12 +180,12 @@ allow(subject).to receive(:update) - create_payment.description = "foo" + create_payment.description = 'foo' create_payment.save } it { - is_expected.to have_received(:update).with(create_payment.id, hash_including(description: "foo")) + is_expected.to have_received(:update).with(create_payment.id, hash_including(description: 'foo')) } end end diff --git a/spec/beyonic/webhook_spec.rb b/spec/beyonic/webhook_spec.rb index 4cf9a3c..bf4d874 100644 --- a/spec/beyonic/webhook_spec.rb +++ b/spec/beyonic/webhook_spec.rb @@ -2,15 +2,15 @@ describe Beyonic::Webhook do before { - Beyonic.api_key = "d349087313cc7a6627d77ab61163d4dab6449b4c" - Beyonic.api_version = "v1" - Beyonic::Webhook.instance_variable_set(:@endpoint_url, "https://staging.beyonic.com/api/webhooks") + Beyonic.api_key = 'd349087313cc7a6627d77ab61163d4dab6449b4c' + Beyonic.api_version = 'v1' + Beyonic::Webhook.instance_variable_set(:@endpoint_url, 'https://staging.beyonic.com/api/webhooks') } let(:payload) { { - event: "payment.status.changed", - target: "https://my.callback.url/" + event: 'payment.status.changed', + target: 'https://my.callback.url/' } } @@ -20,15 +20,15 @@ end } - describe ".crate" do + describe '.crate' do context 'Success response' do subject { create_webhook } it { - is_expected.to have_requested(:post, "https://staging.beyonic.com/api/webhooks").with( - headers: {"Authorization" => "Token d349087313cc7a6627d77ab61163d4dab6449b4c", "Beyonic-Version" => "v1"} + is_expected.to have_requested(:post, 'https://staging.beyonic.com/api/webhooks').with( + headers: {'Authorization' => 'Token d349087313cc7a6627d77ab61163d4dab6449b4c', 'Beyonic-Version' => 'v1'} ) } it { is_expected.to be_an(Beyonic::Webhook) } @@ -51,7 +51,7 @@ context 'Unauthorized' do before { - Beyonic.api_key = "invalid_key" + Beyonic.api_key = 'invalid_key' } subject { -> { @@ -67,7 +67,7 @@ end - describe ".list" do + describe '.list' do context 'Success response' do subject { VCR.use_cassette('webhooks_list') do @@ -76,8 +76,8 @@ } it { - is_expected.to have_requested(:get, "https://staging.beyonic.com/api/webhooks").with( - headers: {"Authorization" => "Token d349087313cc7a6627d77ab61163d4dab6449b4c", "Beyonic-Version" => "v1"} + is_expected.to have_requested(:get, 'https://staging.beyonic.com/api/webhooks').with( + headers: {'Authorization' => 'Token d349087313cc7a6627d77ab61163d4dab6449b4c', 'Beyonic-Version' => 'v1'} ) } it { is_expected.to be_an(Array) } @@ -88,7 +88,7 @@ context 'Unauthorized' do before { - Beyonic.api_key = "invalid_key" + Beyonic.api_key = 'invalid_key' } subject { @@ -104,7 +104,7 @@ end end - describe ".get" do + describe '.get' do context 'Success response' do subject { VCR.use_cassette('webhooks_get') do @@ -114,7 +114,7 @@ it { is_expected.to have_requested(:get, "https://staging.beyonic.com/api/webhooks/#{create_webhook.id}").with( - headers: {"Authorization" => "Token d349087313cc7a6627d77ab61163d4dab6449b4c", "Beyonic-Version" => "v1"} + headers: {'Authorization' => 'Token d349087313cc7a6627d77ab61163d4dab6449b4c', 'Beyonic-Version' => 'v1'} ) } it { is_expected.to be_an(Beyonic::Webhook) } @@ -124,7 +124,7 @@ context 'Unauthorized' do before { - Beyonic.api_key = "invalid_key" + Beyonic.api_key = 'invalid_key' } subject { @@ -153,29 +153,29 @@ end end - describe ".update" do + describe '.update' do context 'Success response' do subject { VCR.use_cassette('webhooks_update') do - Beyonic::Webhook.update(create_webhook.id, target: "https://my.callback2.url/") + Beyonic::Webhook.update(create_webhook.id, target: 'https://my.callback2.url/') end } it { is_expected.to have_requested(:patch, "https://staging.beyonic.com/api/webhooks/#{create_webhook.id}").with( - headers: {"Authorization" => "Token d349087313cc7a6627d77ab61163d4dab6449b4c", "Beyonic-Version" => "v1"} + headers: {'Authorization' => 'Token d349087313cc7a6627d77ab61163d4dab6449b4c', 'Beyonic-Version' => 'v1'} ) } it { is_expected.to be_an(Beyonic::Webhook) } - it { is_expected.to have_attributes(id: create_webhook.id, target: "https://my.callback2.url/") } + it { is_expected.to have_attributes(id: create_webhook.id, target: 'https://my.callback2.url/') } end context 'Bad request' do subject { -> { VCR.use_cassette('webhooks_invalid_update') do - Beyonic::Webhook.update(create_webhook.id, event: "wrongevent") + Beyonic::Webhook.update(create_webhook.id, event: 'wrongevent') end } } @@ -188,7 +188,7 @@ subject { -> { VCR.use_cassette('webhooks_no_permissions_update') do - Beyonic::Webhook.update(666, target: "https://my.callback2.url/") + Beyonic::Webhook.update(666, target: 'https://my.callback2.url/') end } } @@ -200,14 +200,14 @@ context 'Unauthorized' do before { - Beyonic.api_key = "invalid_key" + Beyonic.api_key = 'invalid_key' create_webhook } subject { -> { VCR.use_cassette('webhooks_invalid_token_update') do - Beyonic::Webhook.update(create_webhook.id, target: "https://my.callback2.url/") + Beyonic::Webhook.update(create_webhook.id, target: 'https://my.callback2.url/') end } } @@ -217,7 +217,7 @@ end end - describe "#save" do + describe '#save' do context 'new object' do subject { Beyonic::Webhook } @@ -238,17 +238,17 @@ before { allow(subject).to receive(:update) - create_webhook.target = "https://google.com/" + create_webhook.target = 'https://google.com/' create_webhook.save } it { - is_expected.to have_received(:update).with(create_webhook.id, hash_including(target: "https://google.com/")) + is_expected.to have_received(:update).with(create_webhook.id, hash_including(target: 'https://google.com/')) } end end - describe "#id=" do + describe '#id=' do it { expect{ create_webhook.id=(4) @@ -263,12 +263,12 @@ it { expect { - create_webhook[:target]="foo" + create_webhook[:target]='foo' }.to_not raise_error } end - describe ".delete" do + describe '.delete' do context 'Success response' do subject { VCR.use_cassette('webhooks_delete') do @@ -278,7 +278,7 @@ it { is_expected.to have_requested(:delete, "https://staging.beyonic.com/api/webhooks/#{create_webhook.id}").with( - headers: {"Authorization" => "Token d349087313cc7a6627d77ab61163d4dab6449b4c", "Beyonic-Version" => "v1"} + headers: {'Authorization' => 'Token d349087313cc7a6627d77ab61163d4dab6449b4c', 'Beyonic-Version' => 'v1'} ) } it { is_expected.to be_truthy } @@ -300,7 +300,7 @@ context 'Unauthorized' do before { - Beyonic.api_key = "invalid_key" + Beyonic.api_key = 'invalid_key' } subject { diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 58d7019..7cd4f4e 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,6 +1,6 @@ require 'simplecov' SimpleCov.start do - add_filter "/spec/" + add_filter '/spec/' end From b89bdb7f668c8d4b4330a6f2c4f06a9d64f54bc9 Mon Sep 17 00:00:00 2001 From: alvinkatojr Date: Wed, 24 Jun 2020 07:31:00 +0300 Subject: [PATCH 03/14] Rubocop fix: enforces single line and multi-line sytax for block and lambdas --- .rubocop.yml | 7 ++ .rubocop_todo.yml | 28 ----- spec/beyonic/accounts_spec.rb | 18 ++-- spec/beyonic/collection_request_spec.rb | 66 ++++++------ spec/beyonic/collection_spec.rb | 56 +++++----- spec/beyonic/metadata_spec.rb | 28 ++--- spec/beyonic/payment_spec.rb | 74 ++++++------- spec/beyonic/webhook_spec.rb | 136 ++++++++++++------------ 8 files changed, 196 insertions(+), 217 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 414cdc1..ec3da9c 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,5 +1,12 @@ inherit_from: .rubocop_todo.yml +Style/BlockDelimiters: + Enabled: true + +Style/Lambda: + EnforcedStyle: line_count_dependent + Enabled: true + Style/StringLiterals: EnforcedStyle: single_quotes Enabled: true diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index a6360b8..ff7f883 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -192,22 +192,6 @@ Naming/AccessorMethodName: Exclude: - 'lib/beyonic/abstract_api.rb' -# Offense count: 82 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, ProceduralMethods, FunctionalMethods, IgnoredMethods, AllowBracesOnProceduralOneLiners, BracesRequiredMethods. -# SupportedStyles: line_count_based, semantic, braces_for_chaining, always_braces -# ProceduralMethods: benchmark, bm, bmbm, create, each_with_object, measure, new, realtime, tap, with_object -# FunctionalMethods: let, let!, subject, watch -# IgnoredMethods: lambda, proc, it -Style/BlockDelimiters: - Exclude: - - 'spec/beyonic/accounts_spec.rb' - - 'spec/beyonic/collection_request_spec.rb' - - 'spec/beyonic/collection_spec.rb' - - 'spec/beyonic/metadata_spec.rb' - - 'spec/beyonic/payment_spec.rb' - - 'spec/beyonic/webhook_spec.rb' - # Offense count: 10 # Cop supports --auto-correct. # Configuration parameters: AutoCorrect, EnforcedStyle. @@ -261,18 +245,6 @@ Style/ExpandPathArguments: Style/FrozenStringLiteralComment: Enabled: false -# Offense count: 25 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle. -# SupportedStyles: line_count_dependent, lambda, literal -Style/Lambda: - Exclude: - - 'spec/beyonic/accounts_spec.rb' - - 'spec/beyonic/collection_request_spec.rb' - - 'spec/beyonic/collection_spec.rb' - - 'spec/beyonic/payment_spec.rb' - - 'spec/beyonic/webhook_spec.rb' - # Offense count: 2 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle. diff --git a/spec/beyonic/accounts_spec.rb b/spec/beyonic/accounts_spec.rb index dc788d2..641ff3f 100644 --- a/spec/beyonic/accounts_spec.rb +++ b/spec/beyonic/accounts_spec.rb @@ -1,20 +1,20 @@ require 'spec_helper' describe Beyonic::Account do - before { + before do Beyonic.api_key = 'd349087313cc7a6627d77ab61163d4dab6449b4c' Beyonic.api_version = 'v1' API_ENDPOINT = 'https://staging.beyonic.com/api/accounts' Beyonic::Account.instance_variable_set(:@endpoint_url, API_ENDPOINT) - } + end describe '.list' do context 'Success response' do - subject { + subject do VCR.use_cassette('accounts_list') do Beyonic::Account.list end - } + end it { is_expected.to have_requested(:get, "#{API_ENDPOINT}").with( @@ -27,17 +27,17 @@ end context 'Unauthorized' do - before { + before do Beyonic.api_key = 'invalid_key' - } + end - subject { - -> { + subject do + lambda { VCR.use_cassette('accounts_invalid_token_list') do Beyonic::Account.list end } - } + end it { is_expected.to raise_error diff --git a/spec/beyonic/collection_request_spec.rb b/spec/beyonic/collection_request_spec.rb index e54066f..f153b72 100644 --- a/spec/beyonic/collection_request_spec.rb +++ b/spec/beyonic/collection_request_spec.rb @@ -1,29 +1,29 @@ describe Beyonic::CollectionRequest do - before { + before do Beyonic.api_key = 'd349087313cc7a6627d77ab61163d4dab6449b4c' Beyonic.api_version = 'v1' Beyonic::CollectionRequest.instance_variable_set(:@endpoint_url, 'https://staging.beyonic.com/api/collectionrequests') - } + end - let(:payload) { + let(:payload) do { phonenumber: '+256772781923', currency: 'UGX', amount: 3000 } - } + end - let!(:create_collection_requests) { + let!(:create_collection_requests) do VCR.use_cassette('collection_requests_create') do Beyonic::CollectionRequest.create(payload) end - } + end describe '.crate' do context 'Success response' do - subject { + subject do create_collection_requests - } + end it { is_expected.to have_requested(:post, 'https://staging.beyonic.com/api/collectionrequests').with( @@ -36,30 +36,30 @@ end context 'Bad request' do - subject { - -> { + subject do + lambda { VCR.use_cassette('collection_requests_invalid_create') do Beyonic::CollectionRequest.create(invalid_payload: true) end } - } + end it { is_expected.to raise_error(Beyonic::AbstractApi::ApiError) } end context 'Unauthorized' do - before { + before do Beyonic.api_key = 'invalid_key' - } + end - subject { - -> { + subject do + lambda { VCR.use_cassette('collection_requests_invalid_token_create') do Beyonic::CollectionRequest.create(payload) end } - } + end it { is_expected.to raise_error } @@ -69,11 +69,11 @@ describe '.list' do context 'Success response' do - subject { + subject do VCR.use_cassette('collection_requests_list') do Beyonic::CollectionRequest.list end - } + end it { is_expected.to have_requested(:get, 'https://staging.beyonic.com/api/collectionrequests').with( @@ -86,17 +86,17 @@ end context 'Unauthorized' do - before { + before do Beyonic.api_key = 'invalid_key' - } + end - subject { - -> { + subject do + lambda { VCR.use_cassette('collection_requests_invalid_token_list') do Beyonic::CollectionRequest.list end } - } + end it { is_expected.to raise_error @@ -106,11 +106,11 @@ describe '.get' do context 'Success response' do - subject { + subject do VCR.use_cassette('collection_requests_get') do Beyonic::CollectionRequest.get(create_collection_requests.id) end - } + end it { is_expected.to have_requested(:get, "https://staging.beyonic.com/api/collectionrequests/#{create_collection_requests.id}").with( @@ -123,17 +123,17 @@ end context 'Unauthorized' do - before { + before do Beyonic.api_key = 'invalid_key' - } + end - subject { - -> { + subject do + lambda { VCR.use_cassette('collection_requests_invalid_token_get') do Beyonic::CollectionRequest.get(create_collection_requests.id) end } - } + end it { is_expected.to raise_error @@ -141,13 +141,13 @@ end context 'Unauthorized' do - subject { - -> { + subject do + lambda { VCR.use_cassette('collection_requests_no_permissions_get') do Beyonic::CollectionRequest.get(666) end } - } + end it { is_expected.to raise_error } diff --git a/spec/beyonic/collection_spec.rb b/spec/beyonic/collection_spec.rb index 5bd5786..a9618e4 100644 --- a/spec/beyonic/collection_spec.rb +++ b/spec/beyonic/collection_spec.rb @@ -1,20 +1,20 @@ require 'spec_helper' describe Beyonic::Collection do - before { + before do Beyonic.api_key = 'd349087313cc7a6627d77ab61163d4dab6449b4c' Beyonic.api_version = 'v1' Beyonic::Collection.instance_variable_set(:@endpoint_url, 'https://staging.beyonic.com/api/collections') - } + end describe '.list' do context 'Success response' do - subject { + subject do VCR.use_cassette('collections_list') do Beyonic::Collection.list end - } + end it { is_expected.to have_requested(:get, 'https://staging.beyonic.com/api/collections').with( @@ -28,11 +28,11 @@ end context 'Phonenumber search' do - subject { + subject do VCR.use_cassette('collections_search') do Beyonic::Collection.list(phonenumber: '+254727843600') end - } + end it { is_expected.to have_requested(:get, 'https://staging.beyonic.com/api/collections?phonenumber=%2B254727843600').with( @@ -47,17 +47,17 @@ end context 'Unauthorized' do - before { + before do Beyonic.api_key = 'invalid_key' - } + end - subject { - -> { + subject do + lambda { VCR.use_cassette('collections_invalid_token_list') do Beyonic::Collection.list end } - } + end it { is_expected.to raise_error @@ -67,11 +67,11 @@ describe '.get' do context 'Success response' do - subject { + subject do VCR.use_cassette('collections_get') do Beyonic::Collection.get(1) end - } + end it { is_expected.to have_requested(:get, 'https://staging.beyonic.com/api/collections/1').with( @@ -84,17 +84,17 @@ end context 'Unauthorized' do - before { + before do Beyonic.api_key = 'invalid_key' - } + end - subject { - -> { + subject do + lambda { VCR.use_cassette('collections_invalid_token_get') do Beyonic::Collection.get(1) end } - } + end it { is_expected.to raise_error @@ -102,13 +102,13 @@ end context 'Unauthorized' do - subject { - -> { + subject do + lambda { VCR.use_cassette('collections_no_permissions_get') do Beyonic::Collection.get(666) end } - } + end it { is_expected.to raise_error } @@ -118,11 +118,11 @@ describe '.claim' do context 'by Phonenumber' do - subject { + subject do VCR.use_cassette('collections_claim') do Beyonic::Collection.claim(200, '+254727843600', nil) end - } + end it { is_expected.to have_requested(:get, 'https://staging.beyonic.com/api/collections?amount=200&claim=true&phonenumber=%2B254727843600&remote_transaction_id').with( @@ -137,17 +137,17 @@ end context 'Unauthorized' do - before { + before do Beyonic.api_key = 'invalid_key' - } + end - subject { - -> { + subject do + lambda { VCR.use_cassette('collections_invalid_token_claim') do Beyonic::Collection.claim(200, '+254727843600', nil) end } - } + end it { is_expected.to raise_error diff --git a/spec/beyonic/metadata_spec.rb b/spec/beyonic/metadata_spec.rb index b92729c..8c6ffe9 100644 --- a/spec/beyonic/metadata_spec.rb +++ b/spec/beyonic/metadata_spec.rb @@ -1,40 +1,40 @@ require 'spec_helper' describe Beyonic::CollectionRequest do - before { + before do Beyonic.api_key = 'c4269a8029e8a7c5659d3cb7829ce1d7319b4689' Beyonic.api_version = 'v1' Beyonic::CollectionRequest.instance_variable_set(:@endpoint_url, 'https://staging.beyonic.com/api/collectionrequests') - } + end - let(:array_notation_payload) { + let(:array_notation_payload) do { phonenumber: '+40715441309', currency: 'BXC', amount: 3000, metadata: {"my_id": '123ASDAsd123'} } - } + end - let(:dot_notation_payload) { + let(:dot_notation_payload) do { phonenumber: '+40715441309', currency: 'BXC', amount: 3000, 'metadata.my_id': '123ASDAsd123' } - } + end describe '.create_array_notation' do - let!(:metadata_array_notation_request) { + let!(:metadata_array_notation_request) do VCR.use_cassette('metadata_create_requests_array_notation') do Beyonic::CollectionRequest.create(array_notation_payload) end - } + end context 'Success response' do - subject { + subject do metadata_array_notation_request - } + end it { is_expected.to have_requested(:post, 'https://staging.beyonic.com/api/collectionrequests').with( @@ -47,15 +47,15 @@ end describe '.create_dot_notation' do - let!(:metadata_dot_notation_request) { + let!(:metadata_dot_notation_request) do VCR.use_cassette('metadata_create_requests_dot_notation') do Beyonic::CollectionRequest.create(dot_notation_payload) end - } + end context 'Success response' do - subject { + subject do metadata_dot_notation_request - } + end it { is_expected.to have_requested(:post, 'https://staging.beyonic.com/api/collectionrequests').with( diff --git a/spec/beyonic/payment_spec.rb b/spec/beyonic/payment_spec.rb index a77fd91..6a99529 100644 --- a/spec/beyonic/payment_spec.rb +++ b/spec/beyonic/payment_spec.rb @@ -1,13 +1,13 @@ require 'spec_helper' describe Beyonic::Payment do - before { + before do Beyonic.api_key = 'd349087313cc7a6627d77ab61163d4dab6449b4c' Beyonic.api_version = 'v1' Beyonic::Payment.instance_variable_set(:@endpoint_url, 'https://staging.beyonic.com/api/payments') - } + end - let(:payload) { + let(:payload) do { phonenumber: '+256773712831', amount: '100.2', @@ -17,19 +17,19 @@ callback_url: 'https://my.website/payments/callback', metadata: "{'id': '1234', 'name': 'Lucy'}" } - } + end - let!(:create_payment) { + let!(:create_payment) do VCR.use_cassette('payments_create') do Beyonic::Payment.create(payload) end - } + end describe '.crate' do context 'Success response' do - subject { + subject do create_payment - } + end it { is_expected.to have_requested(:post, 'https://staging.beyonic.com/api/payments').with( @@ -42,30 +42,30 @@ end context 'Bad request' do - subject { - -> { + subject do + lambda { VCR.use_cassette('payments_invalid_create') do Beyonic::Payment.create(invalid_payload: true) end } - } + end it { is_expected.to raise_error(Beyonic::AbstractApi::ApiError) } end context 'Unauthorized' do - before { + before do Beyonic.api_key = 'invalid_key' - } + end - subject { - -> { + subject do + lambda { VCR.use_cassette('payments_invalid_token_create') do Beyonic::Payment.create(payload) end } - } + end it { is_expected.to raise_error } @@ -75,11 +75,11 @@ describe '.list' do context 'Success response' do - subject { + subject do VCR.use_cassette('payments_list') do Beyonic::Payment.list end - } + end it { is_expected.to have_requested(:get, 'https://staging.beyonic.com/api/payments').with( @@ -92,17 +92,17 @@ end context 'Unauthorized' do - before { + before do Beyonic.api_key = 'invalid_key' - } + end - subject { - -> { + subject do + lambda { VCR.use_cassette('payments_invalid_token_list') do Beyonic::Payment.list end } - } + end it { is_expected.to raise_error @@ -112,11 +112,11 @@ describe '.get' do context 'Success response' do - subject { + subject do VCR.use_cassette('payments_get') do Beyonic::Payment.get(create_payment.id) end - } + end it { is_expected.to have_requested(:get, "https://staging.beyonic.com/api/payments/#{create_payment.id}").with( @@ -129,17 +129,17 @@ end context 'Unauthorized' do - before { + before do Beyonic.api_key = 'invalid_key' - } + end - subject { - -> { + subject do + lambda { VCR.use_cassette('payments_invalid_token_get') do Beyonic::Payment.get(create_payment.id) end } - } + end it { is_expected.to raise_error @@ -147,13 +147,13 @@ end context 'Unauthorized' do - subject { - -> { + subject do + lambda { VCR.use_cassette('payments_no_permissions_get') do Beyonic::Payment.get(666) end } - } + end it { is_expected.to raise_error } @@ -164,10 +164,10 @@ context 'new object' do subject { Beyonic::Payment } - before { + before do allow(subject).to receive(:create) subject.new(payload).save - } + end it { is_expected.to have_received(:create).with(payload) @@ -176,13 +176,13 @@ context 'loaded object' do subject { Beyonic::Payment } - before { + before do allow(subject).to receive(:update) create_payment.description = 'foo' create_payment.save - } + end it { is_expected.to have_received(:update).with(create_payment.id, hash_including(description: 'foo')) diff --git a/spec/beyonic/webhook_spec.rb b/spec/beyonic/webhook_spec.rb index bf4d874..6d20a79 100644 --- a/spec/beyonic/webhook_spec.rb +++ b/spec/beyonic/webhook_spec.rb @@ -1,30 +1,30 @@ require 'spec_helper' describe Beyonic::Webhook do - before { + before do Beyonic.api_key = 'd349087313cc7a6627d77ab61163d4dab6449b4c' Beyonic.api_version = 'v1' Beyonic::Webhook.instance_variable_set(:@endpoint_url, 'https://staging.beyonic.com/api/webhooks') - } + end - let(:payload) { + let(:payload) do { event: 'payment.status.changed', target: 'https://my.callback.url/' } - } + end - let!(:create_webhook) { + let!(:create_webhook) do VCR.use_cassette('webhooks_create') do Beyonic::Webhook.create(payload) end - } + end describe '.crate' do context 'Success response' do - subject { + subject do create_webhook - } + end it { is_expected.to have_requested(:post, 'https://staging.beyonic.com/api/webhooks').with( @@ -37,29 +37,29 @@ end context 'Bad request' do - subject { - -> { + subject do + lambda { VCR.use_cassette('webhooks_invalid_create') do Beyonic::Webhook.create(invalid_payload: true) end } - } + end it { is_expected.to raise_error(Beyonic::AbstractApi::ApiError) } end context 'Unauthorized' do - before { + before do Beyonic.api_key = 'invalid_key' - } - subject { - -> { + end + subject do + lambda { VCR.use_cassette('webhooks_invalid_token_create') do Beyonic::Webhook.create(payload) end } - } + end it { is_expected.to raise_error } @@ -69,11 +69,11 @@ describe '.list' do context 'Success response' do - subject { + subject do VCR.use_cassette('webhooks_list') do Beyonic::Webhook.list end - } + end it { is_expected.to have_requested(:get, 'https://staging.beyonic.com/api/webhooks').with( @@ -87,17 +87,17 @@ end context 'Unauthorized' do - before { + before do Beyonic.api_key = 'invalid_key' - } + end - subject { - -> { + subject do + lambda { VCR.use_cassette('webhooks_invalid_token_list') do Beyonic::Webhook.list end } - } + end it { is_expected.to raise_error } @@ -106,11 +106,11 @@ describe '.get' do context 'Success response' do - subject { + subject do VCR.use_cassette('webhooks_get') do Beyonic::Webhook.get(create_webhook.id) end - } + end it { is_expected.to have_requested(:get, "https://staging.beyonic.com/api/webhooks/#{create_webhook.id}").with( @@ -123,30 +123,30 @@ end context 'Unauthorized' do - before { + before do Beyonic.api_key = 'invalid_key' - } + end - subject { - -> { + subject do + lambda { VCR.use_cassette('webhooks_invalid_token_get') do Beyonic::Webhook.get(create_webhook.id) end } - } + end it { is_expected.to raise_error } end context 'Forbidden' do - subject { - -> { + subject do + lambda { VCR.use_cassette('webhooks_no_permissions_get') do Beyonic::Webhook.get(666) end } - } + end it { is_expected.to raise_error } @@ -155,11 +155,11 @@ describe '.update' do context 'Success response' do - subject { + subject do VCR.use_cassette('webhooks_update') do Beyonic::Webhook.update(create_webhook.id, target: 'https://my.callback2.url/') end - } + end it { is_expected.to have_requested(:patch, "https://staging.beyonic.com/api/webhooks/#{create_webhook.id}").with( @@ -172,26 +172,26 @@ end context 'Bad request' do - subject { - -> { + subject do + lambda { VCR.use_cassette('webhooks_invalid_update') do Beyonic::Webhook.update(create_webhook.id, event: 'wrongevent') end } - } + end it { is_expected.to raise_error(Beyonic::AbstractApi::ApiError) } end context 'Forbidden' do - subject { - -> { + subject do + lambda { VCR.use_cassette('webhooks_no_permissions_update') do Beyonic::Webhook.update(666, target: 'https://my.callback2.url/') end } - } + end it { is_expected.to raise_error @@ -199,18 +199,18 @@ end context 'Unauthorized' do - before { + before do Beyonic.api_key = 'invalid_key' create_webhook - } + end - subject { - -> { + subject do + lambda { VCR.use_cassette('webhooks_invalid_token_update') do Beyonic::Webhook.update(create_webhook.id, target: 'https://my.callback2.url/') end } - } + end it { is_expected.to raise_error } @@ -221,10 +221,10 @@ context 'new object' do subject { Beyonic::Webhook } - before { + before do allow(subject).to receive(:create) subject.new(payload).save - } + end it { is_expected.to have_received(:create).with(payload) @@ -232,15 +232,15 @@ end context 'loaded object' do - subject { + subject do Beyonic::Webhook - } + end - before { + before do allow(subject).to receive(:update) create_webhook.target = 'https://google.com/' create_webhook.save - } + end it { is_expected.to have_received(:update).with(create_webhook.id, hash_including(target: 'https://google.com/')) @@ -250,31 +250,31 @@ describe '#id=' do it { - expect{ + expect do create_webhook.id=(4) - }.to raise_error "Can't change id of existing Beyonic::Webhook" + end.to raise_error "Can't change id of existing Beyonic::Webhook" } it { - expect { + expect do create_webhook[:id]=(4) - }.to raise_error "Can't change id of existing Beyonic::Webhook" + end.to raise_error "Can't change id of existing Beyonic::Webhook" } it { - expect { + expect do create_webhook[:target]='foo' - }.to_not raise_error + end.to_not raise_error } end describe '.delete' do context 'Success response' do - subject { + subject do VCR.use_cassette('webhooks_delete') do Beyonic::Webhook.delete(create_webhook.id) end - } + end it { is_expected.to have_requested(:delete, "https://staging.beyonic.com/api/webhooks/#{create_webhook.id}").with( @@ -286,30 +286,30 @@ end context 'Forbidden' do - subject { - -> { + subject do + lambda { VCR.use_cassette('webhooks_no_permissions_delete') do Beyonic::Webhook.delete(666) end } - } + end it { is_expected.to raise_error } end context 'Unauthorized' do - before { + before do Beyonic.api_key = 'invalid_key' - } + end - subject { - -> { + subject do + lambda { VCR.use_cassette('webhooks_invalid_token_delete') do Beyonic::Webhook.delete(create_webhook.id) end } - } + end it { is_expected.to raise_error } From 144c1e394d6ad4165158840a0e1316ccdd5aca10 Mon Sep 17 00:00:00 2001 From: alvinkatojr Date: Wed, 24 Jun 2020 08:08:54 +0300 Subject: [PATCH 04/14] Rubocop fix: adds final new lines and removes trailing whitespace --- .rubocop.yml | 8 +++++ .rubocop_todo.yml | 25 -------------- Gemfile | 2 +- Rakefile | 1 - lib/beyonic/collection_request.rb | 2 +- lib/beyonic/contact.rb | 2 +- lib/beyonic/payment.rb | 2 +- lib/beyonic/webhook.rb | 2 +- spec/beyonic/collection_request_spec.rb | 22 ++++++------ spec/beyonic/collection_spec.rb | 20 +++++------ spec/beyonic/payment_spec.rb | 30 ++++++++-------- spec/beyonic/webhook_spec.rb | 46 ++++++++++++------------- spec/spec_helper.rb | 2 +- 13 files changed, 72 insertions(+), 92 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index ec3da9c..8e4a1cc 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,5 +1,13 @@ inherit_from: .rubocop_todo.yml +Layout/TrailingEmptyLines: + EnforcedStyle: final_newline + Enabled: true + +Layout/TrailingWhitespace: + AllowInHeredoc: false + Enabled: true + Style/BlockDelimiters: Enabled: true diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index ff7f883..9b903a1 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -143,31 +143,6 @@ Layout/SpaceInsideHashLiteralBraces: - 'spec/beyonic/payment_spec.rb' - 'spec/beyonic/webhook_spec.rb' -# Offense count: 7 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle. -# SupportedStyles: final_newline, final_blank_line -Layout/TrailingEmptyLines: - Exclude: - - 'Gemfile' - - 'Rakefile' - - 'lib/beyonic/collection_request.rb' - - 'lib/beyonic/contact.rb' - - 'lib/beyonic/payment.rb' - - 'lib/beyonic/webhook.rb' - - 'spec/beyonic/webhook_spec.rb' - -# Offense count: 60 -# Cop supports --auto-correct. -# Configuration parameters: AllowInHeredoc. -Layout/TrailingWhitespace: - Exclude: - - 'spec/beyonic/collection_request_spec.rb' - - 'spec/beyonic/collection_spec.rb' - - 'spec/beyonic/payment_spec.rb' - - 'spec/beyonic/webhook_spec.rb' - - 'spec/spec_helper.rb' - # Offense count: 2 # Cop supports --auto-correct. # Configuration parameters: IgnoreEmptyBlocks, AllowUnusedKeywordArguments. diff --git a/Gemfile b/Gemfile index 9fbc3b4..5caef61 100644 --- a/Gemfile +++ b/Gemfile @@ -1,4 +1,4 @@ source 'https://rubygems.org' # Specify your gem's dependencies in beyonic.gemspec -gemspec \ No newline at end of file +gemspec diff --git a/Rakefile b/Rakefile index 33eb07c..c702cfc 100644 --- a/Rakefile +++ b/Rakefile @@ -1,2 +1 @@ require 'bundler/gem_tasks' - diff --git a/lib/beyonic/collection_request.rb b/lib/beyonic/collection_request.rb index a3f5a4c..6bd2996 100644 --- a/lib/beyonic/collection_request.rb +++ b/lib/beyonic/collection_request.rb @@ -2,4 +2,4 @@ class Beyonic::CollectionRequest < OpenStruct include Beyonic::AbstractApi set_endpoint_resource 'collectionrequests' -end \ No newline at end of file +end diff --git a/lib/beyonic/contact.rb b/lib/beyonic/contact.rb index 1e78584..58da158 100644 --- a/lib/beyonic/contact.rb +++ b/lib/beyonic/contact.rb @@ -2,4 +2,4 @@ class Beyonic::Contact < OpenStruct include Beyonic::AbstractApi set_endpoint_resource 'contacts' -end \ No newline at end of file +end diff --git a/lib/beyonic/payment.rb b/lib/beyonic/payment.rb index 96155e2..505f260 100644 --- a/lib/beyonic/payment.rb +++ b/lib/beyonic/payment.rb @@ -2,4 +2,4 @@ class Beyonic::Payment < OpenStruct include Beyonic::AbstractApi set_endpoint_resource 'payments' -end \ No newline at end of file +end diff --git a/lib/beyonic/webhook.rb b/lib/beyonic/webhook.rb index e6bd704..792fae2 100644 --- a/lib/beyonic/webhook.rb +++ b/lib/beyonic/webhook.rb @@ -2,4 +2,4 @@ class Beyonic::Webhook < OpenStruct include Beyonic::AbstractApi set_endpoint_resource 'webhooks' -end \ No newline at end of file +end diff --git a/spec/beyonic/collection_request_spec.rb b/spec/beyonic/collection_request_spec.rb index f153b72..2b4ac56 100644 --- a/spec/beyonic/collection_request_spec.rb +++ b/spec/beyonic/collection_request_spec.rb @@ -18,14 +18,14 @@ Beyonic::CollectionRequest.create(payload) end end - + describe '.crate' do context 'Success response' do subject do create_collection_requests end - it { + it { is_expected.to have_requested(:post, 'https://staging.beyonic.com/api/collectionrequests').with( headers: {'Authorization' => 'Token d349087313cc7a6627d77ab61163d4dab6449b4c', 'Beyonic-Version' => 'v1'} ) @@ -43,13 +43,13 @@ end } end - it { + it { is_expected.to raise_error(Beyonic::AbstractApi::ApiError) } end context 'Unauthorized' do - before do + before do Beyonic.api_key = 'invalid_key' end @@ -60,7 +60,7 @@ end } end - it { + it { is_expected.to raise_error } end @@ -75,7 +75,7 @@ end end - it { + it { is_expected.to have_requested(:get, 'https://staging.beyonic.com/api/collectionrequests').with( headers: {'Authorization' => 'Token d349087313cc7a6627d77ab61163d4dab6449b4c', 'Beyonic-Version' => 'v1'} ) @@ -98,7 +98,7 @@ } end - it { + it { is_expected.to raise_error } end @@ -112,7 +112,7 @@ end end - it { + it { is_expected.to have_requested(:get, "https://staging.beyonic.com/api/collectionrequests/#{create_collection_requests.id}").with( headers: {'Authorization' => 'Token d349087313cc7a6627d77ab61163d4dab6449b4c', 'Beyonic-Version' => 'v1'} ) @@ -123,7 +123,7 @@ end context 'Unauthorized' do - before do + before do Beyonic.api_key = 'invalid_key' end @@ -135,7 +135,7 @@ } end - it { + it { is_expected.to raise_error } end @@ -148,7 +148,7 @@ end } end - it { + it { is_expected.to raise_error } end diff --git a/spec/beyonic/collection_spec.rb b/spec/beyonic/collection_spec.rb index a9618e4..30d7a9e 100644 --- a/spec/beyonic/collection_spec.rb +++ b/spec/beyonic/collection_spec.rb @@ -6,7 +6,6 @@ Beyonic.api_version = 'v1' Beyonic::Collection.instance_variable_set(:@endpoint_url, 'https://staging.beyonic.com/api/collections') end - describe '.list' do context 'Success response' do @@ -16,7 +15,7 @@ end end - it { + it { is_expected.to have_requested(:get, 'https://staging.beyonic.com/api/collections').with( headers: {'Authorization' => 'Token d349087313cc7a6627d77ab61163d4dab6449b4c', 'Beyonic-Version' => 'v1'} ) @@ -34,7 +33,7 @@ end end - it { + it { is_expected.to have_requested(:get, 'https://staging.beyonic.com/api/collections?phonenumber=%2B254727843600').with( headers: {'Authorization' => 'Token d349087313cc7a6627d77ab61163d4dab6449b4c', 'Beyonic-Version' => 'v1'} ) @@ -59,7 +58,7 @@ } end - it { + it { is_expected.to raise_error } end @@ -73,7 +72,7 @@ end end - it { + it { is_expected.to have_requested(:get, 'https://staging.beyonic.com/api/collections/1').with( headers: {'Authorization' => 'Token d349087313cc7a6627d77ab61163d4dab6449b4c', 'Beyonic-Version' => 'v1'} ) @@ -84,7 +83,7 @@ end context 'Unauthorized' do - before do + before do Beyonic.api_key = 'invalid_key' end @@ -96,7 +95,7 @@ } end - it { + it { is_expected.to raise_error } end @@ -109,14 +108,13 @@ end } end - it { + it { is_expected.to raise_error } end end describe '.claim' do - context 'by Phonenumber' do subject do VCR.use_cassette('collections_claim') do @@ -124,7 +122,7 @@ end end - it { + it { is_expected.to have_requested(:get, 'https://staging.beyonic.com/api/collections?amount=200&claim=true&phonenumber=%2B254727843600&remote_transaction_id').with( headers: {'Authorization' => 'Token d349087313cc7a6627d77ab61163d4dab6449b4c', 'Beyonic-Version' => 'v1'} ) @@ -149,7 +147,7 @@ } end - it { + it { is_expected.to raise_error } end diff --git a/spec/beyonic/payment_spec.rb b/spec/beyonic/payment_spec.rb index 6a99529..8ab06fd 100644 --- a/spec/beyonic/payment_spec.rb +++ b/spec/beyonic/payment_spec.rb @@ -24,14 +24,14 @@ Beyonic::Payment.create(payload) end end - + describe '.crate' do context 'Success response' do subject do create_payment end - it { + it { is_expected.to have_requested(:post, 'https://staging.beyonic.com/api/payments').with( headers: {'Authorization' => 'Token d349087313cc7a6627d77ab61163d4dab6449b4c', 'Beyonic-Version' => 'v1'} ) @@ -49,13 +49,13 @@ end } end - it { + it { is_expected.to raise_error(Beyonic::AbstractApi::ApiError) } end context 'Unauthorized' do - before do + before do Beyonic.api_key = 'invalid_key' end @@ -66,7 +66,7 @@ end } end - it { + it { is_expected.to raise_error } end @@ -81,7 +81,7 @@ end end - it { + it { is_expected.to have_requested(:get, 'https://staging.beyonic.com/api/payments').with( headers: {'Authorization' => 'Token d349087313cc7a6627d77ab61163d4dab6449b4c', 'Beyonic-Version' => 'v1'} ) @@ -104,7 +104,7 @@ } end - it { + it { is_expected.to raise_error } end @@ -118,7 +118,7 @@ end end - it { + it { is_expected.to have_requested(:get, "https://staging.beyonic.com/api/payments/#{create_payment.id}").with( headers: {'Authorization' => 'Token d349087313cc7a6627d77ab61163d4dab6449b4c', 'Beyonic-Version' => 'v1'} ) @@ -129,7 +129,7 @@ end context 'Unauthorized' do - before do + before do Beyonic.api_key = 'invalid_key' end @@ -141,7 +141,7 @@ } end - it { + it { is_expected.to raise_error } end @@ -154,7 +154,7 @@ end } end - it { + it { is_expected.to raise_error } end @@ -167,16 +167,16 @@ before do allow(subject).to receive(:create) subject.new(payload).save - end + end - it { + it { is_expected.to have_received(:create).with(payload) } end context 'loaded object' do subject { Beyonic::Payment } - before do + before do allow(subject).to receive(:update) @@ -184,7 +184,7 @@ create_payment.save end - it { + it { is_expected.to have_received(:update).with(create_payment.id, hash_including(description: 'foo')) } end diff --git a/spec/beyonic/webhook_spec.rb b/spec/beyonic/webhook_spec.rb index 6d20a79..e9dc044 100644 --- a/spec/beyonic/webhook_spec.rb +++ b/spec/beyonic/webhook_spec.rb @@ -12,21 +12,21 @@ event: 'payment.status.changed', target: 'https://my.callback.url/' } - end + end let!(:create_webhook) do VCR.use_cassette('webhooks_create') do Beyonic::Webhook.create(payload) end end - + describe '.crate' do context 'Success response' do subject do create_webhook end - it { + it { is_expected.to have_requested(:post, 'https://staging.beyonic.com/api/webhooks').with( headers: {'Authorization' => 'Token d349087313cc7a6627d77ab61163d4dab6449b4c', 'Beyonic-Version' => 'v1'} ) @@ -44,7 +44,7 @@ end } end - it { + it { is_expected.to raise_error(Beyonic::AbstractApi::ApiError) } end @@ -60,7 +60,7 @@ end } end - it { + it { is_expected.to raise_error } end @@ -75,7 +75,7 @@ end end - it { + it { is_expected.to have_requested(:get, 'https://staging.beyonic.com/api/webhooks').with( headers: {'Authorization' => 'Token d349087313cc7a6627d77ab61163d4dab6449b4c', 'Beyonic-Version' => 'v1'} ) @@ -98,7 +98,7 @@ end } end - it { + it { is_expected.to raise_error } end @@ -112,7 +112,7 @@ end end - it { + it { is_expected.to have_requested(:get, "https://staging.beyonic.com/api/webhooks/#{create_webhook.id}").with( headers: {'Authorization' => 'Token d349087313cc7a6627d77ab61163d4dab6449b4c', 'Beyonic-Version' => 'v1'} ) @@ -134,7 +134,7 @@ end } end - it { + it { is_expected.to raise_error } end @@ -147,7 +147,7 @@ end } end - it { + it { is_expected.to raise_error } end @@ -161,7 +161,7 @@ end end - it { + it { is_expected.to have_requested(:patch, "https://staging.beyonic.com/api/webhooks/#{create_webhook.id}").with( headers: {'Authorization' => 'Token d349087313cc7a6627d77ab61163d4dab6449b4c', 'Beyonic-Version' => 'v1'} ) @@ -179,7 +179,7 @@ end } end - it { + it { is_expected.to raise_error(Beyonic::AbstractApi::ApiError) } end @@ -193,7 +193,7 @@ } end - it { + it { is_expected.to raise_error } end @@ -211,7 +211,7 @@ end } end - it { + it { is_expected.to raise_error } end @@ -224,15 +224,15 @@ before do allow(subject).to receive(:create) subject.new(payload).save - end + end - it { + it { is_expected.to have_received(:create).with(payload) } end context 'loaded object' do - subject do + subject do Beyonic::Webhook end @@ -242,14 +242,14 @@ create_webhook.save end - it { + it { is_expected.to have_received(:update).with(create_webhook.id, hash_including(target: 'https://google.com/')) } end end describe '#id=' do - it { + it { expect do create_webhook.id=(4) end.to raise_error "Can't change id of existing Beyonic::Webhook" @@ -276,7 +276,7 @@ end end - it { + it { is_expected.to have_requested(:delete, "https://staging.beyonic.com/api/webhooks/#{create_webhook.id}").with( headers: {'Authorization' => 'Token d349087313cc7a6627d77ab61163d4dab6449b4c', 'Beyonic-Version' => 'v1'} ) @@ -293,7 +293,7 @@ end } end - it { + it { is_expected.to raise_error } end @@ -310,9 +310,9 @@ end } end - it { + it { is_expected.to raise_error } end end -end \ No newline at end of file +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 7cd4f4e..30c1873 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,5 +1,5 @@ require 'simplecov' -SimpleCov.start do +SimpleCov.start do add_filter '/spec/' end From 0332a6480147a75b364683a96d77fca7cb693fa5 Mon Sep 17 00:00:00 2001 From: alvinkatojr Date: Wed, 24 Jun 2020 08:57:46 +0300 Subject: [PATCH 05/14] Rubocop fix: better argument alignment and indentation --- .rubocop.yml | 7 +++++++ .rubocop_todo.yml | 13 ------------- spec/beyonic/accounts_spec.rb | 4 ++-- spec/beyonic/collection_request_spec.rb | 12 ++++++------ spec/beyonic/collection_spec.rb | 16 ++++++++-------- spec/beyonic/metadata_spec.rb | 8 ++++---- spec/beyonic/payment_spec.rb | 12 ++++++------ spec/beyonic/webhook_spec.rb | 20 ++++++++++---------- 8 files changed, 43 insertions(+), 49 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 8e4a1cc..e951afe 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,5 +1,12 @@ inherit_from: .rubocop_todo.yml +Layout/ArgumentAlignment: + EnforcedStyle: with_first_argument + Enabled: true + +Layout/FirstArgumentIndentation:i + Enabled: true + Layout/TrailingEmptyLines: EnforcedStyle: final_newline Enabled: true diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 9b903a1..e552096 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -55,19 +55,6 @@ Layout/EmptyLinesAroundModuleBody: - 'lib/beyonic.rb' - 'lib/beyonic/abstract_api.rb' -# Offense count: 18 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, IndentationWidth. -# SupportedStyles: consistent, consistent_relative_to_receiver, special_for_inner_method_call, special_for_inner_method_call_in_parentheses -Layout/FirstArgumentIndentation: - Exclude: - - 'spec/beyonic/accounts_spec.rb' - - 'spec/beyonic/collection_request_spec.rb' - - 'spec/beyonic/collection_spec.rb' - - 'spec/beyonic/metadata_spec.rb' - - 'spec/beyonic/payment_spec.rb' - - 'spec/beyonic/webhook_spec.rb' - # Offense count: 1 # Cop supports --auto-correct. # Configuration parameters: Width, IgnoredPatterns. diff --git a/spec/beyonic/accounts_spec.rb b/spec/beyonic/accounts_spec.rb index 641ff3f..f88b1ad 100644 --- a/spec/beyonic/accounts_spec.rb +++ b/spec/beyonic/accounts_spec.rb @@ -18,8 +18,8 @@ it { is_expected.to have_requested(:get, "#{API_ENDPOINT}").with( - headers: {'Authorization' => "Token #{Beyonic.api_key}", 'Beyonic-Version' => Beyonic.api_version} - ) + headers: {'Authorization' => "Token #{Beyonic.api_key}", 'Beyonic-Version' => Beyonic.api_version} + ) } it { is_expected.to be_an(Array) } diff --git a/spec/beyonic/collection_request_spec.rb b/spec/beyonic/collection_request_spec.rb index 2b4ac56..2d10f78 100644 --- a/spec/beyonic/collection_request_spec.rb +++ b/spec/beyonic/collection_request_spec.rb @@ -27,8 +27,8 @@ it { is_expected.to have_requested(:post, 'https://staging.beyonic.com/api/collectionrequests').with( - headers: {'Authorization' => 'Token d349087313cc7a6627d77ab61163d4dab6449b4c', 'Beyonic-Version' => 'v1'} - ) + headers: {'Authorization' => 'Token d349087313cc7a6627d77ab61163d4dab6449b4c', 'Beyonic-Version' => 'v1'} + ) } it { is_expected.to be_an(Beyonic::CollectionRequest) } @@ -77,8 +77,8 @@ it { is_expected.to have_requested(:get, 'https://staging.beyonic.com/api/collectionrequests').with( - headers: {'Authorization' => 'Token d349087313cc7a6627d77ab61163d4dab6449b4c', 'Beyonic-Version' => 'v1'} - ) + headers: {'Authorization' => 'Token d349087313cc7a6627d77ab61163d4dab6449b4c', 'Beyonic-Version' => 'v1'} + ) } it { is_expected.to be_an(Array) } @@ -114,8 +114,8 @@ it { is_expected.to have_requested(:get, "https://staging.beyonic.com/api/collectionrequests/#{create_collection_requests.id}").with( - headers: {'Authorization' => 'Token d349087313cc7a6627d77ab61163d4dab6449b4c', 'Beyonic-Version' => 'v1'} - ) + headers: {'Authorization' => 'Token d349087313cc7a6627d77ab61163d4dab6449b4c', 'Beyonic-Version' => 'v1'} + ) } it { is_expected.to be_an(Beyonic::CollectionRequest) } diff --git a/spec/beyonic/collection_spec.rb b/spec/beyonic/collection_spec.rb index 30d7a9e..dbdf348 100644 --- a/spec/beyonic/collection_spec.rb +++ b/spec/beyonic/collection_spec.rb @@ -17,8 +17,8 @@ it { is_expected.to have_requested(:get, 'https://staging.beyonic.com/api/collections').with( - headers: {'Authorization' => 'Token d349087313cc7a6627d77ab61163d4dab6449b4c', 'Beyonic-Version' => 'v1'} - ) + headers: {'Authorization' => 'Token d349087313cc7a6627d77ab61163d4dab6449b4c', 'Beyonic-Version' => 'v1'} + ) } it { is_expected.to be_an(Array) } it { is_expected.to have(1).items } @@ -35,8 +35,8 @@ it { is_expected.to have_requested(:get, 'https://staging.beyonic.com/api/collections?phonenumber=%2B254727843600').with( - headers: {'Authorization' => 'Token d349087313cc7a6627d77ab61163d4dab6449b4c', 'Beyonic-Version' => 'v1'} - ) + headers: {'Authorization' => 'Token d349087313cc7a6627d77ab61163d4dab6449b4c', 'Beyonic-Version' => 'v1'} + ) } it { is_expected.to be_an(Array) } @@ -74,8 +74,8 @@ it { is_expected.to have_requested(:get, 'https://staging.beyonic.com/api/collections/1').with( - headers: {'Authorization' => 'Token d349087313cc7a6627d77ab61163d4dab6449b4c', 'Beyonic-Version' => 'v1'} - ) + headers: {'Authorization' => 'Token d349087313cc7a6627d77ab61163d4dab6449b4c', 'Beyonic-Version' => 'v1'} + ) } it { is_expected.to be_an(Beyonic::Collection) } @@ -124,8 +124,8 @@ it { is_expected.to have_requested(:get, 'https://staging.beyonic.com/api/collections?amount=200&claim=true&phonenumber=%2B254727843600&remote_transaction_id').with( - headers: {'Authorization' => 'Token d349087313cc7a6627d77ab61163d4dab6449b4c', 'Beyonic-Version' => 'v1'} - ) + headers: {'Authorization' => 'Token d349087313cc7a6627d77ab61163d4dab6449b4c', 'Beyonic-Version' => 'v1'} + ) } it { is_expected.to be_an(Array) } diff --git a/spec/beyonic/metadata_spec.rb b/spec/beyonic/metadata_spec.rb index 8c6ffe9..c3d7c4d 100644 --- a/spec/beyonic/metadata_spec.rb +++ b/spec/beyonic/metadata_spec.rb @@ -38,8 +38,8 @@ it { is_expected.to have_requested(:post, 'https://staging.beyonic.com/api/collectionrequests').with( - headers: {'Authorization' => 'Token c4269a8029e8a7c5659d3cb7829ce1d7319b4689', 'Beyonic-Version' => 'v1'} - ) + headers: {'Authorization' => 'Token c4269a8029e8a7c5659d3cb7829ce1d7319b4689', 'Beyonic-Version' => 'v1'} + ) } it { is_expected.to be_an(Beyonic::CollectionRequest) } it { is_expected.to have_attributes('metadata': metadata_array_notation_request.metadata, currency: 'BXC') } @@ -59,8 +59,8 @@ it { is_expected.to have_requested(:post, 'https://staging.beyonic.com/api/collectionrequests').with( - headers: {'Authorization' => 'Token c4269a8029e8a7c5659d3cb7829ce1d7319b4689', 'Beyonic-Version' => 'v1'} - ) + headers: {'Authorization' => 'Token c4269a8029e8a7c5659d3cb7829ce1d7319b4689', 'Beyonic-Version' => 'v1'} + ) } it { is_expected.to be_an(Beyonic::CollectionRequest) } it { is_expected.to have_attributes('metadata': metadata_dot_notation_request.metadata, currency: 'BXC') } diff --git a/spec/beyonic/payment_spec.rb b/spec/beyonic/payment_spec.rb index 8ab06fd..75908c3 100644 --- a/spec/beyonic/payment_spec.rb +++ b/spec/beyonic/payment_spec.rb @@ -33,8 +33,8 @@ it { is_expected.to have_requested(:post, 'https://staging.beyonic.com/api/payments').with( - headers: {'Authorization' => 'Token d349087313cc7a6627d77ab61163d4dab6449b4c', 'Beyonic-Version' => 'v1'} - ) + headers: {'Authorization' => 'Token d349087313cc7a6627d77ab61163d4dab6449b4c', 'Beyonic-Version' => 'v1'} + ) } it { is_expected.to be_an(Beyonic::Payment) } @@ -83,8 +83,8 @@ it { is_expected.to have_requested(:get, 'https://staging.beyonic.com/api/payments').with( - headers: {'Authorization' => 'Token d349087313cc7a6627d77ab61163d4dab6449b4c', 'Beyonic-Version' => 'v1'} - ) + headers: {'Authorization' => 'Token d349087313cc7a6627d77ab61163d4dab6449b4c', 'Beyonic-Version' => 'v1'} + ) } it { is_expected.to be_an(Array) } @@ -120,8 +120,8 @@ it { is_expected.to have_requested(:get, "https://staging.beyonic.com/api/payments/#{create_payment.id}").with( - headers: {'Authorization' => 'Token d349087313cc7a6627d77ab61163d4dab6449b4c', 'Beyonic-Version' => 'v1'} - ) + headers: {'Authorization' => 'Token d349087313cc7a6627d77ab61163d4dab6449b4c', 'Beyonic-Version' => 'v1'} + ) } it { is_expected.to be_an(Beyonic::Payment) } diff --git a/spec/beyonic/webhook_spec.rb b/spec/beyonic/webhook_spec.rb index e9dc044..7303c3c 100644 --- a/spec/beyonic/webhook_spec.rb +++ b/spec/beyonic/webhook_spec.rb @@ -28,8 +28,8 @@ it { is_expected.to have_requested(:post, 'https://staging.beyonic.com/api/webhooks').with( - headers: {'Authorization' => 'Token d349087313cc7a6627d77ab61163d4dab6449b4c', 'Beyonic-Version' => 'v1'} - ) + headers: {'Authorization' => 'Token d349087313cc7a6627d77ab61163d4dab6449b4c', 'Beyonic-Version' => 'v1'} + ) } it { is_expected.to be_an(Beyonic::Webhook) } @@ -77,8 +77,8 @@ it { is_expected.to have_requested(:get, 'https://staging.beyonic.com/api/webhooks').with( - headers: {'Authorization' => 'Token d349087313cc7a6627d77ab61163d4dab6449b4c', 'Beyonic-Version' => 'v1'} - ) + headers: {'Authorization' => 'Token d349087313cc7a6627d77ab61163d4dab6449b4c', 'Beyonic-Version' => 'v1'} + ) } it { is_expected.to be_an(Array) } it { is_expected.to have(2).items } @@ -114,8 +114,8 @@ it { is_expected.to have_requested(:get, "https://staging.beyonic.com/api/webhooks/#{create_webhook.id}").with( - headers: {'Authorization' => 'Token d349087313cc7a6627d77ab61163d4dab6449b4c', 'Beyonic-Version' => 'v1'} - ) + headers: {'Authorization' => 'Token d349087313cc7a6627d77ab61163d4dab6449b4c', 'Beyonic-Version' => 'v1'} + ) } it { is_expected.to be_an(Beyonic::Webhook) } @@ -163,8 +163,8 @@ it { is_expected.to have_requested(:patch, "https://staging.beyonic.com/api/webhooks/#{create_webhook.id}").with( - headers: {'Authorization' => 'Token d349087313cc7a6627d77ab61163d4dab6449b4c', 'Beyonic-Version' => 'v1'} - ) + headers: {'Authorization' => 'Token d349087313cc7a6627d77ab61163d4dab6449b4c', 'Beyonic-Version' => 'v1'} + ) } it { is_expected.to be_an(Beyonic::Webhook) } @@ -278,8 +278,8 @@ it { is_expected.to have_requested(:delete, "https://staging.beyonic.com/api/webhooks/#{create_webhook.id}").with( - headers: {'Authorization' => 'Token d349087313cc7a6627d77ab61163d4dab6449b4c', 'Beyonic-Version' => 'v1'} - ) + headers: {'Authorization' => 'Token d349087313cc7a6627d77ab61163d4dab6449b4c', 'Beyonic-Version' => 'v1'} + ) } it { is_expected.to be_truthy } From 8bb668eb7c34735ab02b79e9d2f76cf9b9bcca8b Mon Sep 17 00:00:00 2001 From: alvinkatojr Date: Wed, 24 Jun 2020 09:31:27 +0300 Subject: [PATCH 06/14] Rubocop fix: better spacing for arguments, blocks, block variables, hashes, commas and operators --- .rubocop.yml | 30 +++++++++++++- .rubocop_todo.yml | 55 ------------------------- lib/beyonic/abstract_api.rb | 18 ++++---- spec/beyonic/accounts_spec.rb | 2 +- spec/beyonic/collection_request_spec.rb | 6 +-- spec/beyonic/collection_spec.rb | 8 ++-- spec/beyonic/metadata_spec.rb | 6 +-- spec/beyonic/payment_spec.rb | 6 +-- spec/beyonic/webhook_spec.rb | 16 +++---- 9 files changed, 60 insertions(+), 87 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index e951afe..c6f2853 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -4,7 +4,35 @@ Layout/ArgumentAlignment: EnforcedStyle: with_first_argument Enabled: true -Layout/FirstArgumentIndentation:i +Layout/FirstArgumentIndentation: + Enabled: true + +Layout/SpaceAfterComma: + Enabled: true + +Layout/SpaceAroundOperators: + AllowForAlignment: true + EnforcedStyleForExponentOperator: no_space + Enabled: true + +Layout/SpaceBeforeBlockBraces: + EnforcedStyle: space + EnforcedStyleForEmptyBraces: space + Enabled: true + +Layout/SpaceBeforeFirstArg: + AllowForAlignment: true + Enabled: true + +Layout/SpaceInsideBlockBraces: + EnforcedStyle: space + EnforcedStyleForEmptyBraces: no_space + SpaceBeforeBlockParameters: true + Enabled: true + +Layout/SpaceInsideHashLiteralBraces: + EnforcedStyle: compact + EnforcedStyleForEmptyBraces: no_space Enabled: true Layout/TrailingEmptyLines: diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index e552096..b19a1ba 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -75,61 +75,6 @@ Layout/RescueEnsureAlignment: Exclude: - 'lib/beyonic/abstract_api.rb' -# Offense count: 1 -# Cop supports --auto-correct. -Layout/SpaceAfterComma: - Exclude: - - 'lib/beyonic/abstract_api.rb' - -# Offense count: 4 -# Cop supports --auto-correct. -# Configuration parameters: AllowForAlignment, EnforcedStyleForExponentOperator. -# SupportedStylesForExponentOperator: space, no_space -Layout/SpaceAroundOperators: - Exclude: - - 'lib/beyonic/abstract_api.rb' - - 'spec/beyonic/webhook_spec.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces. -# SupportedStyles: space, no_space -# SupportedStylesForEmptyBraces: space, no_space -Layout/SpaceBeforeBlockBraces: - Exclude: - - 'spec/beyonic/webhook_spec.rb' - -# Offense count: 2 -# Cop supports --auto-correct. -# Configuration parameters: AllowForAlignment. -Layout/SpaceBeforeFirstArg: - Exclude: - - 'lib/beyonic/abstract_api.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces, SpaceBeforeBlockParameters. -# SupportedStyles: space, no_space -# SupportedStylesForEmptyBraces: space, no_space -Layout/SpaceInsideBlockBraces: - Exclude: - - 'lib/beyonic/abstract_api.rb' - -# Offense count: 46 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces. -# SupportedStyles: space, no_space, compact -# SupportedStylesForEmptyBraces: space, no_space -Layout/SpaceInsideHashLiteralBraces: - Exclude: - - 'lib/beyonic/abstract_api.rb' - - 'spec/beyonic/accounts_spec.rb' - - 'spec/beyonic/collection_request_spec.rb' - - 'spec/beyonic/collection_spec.rb' - - 'spec/beyonic/metadata_spec.rb' - - 'spec/beyonic/payment_spec.rb' - - 'spec/beyonic/webhook_spec.rb' - # Offense count: 2 # Cop supports --auto-correct. # Configuration parameters: IgnoreEmptyBlocks, AllowUnusedKeywordArguments. diff --git a/lib/beyonic/abstract_api.rb b/lib/beyonic/abstract_api.rb index ef278b8..34e3733 100644 --- a/lib/beyonic/abstract_api.rb +++ b/lib/beyonic/abstract_api.rb @@ -10,11 +10,11 @@ def set_endpoint_resource(resource) def create(payload = {}, header_overrides = {}) # transform metadata from hash notation to dot notation - if (payload.has_key?:metadata) && (!payload[:metadata].empty?) + if (payload.has_key? :metadata) && (!payload[:metadata].empty?) payload[:metadata].each do |key, value| payload["metadata.#{key}"] = value end - payload.delete:metadata + payload.delete :metadata end resp = RestClient.post(@endpoint_url, payload, headers(header_overrides)) self.new(Oj.load(resp)) @@ -30,7 +30,7 @@ def list(payload = {}) resp = RestClient.get(@endpoint_url + '?' + uri.query, headers) ret = self.new(Oj.load(resp)) - ret.results = ret.results.map { |obj_attrs| self.new(obj_attrs)} + ret.results = ret.results.map { |obj_attrs| self.new(obj_attrs) } return ret end @@ -55,10 +55,10 @@ def delete(id) def headers(header_overrides = {}) headers_hash = {} - headers_hash.merge!({'Authorization' => "Token #{Beyonic.api_key}"}) if Beyonic.api_key - headers_hash.merge!({'Beyonic-Version' => Beyonic.api_version}) if Beyonic.api_version - headers_hash.merge!({'Beyonic-Client' => 'Ruby'}) - headers_hash.merge!({'Beyonic-Client-Version' => Beyonic::VERSION}) + headers_hash.merge!({ 'Authorization' => "Token #{Beyonic.api_key}" }) if Beyonic.api_key + headers_hash.merge!({ 'Beyonic-Version' => Beyonic.api_version }) if Beyonic.api_version + headers_hash.merge!({ 'Beyonic-Client' => 'Ruby' }) + headers_hash.merge!({ 'Beyonic-Client-Version' => Beyonic::VERSION }) headers_hash.merge!(header_overrides) headers_hash end @@ -78,9 +78,9 @@ def save def []=(name, value) if name.to_sym == :id - self.id=(value) + self.id = (value) else - super(name,value) + super(name, value) end end diff --git a/spec/beyonic/accounts_spec.rb b/spec/beyonic/accounts_spec.rb index f88b1ad..4d15f57 100644 --- a/spec/beyonic/accounts_spec.rb +++ b/spec/beyonic/accounts_spec.rb @@ -18,7 +18,7 @@ it { is_expected.to have_requested(:get, "#{API_ENDPOINT}").with( - headers: {'Authorization' => "Token #{Beyonic.api_key}", 'Beyonic-Version' => Beyonic.api_version} + headers: { 'Authorization' => "Token #{Beyonic.api_key}", 'Beyonic-Version' => Beyonic.api_version } ) } it { is_expected.to be_an(Array) } diff --git a/spec/beyonic/collection_request_spec.rb b/spec/beyonic/collection_request_spec.rb index 2d10f78..3735453 100644 --- a/spec/beyonic/collection_request_spec.rb +++ b/spec/beyonic/collection_request_spec.rb @@ -27,7 +27,7 @@ it { is_expected.to have_requested(:post, 'https://staging.beyonic.com/api/collectionrequests').with( - headers: {'Authorization' => 'Token d349087313cc7a6627d77ab61163d4dab6449b4c', 'Beyonic-Version' => 'v1'} + headers: { 'Authorization' => 'Token d349087313cc7a6627d77ab61163d4dab6449b4c', 'Beyonic-Version' => 'v1' } ) } it { is_expected.to be_an(Beyonic::CollectionRequest) } @@ -77,7 +77,7 @@ it { is_expected.to have_requested(:get, 'https://staging.beyonic.com/api/collectionrequests').with( - headers: {'Authorization' => 'Token d349087313cc7a6627d77ab61163d4dab6449b4c', 'Beyonic-Version' => 'v1'} + headers: { 'Authorization' => 'Token d349087313cc7a6627d77ab61163d4dab6449b4c', 'Beyonic-Version' => 'v1' } ) } it { is_expected.to be_an(Array) } @@ -114,7 +114,7 @@ it { is_expected.to have_requested(:get, "https://staging.beyonic.com/api/collectionrequests/#{create_collection_requests.id}").with( - headers: {'Authorization' => 'Token d349087313cc7a6627d77ab61163d4dab6449b4c', 'Beyonic-Version' => 'v1'} + headers: { 'Authorization' => 'Token d349087313cc7a6627d77ab61163d4dab6449b4c', 'Beyonic-Version' => 'v1' } ) } it { is_expected.to be_an(Beyonic::CollectionRequest) } diff --git a/spec/beyonic/collection_spec.rb b/spec/beyonic/collection_spec.rb index dbdf348..0b4fae6 100644 --- a/spec/beyonic/collection_spec.rb +++ b/spec/beyonic/collection_spec.rb @@ -17,7 +17,7 @@ it { is_expected.to have_requested(:get, 'https://staging.beyonic.com/api/collections').with( - headers: {'Authorization' => 'Token d349087313cc7a6627d77ab61163d4dab6449b4c', 'Beyonic-Version' => 'v1'} + headers: { 'Authorization' => 'Token d349087313cc7a6627d77ab61163d4dab6449b4c', 'Beyonic-Version' => 'v1' } ) } it { is_expected.to be_an(Array) } @@ -35,7 +35,7 @@ it { is_expected.to have_requested(:get, 'https://staging.beyonic.com/api/collections?phonenumber=%2B254727843600').with( - headers: {'Authorization' => 'Token d349087313cc7a6627d77ab61163d4dab6449b4c', 'Beyonic-Version' => 'v1'} + headers: { 'Authorization' => 'Token d349087313cc7a6627d77ab61163d4dab6449b4c', 'Beyonic-Version' => 'v1' } ) } it { is_expected.to be_an(Array) } @@ -74,7 +74,7 @@ it { is_expected.to have_requested(:get, 'https://staging.beyonic.com/api/collections/1').with( - headers: {'Authorization' => 'Token d349087313cc7a6627d77ab61163d4dab6449b4c', 'Beyonic-Version' => 'v1'} + headers: { 'Authorization' => 'Token d349087313cc7a6627d77ab61163d4dab6449b4c', 'Beyonic-Version' => 'v1' } ) } it { is_expected.to be_an(Beyonic::Collection) } @@ -124,7 +124,7 @@ it { is_expected.to have_requested(:get, 'https://staging.beyonic.com/api/collections?amount=200&claim=true&phonenumber=%2B254727843600&remote_transaction_id').with( - headers: {'Authorization' => 'Token d349087313cc7a6627d77ab61163d4dab6449b4c', 'Beyonic-Version' => 'v1'} + headers: { 'Authorization' => 'Token d349087313cc7a6627d77ab61163d4dab6449b4c', 'Beyonic-Version' => 'v1' } ) } it { is_expected.to be_an(Array) } diff --git a/spec/beyonic/metadata_spec.rb b/spec/beyonic/metadata_spec.rb index c3d7c4d..9fbb1b5 100644 --- a/spec/beyonic/metadata_spec.rb +++ b/spec/beyonic/metadata_spec.rb @@ -12,7 +12,7 @@ phonenumber: '+40715441309', currency: 'BXC', amount: 3000, - metadata: {"my_id": '123ASDAsd123'} + metadata: { "my_id": '123ASDAsd123' } } end @@ -38,7 +38,7 @@ it { is_expected.to have_requested(:post, 'https://staging.beyonic.com/api/collectionrequests').with( - headers: {'Authorization' => 'Token c4269a8029e8a7c5659d3cb7829ce1d7319b4689', 'Beyonic-Version' => 'v1'} + headers: { 'Authorization' => 'Token c4269a8029e8a7c5659d3cb7829ce1d7319b4689', 'Beyonic-Version' => 'v1' } ) } it { is_expected.to be_an(Beyonic::CollectionRequest) } @@ -59,7 +59,7 @@ it { is_expected.to have_requested(:post, 'https://staging.beyonic.com/api/collectionrequests').with( - headers: {'Authorization' => 'Token c4269a8029e8a7c5659d3cb7829ce1d7319b4689', 'Beyonic-Version' => 'v1'} + headers: { 'Authorization' => 'Token c4269a8029e8a7c5659d3cb7829ce1d7319b4689', 'Beyonic-Version' => 'v1' } ) } it { is_expected.to be_an(Beyonic::CollectionRequest) } diff --git a/spec/beyonic/payment_spec.rb b/spec/beyonic/payment_spec.rb index 75908c3..e2cc41a 100644 --- a/spec/beyonic/payment_spec.rb +++ b/spec/beyonic/payment_spec.rb @@ -33,7 +33,7 @@ it { is_expected.to have_requested(:post, 'https://staging.beyonic.com/api/payments').with( - headers: {'Authorization' => 'Token d349087313cc7a6627d77ab61163d4dab6449b4c', 'Beyonic-Version' => 'v1'} + headers: { 'Authorization' => 'Token d349087313cc7a6627d77ab61163d4dab6449b4c', 'Beyonic-Version' => 'v1' } ) } it { is_expected.to be_an(Beyonic::Payment) } @@ -83,7 +83,7 @@ it { is_expected.to have_requested(:get, 'https://staging.beyonic.com/api/payments').with( - headers: {'Authorization' => 'Token d349087313cc7a6627d77ab61163d4dab6449b4c', 'Beyonic-Version' => 'v1'} + headers: { 'Authorization' => 'Token d349087313cc7a6627d77ab61163d4dab6449b4c', 'Beyonic-Version' => 'v1' } ) } it { is_expected.to be_an(Array) } @@ -120,7 +120,7 @@ it { is_expected.to have_requested(:get, "https://staging.beyonic.com/api/payments/#{create_payment.id}").with( - headers: {'Authorization' => 'Token d349087313cc7a6627d77ab61163d4dab6449b4c', 'Beyonic-Version' => 'v1'} + headers: { 'Authorization' => 'Token d349087313cc7a6627d77ab61163d4dab6449b4c', 'Beyonic-Version' => 'v1' } ) } it { is_expected.to be_an(Beyonic::Payment) } diff --git a/spec/beyonic/webhook_spec.rb b/spec/beyonic/webhook_spec.rb index 7303c3c..a40d95f 100644 --- a/spec/beyonic/webhook_spec.rb +++ b/spec/beyonic/webhook_spec.rb @@ -28,7 +28,7 @@ it { is_expected.to have_requested(:post, 'https://staging.beyonic.com/api/webhooks').with( - headers: {'Authorization' => 'Token d349087313cc7a6627d77ab61163d4dab6449b4c', 'Beyonic-Version' => 'v1'} + headers: { 'Authorization' => 'Token d349087313cc7a6627d77ab61163d4dab6449b4c', 'Beyonic-Version' => 'v1' } ) } it { is_expected.to be_an(Beyonic::Webhook) } @@ -77,7 +77,7 @@ it { is_expected.to have_requested(:get, 'https://staging.beyonic.com/api/webhooks').with( - headers: {'Authorization' => 'Token d349087313cc7a6627d77ab61163d4dab6449b4c', 'Beyonic-Version' => 'v1'} + headers: { 'Authorization' => 'Token d349087313cc7a6627d77ab61163d4dab6449b4c', 'Beyonic-Version' => 'v1' } ) } it { is_expected.to be_an(Array) } @@ -114,7 +114,7 @@ it { is_expected.to have_requested(:get, "https://staging.beyonic.com/api/webhooks/#{create_webhook.id}").with( - headers: {'Authorization' => 'Token d349087313cc7a6627d77ab61163d4dab6449b4c', 'Beyonic-Version' => 'v1'} + headers: { 'Authorization' => 'Token d349087313cc7a6627d77ab61163d4dab6449b4c', 'Beyonic-Version' => 'v1' } ) } it { is_expected.to be_an(Beyonic::Webhook) } @@ -163,7 +163,7 @@ it { is_expected.to have_requested(:patch, "https://staging.beyonic.com/api/webhooks/#{create_webhook.id}").with( - headers: {'Authorization' => 'Token d349087313cc7a6627d77ab61163d4dab6449b4c', 'Beyonic-Version' => 'v1'} + headers: { 'Authorization' => 'Token d349087313cc7a6627d77ab61163d4dab6449b4c', 'Beyonic-Version' => 'v1' } ) } it { is_expected.to be_an(Beyonic::Webhook) } @@ -251,19 +251,19 @@ describe '#id=' do it { expect do - create_webhook.id=(4) + create_webhook.id = (4) end.to raise_error "Can't change id of existing Beyonic::Webhook" } it { expect do - create_webhook[:id]=(4) + create_webhook[:id] = (4) end.to raise_error "Can't change id of existing Beyonic::Webhook" } it { expect do - create_webhook[:target]='foo' + create_webhook[:target] = 'foo' end.to_not raise_error } end @@ -278,7 +278,7 @@ it { is_expected.to have_requested(:delete, "https://staging.beyonic.com/api/webhooks/#{create_webhook.id}").with( - headers: {'Authorization' => 'Token d349087313cc7a6627d77ab61163d4dab6449b4c', 'Beyonic-Version' => 'v1'} + headers: { 'Authorization' => 'Token d349087313cc7a6627d77ab61163d4dab6449b4c', 'Beyonic-Version' => 'v1' } ) } it { is_expected.to be_truthy } From 492c0d217aa0f770d103627f66196daacd452106 Mon Sep 17 00:00:00 2001 From: alvinkatojr Date: Wed, 24 Jun 2020 09:49:53 +0300 Subject: [PATCH 07/14] Rubocop fix: removes unnecessary empty lines around blocks and modules and adds necessary ones for magic comments and method definitions --- .rubocop.yml | 18 +++++++++++ .rubocop_todo.yml | 41 ------------------------- beyonic.gemspec | 1 + lib/beyonic.rb | 2 -- lib/beyonic/abstract_api.rb | 6 ---- spec/beyonic/collection_request_spec.rb | 1 - spec/beyonic/metadata_spec.rb | 2 -- spec/beyonic/payment_spec.rb | 2 -- spec/beyonic/webhook_spec.rb | 2 -- spec/spec_helper.rb | 1 - 10 files changed, 19 insertions(+), 57 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index c6f2853..81fa20a 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -4,6 +4,24 @@ Layout/ArgumentAlignment: EnforcedStyle: with_first_argument Enabled: true +Layout/EmptyLineAfterMagicComment: + Enabled: true + +Layout/EmptyLineBetweenDefs: + AllowAdjacentOneLineDefs: false + Enabled: true + +Layout/EmptyLines: + Enabled: true + +Layout/EmptyLinesAroundBlockBody: + EnforcedStyle: no_empty_lines + Enabled: true + +Layout/EmptyLinesAroundModuleBody: + EnforcedStyle: no_empty_lines + Enabled: true + Layout/FirstArgumentIndentation: Enabled: true diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index b19a1ba..57454b2 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -14,47 +14,6 @@ Gemspec/OrderedDependencies: Exclude: - 'beyonic.gemspec' -# Offense count: 1 -# Cop supports --auto-correct. -Layout/EmptyLineAfterMagicComment: - Exclude: - - 'beyonic.gemspec' - -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: AllowAdjacentOneLineDefs, NumberOfEmptyLines. -Layout/EmptyLineBetweenDefs: - Exclude: - - 'lib/beyonic/abstract_api.rb' - -# Offense count: 3 -# Cop supports --auto-correct. -Layout/EmptyLines: - Exclude: - - 'lib/beyonic/abstract_api.rb' - - 'spec/beyonic/metadata_spec.rb' - - 'spec/spec_helper.rb' - -# Offense count: 6 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle. -# SupportedStyles: empty_lines, no_empty_lines -Layout/EmptyLinesAroundBlockBody: - Exclude: - - 'spec/beyonic/collection_request_spec.rb' - - 'spec/beyonic/metadata_spec.rb' - - 'spec/beyonic/payment_spec.rb' - - 'spec/beyonic/webhook_spec.rb' - -# Offense count: 7 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle. -# SupportedStyles: empty_lines, empty_lines_except_namespace, empty_lines_special, no_empty_lines -Layout/EmptyLinesAroundModuleBody: - Exclude: - - 'lib/beyonic.rb' - - 'lib/beyonic/abstract_api.rb' - # Offense count: 1 # Cop supports --auto-correct. # Configuration parameters: Width, IgnoredPatterns. diff --git a/beyonic.gemspec b/beyonic.gemspec index 4016a7c..4d4638e 100644 --- a/beyonic.gemspec +++ b/beyonic.gemspec @@ -1,4 +1,5 @@ # coding: utf-8 + lib = File.expand_path('../lib', __FILE__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require 'beyonic/version' diff --git a/lib/beyonic.rb b/lib/beyonic.rb index f542a91..2355d6e 100644 --- a/lib/beyonic.rb +++ b/lib/beyonic.rb @@ -1,5 +1,4 @@ module Beyonic - require 'rest-client' require 'oj' @@ -25,7 +24,6 @@ def self.api_version def self.endpoint_base 'https://app.beyonic.us/api/' end - end require 'beyonic/version' diff --git a/lib/beyonic/abstract_api.rb b/lib/beyonic/abstract_api.rb index 34e3733..1d3b1b1 100644 --- a/lib/beyonic/abstract_api.rb +++ b/lib/beyonic/abstract_api.rb @@ -3,7 +3,6 @@ class ApiError < StandardError end module ClassMethods - def set_endpoint_resource(resource) @endpoint_url = Beyonic.endpoint_base + resource end @@ -62,11 +61,9 @@ def headers(header_overrides = {}) headers_hash.merge!(header_overrides) headers_hash end - end module InstanceMethods - def save if respond_to?(:id) && !id.nil? self.class.update(id, to_h) @@ -75,7 +72,6 @@ def save end end - def []=(name, value) if name.to_sym == :id self.id = (value) @@ -83,7 +79,6 @@ def []=(name, value) super(name, value) end end - end module Initializer @@ -101,5 +96,4 @@ def self.included(receiver) receiver.send :include, InstanceMethods receiver.send :prepend, Initializer end - end diff --git a/spec/beyonic/collection_request_spec.rb b/spec/beyonic/collection_request_spec.rb index 3735453..0673145 100644 --- a/spec/beyonic/collection_request_spec.rb +++ b/spec/beyonic/collection_request_spec.rb @@ -64,7 +64,6 @@ is_expected.to raise_error } end - end describe '.list' do diff --git a/spec/beyonic/metadata_spec.rb b/spec/beyonic/metadata_spec.rb index 9fbb1b5..c0872bb 100644 --- a/spec/beyonic/metadata_spec.rb +++ b/spec/beyonic/metadata_spec.rb @@ -66,6 +66,4 @@ it { is_expected.to have_attributes('metadata': metadata_dot_notation_request.metadata, currency: 'BXC') } end end - - end diff --git a/spec/beyonic/payment_spec.rb b/spec/beyonic/payment_spec.rb index e2cc41a..0e274d2 100644 --- a/spec/beyonic/payment_spec.rb +++ b/spec/beyonic/payment_spec.rb @@ -70,7 +70,6 @@ is_expected.to raise_error } end - end describe '.list' do @@ -177,7 +176,6 @@ context 'loaded object' do subject { Beyonic::Payment } before do - allow(subject).to receive(:update) create_payment.description = 'foo' diff --git a/spec/beyonic/webhook_spec.rb b/spec/beyonic/webhook_spec.rb index a40d95f..80c446e 100644 --- a/spec/beyonic/webhook_spec.rb +++ b/spec/beyonic/webhook_spec.rb @@ -64,7 +64,6 @@ is_expected.to raise_error } end - end describe '.list' do @@ -282,7 +281,6 @@ ) } it { is_expected.to be_truthy } - end context 'Forbidden' do diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 30c1873..b6c2627 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -3,7 +3,6 @@ add_filter '/spec/' end - require 'rubygems' require 'bundler/setup' From 409df5d4d0a00e75404f1b887561438533edab2b Mon Sep 17 00:00:00 2001 From: alvinkatojr Date: Thu, 25 Jun 2020 07:36:27 +0300 Subject: [PATCH 08/14] Rubocop fix: removes redundancies eg: interpolations, explicit returns, parentheses, percents and opts for mutable constants, compact hash methods and directory path expansion --- .rubocop.yml | 42 +++++++++++++ .rubocop_todo.yml | 109 ---------------------------------- beyonic.gemspec | 8 +-- lib/beyonic/abstract_api.rb | 16 ++--- lib/beyonic/version.rb | 2 +- spec/beyonic/accounts_spec.rb | 2 +- spec/beyonic/webhook_spec.rb | 4 +- 7 files changed, 57 insertions(+), 126 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 81fa20a..e6f3afe 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -71,3 +71,45 @@ Style/Lambda: Style/StringLiterals: EnforcedStyle: single_quotes Enabled: true + +Style/ClassAndModuleChildren: + Enabled: false + +Style/Documentation: + Enabled: false + +Style/RedundantInterpolation: + Enabled: false + +Style/RedundantParentheses: + Enabled: true + +Style/RedundantPercentQ: + Enabled: true + +Style/RedundantReturn: + Enabled: true + +Style/RedundantSelf: + Enabled: true + +Style/MutableConstant: + EnforcedStyle: literals + Enabled: true + +Style/PercentLiteralDelimiters: + Enabled: true + +Style/PreferredHashMethods: + EnforcedStyle: short + Enabled: true + +Style/RaiseArgs: + Enabled: true + EnforcedStyle: compact + +Style/Encoding: + Enabled: true + +Style/ExpandPathArguments: + Enabled: true \ No newline at end of file diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 57454b2..f88e78b 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -58,52 +58,6 @@ Naming/AccessorMethodName: Exclude: - 'lib/beyonic/abstract_api.rb' -# Offense count: 10 -# Cop supports --auto-correct. -# Configuration parameters: AutoCorrect, EnforcedStyle. -# SupportedStyles: nested, compact -Style/ClassAndModuleChildren: - Exclude: - - 'lib/beyonic/abstract_api.rb' - - 'lib/beyonic/account.rb' - - 'lib/beyonic/collection.rb' - - 'lib/beyonic/collection_request.rb' - - 'lib/beyonic/contact.rb' - - 'lib/beyonic/currency.rb' - - 'lib/beyonic/network.rb' - - 'lib/beyonic/payment.rb' - - 'lib/beyonic/transaction.rb' - - 'lib/beyonic/webhook.rb' - -# Offense count: 14 -Style/Documentation: - Exclude: - - 'spec/**/*' - - 'test/**/*' - - 'lib/beyonic.rb' - - 'lib/beyonic/abstract_api.rb' - - 'lib/beyonic/account.rb' - - 'lib/beyonic/collection.rb' - - 'lib/beyonic/collection_request.rb' - - 'lib/beyonic/contact.rb' - - 'lib/beyonic/currency.rb' - - 'lib/beyonic/network.rb' - - 'lib/beyonic/payment.rb' - - 'lib/beyonic/transaction.rb' - - 'lib/beyonic/webhook.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -Style/Encoding: - Exclude: - - 'beyonic.gemspec' - -# Offense count: 1 -# Cop supports --auto-correct. -Style/ExpandPathArguments: - Exclude: - - 'beyonic.gemspec' - # Offense count: 22 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle. @@ -111,69 +65,6 @@ Style/ExpandPathArguments: Style/FrozenStringLiteralComment: Enabled: false -# Offense count: 2 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle. -# SupportedStyles: literals, strict -Style/MutableConstant: - Exclude: - - 'lib/beyonic/version.rb' - - 'spec/beyonic/accounts_spec.rb' - -# Offense count: 2 -# Cop supports --auto-correct. -# Configuration parameters: PreferredDelimiters. -Style/PercentLiteralDelimiters: - Exclude: - - 'beyonic.gemspec' - -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle. -# SupportedStyles: short, verbose -Style/PreferredHashMethods: - Exclude: - - 'lib/beyonic/abstract_api.rb' - -# Offense count: 2 -# Cop supports --auto-correct. -# Configuration parameters: . -# SupportedStyles: compact, exploded -Style/RaiseArgs: - EnforcedStyle: compact - -# Offense count: 1 -# Cop supports --auto-correct. -Style/RedundantInterpolation: - Exclude: - - 'spec/beyonic/accounts_spec.rb' - -# Offense count: 4 -# Cop supports --auto-correct. -Style/RedundantParentheses: - Exclude: - - 'lib/beyonic/abstract_api.rb' - - 'spec/beyonic/webhook_spec.rb' - -# Offense count: 2 -# Cop supports --auto-correct. -Style/RedundantPercentQ: - Exclude: - - 'beyonic.gemspec' - -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: AllowMultipleReturnValues. -Style/RedundantReturn: - Exclude: - - 'lib/beyonic/abstract_api.rb' - -# Offense count: 5 -# Cop supports --auto-correct. -Style/RedundantSelf: - Exclude: - - 'lib/beyonic/abstract_api.rb' - # Offense count: 5 # Cop supports --auto-correct. # Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns. diff --git a/beyonic.gemspec b/beyonic.gemspec index 4d4638e..c4a2f71 100644 --- a/beyonic.gemspec +++ b/beyonic.gemspec @@ -1,6 +1,4 @@ -# coding: utf-8 - -lib = File.expand_path('../lib', __FILE__) +lib = File.expand_path('lib', __dir__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require 'beyonic/version' @@ -9,8 +7,8 @@ Gem::Specification.new do |spec| spec.version = Beyonic::VERSION spec.authors = ['Oleg German', 'Luke Kyohere'] spec.email = ['oleg.german@gmail.com', 'luke@beyonic.com'] - spec.summary = %q{Ruby library for the beyonic.com api} - spec.description = %q{Beyonic.com makes enterprise payments to mobile easy. Details: http://beyonic.com} + spec.summary = 'Ruby library for the beyonic.com api' + spec.description = 'Beyonic.com makes enterprise payments to mobile easy. Details: http://beyonic.com' spec.homepage = 'http://support.beyonic.com/api/' spec.license = 'MIT' diff --git a/lib/beyonic/abstract_api.rb b/lib/beyonic/abstract_api.rb index 1d3b1b1..c5404d7 100644 --- a/lib/beyonic/abstract_api.rb +++ b/lib/beyonic/abstract_api.rb @@ -9,14 +9,14 @@ def set_endpoint_resource(resource) def create(payload = {}, header_overrides = {}) # transform metadata from hash notation to dot notation - if (payload.has_key? :metadata) && (!payload[:metadata].empty?) + if (payload.key? :metadata) && !payload[:metadata].empty? payload[:metadata].each do |key, value| payload["metadata.#{key}"] = value end payload.delete :metadata end resp = RestClient.post(@endpoint_url, payload, headers(header_overrides)) - self.new(Oj.load(resp)) + new(Oj.load(resp)) rescue RestClient::BadRequest => e raise ApiError.new(Oj.load(e.response.body)) end @@ -28,19 +28,19 @@ def list(payload = {}) uri.query_values = payload resp = RestClient.get(@endpoint_url + '?' + uri.query, headers) - ret = self.new(Oj.load(resp)) - ret.results = ret.results.map { |obj_attrs| self.new(obj_attrs) } - return ret + ret = new(Oj.load(resp)) + ret.results = ret.results.map { |obj_attrs| new(obj_attrs) } + ret end def get(id) resp = RestClient.get("#{@endpoint_url}/#{id}", headers) - self.new(Oj.load(resp)) + new(Oj.load(resp)) end def update(id, payload, header_overrides = {}) resp = RestClient.patch("#{@endpoint_url}/#{id}", payload, headers(header_overrides)) - self.new(Oj.load(resp)) + new(Oj.load(resp)) rescue RestClient::BadRequest => e raise ApiError.new(Oj.load(e.response.body)) end @@ -74,7 +74,7 @@ def save def []=(name, value) if name.to_sym == :id - self.id = (value) + self.id = value else super(name, value) end diff --git a/lib/beyonic/version.rb b/lib/beyonic/version.rb index 021e919..aecc048 100644 --- a/lib/beyonic/version.rb +++ b/lib/beyonic/version.rb @@ -1,3 +1,3 @@ module Beyonic - VERSION = '0.0.15' + VERSION = '0.0.15'.freeze end diff --git a/spec/beyonic/accounts_spec.rb b/spec/beyonic/accounts_spec.rb index 4d15f57..1c7c1ce 100644 --- a/spec/beyonic/accounts_spec.rb +++ b/spec/beyonic/accounts_spec.rb @@ -4,7 +4,7 @@ before do Beyonic.api_key = 'd349087313cc7a6627d77ab61163d4dab6449b4c' Beyonic.api_version = 'v1' - API_ENDPOINT = 'https://staging.beyonic.com/api/accounts' + API_ENDPOINT = 'https://staging.beyonic.com/api/accounts'.freeze Beyonic::Account.instance_variable_set(:@endpoint_url, API_ENDPOINT) end diff --git a/spec/beyonic/webhook_spec.rb b/spec/beyonic/webhook_spec.rb index 80c446e..5961308 100644 --- a/spec/beyonic/webhook_spec.rb +++ b/spec/beyonic/webhook_spec.rb @@ -250,13 +250,13 @@ describe '#id=' do it { expect do - create_webhook.id = (4) + create_webhook.id = 4 end.to raise_error "Can't change id of existing Beyonic::Webhook" } it { expect do - create_webhook[:id] = (4) + create_webhook[:id] = 4 end.to raise_error "Can't change id of existing Beyonic::Webhook" } From 4f72078aa0c953f038aa52af85980ac14f53d6eb Mon Sep 17 00:00:00 2001 From: alvinkatojr Date: Thu, 25 Jun 2020 07:58:23 +0300 Subject: [PATCH 09/14] Rubocop fix: better indentation, leading white space for comments and rescue errors alignment --- .rubocop.yml | 16 ++++++++++++++++ .rubocop_todo.yml | 34 +--------------------------------- lib/beyonic/abstract_api.rb | 6 +++--- spec/beyonic/webhook_spec.rb | 6 +++--- 4 files changed, 23 insertions(+), 39 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index e6f3afe..f8c3d02 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -61,6 +61,22 @@ Layout/TrailingWhitespace: AllowInHeredoc: false Enabled: true +Layout/IndentationWidth: + Enabled: true + +Layout/LeadingCommentSpace: + Enabled: true + +Layout/LineLength: + Enabled: true + Max: 168 + +Layout/RescueEnsureAlignment: + Enabled: true + +Naming/AccessorMethodName: + Enabled: false + Style/BlockDelimiters: Enabled: true diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index f88e78b..01e2e82 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -14,26 +14,6 @@ Gemspec/OrderedDependencies: Exclude: - 'beyonic.gemspec' -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: Width, IgnoredPatterns. -Layout/IndentationWidth: - Exclude: - - 'spec/beyonic/webhook_spec.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: AllowDoxygenCommentStyle, AllowGemfileRubyComment. -Layout/LeadingCommentSpace: - Exclude: - - 'lib/beyonic/abstract_api.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -Layout/RescueEnsureAlignment: - Exclude: - - 'lib/beyonic/abstract_api.rb' - # Offense count: 2 # Cop supports --auto-correct. # Configuration parameters: IgnoreEmptyBlocks, AllowUnusedKeywordArguments. @@ -53,21 +33,9 @@ Metrics/AbcSize: Metrics/BlockLength: Max: 272 -# Offense count: 1 -Naming/AccessorMethodName: - Exclude: - - 'lib/beyonic/abstract_api.rb' - # Offense count: 22 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle. # SupportedStyles: always, always_true, never Style/FrozenStringLiteralComment: - Enabled: false - -# Offense count: 5 -# Cop supports --auto-correct. -# Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns. -# URISchemes: http, https -Layout/LineLength: - Max: 168 + Enabled: false \ No newline at end of file diff --git a/lib/beyonic/abstract_api.rb b/lib/beyonic/abstract_api.rb index c5404d7..34398c5 100644 --- a/lib/beyonic/abstract_api.rb +++ b/lib/beyonic/abstract_api.rb @@ -41,8 +41,8 @@ def get(id) def update(id, payload, header_overrides = {}) resp = RestClient.patch("#{@endpoint_url}/#{id}", payload, headers(header_overrides)) new(Oj.load(resp)) - rescue RestClient::BadRequest => e - raise ApiError.new(Oj.load(e.response.body)) + rescue RestClient::BadRequest => e + raise ApiError.new(Oj.load(e.response.body)) end def delete(id) @@ -84,7 +84,7 @@ def []=(name, value) module Initializer def initialize(*args) super(*args) - #We should define it after Object initialization + # We should define it after Object initialization define_singleton_method(:id=) do |val| raise "Can't change id of existing #{self.class}" end diff --git a/spec/beyonic/webhook_spec.rb b/spec/beyonic/webhook_spec.rb index 5961308..4798175 100644 --- a/spec/beyonic/webhook_spec.rb +++ b/spec/beyonic/webhook_spec.rb @@ -92,9 +92,9 @@ subject do lambda { - VCR.use_cassette('webhooks_invalid_token_list') do - Beyonic::Webhook.list - end + VCR.use_cassette('webhooks_invalid_token_list') do + Beyonic::Webhook.list + end } end it { From d2d1049fcd51193cee65da4169ddc1f57fbc4804 Mon Sep 17 00:00:00 2001 From: alvinkatojr Date: Thu, 25 Jun 2020 09:18:06 +0300 Subject: [PATCH 10/14] Adds versioned runtime and development dependencies --- beyonic.gemspec | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/beyonic.gemspec b/beyonic.gemspec index c4a2f71..6988dfe 100644 --- a/beyonic.gemspec +++ b/beyonic.gemspec @@ -17,15 +17,15 @@ Gem::Specification.new do |spec| spec.test_files = spec.files.grep(%r{^(test|spec|features)/}) spec.require_paths = ['lib'] - spec.add_runtime_dependency 'rest-client' + spec.add_runtime_dependency 'rest-client', '~> 2.1.0' spec.add_runtime_dependency 'oj', '~> 2.11' - spec.add_runtime_dependency 'addressable' + spec.add_runtime_dependency 'addressable', '~> 2.7' - spec.add_development_dependency 'bundler', '~> 1.7' - spec.add_development_dependency 'rake', '~> 12.3.3' - spec.add_development_dependency 'rspec' - spec.add_development_dependency 'rspec-collection_matchers' - spec.add_development_dependency 'webmock' - spec.add_development_dependency 'simplecov' - spec.add_development_dependency 'vcr' + spec.add_development_dependency 'bundler', '~> 2.1.4' + spec.add_development_dependency 'rake', '~> 13.0.1' + spec.add_development_dependency 'rspec', '~> 3.9' + spec.add_development_dependency 'rspec-collection_matchers', '~> 1.2.0' + spec.add_development_dependency 'webmock', '~> 3.8.3' + spec.add_development_dependency 'simplecov', '~> 0.18.5' + spec.add_development_dependency 'vcr', '~> 6.0.0' end From 5554d5a35a77abceec61d2bb8805a7cf14c29b62 Mon Sep 17 00:00:00 2001 From: alvinkatojr Date: Tue, 30 Jun 2020 08:59:09 +0300 Subject: [PATCH 11/14] Rubocop fix: prefixes unused variables with an underscore --- .rubocop.yml | 11 +++++++++++ .rubocop_todo.yml | 19 ------------------- lib/beyonic/abstract_api.rb | 2 +- spec/spec_helper.rb | 2 +- 4 files changed, 13 insertions(+), 21 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index f8c3d02..72f147b 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -74,6 +74,17 @@ Layout/LineLength: Layout/RescueEnsureAlignment: Enabled: true +Lint/UnusedBlockArgument: + Enabled: true + +Metrics/AbcSize: + Enabled: true + Max: 17 + +Metrics/BlockLength: + Enabled: true + Max: 272 + Naming/AccessorMethodName: Enabled: false diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 01e2e82..122f620 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -14,25 +14,6 @@ Gemspec/OrderedDependencies: Exclude: - 'beyonic.gemspec' -# Offense count: 2 -# Cop supports --auto-correct. -# Configuration parameters: IgnoreEmptyBlocks, AllowUnusedKeywordArguments. -Lint/UnusedBlockArgument: - Exclude: - - 'lib/beyonic/abstract_api.rb' - - 'spec/spec_helper.rb' - -# Offense count: 1 -# Configuration parameters: IgnoredMethods. -Metrics/AbcSize: - Max: 17 - -# Offense count: 21 -# Configuration parameters: CountComments, ExcludedMethods. -# ExcludedMethods: refine -Metrics/BlockLength: - Max: 272 - # Offense count: 22 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle. diff --git a/lib/beyonic/abstract_api.rb b/lib/beyonic/abstract_api.rb index 34398c5..57d29f2 100644 --- a/lib/beyonic/abstract_api.rb +++ b/lib/beyonic/abstract_api.rb @@ -85,7 +85,7 @@ module Initializer def initialize(*args) super(*args) # We should define it after Object initialization - define_singleton_method(:id=) do |val| + define_singleton_method(:id=) do |_val| raise "Can't change id of existing #{self.class}" end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index b6c2627..31637a0 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -32,7 +32,7 @@ c.cassette_library_dir = 'fixtures/vcr_cassettes' c.ignore_hosts '127.0.0.1', 'localhost' c.hook_into :webmock - c.before_record do |i| + c.before_record do |_i| OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE end end From c5be24185ad9bf2f08e5e3ed330c3019099f9732 Mon Sep 17 00:00:00 2001 From: alvinkatojr Date: Tue, 30 Jun 2020 09:15:33 +0300 Subject: [PATCH 12/14] Rubocop fix: adds frozen strings magic comment making all strings immmutable by default in preparation for Ruby 3 --- .rubocop.yml | 3 +++ .rubocop_todo.yml | 16 +--------------- Gemfile | 2 ++ Rakefile | 2 ++ lib/beyonic.rb | 2 ++ lib/beyonic/abstract_api.rb | 2 ++ lib/beyonic/account.rb | 2 ++ lib/beyonic/collection.rb | 2 ++ lib/beyonic/collection_request.rb | 2 ++ lib/beyonic/contact.rb | 2 ++ lib/beyonic/currency.rb | 2 ++ lib/beyonic/network.rb | 2 ++ lib/beyonic/payment.rb | 2 ++ lib/beyonic/transaction.rb | 2 ++ lib/beyonic/version.rb | 4 +++- lib/beyonic/webhook.rb | 2 ++ spec/beyonic/accounts_spec.rb | 4 +++- spec/beyonic/collection_request_spec.rb | 2 ++ spec/beyonic/collection_spec.rb | 2 ++ spec/beyonic/metadata_spec.rb | 2 ++ spec/beyonic/payment_spec.rb | 2 ++ spec/beyonic/webhook_spec.rb | 2 ++ spec/spec_helper.rb | 2 ++ 23 files changed, 48 insertions(+), 17 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 72f147b..73f922c 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -91,6 +91,9 @@ Naming/AccessorMethodName: Style/BlockDelimiters: Enabled: true +Style/FrozenStringLiteralComment: + Enabled: true + Style/Lambda: EnforcedStyle: line_count_dependent Enabled: true diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 122f620..50f1b1d 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -5,18 +5,4 @@ # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. - -# Offense count: 3 -# Cop supports --auto-correct. -# Configuration parameters: TreatCommentsAsGroupSeparators, Include. -# Include: **/*.gemspec -Gemspec/OrderedDependencies: - Exclude: - - 'beyonic.gemspec' - -# Offense count: 22 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle. -# SupportedStyles: always, always_true, never -Style/FrozenStringLiteralComment: - Enabled: false \ No newline at end of file + \ No newline at end of file diff --git a/Gemfile b/Gemfile index 5caef61..1c4b182 100644 --- a/Gemfile +++ b/Gemfile @@ -1,3 +1,5 @@ +# frozen_string_literal: true + source 'https://rubygems.org' # Specify your gem's dependencies in beyonic.gemspec diff --git a/Rakefile b/Rakefile index c702cfc..7398a90 100644 --- a/Rakefile +++ b/Rakefile @@ -1 +1,3 @@ +# frozen_string_literal: true + require 'bundler/gem_tasks' diff --git a/lib/beyonic.rb b/lib/beyonic.rb index 2355d6e..86bb243 100644 --- a/lib/beyonic.rb +++ b/lib/beyonic.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Beyonic require 'rest-client' require 'oj' diff --git a/lib/beyonic/abstract_api.rb b/lib/beyonic/abstract_api.rb index 57d29f2..4796e74 100644 --- a/lib/beyonic/abstract_api.rb +++ b/lib/beyonic/abstract_api.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Beyonic::AbstractApi class ApiError < StandardError end diff --git a/lib/beyonic/account.rb b/lib/beyonic/account.rb index ec9d9bc..7dfcdd7 100644 --- a/lib/beyonic/account.rb +++ b/lib/beyonic/account.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'ostruct' class Beyonic::Account < OpenStruct include Beyonic::AbstractApi diff --git a/lib/beyonic/collection.rb b/lib/beyonic/collection.rb index 55f8992..d663136 100644 --- a/lib/beyonic/collection.rb +++ b/lib/beyonic/collection.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'ostruct' class Beyonic::Collection < OpenStruct include Beyonic::AbstractApi diff --git a/lib/beyonic/collection_request.rb b/lib/beyonic/collection_request.rb index 6bd2996..812529d 100644 --- a/lib/beyonic/collection_request.rb +++ b/lib/beyonic/collection_request.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'ostruct' class Beyonic::CollectionRequest < OpenStruct include Beyonic::AbstractApi diff --git a/lib/beyonic/contact.rb b/lib/beyonic/contact.rb index 58da158..e41f6bd 100644 --- a/lib/beyonic/contact.rb +++ b/lib/beyonic/contact.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'ostruct' class Beyonic::Contact < OpenStruct include Beyonic::AbstractApi diff --git a/lib/beyonic/currency.rb b/lib/beyonic/currency.rb index d8396cc..12f8702 100644 --- a/lib/beyonic/currency.rb +++ b/lib/beyonic/currency.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'ostruct' class Beyonic::Currency < OpenStruct include Beyonic::AbstractApi diff --git a/lib/beyonic/network.rb b/lib/beyonic/network.rb index 5a8d6d6..43a1dfb 100644 --- a/lib/beyonic/network.rb +++ b/lib/beyonic/network.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'ostruct' class Beyonic::Network < OpenStruct include Beyonic::AbstractApi diff --git a/lib/beyonic/payment.rb b/lib/beyonic/payment.rb index 505f260..0f365ac 100644 --- a/lib/beyonic/payment.rb +++ b/lib/beyonic/payment.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'ostruct' class Beyonic::Payment < OpenStruct include Beyonic::AbstractApi diff --git a/lib/beyonic/transaction.rb b/lib/beyonic/transaction.rb index 3f056fa..80f9252 100644 --- a/lib/beyonic/transaction.rb +++ b/lib/beyonic/transaction.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'ostruct' class Beyonic::Transaction < OpenStruct include Beyonic::AbstractApi diff --git a/lib/beyonic/version.rb b/lib/beyonic/version.rb index aecc048..54b4cad 100644 --- a/lib/beyonic/version.rb +++ b/lib/beyonic/version.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Beyonic - VERSION = '0.0.15'.freeze + VERSION = '0.0.15' end diff --git a/lib/beyonic/webhook.rb b/lib/beyonic/webhook.rb index 792fae2..f1361d2 100644 --- a/lib/beyonic/webhook.rb +++ b/lib/beyonic/webhook.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'ostruct' class Beyonic::Webhook < OpenStruct include Beyonic::AbstractApi diff --git a/spec/beyonic/accounts_spec.rb b/spec/beyonic/accounts_spec.rb index 1c7c1ce..8cb4717 100644 --- a/spec/beyonic/accounts_spec.rb +++ b/spec/beyonic/accounts_spec.rb @@ -1,10 +1,12 @@ +# frozen_string_literal: true + require 'spec_helper' describe Beyonic::Account do before do Beyonic.api_key = 'd349087313cc7a6627d77ab61163d4dab6449b4c' Beyonic.api_version = 'v1' - API_ENDPOINT = 'https://staging.beyonic.com/api/accounts'.freeze + API_ENDPOINT = 'https://staging.beyonic.com/api/accounts' Beyonic::Account.instance_variable_set(:@endpoint_url, API_ENDPOINT) end diff --git a/spec/beyonic/collection_request_spec.rb b/spec/beyonic/collection_request_spec.rb index 0673145..616b77f 100644 --- a/spec/beyonic/collection_request_spec.rb +++ b/spec/beyonic/collection_request_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + describe Beyonic::CollectionRequest do before do Beyonic.api_key = 'd349087313cc7a6627d77ab61163d4dab6449b4c' diff --git a/spec/beyonic/collection_spec.rb b/spec/beyonic/collection_spec.rb index 0b4fae6..bdcbd22 100644 --- a/spec/beyonic/collection_spec.rb +++ b/spec/beyonic/collection_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Beyonic::Collection do diff --git a/spec/beyonic/metadata_spec.rb b/spec/beyonic/metadata_spec.rb index c0872bb..55108b0 100644 --- a/spec/beyonic/metadata_spec.rb +++ b/spec/beyonic/metadata_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Beyonic::CollectionRequest do diff --git a/spec/beyonic/payment_spec.rb b/spec/beyonic/payment_spec.rb index 0e274d2..cd86c50 100644 --- a/spec/beyonic/payment_spec.rb +++ b/spec/beyonic/payment_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Beyonic::Payment do diff --git a/spec/beyonic/webhook_spec.rb b/spec/beyonic/webhook_spec.rb index 4798175..17ff2c8 100644 --- a/spec/beyonic/webhook_spec.rb +++ b/spec/beyonic/webhook_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Beyonic::Webhook do diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 31637a0..fe26036 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'simplecov' SimpleCov.start do add_filter '/spec/' From a02975fc5df5116ddf3b6c263eb658fe95e72e53 Mon Sep 17 00:00:00 2001 From: alvinkatojr Date: Tue, 30 Jun 2020 09:32:26 +0300 Subject: [PATCH 13/14] Rubocop fix: reorders gem spec dependencies and sets minimum ruby version to 2.5.8 which is in maintenance mode and should be the lowest secure version available --- .rubocop.yml | 12 ++++++++++++ beyonic.gemspec | 9 ++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 73f922c..37c8190 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,5 +1,17 @@ inherit_from: .rubocop_todo.yml +AllCops: + TargetRubyVersion: 2.5.8 + +Gemspec/OrderedDependencies: + Enabled: true + +Gemspec/DuplicatedAssignment: + Enabled: true + +Gemspec/RubyVersionGlobalsUsage: + Enabled: true + Layout/ArgumentAlignment: EnforcedStyle: with_first_argument Enabled: true diff --git a/beyonic.gemspec b/beyonic.gemspec index 6988dfe..3d14d50 100644 --- a/beyonic.gemspec +++ b/beyonic.gemspec @@ -1,3 +1,5 @@ +# frozen_string_literal: true + lib = File.expand_path('lib', __dir__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require 'beyonic/version' @@ -5,6 +7,7 @@ require 'beyonic/version' Gem::Specification.new do |spec| spec.name = 'beyonic' spec.version = Beyonic::VERSION + spec.required_ruby_version = '2.5.8' spec.authors = ['Oleg German', 'Luke Kyohere'] spec.email = ['oleg.german@gmail.com', 'luke@beyonic.com'] spec.summary = 'Ruby library for the beyonic.com api' @@ -17,15 +20,15 @@ Gem::Specification.new do |spec| spec.test_files = spec.files.grep(%r{^(test|spec|features)/}) spec.require_paths = ['lib'] - spec.add_runtime_dependency 'rest-client', '~> 2.1.0' - spec.add_runtime_dependency 'oj', '~> 2.11' spec.add_runtime_dependency 'addressable', '~> 2.7' + spec.add_runtime_dependency 'oj', '~> 2.11' + spec.add_runtime_dependency 'rest-client', '~> 2.1.0' spec.add_development_dependency 'bundler', '~> 2.1.4' spec.add_development_dependency 'rake', '~> 13.0.1' spec.add_development_dependency 'rspec', '~> 3.9' spec.add_development_dependency 'rspec-collection_matchers', '~> 1.2.0' - spec.add_development_dependency 'webmock', '~> 3.8.3' spec.add_development_dependency 'simplecov', '~> 0.18.5' spec.add_development_dependency 'vcr', '~> 6.0.0' + spec.add_development_dependency 'webmock', '~> 3.8.3' end From 7877ce8f4038cd820e2447a72514b2dfd0d00260 Mon Sep 17 00:00:00 2001 From: alvinkatojr Date: Tue, 30 Jun 2020 09:32:43 +0300 Subject: [PATCH 14/14] Adds rbenv version file --- .ruby-version | 1 + 1 file changed, 1 insertion(+) create mode 100644 .ruby-version diff --git a/.ruby-version b/.ruby-version new file mode 100644 index 0000000..ecd7ee5 --- /dev/null +++ b/.ruby-version @@ -0,0 +1 @@ +2.5.8