spelpaus.rb 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 5e2290fe67ff628af249086a4cd07fb5cf9e91d0c3c0803aa02fa3ecbeca0c19
4
+ data.tar.gz: b267b1db0688f3561fe4a82f27b172b5241fd1ff2483ad3cc8e3ef83aff67694
5
+ SHA512:
6
+ metadata.gz: 915f9ff11732768e2f82e3a17552c08d589eed4e9c7ba2f6a0001e80dbce3f11c858906143a6c4df81d698cf7777469712d31c870c3fd20c361057191a1697ce
7
+ data.tar.gz: 1c1c8e5140a6b3291dcf194a8d35c0eb2d2a1389a7971ff5ac957dcb4e37a8ca1e954922ba61602a8826128c59de37694a50566b2202bdb5691751a049300d99
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2023-05-21
4
+
5
+ - Initial release
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in spelpaus.gemspec
6
+ gemspec
7
+
8
+ group :development, :test do
9
+ gem 'pry-byebug', '3.10.1'
10
+ gem 'rake', '13.0.6'
11
+ gem 'rspec', '3.12.0'
12
+ gem 'securerandom', '0.2.2'
13
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,54 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ spelpaus.rb (0.1.0)
5
+ httparty (~> 0.21.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ byebug (11.1.3)
11
+ coderay (1.1.3)
12
+ diff-lcs (1.5.0)
13
+ httparty (0.21.0)
14
+ mini_mime (>= 1.0.0)
15
+ multi_xml (>= 0.5.2)
16
+ json (2.6.3)
17
+ method_source (1.0.0)
18
+ mini_mime (1.1.2)
19
+ multi_xml (0.6.0)
20
+ pry (0.14.2)
21
+ coderay (~> 1.1)
22
+ method_source (~> 1.0)
23
+ pry-byebug (3.10.1)
24
+ byebug (~> 11.0)
25
+ pry (>= 0.13, < 0.15)
26
+ rake (13.0.6)
27
+ rspec (3.12.0)
28
+ rspec-core (~> 3.12.0)
29
+ rspec-expectations (~> 3.12.0)
30
+ rspec-mocks (~> 3.12.0)
31
+ rspec-core (3.12.2)
32
+ rspec-support (~> 3.12.0)
33
+ rspec-expectations (3.12.3)
34
+ diff-lcs (>= 1.2.0, < 2.0)
35
+ rspec-support (~> 3.12.0)
36
+ rspec-mocks (3.12.5)
37
+ diff-lcs (>= 1.2.0, < 2.0)
38
+ rspec-support (~> 3.12.0)
39
+ rspec-support (3.12.0)
40
+ securerandom (0.2.2)
41
+
42
+ PLATFORMS
43
+ ruby
44
+
45
+ DEPENDENCIES
46
+ json (~> 2.6.3)
47
+ pry-byebug (= 3.10.1)
48
+ rake (= 13.0.6)
49
+ rspec (= 3.12.0)
50
+ securerandom (= 0.2.2)
51
+ spelpaus.rb!
52
+
53
+ BUNDLED WITH
54
+ 2.4.10
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2023 tomczak-mateusz
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,43 @@
1
+ # Spelpaus.rb
2
+
3
+ TODO: Delete this and the text below, and describe your gem
4
+
5
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/spelpaus`. To experiment with that code, run `bin/console` for an interactive prompt.
6
+
7
+ ---
8
+
9
+ ## Supported Ruby versions:
10
+ - Gem requires version >= 2.7.6
11
+ - Gem supports & was tested on versions listed below:
12
+ - 2.7.6, 2.7.7, 2.7.8
13
+ - 3.0.0, 3.0.1, 3.0.2, 3.0.3, 3.0.4, 3.0.5, 3.0.6
14
+ - 3.1.0, 3.1.1, 3.1.2, 3.1.3, 3.1.4
15
+ - 3.2.0, 3.2.1, 3.2.2
16
+
17
+ ---
18
+
19
+ ## Installation
20
+
21
+ TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
22
+
23
+ Install the gem and add to the application's Gemfile by executing:
24
+
25
+ $ bundle add UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
26
+
27
+ If bundler is not being used to manage dependencies, install the gem by executing:
28
+
29
+ $ gem install UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
30
+
31
+ ## Usage
32
+
33
+ TODO: Write usage instructions here
34
+
35
+ ## Development
36
+
37
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
38
+
39
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
40
+
41
+ ## License
42
+
43
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Spelpaus
4
+ class BlockingInfo
5
+ attr_accessor :client
6
+
7
+ def initialize(client = Spelpaus::Client.default)
8
+ @client = client
9
+ end
10
+
11
+ def blocked?(user_ssn)
12
+ path = '/blocking-info'
13
+ response = client.call(path, user_ssn)
14
+
15
+ user_blocked?(response)
16
+ end
17
+
18
+ private
19
+
20
+ def user_blocked?(response)
21
+ if response.key?('isBlocked')
22
+ response['isBlocked']
23
+ else
24
+ raise Spelpaus::Error, 'Blocked status not included in response'
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,61 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'httparty'
4
+ require 'securerandom'
5
+ require 'json'
6
+
7
+ module Spelpaus
8
+ class Client
9
+ include HTTParty
10
+
11
+ # The Configuration object holding settings to be used in the Spelpaus::Client.
12
+ attr_accessor :config
13
+
14
+ # Initializes the Spelpaus::Client
15
+ # @option config [Configuration] Configuration for initializing the object, default to Configuration.default
16
+ def initialize(config = Configuration.default)
17
+ @config = config
18
+ end
19
+
20
+ def call(path, user_ssn)
21
+ self.class.post(
22
+ build_request_url(path),
23
+ body: body_params(user_ssn),
24
+ headers: header_params
25
+ )
26
+ end
27
+
28
+ def self.default
29
+ @@default ||= Spelpaus::Client.new
30
+ end
31
+
32
+ def header_params
33
+ {
34
+ "Content-Type" => "application/json",
35
+ "Authorization" => @config.api_key
36
+ }
37
+ end
38
+
39
+ def body_params(user_ssn)
40
+ raise Spelpaus::Error, 'SSN value must be of type string' unless user_ssn.is_a? String
41
+
42
+ {
43
+ "requestId" => generate_request_uuid,
44
+ "subjectId" => user_ssn
45
+ }.to_json
46
+ end
47
+
48
+ def generate_request_uuid
49
+ SecureRandom.uuid
50
+ end
51
+
52
+ def build_request_url(path)
53
+ raise Spelpaus::Error, 'Base URL not provided' unless @config.base_url
54
+ raise Spelpaus::Error, 'Actor ID not provided' unless @config.actor_id
55
+
56
+ # Add leading and trailing slashes to path
57
+ path = "/#{path}".gsub(/\/+/, '/')
58
+ "#{@config.base_url}#{path}/#{@config.actor_id}"
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Spelpaus
4
+ class Configuration
5
+ attr_accessor :actor_id
6
+ attr_accessor :api_key
7
+ attr_accessor :base_url
8
+
9
+ def initialize
10
+ @actor_id = nil
11
+ @api_key = nil
12
+ @base_url = nil
13
+
14
+ yield(self) if block_given?
15
+ end
16
+
17
+ def self.default
18
+ @@default ||= Configuration.new
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Spelpaus
4
+ class Error < StandardError
5
+ end
6
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Spelpaus
4
+ VERSION = '0.1.0'
5
+ end
data/lib/spelpaus.rb ADDED
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Common files:
4
+ require 'spelpaus/client'
5
+ require 'spelpaus/configuration'
6
+ require 'spelpaus/error'
7
+ require 'spelpaus/version'
8
+
9
+ # APIs:
10
+ require 'spelpaus/api/blocking_info'
11
+
12
+ module Spelpaus
13
+ class << self
14
+ # Customize default settings for the SDK using block.
15
+ # Spelpaus.configure do |config|
16
+ # config.actor_id = "xxx"
17
+ # config.api_key = "xxx"
18
+ # config.base_url = "xxx"
19
+ # end
20
+ # If no block given, return the default Configuration object.
21
+
22
+ def configure
23
+ if block_given?
24
+ yield(Configuration.default)
25
+ else
26
+ Configuration.default
27
+ end
28
+ end
29
+ end
30
+ end
data/sig/spelpaus.rbs ADDED
@@ -0,0 +1,4 @@
1
+ module Spelpaus
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,146 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: spelpaus.rb
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Mateusz Tomczak
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2023-08-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: httparty
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.21.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.21.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: json
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 2.6.3
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 2.6.3
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry-byebug
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '='
46
+ - !ruby/object:Gem::Version
47
+ version: 3.10.1
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '='
53
+ - !ruby/object:Gem::Version
54
+ version: 3.10.1
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '='
60
+ - !ruby/object:Gem::Version
61
+ version: 13.0.6
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '='
67
+ - !ruby/object:Gem::Version
68
+ version: 13.0.6
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '='
74
+ - !ruby/object:Gem::Version
75
+ version: 3.12.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '='
81
+ - !ruby/object:Gem::Version
82
+ version: 3.12.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: securerandom
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '='
88
+ - !ruby/object:Gem::Version
89
+ version: 0.2.2
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '='
95
+ - !ruby/object:Gem::Version
96
+ version: 0.2.2
97
+ description: Ruby API wrapper for Spelpaus gambling self-exclusion system from Swedish
98
+ Spelinspektionen
99
+ email:
100
+ - tmt.contact.business@gmail.com
101
+ executables: []
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - ".rspec"
106
+ - CHANGELOG.md
107
+ - Gemfile
108
+ - Gemfile.lock
109
+ - LICENSE.txt
110
+ - README.md
111
+ - Rakefile
112
+ - lib/spelpaus.rb
113
+ - lib/spelpaus/api/blocking_info.rb
114
+ - lib/spelpaus/client.rb
115
+ - lib/spelpaus/configuration.rb
116
+ - lib/spelpaus/error.rb
117
+ - lib/spelpaus/version.rb
118
+ - sig/spelpaus.rbs
119
+ homepage: https://github.com/vinst-dev/spelpaus.rb
120
+ licenses:
121
+ - MIT
122
+ metadata:
123
+ homepage_uri: https://github.com/vinst-dev/spelpaus.rb
124
+ source_code_uri: https://github.com/vinst-dev/spelpaus.rb
125
+ changelog_uri: https://github.com/vinst-dev/spelpaus.rb/blob/main/CHANGELOG.md
126
+ post_install_message:
127
+ rdoc_options: []
128
+ require_paths:
129
+ - lib
130
+ required_ruby_version: !ruby/object:Gem::Requirement
131
+ requirements:
132
+ - - ">="
133
+ - !ruby/object:Gem::Version
134
+ version: 2.7.6
135
+ required_rubygems_version: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - ">="
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
140
+ requirements: []
141
+ rubygems_version: 3.4.14
142
+ signing_key:
143
+ specification_version: 4
144
+ summary: Ruby API wrapper for Spelpaus gambling self-exclusion system from Swedish
145
+ Spelinspektionen
146
+ test_files: []