swish_qr 0.0.3 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/swish_qr.rb +15 -13
  3. metadata +5 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d74217fa684799cd15d8abc1ae3e64a7a6bb192d
4
- data.tar.gz: f9bf83f426042ca00e4f8ec8cbb941d40efa4b7c
3
+ metadata.gz: 74229711ef84fe4804407236ca30b50e7e611956
4
+ data.tar.gz: e3a7ea9ecd2484575dd8a86741d101246c090dba
5
5
  SHA512:
6
- metadata.gz: 3b047569b1630493a0631c8a2784efc264e2faf1f8011346cfa5d4a4695089fc4e633697141d419e34046b8e4ce3bf59525c920d4df45c2efe68b1d4710a934e
7
- data.tar.gz: 178d855fdc6bfd4cdfbc439cd3b47a54aca8b04e9cfe0bd0b4f8f7770bc0e477526345353826d7c052fa1e949c838faffac13c06eccc92064b8738e45e42894d
6
+ metadata.gz: 8417ba48f25b053d6e02a2ffebaf77f894718630e0b9d8d360b94365021bc0b5dab7785e17399f65f2b170478a4e69b3dbe22379920f5116b765937d1270093d
7
+ data.tar.gz: 06eb8c88934a31e33a5aee3526247646dd9735fb9fbc79100a0cb94fa8579be34548ec5be41b77ea8f641b20d4eaa776edf89a80d9012c72276c7fa256fbd894
data/lib/swish_qr.rb CHANGED
@@ -7,9 +7,9 @@ class SwishQr
7
7
 
8
8
  SWISH_QR_API_ENDPOINT="https://www.swish.bankgirot.se/qrg-swish/api/v1/prefilled"
9
9
  @result = {}
10
- @request_hash = {}
10
+ @data_hash = {}
11
11
  @image_format
12
- attr_accessor :request_hash
12
+ attr_accessor :data_hash
13
13
 
14
14
  SIMPLE_VALUES = [ :format, :size, :border, :transparent ]
15
15
  COMPLEX_VALUES = [ :payee, :amount, :message ]
@@ -18,7 +18,7 @@ class SwishQr
18
18
  def initialize(args)
19
19
  check_args(args)
20
20
  @result = HTTParty.post(SWISH_QR_API_ENDPOINT,
21
- :body => build_request_body(args),
21
+ :body => build_data_hash(args),
22
22
  :headers => { 'Content-Type' => 'application/json' } )
23
23
  end
24
24
 
@@ -38,6 +38,8 @@ class SwishQr
38
38
  @result.parsed_response['error']
39
39
  end
40
40
 
41
+ private
42
+
41
43
  def check_args(args)
42
44
  raise ArgumentError, "Invalid format: '#{args[:format]}', must specify one of: #{VALID_FORMATS}" unless VALID_FORMATS.include?(args[:format])
43
45
  raise ArgumentError, "Size (minimum 300) must be specified for #{args[:format]}" unless (args[:format] == 'svg' || args[:size].to_i >= 300)
@@ -45,23 +47,23 @@ class SwishQr
45
47
  raise ArgumentError, "Max border is 4" if (args[:border].to_i > 4)
46
48
  end
47
49
 
48
- def build_request_body(args)
50
+ def build_data_hash(args)
49
51
  @image_format = args[:format]
50
- @request_hash = get_simple_values_from_args(args)
51
- @request_hash.merge!(get_complex_values_from_args(args))
52
+ @data_hash = get_simple_values_from_args(args)
53
+ @data_hash.merge!(get_complex_values_from_args(args))
52
54
  sanitise_amount
53
- @request_hash.to_json
55
+ @data_hash.to_json
54
56
  end
55
57
 
56
58
  def sanitise_amount
57
- return unless @request_hash[:amount]
59
+ return unless @data_hash[:amount]
58
60
  # Delete amount if it's blank / 0, to ensure that the request is valid
59
- if @request_hash[:amount][:value].to_i == 0
60
- @request_hash.delete(:amount)
61
+ if @data_hash[:amount][:value].to_i == 0
62
+ @data_hash.delete(:amount)
61
63
  return
62
64
  end
63
65
  # This is to support BigDecimal, which would otherwise get misrepresented as a string in the JSON
64
- @request_hash[:amount][:value] = @request_hash[:amount][:value].to_f unless @request_hash[:amount][:value].is_a?(Integer)
66
+ @data_hash[:amount][:value] = @data_hash[:amount][:value].to_f unless @data_hash[:amount][:value].is_a?(Integer)
65
67
  end
66
68
 
67
69
  def get_simple_values_from_args(args)
@@ -79,11 +81,11 @@ end
79
81
 
80
82
  class SwishUri < SwishQr
81
83
  def initialize(args)
82
- build_request_body(args)
84
+ build_data_hash(args)
83
85
  end
84
86
 
85
87
  def uri
86
- "swish://payment?data=#{{version: 1}.merge(@request_hash).to_json}"
88
+ "swish://payment?data=#{{version: 1}.merge(@data_hash).to_json}"
87
89
  end
88
90
  end
89
91
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: swish_qr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Linus Corin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-11-16 00:00:00.000000000 Z
11
+ date: 2017-12-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -80,7 +80,8 @@ dependencies:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
- description: An interface for the public Swish QR API
83
+ description: An interface for the public Swish QR API, and generator of Swish payment
84
+ URIs
84
85
  email:
85
86
  - noreply+see_website_for_email@corin.net
86
87
  executables: []
@@ -111,5 +112,5 @@ rubyforge_project:
111
112
  rubygems_version: 2.5.2
112
113
  signing_key:
113
114
  specification_version: 4
114
- summary: QR code generator for Swish
115
+ summary: QR code and URI generator for Swish
115
116
  test_files: []