tik_tak_tioki_client 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: 617d252b375cd09fb3814731f69626032b4b498846078417c76c138a0a5ab18c
4
+ data.tar.gz: 89b534d50806028088854fd6169ca1c14fa69cd5986581d103746d88b0a4b27e
5
+ SHA512:
6
+ metadata.gz: c91a093d443764235d4bc84275f84390f6eee54318d2ee484d1b32c0787fdfd982d50a229a958f53b5eb3a177730be8766742f713fbfc984c4d54c54b7003fe7
7
+ data.tar.gz: 515bb63cad048b312b8b86130f93498b250560e72a26fc59b37429369507772d048cdf9d09e8e659b981f73193070e4aff0f84f8f256ea259bf49300e9abdd84
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,13 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.6
3
+
4
+ Style/StringLiterals:
5
+ Enabled: true
6
+ EnforcedStyle: double_quotes
7
+
8
+ Style/StringLiteralsInInterpolation:
9
+ Enabled: true
10
+ EnforcedStyle: double_quotes
11
+
12
+ Layout/LineLength:
13
+ Max: 120
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at fabrik42@gmail.com. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/Gemfile ADDED
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in tik_tak_tioki_client.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "rspec", "~> 3.0"
11
+
12
+ gem "vcr", "~> 6.1"
13
+
14
+ gem "webmock", "~> 3.1"
15
+
16
+ gem "rubocop", "~> 1.21"
17
+
18
+ gem "awesome_print"
data/Gemfile.lock ADDED
@@ -0,0 +1,91 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ tik_tak_tioki_client (0.1.0)
5
+ activesupport (~> 7.0)
6
+ faraday (~> 2.0)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ activesupport (7.0.3.1)
12
+ concurrent-ruby (~> 1.0, >= 1.0.2)
13
+ i18n (>= 1.6, < 2)
14
+ minitest (>= 5.1)
15
+ tzinfo (~> 2.0)
16
+ addressable (2.8.1)
17
+ public_suffix (>= 2.0.2, < 6.0)
18
+ ast (2.4.2)
19
+ awesome_print (1.9.2)
20
+ concurrent-ruby (1.1.10)
21
+ crack (0.4.5)
22
+ rexml
23
+ diff-lcs (1.5.0)
24
+ faraday (2.5.2)
25
+ faraday-net_http (>= 2.0, < 3.1)
26
+ ruby2_keywords (>= 0.0.4)
27
+ faraday-net_http (3.0.0)
28
+ hashdiff (1.0.1)
29
+ i18n (1.12.0)
30
+ concurrent-ruby (~> 1.0)
31
+ json (2.6.2)
32
+ minitest (5.16.3)
33
+ parallel (1.22.1)
34
+ parser (3.1.2.1)
35
+ ast (~> 2.4.1)
36
+ public_suffix (5.0.0)
37
+ rainbow (3.1.1)
38
+ rake (13.0.6)
39
+ regexp_parser (2.5.0)
40
+ rexml (3.2.5)
41
+ rspec (3.11.0)
42
+ rspec-core (~> 3.11.0)
43
+ rspec-expectations (~> 3.11.0)
44
+ rspec-mocks (~> 3.11.0)
45
+ rspec-core (3.11.0)
46
+ rspec-support (~> 3.11.0)
47
+ rspec-expectations (3.11.0)
48
+ diff-lcs (>= 1.2.0, < 2.0)
49
+ rspec-support (~> 3.11.0)
50
+ rspec-mocks (3.11.1)
51
+ diff-lcs (>= 1.2.0, < 2.0)
52
+ rspec-support (~> 3.11.0)
53
+ rspec-support (3.11.0)
54
+ rubocop (1.35.0)
55
+ json (~> 2.3)
56
+ parallel (~> 1.10)
57
+ parser (>= 3.1.2.1)
58
+ rainbow (>= 2.2.2, < 4.0)
59
+ regexp_parser (>= 1.8, < 3.0)
60
+ rexml (>= 3.2.5, < 4.0)
61
+ rubocop-ast (>= 1.20.1, < 2.0)
62
+ ruby-progressbar (~> 1.7)
63
+ unicode-display_width (>= 1.4.0, < 3.0)
64
+ rubocop-ast (1.21.0)
65
+ parser (>= 3.1.1.0)
66
+ ruby-progressbar (1.11.0)
67
+ ruby2_keywords (0.0.5)
68
+ tzinfo (2.0.5)
69
+ concurrent-ruby (~> 1.0)
70
+ unicode-display_width (2.2.0)
71
+ vcr (6.1.0)
72
+ webmock (3.18.1)
73
+ addressable (>= 2.8.0)
74
+ crack (>= 0.3.2)
75
+ hashdiff (>= 0.4.0, < 2.0.0)
76
+
77
+ PLATFORMS
78
+ arm64-darwin-21
79
+ x86_64-darwin-21
80
+
81
+ DEPENDENCIES
82
+ awesome_print
83
+ rake (~> 13.0)
84
+ rspec (~> 3.0)
85
+ rubocop (~> 1.21)
86
+ tik_tak_tioki_client!
87
+ vcr (~> 6.1)
88
+ webmock (~> 3.1)
89
+
90
+ BUNDLED WITH
91
+ 2.3.15
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2022 ioki GmbH
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,68 @@
1
+ # TikTakTiokiClient
2
+
3
+ This is a minimal client implementation for the TikTakTioki server.
4
+
5
+ ## Installation
6
+
7
+ Install the gem and add to the application's Gemfile by executing:
8
+
9
+ $ bundle add tik_tak_tioki_client
10
+
11
+ If bundler is not being used to manage dependencies, install the gem by executing:
12
+
13
+ $ gem install tik_tak_tioki_client
14
+
15
+ ## Usage
16
+
17
+ First: Obtain a game instance
18
+
19
+ ```ruby
20
+ # Either: Create a new game
21
+ game = TikTakTiokiClient::Game.create!
22
+
23
+ # Or: Join an existing game
24
+ list = TikTakTiokiClient::Game.all_joinables
25
+ game = TikTakTiokiClient::Game.join! list.first["name"]
26
+ ```
27
+
28
+ Then: Have fun playing the game!
29
+
30
+ ```ruby
31
+ # Updating the game
32
+ game.update!
33
+
34
+ # Make a move (game gets updated automatically)
35
+ game.make_move(1)
36
+
37
+ # Note: when an operation fails, it will raise a Faraday exception
38
+ # In this example: Making a move when it is the other player's turn
39
+ begin
40
+ game.make_move(1)
41
+ rescue Faraday::ClientError => e
42
+ puts "Operation failed!"
43
+ puts e.response[:status]
44
+ puts e.response[:body]
45
+ end
46
+
47
+ # Operation failed!
48
+ # 422
49
+ # {"error":"It's not the players turn"}
50
+ ```
51
+
52
+ ## Development
53
+
54
+ 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.
55
+
56
+ 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).
57
+
58
+ ## Contributing
59
+
60
+ Bug reports and pull requests are welcome on GitHub at https://github.com/fabrik42/tik_tak_tioki_client. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/fabrik42/tik_tak_tioki_client/blob/master/CODE_OF_CONDUCT.md).
61
+
62
+ ## License
63
+
64
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
65
+
66
+ ## Code of Conduct
67
+
68
+ Everyone interacting in the TikTakTiokiClient project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/fabrik42/tik_tak_tioki_client/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
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
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
@@ -0,0 +1,66 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support/core_ext/module/delegation"
4
+ require "ostruct"
5
+
6
+ module TikTakTiokiClient
7
+ class Game
8
+ attr_accessor :http_client, :data
9
+
10
+ delegate_missing_to :data
11
+
12
+ def self.create!
13
+ client = HttpClient.new
14
+ response = client.post("/game")
15
+ Game.new(response.body, client)
16
+ end
17
+
18
+ def self.all_joinables
19
+ client = HttpClient.new
20
+ response = client.get("/join")
21
+ response.body
22
+ end
23
+
24
+ def self.join!(game_name)
25
+ client = HttpClient.new
26
+ response = client.post("/join", data: { name: game_name })
27
+ Game.new(response.body, client)
28
+ end
29
+
30
+ def initialize(data, http_client)
31
+ self.data = data
32
+ self.http_client = http_client || HttpClient.new
33
+ end
34
+
35
+ def fetch
36
+ response = http_client.get("/game", query_params: { player_token: player_token })
37
+ response.body
38
+ end
39
+
40
+ def update!
41
+ self.data = fetch
42
+ end
43
+
44
+ def make_move(field)
45
+ data = {
46
+ next_move_token: next_move_token,
47
+ field: field
48
+ }
49
+ response = http_client.post("/move", data: data, query_params: { player_token: player_token })
50
+ self.data = response.body
51
+ end
52
+
53
+ def inspect
54
+ fields = %i[name player_role state created_at updated_at]
55
+ inspection = fields.map { |field| "#{field}: #{public_send(field)}" }.join(", ")
56
+ inspection << ", board: " << board.join("-")
57
+ "#<#{self.class.name} #{inspection}>"
58
+ end
59
+
60
+ private
61
+
62
+ def data=(data)
63
+ @data = OpenStruct.new(data)
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "faraday"
4
+ require "active_support/core_ext/object/to_query"
5
+
6
+ module TikTakTiokiClient
7
+ class HttpClient
8
+ def get(path, query_params: {})
9
+ url = build_url(path, query_params)
10
+ connection.get(url)
11
+ end
12
+
13
+ def post(path, data: nil, query_params: {})
14
+ url = build_url(path, query_params)
15
+ connection.post(url, data)
16
+ end
17
+
18
+ private
19
+
20
+ def build_url(path, query_params = {})
21
+ "#{TikTakTiokiClient.config.api_base_url}/api#{path}?#{query_params.to_query}"
22
+ end
23
+
24
+ def connection
25
+ @conn ||= Faraday.new do |f|
26
+ f.request :json
27
+ f.response :json
28
+ f.response :logger, nil, { bodies: true }
29
+ # will throw a Faraday::Error in case of a 4xx/5xx response
30
+ # https://lostisland.github.io/faraday/middleware/raise-error
31
+ f.response :raise_error
32
+ f.adapter :net_http
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TikTakTiokiClient
4
+ VERSION = "0.1.0"
5
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support/configurable"
4
+ require_relative "tik_tak_tioki_client/version"
5
+ require_relative "tik_tak_tioki_client/game"
6
+ require_relative "tik_tak_tioki_client/http_client"
7
+
8
+ module TikTakTiokiClient
9
+ include ActiveSupport::Configurable
10
+
11
+ configure do |config|
12
+ config.api_base_url = "https://tik-tak-tioki.fly.dev"
13
+ end
14
+ end
@@ -0,0 +1,4 @@
1
+ module TikTakTiokiClient
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/tik_tak_tioki_client/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "tik_tak_tioki_client"
7
+ spec.version = TikTakTiokiClient::VERSION
8
+ spec.authors = ["Christian Bäuerlein"]
9
+ spec.email = ["hello@christianbaeuerlein.com"]
10
+
11
+ spec.summary = "Ruby client for the TikTakTioki server"
12
+ spec.description = "Client implementation of the API of the TikTakTioki server"
13
+ spec.homepage = "https://ioki.enineering"
14
+ spec.license = "MIT"
15
+ spec.required_ruby_version = ">= 2.6.0"
16
+
17
+ spec.metadata["homepage_uri"] = spec.homepage
18
+ spec.metadata["source_code_uri"] = "https://github.com/ioki-mobility"
19
+
20
+ # Specify which files should be added to the gem when it is released.
21
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
22
+ spec.files = Dir.chdir(__dir__) do
23
+ `git ls-files -z`.split("\x0").reject do |f|
24
+ (f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
25
+ end
26
+ end
27
+ spec.bindir = "exe"
28
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
29
+ spec.require_paths = ["lib"]
30
+
31
+ spec.add_dependency 'faraday', '~> 2.0'
32
+ spec.add_dependency 'activesupport', '~> 7.0'
33
+ end
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tik_tak_tioki_client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Christian Bäuerlein
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-09-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: activesupport
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '7.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '7.0'
41
+ description: Client implementation of the API of the TikTakTioki server
42
+ email:
43
+ - hello@christianbaeuerlein.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".rspec"
49
+ - ".rubocop.yml"
50
+ - CODE_OF_CONDUCT.md
51
+ - Gemfile
52
+ - Gemfile.lock
53
+ - LICENSE.txt
54
+ - README.md
55
+ - Rakefile
56
+ - lib/tik_tak_tioki_client.rb
57
+ - lib/tik_tak_tioki_client/game.rb
58
+ - lib/tik_tak_tioki_client/http_client.rb
59
+ - lib/tik_tak_tioki_client/version.rb
60
+ - sig/tik_tak_tioki_client.rbs
61
+ - tik_tak_tioki_client.gemspec
62
+ homepage: https://ioki.enineering
63
+ licenses:
64
+ - MIT
65
+ metadata:
66
+ homepage_uri: https://ioki.enineering
67
+ source_code_uri: https://github.com/ioki-mobility
68
+ post_install_message:
69
+ rdoc_options: []
70
+ require_paths:
71
+ - lib
72
+ required_ruby_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: 2.6.0
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ requirements: []
83
+ rubygems_version: 3.3.3
84
+ signing_key:
85
+ specification_version: 4
86
+ summary: Ruby client for the TikTakTioki server
87
+ test_files: []