epay_tools 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 86a7d1fe9a1ab192dac56eda9de0603d138ef6fb
4
- data.tar.gz: '009453ed0b480464cbb884fa4059c52195b1413c'
3
+ metadata.gz: deb853647418c084bd3c0ce9508e1652ca44b34e
4
+ data.tar.gz: 1973a1ddaf14c07f957f150be0c6a0d3d8588a75
5
5
  SHA512:
6
- metadata.gz: 58121ca27e808864e2e140082c306d855b3575dd88381fc4d4d0d515907cb914f3515d65e2ea75e5742fb7370fb1306a0e3291a0ac9f34e57c1dd8b33a7443d4
7
- data.tar.gz: 75b38dca8fde59b2de0628d108a7416e8b2fb14af96a5c8c3f58a8aee5c0b4a4f0c01030c60323f449e4dbc0c4a22cf32448071c9614135684cb24a181f9dbe6
6
+ metadata.gz: e5b29cc63c9eacf996c301cb69703d0d0bb545e91c28ca0b7ae7e0992fde03ad76a30adec20c7cf1a5ad4a154a2cfd5548f2b6c24568ebbb90281bbd171c1fd3
7
+ data.tar.gz: e616ee15165fcd619d8ffc8a055943c1bd9bd2c2b542b44589b30f4a8f2ce38a9f04d3b0209f9b16181b8054df82d2e0a60bdff7502aba239c2f3723560ca2a6
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1
1
+ 0.0.2
data/epay_tools.gemspec CHANGED
@@ -2,11 +2,11 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: epay_tools 0.0.1 ruby lib
5
+ # stub: epay_tools 0.0.2 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "epay_tools".freeze
9
- s.version = "0.0.1"
9
+ s.version = "0.0.2"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib".freeze]
@@ -30,11 +30,11 @@ Gem::Specification.new do |s|
30
30
  "VERSION",
31
31
  "epay_tools.gemspec",
32
32
  "lib/epay_tools.rb",
33
- "lib/epay_tools/hash_calculator_service.rb",
33
+ "lib/epay_tools/calculator.rb",
34
+ "lib/epay_tools/hash_generator.rb",
34
35
  "lib/epay_tools/ordered_parameters.rb",
35
- "lib/epay_tools/params_generator_service.rb",
36
36
  "shippable.yml",
37
- "spec/epay_tools/hash_calculator_service_spec.rb",
37
+ "spec/epay_tools/calculator_spec.rb",
38
38
  "spec/spec_helper.rb"
39
39
  ]
40
40
  s.homepage = "http://github.com/kaspernj/epay_tools".freeze
@@ -1,4 +1,4 @@
1
- class EpayTools::ParamsGeneratorService < ServicePattern::Service
1
+ class EpayTools::Calculator < ServicePattern::Service
2
2
  attr_reader :epay_merchant_number, :epay_md5_key, :params
3
3
 
4
4
  def initialize(epay_md5_key:, params:)
@@ -12,7 +12,7 @@ class EpayTools::ParamsGeneratorService < ServicePattern::Service
12
12
  epay_params[ordered_parameter] = params.fetch(ordered_parameter)
13
13
  end
14
14
 
15
- epay_hash = Digest::MD5.hexdigest("#{epay_params.values.join}#{epay_md5_key}")
15
+ epay_hash = EpayTools::HashGenerator.execute!(epay_md5_key: epay_md5_key, params: epay_params).result
16
16
  epay_params_with_hash = epay_params.merge("hash" => epay_hash)
17
17
 
18
18
  ServicePattern::Response.new(
@@ -0,0 +1,18 @@
1
+ class EpayTools::HashGenerator < ServicePattern::Service
2
+ attr_reader :epay_md5_key, :params
3
+
4
+ def initialize(epay_md5_key:, params:)
5
+ @epay_md5_key = epay_md5_key
6
+ @params = params.reject { |key, _value| key.to_s == "hash" }
7
+ end
8
+
9
+ def execute!
10
+ ServicePattern::Response.new(result: hash)
11
+ end
12
+
13
+ private
14
+
15
+ def hash
16
+ Digest::MD5.hexdigest("#{params.values.join}#{epay_md5_key}")
17
+ end
18
+ end
@@ -1,6 +1,6 @@
1
1
  require "spec_helper"
2
2
 
3
- describe EpayTools::HashCalculatorService do
3
+ describe EpayTools::Calculator do
4
4
  let(:epay_parameters) do
5
5
  {
6
6
  "merchantnumber" => "123123",
@@ -19,21 +19,15 @@ describe EpayTools::HashCalculatorService do
19
19
  }
20
20
  end
21
21
  let(:service) do
22
- EpayTools::HashCalculatorService.new(
22
+ EpayTools::Calculator.new(
23
23
  epay_md5_key: "secret-md5-key",
24
- query_parameters: epay_parameters
24
+ params: epay_parameters
25
25
  )
26
26
  end
27
27
 
28
28
  describe "#calculated_hash" do
29
29
  it "calculates the right hash" do
30
- expect(service.__send__(:calculated_hash)).to eq "edc52b2b2f619551146682061d3a9d0d"
31
- end
32
- end
33
-
34
- describe "#validated?" do
35
- it "returns true when the hash is right" do
36
- expect(service.__send__(:validated?)).to eq true
30
+ expect(service.execute!.result.fetch(:epay_hash)).to eq "edc52b2b2f619551146682061d3a9d0d"
37
31
  end
38
32
  end
39
33
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: epay_tools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - kaspernj
@@ -127,11 +127,11 @@ files:
127
127
  - VERSION
128
128
  - epay_tools.gemspec
129
129
  - lib/epay_tools.rb
130
- - lib/epay_tools/hash_calculator_service.rb
130
+ - lib/epay_tools/calculator.rb
131
+ - lib/epay_tools/hash_generator.rb
131
132
  - lib/epay_tools/ordered_parameters.rb
132
- - lib/epay_tools/params_generator_service.rb
133
133
  - shippable.yml
134
- - spec/epay_tools/hash_calculator_service_spec.rb
134
+ - spec/epay_tools/calculator_spec.rb
135
135
  - spec/spec_helper.rb
136
136
  homepage: http://github.com/kaspernj/epay_tools
137
137
  licenses:
@@ -1,39 +0,0 @@
1
- class EpayTools::HashCalculatorService < ServicePattern::Service
2
- attr_reader :query_parameters, :epay_md5_key
3
-
4
- def initialize(query_parameters:, epay_md5_key:)
5
- @query_parameters = query_parameters
6
- @epay_md5_key = epay_md5_key
7
- end
8
-
9
- def execute!
10
- ServicePattern::Response.new(
11
- result: {
12
- calculated_hash: calculated_hash,
13
- validated: validated?
14
- }
15
- )
16
- end
17
-
18
- private
19
-
20
- def calculated_hash
21
- @_calculated_hash ||= Digest::MD5.hexdigest("#{parameters_to_use.values.join}#{epay_md5_key}")
22
- end
23
-
24
- def parameters_to_use
25
- parameters = {}
26
-
27
- EpayTools::OrderedParameters::ORDERED_PARAMETERS.each do |ordered_parameter|
28
- parameters[ordered_parameter] = query_parameters.fetch(ordered_parameter)
29
- end
30
-
31
- parameters
32
- end
33
-
34
- def validated?
35
- return false unless query_parameters.key?("hash")
36
- return true if calculated_hash == query_parameters.fetch("hash")
37
- false
38
- end
39
- end