slapi 0.1.1

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: b954b5b5faa6f7b55cf8b2a1e2ea2a54300ef4ab7199bf113635c55fed47203b
4
+ data.tar.gz: 14cae6e55b9e429fa0113816a5c4b787077a794de5b0fa64f8e8a9ba8a73bcb2
5
+ SHA512:
6
+ metadata.gz: d4e872707af006daf997ed79876334a3deeb348b8d34007535167d51cd1b5185fe441ddaafcd9dac0b2c38fdd020dce536b8a8acbd2ddd24addeb40396031153
7
+ data.tar.gz: e618cd24110289386862063ced29e824116217ed3cc085af6048237dbd74cea9a8579eb6ffb39f91143c54304002ce4660c9190c0e8686e3729537cd3bb2b8e2
data/.idea/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ # Default ignored files
2
+ /shelf/
3
+ /workspace.xml
4
+ # Editor-based HTTP Client requests
5
+ /httpRequests/
6
+ # Datasource local storage ignored files
7
+ /dataSources/
8
+ /dataSources.local.xml
@@ -0,0 +1,9 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="MarkdownSettings">
4
+ <enabledExtensions>
5
+ <entry key="MermaidLanguageExtension" value="true" />
6
+ <entry key="PlantUMLLanguageExtension" value="true" />
7
+ </enabledExtensions>
8
+ </component>
9
+ </project>
data/.idea/misc.xml ADDED
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="ProjectRootManager" version="2" project-jdk-name="ruby-2.6.3-p62" project-jdk-type="RUBY_SDK">
4
+ <output url="file://$PROJECT_DIR$/out" />
5
+ </component>
6
+ </project>
data/.idea/modules.xml ADDED
@@ -0,0 +1,8 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="ProjectModuleManager">
4
+ <modules>
5
+ <module fileurl="file://$PROJECT_DIR$/.idea/slapi.iml" filepath="$PROJECT_DIR$/.idea/slapi.iml" />
6
+ </modules>
7
+ </component>
8
+ </project>
data/.idea/vcs.xml ADDED
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="VcsDirectoryMappings">
4
+ <mapping directory="" vcs="Git" />
5
+ </component>
6
+ </project>
data/CHANGELOG.md ADDED
@@ -0,0 +1,12 @@
1
+ # Change Log
2
+
3
+ ## [0.1.1] - 2024/03/11
4
+ ### Fixed
5
+ - クラスが読み込まれていなかったのを修正
6
+
7
+ ### Added
8
+ - CHANGELOG.mdを追加
9
+
10
+ ## [0.1.0] - 2024/03/11
11
+ ### Added
12
+ - Work In Progress.
data/README.md ADDED
@@ -0,0 +1,30 @@
1
+ # Slapi
2
+
3
+ 自分が雑に外部サービスのapiリクエストをするとき用のクライアントです。
4
+ ※作成中
5
+
6
+ # Usage
7
+
8
+ ```irb
9
+
10
+ # 1. Prepare
11
+ ## 1-a. Existing access_token
12
+ > base_url = "https://example.com"
13
+ > access_token = "<YOUR_ACCESS_TOKEN>"
14
+ > client = Slapi::Client(base_url, access_token)
15
+
16
+ ## 1-b. Existing client id & client secret
17
+ > base_url = "https://example.com"
18
+ > client = Slapi::Client(base_url)
19
+ > client_id = "<YOUR_CLIENT_ID>"
20
+ > client_secret = "<YOUR_CLIENT_SECRET>"
21
+ > client.authentiate!(client_id, client_secret) # => set access_token
22
+
23
+
24
+ # 2. Request
25
+ > path = "v1/users/aaabbbsss"
26
+ > params = "filter=closed&order=asc"
27
+ > response = client.get(path, query)
28
+ > p response
29
+
30
+ ```
data/Rakefile ADDED
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ task default: %i[]
@@ -0,0 +1,39 @@
1
+ module Slapi
2
+ class Authentication
3
+ def initialize(base_url)
4
+ @base_url = base_url
5
+ @access_token = ""
6
+ @client_id = ""
7
+ @client_secret = ""
8
+ end
9
+
10
+ def authenticate!(client_id, client_secret)
11
+ client_id = client_id
12
+ client_secret = client_secret
13
+
14
+ unless client_id || client_secret
15
+ raise ArgumentError, "client_id and client_secret are required"
16
+ end
17
+
18
+ credential = Base64.strict_encode64("#{client_id}:#{client_secret}")
19
+ url = URI.parse("#{@base_url}/oauth/token") # CHECK: ここって共通?
20
+ https = Net::HTTP.new(url.host, url.port)
21
+ https.use_ssl = true
22
+ request_header = {
23
+ 'Content-Type' => 'application/x-www-form-urlencoded',
24
+ 'Authorization' => "Basic #{credential}"
25
+ }
26
+
27
+ request = Net::HTTP::Post.new(url.path, request_header)
28
+ request.body = "grant_type=client_credentials"
29
+ response = https.request(request)
30
+ response_body = JSON.parse(response.body)
31
+
32
+ @access_token = response_body['access_token']
33
+ end
34
+
35
+ def access_token
36
+ @access_token
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,38 @@
1
+ module Slapi
2
+ class Client
3
+ def initialize(base_url, access_token = nil)
4
+ @base_url = base_url
5
+ @access_token = access_token
6
+ @authentication = Slapi::Authentication.new(@base_url)
7
+ @content_type = 'application/x-www-form-urlencoded'
8
+ @request_header = {
9
+ 'Authorization' => "Bearer #{@access_token}",
10
+ 'Content-Type' => @content_type,
11
+ 'Accept' => 'application/json',
12
+ }
13
+ url = URI.parse("#{@base_url}")
14
+ @https = Net::HTTP.new(url.host, url.port)
15
+ @https.use_ssl = true
16
+ end
17
+
18
+ def authenticate!(client_id, client_secret)
19
+ @authentication.authenticate!(client_id, client_secret)
20
+ @access_token = @authentication.access_token
21
+ @request_header = {
22
+ 'Authorization' => "Bearer #{@access_token}",
23
+ 'Content-Type' => 'x-www-form-urlencoded',
24
+ 'Accept' => 'application/json',
25
+ }
26
+ end
27
+
28
+ def get(path, params = "")
29
+ url = URI.parse("#{@base_url}/#{path}?#{params}")
30
+ response = @https.get(url, @request_header)
31
+ JSON.parse(response.body)
32
+ end
33
+
34
+ def post(path, params = "")
35
+ # TODO 実装
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Slapi
4
+ VERSION = "0.1.1"
5
+ end
data/lib/slapi.rb ADDED
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'net/http'
4
+ require 'openssl'
5
+ require 'base64'
6
+ require 'json'
7
+
8
+ require_relative "slapi/version"
9
+ require_relative "slapi/version"
10
+ require_relative "slapi/version"
11
+ require_relative "slapi/client"
12
+ require_relative "slapi/authentication"
13
+
14
+
15
+ module Slapi
16
+ class Error < StandardError; end
17
+ # Your code goes here...
18
+ end
data/sig/slapi.rbs ADDED
@@ -0,0 +1,4 @@
1
+ module Slapi
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,59 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: slapi
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Ayumu Takatori
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2024-03-11 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Sloppy api client for ruby
14
+ email:
15
+ - ayumu.takatori@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - ".idea/.gitignore"
21
+ - ".idea/markdown.xml"
22
+ - ".idea/misc.xml"
23
+ - ".idea/modules.xml"
24
+ - ".idea/vcs.xml"
25
+ - CHANGELOG.md
26
+ - README.md
27
+ - Rakefile
28
+ - lib/slapi.rb
29
+ - lib/slapi/authentication.rb
30
+ - lib/slapi/client.rb
31
+ - lib/slapi/version.rb
32
+ - sig/slapi.rbs
33
+ homepage: https://github.com/ayumutakatori/slapi
34
+ licenses: []
35
+ metadata:
36
+ allowed_push_host: https://rubygems.org
37
+ homepage_uri: https://github.com/ayumutakatori/slapi
38
+ source_code_uri: https://github.com/ayumutakatori/slapi
39
+ changelog_uri: https://github.com/ayumutakatori/slapi/blob/main/CHANGELOG.md
40
+ post_install_message:
41
+ rdoc_options: []
42
+ require_paths:
43
+ - lib
44
+ required_ruby_version: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: 2.6.0
49
+ required_rubygems_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ requirements: []
55
+ rubygems_version: 3.5.5
56
+ signing_key:
57
+ specification_version: 4
58
+ summary: Sloppy api client for ruby
59
+ test_files: []