shikimori-oauth2 1.0.0

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: db6330805d175e1501e7f35c7be342dcd93fe25c71683006f40812d50a455977
4
+ data.tar.gz: 680f3e744b7ffb4f3bf004b6bfd9ccdf0fbfc561566b923ffecc2612a63d46ae
5
+ SHA512:
6
+ metadata.gz: '0969c3b8eaa1ea143cbe6a0123c8d81143756215e532106f5d3eb5c134a5d01b5f87759a50d9a9ca13e24d79fc8378edf780d8e393411ef3d886455f314cf54b'
7
+ data.tar.gz: f515c3178a56b7a99d939519cf23bfd1ca9a75e9fbda9b218cf4f30d57f6808a9af3e8ec36cccee824bb70e0726ae549f07280c8ff60d751f26747a6b501d7e2
data/README.md ADDED
@@ -0,0 +1,20 @@
1
+ [![CI](https://github.com/iwdt/shikikit/actions/workflows/main.yml/badge.svg)](https://github.com/iwdt/shikikit/actions/workflows/main.yml) [![codecov](https://codecov.io/gh/iwdt/shikikit/graph/badge.svg)](https://codecov.io/gh/iwdt/shikikit)
2
+
3
+ # Shikikit
4
+ Ruby toolkit for the [Shikimori API](https://shikimori.one)
5
+
6
+ ## TODO:
7
+ - logger
8
+ - #as_app
9
+ - proxy config
10
+ - oauth methods on API
11
+ - optional auto refresh token
12
+ - more information at errors
13
+ - more tests
14
+ - entities for responses
15
+ - contracts for requests (client-side validations)
16
+ - better documentation
17
+ - mutator
18
+ - CI/CD
19
+ - auto version increment on main branch pushing
20
+ - deploy to rubygems
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Shikimori
4
+ module OAuth2
5
+ # Client for Shikimori OAuth2
6
+ class Client < ::OAuth2::Client
7
+ SCOPE_JOIN_SYMBOL = '+'
8
+ SCOPE_JOIN_ENCODED_SYMBOL = '%2B'
9
+
10
+ def initialize(
11
+ client_id,
12
+ client_secret,
13
+ options = {},
14
+ app_name: config.app_name,
15
+ &block
16
+ )
17
+ options = config.options.merge(options)
18
+
19
+ @app_name = app_name
20
+
21
+ super(client_id, client_secret, options, &block)
22
+ end
23
+
24
+ def authorize_url(params = {})
25
+ # Shikimori only works with `+` sign, not encoded value
26
+ super(params).gsub(SCOPE_JOIN_ENCODED_SYMBOL, SCOPE_JOIN_SYMBOL)
27
+ end
28
+
29
+ def get_token(params, access_token_opts = {}, extract_access_token = nil, &block)
30
+ params[:headers] ||= {}
31
+ params[:headers]['User-Agent'] ||= @app_name
32
+
33
+ super(params, access_token_opts, extract_access_token, &block)
34
+ end
35
+
36
+ def config
37
+ @config ||= OAuth2.config
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Shikimori
4
+ module OAuth2
5
+ # Configuration for Shikimori OAuth2 client
6
+ class Config
7
+ DEFAULT_SITE_URL = 'https://shikimori.one/'
8
+ DEFAULT_APP_NAME = 'Api Test'
9
+
10
+ attr_accessor :options, :site, :app_name
11
+
12
+ def initialize(site: DEFAULT_SITE_URL, app_name: DEFAULT_APP_NAME, **options)
13
+ @app_name = app_name
14
+ @options = { site: site }.merge(options)
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Shikimori
4
+ module OAuth2
5
+ # @return [String] Semantic version of library
6
+ VERSION = '1.0.0'
7
+ end
8
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'oauth2'
4
+
5
+ require_relative 'oauth2/config'
6
+ require_relative 'oauth2/client'
7
+
8
+ module Shikimori
9
+ # Tools for Shikimori OAuth2
10
+ #
11
+ # @see https://shikimori.one/oauth Official documentation
12
+ module OAuth2
13
+ class << self
14
+ def config
15
+ @config ||= Config.new
16
+ end
17
+
18
+ def configure
19
+ yield(config)
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'shikimori/oauth2'
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/shikimori/oauth2/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'shikimori-oauth2'
7
+ spec.version = Shikimori::OAuth2::VERSION
8
+ spec.authors = ['Ivan Naumov']
9
+ spec.email = ['ivannaymov@gmail.com']
10
+
11
+ spec.summary = 'Simple wrapper for the Shikimori OAuth2'
12
+ spec.description = 'Ruby toolkit for working with the Shikimori OAuth2'
13
+ spec.homepage = 'https://github.com/iwdt/shikikit'
14
+ spec.license = 'MIT'
15
+ spec.required_ruby_version = '>= 3.0'
16
+
17
+ spec.metadata['homepage_uri'] = spec.homepage
18
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org'
19
+ spec.metadata['source_code_uri'] = 'https://github.com/iwdt/shikikit'
20
+ spec.metadata['bug_tracker_uri'] = 'https://github.com/iwdt/shikikit/issues'
21
+ spec.metadata['changelog_uri'] = 'https://github.com/iwdt/shikikit/blob/main/CHANGELOG.md'
22
+ spec.metadata['rubygems_mfa_required'] = 'true'
23
+
24
+ spec.files = Dir[
25
+ # Common files
26
+ 'LICENSE',
27
+ 'README.md',
28
+ 'shikimori-oauth2.gemspec',
29
+ # Code
30
+ 'lib/shikimori-oauth2.rb',
31
+ 'lib/shikimori/oauth2.rb',
32
+ 'lib/shikimori/oauth2/**/*',
33
+ # Signtures
34
+ 'sig/shikimori/oauth2.rbs',
35
+ 'sig/shikimori/oauth2/**/*'
36
+ ]
37
+ spec.bindir = 'bin'
38
+ spec.executables = []
39
+ spec.require_paths = ['lib']
40
+
41
+ spec.add_runtime_dependency 'oauth2', '~> 2.0.0'
42
+ end
@@ -0,0 +1,15 @@
1
+ module Shikimori
2
+ module OAuth2
3
+ class Client < ::OAuth2::Client
4
+ SCOPE_JOIN_SYMBOL: String
5
+ SCOPE_JOIN_ENCODED_SYMBOL: String
6
+ @config: Config
7
+ @app_name: String
8
+ attr_reader site: URI::Generic
9
+
10
+ def initialize: (String client_id, String client_secret, ?Hash[_ToS, untyped] options, ?app_name: String) -> void
11
+
12
+ def config: -> Config
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,14 @@
1
+ module Shikimori
2
+ module OAuth2
3
+ class Config
4
+ DEFAULT_SITE_URL: String
5
+ DEFAULT_APP_NAME: String
6
+
7
+ attr_accessor options: Hash[Symbol, untyped]
8
+ attr_accessor site: String
9
+ attr_accessor app_name: String
10
+
11
+ def initialize: (?site: String, ?app_name: String, **untyped) -> void
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,5 @@
1
+ module Shikimori
2
+ module OAuth2
3
+ VERSION: String
4
+ end
5
+ end
@@ -0,0 +1,8 @@
1
+ module Shikimori
2
+ module OAuth2
3
+ self.@config: Config
4
+
5
+ def self.config: -> Config
6
+ def self.configure: { (Config) -> Config } -> void
7
+ end
8
+ end
metadata ADDED
@@ -0,0 +1,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: shikimori-oauth2
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Ivan Naumov
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2024-02-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: oauth2
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 2.0.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.0
27
+ description: Ruby toolkit for working with the Shikimori OAuth2
28
+ email:
29
+ - ivannaymov@gmail.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - README.md
35
+ - lib/shikimori-oauth2.rb
36
+ - lib/shikimori/oauth2.rb
37
+ - lib/shikimori/oauth2/client.rb
38
+ - lib/shikimori/oauth2/config.rb
39
+ - lib/shikimori/oauth2/version.rb
40
+ - shikimori-oauth2.gemspec
41
+ - sig/shikimori/oauth2.rbs
42
+ - sig/shikimori/oauth2/client.rbs
43
+ - sig/shikimori/oauth2/config.rbs
44
+ - sig/shikimori/oauth2/version.rbs
45
+ homepage: https://github.com/iwdt/shikikit
46
+ licenses:
47
+ - MIT
48
+ metadata:
49
+ homepage_uri: https://github.com/iwdt/shikikit
50
+ allowed_push_host: https://rubygems.org
51
+ source_code_uri: https://github.com/iwdt/shikikit
52
+ bug_tracker_uri: https://github.com/iwdt/shikikit/issues
53
+ changelog_uri: https://github.com/iwdt/shikikit/blob/main/CHANGELOG.md
54
+ rubygems_mfa_required: 'true'
55
+ post_install_message:
56
+ rdoc_options: []
57
+ require_paths:
58
+ - lib
59
+ required_ruby_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: '3.0'
64
+ required_rubygems_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ requirements: []
70
+ rubygems_version: 3.0.3.1
71
+ signing_key:
72
+ specification_version: 4
73
+ summary: Simple wrapper for the Shikimori OAuth2
74
+ test_files: []