Skip to content

Commit

Permalink
Merge pull request #6 from PaymentInstruments/configurator
Browse files Browse the repository at this point in the history
Adding configurator
  • Loading branch information
IvanShamatov authored Oct 28, 2021
2 parents b6bbdad + 629eeaf commit c27617e
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 4 deletions.
13 changes: 13 additions & 0 deletions bin/console
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

require "bundler/setup"
require "yookassa"

begin
require "pry-byebug"
Pry.start
rescue LoadError
require "irb"
IRB.start
end
8 changes: 8 additions & 0 deletions bin/setup
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash
set -euo pipefail
IFS=$'\n\t'
set -vx

bundle install

# Do any other automated setup that you need to do here
11 changes: 11 additions & 0 deletions lib/yookassa.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,14 @@
require "yookassa/entity/payment"
require "yookassa/entity/refund"
require "yookassa/error"
require "yookassa/config"

module Yookassa
def self.configure
yield(config)
end

def self.config
@config ||= Config.new
end
end
7 changes: 7 additions & 0 deletions lib/yookassa/config.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

module Yookassa
class Config
attr_accessor :shop_id, :api_key
end
end
4 changes: 2 additions & 2 deletions lib/yookassa/payment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

module Yookassa
class Payment < Evil::Client
option :shop_id, proc(&:to_s)
option :api_key, proc(&:to_s)
option :shop_id, proc(&:to_s), default: proc { Yookassa.config.shop_id }
option :api_key, proc(&:to_s), default: proc { Yookassa.config.api_key }

path { "https://api.yookassa.ru/v3/payments" }
security { basic_auth shop_id, api_key }
Expand Down
4 changes: 2 additions & 2 deletions lib/yookassa/refund.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

module Yookassa
class Refund < Evil::Client
option :shop_id, proc(&:to_s)
option :api_key, proc(&:to_s)
option :shop_id, proc(&:to_s), default: proc { Yookassa.config.shop_id }
option :api_key, proc(&:to_s), default: proc { Yookassa.config.api_key }

path { "https://api.yookassa.ru/v3/refunds" }
security { basic_auth shop_id, api_key }
Expand Down
9 changes: 9 additions & 0 deletions spec/yookassa/config_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# frozen_string_literal: true

module Yookassa
RSpec.describe Config do
subject { described_class.new }
it { is_expected.to respond_to(:shop_id) }
it { is_expected.to respond_to(:api_key) }
end
end
14 changes: 14 additions & 0 deletions spec/yookassa_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,18 @@
it "has a version number" do
expect(Yookassa::VERSION).not_to be nil
end

describe ".configure" do
before do
Yookassa.configure do |config|
config.shop_id = 123
config.api_key = "test_321"
end
end

it "stores settings and provides access to credentials" do
expect(Yookassa.config.shop_id).to eq(123)
expect(Yookassa.config.api_key).to eq("test_321")
end
end
end

0 comments on commit c27617e

Please sign in to comment.