hiya 0.1.0 → 0.2.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 +4 -4
- data/Gemfile.lock +2 -2
- data/README.md +126 -12
- data/lib/hiya/attach_base.rb +1 -8
- data/lib/hiya/base.rb +19 -3
- data/lib/hiya/link.rb +42 -0
- data/lib/hiya/oauth.rb +30 -0
- data/lib/hiya/url.rb +1 -10
- data/lib/hiya/users/links.rb +110 -0
- data/lib/hiya/version.rb +1 -1
- data/lib/hiya.rb +2 -0
- metadata +9 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a17b8a35230831183946a90c4104030acbc22763411f3f28562ec23fefac0e69
|
4
|
+
data.tar.gz: 67b4d9fb4fd6de89ff00c0c589f43b7d4803acabd57976ffb8d65ddf76cb757a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 311ab3e4ac8bcc998a0501fbaa1a4cd3db94dca6e12da0c0502c2a2590198966ade8e4eef16f0ec96b5186b0aa63de0b3a393d433d8848f6a57c060119cd89bb
|
7
|
+
data.tar.gz: 42c6f7fb6f7ce7db2029ef443bdfc7849bc69019a1fe9a8dfe7612b9bb1e062d78d383ce7ddbd32394c158dc085b53bc5c27930cd13127bed7d940081a3a3185
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -35,44 +35,158 @@ Hiya::Url.new.create(links)
|
|
35
35
|
### Image - create images short link
|
36
36
|
|
37
37
|
``` ruby
|
38
|
-
|
38
|
+
files = [
|
39
39
|
'/Users/username/Desktop/aaa.jpg',
|
40
40
|
'/Users/username/Desktop/bbb.png',
|
41
41
|
'/Users/username/Desktop/ccc.gif'
|
42
42
|
]
|
43
|
-
Hiya::Image.new.create(
|
44
|
-
attach: {
|
45
|
-
|
43
|
+
Hiya::Image.new.create(files, {
|
44
|
+
attach: {
|
45
|
+
password: '1234',
|
46
|
+
password_note: 'today',
|
47
|
+
expired_num: 300,
|
48
|
+
view_count_limit: 100
|
49
|
+
},
|
50
|
+
post: {
|
51
|
+
content: "haha\nhttps://www.google.com"
|
52
|
+
}
|
46
53
|
})
|
47
54
|
```
|
48
55
|
|
49
56
|
### Video - create videos short link
|
50
57
|
|
51
58
|
``` ruby
|
52
|
-
|
59
|
+
files = [
|
53
60
|
'/Users/username/Desktop/aaa.mp4',
|
54
61
|
'/Users/username/Desktop/bbb.mp4'
|
55
62
|
]
|
56
|
-
Hiya::Video.new.create(
|
57
|
-
attach: {
|
58
|
-
|
63
|
+
Hiya::Video.new.create(files, {
|
64
|
+
attach: {
|
65
|
+
password: '1234',
|
66
|
+
password_note: 'today',
|
67
|
+
expired_num: 300,
|
68
|
+
view_count_limit: 100
|
69
|
+
},
|
70
|
+
post: {
|
71
|
+
content: "yoyo\nhttps://www.google.com"
|
72
|
+
}
|
59
73
|
})
|
60
74
|
```
|
61
75
|
|
62
76
|
### Audio - create audios short link
|
63
77
|
|
64
78
|
``` ruby
|
65
|
-
|
79
|
+
files = [
|
66
80
|
'/Users/username/Desktop/aaa.mp3',
|
67
81
|
'/Users/username/Desktop/bbb.mp3',
|
68
82
|
'/Users/username/Desktop/ccc.mp3'
|
69
83
|
]
|
70
|
-
Hiya::Audio.new.create(
|
71
|
-
attach: {
|
72
|
-
|
84
|
+
Hiya::Audio.new.create(files, {
|
85
|
+
attach: {
|
86
|
+
password: '1234',
|
87
|
+
password_note: 'today',
|
88
|
+
expired_num: 300,
|
89
|
+
view_count_limit: 100
|
90
|
+
},
|
91
|
+
post: {
|
92
|
+
content: "hehe\nhttps://www.google.com"
|
93
|
+
}
|
73
94
|
})
|
74
95
|
```
|
75
96
|
|
97
|
+
### Login - get token
|
98
|
+
|
99
|
+
``` ruby
|
100
|
+
params = {
|
101
|
+
grant_type: 'password', # required
|
102
|
+
|
103
|
+
# facebook
|
104
|
+
facebook_token: '<facebook_token>', # facebook token(String)
|
105
|
+
# google
|
106
|
+
google_token: '<google_token>', # google token(String)
|
107
|
+
google_refresh_token: '<google_refresh_token>', # google refresh token(String)
|
108
|
+
# line
|
109
|
+
line_token: '<line_token>', # line token(String)
|
110
|
+
# chatbot
|
111
|
+
chatbot_token: '<chatbot_token>', # chatbot token(String)
|
112
|
+
}
|
113
|
+
response = Hiya::Oauth.new.token(params)
|
114
|
+
|
115
|
+
puts response
|
116
|
+
{
|
117
|
+
access_token: '-qsizxNy83YTh7kdnZ7f20mKpty00-G0SidjWitGj0g',
|
118
|
+
token_type: 'Bearer',
|
119
|
+
created_at: 1688109992
|
120
|
+
}
|
121
|
+
|
122
|
+
# use user token create short link
|
123
|
+
links = [
|
124
|
+
{ url: 'https://www.google.coom', weight: 1 }
|
125
|
+
]
|
126
|
+
Hiya::Url.new(response[:token]).create(links)
|
127
|
+
```
|
128
|
+
|
129
|
+
### Get links
|
130
|
+
|
131
|
+
``` ruby
|
132
|
+
Hiya::Users::Links.new(response[:token]).all
|
133
|
+
```
|
134
|
+
|
135
|
+
### Get link
|
136
|
+
|
137
|
+
``` ruby
|
138
|
+
Hiya::Users::Links.new(response[:token]).find(code)
|
139
|
+
```
|
140
|
+
|
141
|
+
### Append files attach to link
|
142
|
+
|
143
|
+
``` ruby
|
144
|
+
files = [
|
145
|
+
'/Users/username/Desktop/aaa.jpg',
|
146
|
+
'/Users/username/Desktop/bbb.png',
|
147
|
+
'/Users/username/Desktop/ccc.gif'
|
148
|
+
]
|
149
|
+
Hiya::Users::Links.new(response[:token]).attach_files(code, files)
|
150
|
+
```
|
151
|
+
|
152
|
+
### Update attach to link
|
153
|
+
|
154
|
+
``` ruby
|
155
|
+
params = {
|
156
|
+
attach: {
|
157
|
+
password: 'kopi',
|
158
|
+
password_note: 'こぴ / kopi',
|
159
|
+
view_count_limit: 9999
|
160
|
+
},
|
161
|
+
post: {
|
162
|
+
content: "こぴ / kopi\nhttps://youtu.be/kmPgjr0EL64"
|
163
|
+
}
|
164
|
+
}
|
165
|
+
Hiya::Users::Links.new(response[:token]).update(code, params)
|
166
|
+
```
|
167
|
+
|
168
|
+
### Update IP info to link
|
169
|
+
|
170
|
+
``` ruby
|
171
|
+
params = {
|
172
|
+
ip: String: "125.227.100.100",
|
173
|
+
hostname: String: "125-227-100-100.hinet-ip.hinet.net",
|
174
|
+
city: String: "Taipei",
|
175
|
+
region: String: "Taiwan",
|
176
|
+
country: String: "TW",
|
177
|
+
loc: String: "25.0418,121.5359",
|
178
|
+
org: String: "AS3462 Data Communication Business Group",
|
179
|
+
timezone: String: "Asia/Taipei"
|
180
|
+
}
|
181
|
+
Hiya::Users::Links.new(response[:token]).update_ip_info(code, params)
|
182
|
+
```
|
183
|
+
|
184
|
+
### Destroy link
|
185
|
+
|
186
|
+
``` ruby
|
187
|
+
Hiya::Users::Links.new(response[:token]).destroy(code)
|
188
|
+
```
|
189
|
+
|
76
190
|
## Development
|
77
191
|
|
78
192
|
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.
|
data/lib/hiya/attach_base.rb
CHANGED
@@ -22,7 +22,7 @@ module Hiya
|
|
22
22
|
@files = files
|
23
23
|
@opts = opts
|
24
24
|
|
25
|
-
response =
|
25
|
+
@response = multipart_conn.post(url) do |req|
|
26
26
|
req.body = create_params
|
27
27
|
end
|
28
28
|
Oj.load(response.body, symbol_keys: true)
|
@@ -30,13 +30,6 @@ module Hiya
|
|
30
30
|
{}
|
31
31
|
end
|
32
32
|
|
33
|
-
def conn
|
34
|
-
@conn ||= Faraday.new(api_url) do |f|
|
35
|
-
f.request :authorization, 'Bearer', -> { token }
|
36
|
-
f.request :multipart
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
33
|
private
|
41
34
|
|
42
35
|
attr_reader :files, :opts, :params
|
data/lib/hiya/base.rb
CHANGED
@@ -2,15 +2,17 @@
|
|
2
2
|
|
3
3
|
# require_relative 'url'
|
4
4
|
|
5
|
+
require 'faraday'
|
6
|
+
|
5
7
|
module Hiya
|
6
8
|
class Base
|
7
|
-
def initialize(
|
8
|
-
@
|
9
|
+
def initialize(bearer_token = nil)
|
10
|
+
@bearer_token = bearer_token
|
9
11
|
|
10
12
|
setup
|
11
13
|
end
|
12
14
|
|
13
|
-
attr_reader :source, :api_url, :
|
15
|
+
attr_reader :source, :api_url, :bearer_token, :response
|
14
16
|
|
15
17
|
private
|
16
18
|
|
@@ -27,5 +29,19 @@ module Hiya
|
|
27
29
|
def api_url_name
|
28
30
|
self.class.name.split('::').last.downcase
|
29
31
|
end
|
32
|
+
|
33
|
+
def conn
|
34
|
+
@conn ||= Faraday.new(api_url) do |f|
|
35
|
+
f.request :authorization, 'Bearer', -> { bearer_token }
|
36
|
+
f.request :json
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def multipart_conn
|
41
|
+
@multipart_conn ||= Faraday.new(api_url) do |f|
|
42
|
+
f.request :authorization, 'Bearer', -> { bearer_token }
|
43
|
+
f.request :multipart
|
44
|
+
end
|
45
|
+
end
|
30
46
|
end
|
31
47
|
end
|
data/lib/hiya/link.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Hiya
|
4
|
+
class Link < Base
|
5
|
+
attr_reader :code
|
6
|
+
|
7
|
+
# code: a2e1M
|
8
|
+
# params: Hash: {
|
9
|
+
# token: String(required),
|
10
|
+
# attach: Hash: {
|
11
|
+
# password: String: '1234'
|
12
|
+
# password_note: String: 'today'
|
13
|
+
# expired_num: Integer: 3600
|
14
|
+
# view_count_limit: Integer: 100
|
15
|
+
# }
|
16
|
+
# post: Hash: {
|
17
|
+
# content: String: 'This is post content'
|
18
|
+
# }
|
19
|
+
# }
|
20
|
+
def update(code, params)
|
21
|
+
@response = conn.put("/v1/links/#{code}") do |req|
|
22
|
+
req.body = params.to_json
|
23
|
+
end
|
24
|
+
Oj.load(response.body, symbol_keys: true)
|
25
|
+
rescue StandardError => _e
|
26
|
+
{}
|
27
|
+
end
|
28
|
+
|
29
|
+
# code: a2e1M
|
30
|
+
# params: Hash: {
|
31
|
+
# token: String(required),
|
32
|
+
# }
|
33
|
+
def destroy(code, params)
|
34
|
+
@response = conn.delete("/v1/links/#{code}") do |req|
|
35
|
+
req.body = params.to_json
|
36
|
+
end
|
37
|
+
Oj.load(response.body, symbol_keys: true)
|
38
|
+
rescue StandardError => _e
|
39
|
+
{}
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
data/lib/hiya/oauth.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Hiya
|
4
|
+
class Oauth < Base
|
5
|
+
def self.token(params)
|
6
|
+
new.token(params)
|
7
|
+
end
|
8
|
+
|
9
|
+
# params: Hash: {
|
10
|
+
# grant_type: 'password',
|
11
|
+
# --- facebook
|
12
|
+
# facebook_token: String,
|
13
|
+
# --- google
|
14
|
+
# google_token: String,
|
15
|
+
# google_refresh_token: String,
|
16
|
+
# --- line
|
17
|
+
# line_token: String,
|
18
|
+
# --- chatbot
|
19
|
+
# chatbot_token: String,
|
20
|
+
# }
|
21
|
+
def token(params)
|
22
|
+
@response = conn.post('/v1/oauth/token') do |req|
|
23
|
+
req.body = params.to_json
|
24
|
+
end
|
25
|
+
Oj.load(response.body, symbol_keys: true)
|
26
|
+
rescue StandardError => _e
|
27
|
+
{}
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/lib/hiya/url.rb
CHANGED
@@ -6,21 +6,12 @@ module Hiya
|
|
6
6
|
def create(links)
|
7
7
|
params = { links: links, source: source }
|
8
8
|
|
9
|
-
response = conn.post(url) do |req|
|
9
|
+
@response = conn.post(url) do |req|
|
10
10
|
req.body = params.to_json
|
11
11
|
end
|
12
12
|
Oj.load(response.body, symbol_keys: true)
|
13
13
|
rescue StandardError => _e
|
14
14
|
{}
|
15
15
|
end
|
16
|
-
|
17
|
-
private
|
18
|
-
|
19
|
-
def conn
|
20
|
-
@conn ||= Faraday.new(api_url) do |f|
|
21
|
-
f.request :authorization, 'Bearer', -> { token }
|
22
|
-
f.request :json
|
23
|
-
end
|
24
|
-
end
|
25
16
|
end
|
26
17
|
end
|
@@ -0,0 +1,110 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Hiya
|
4
|
+
module Users
|
5
|
+
class Links < Base
|
6
|
+
def all
|
7
|
+
@response = conn.get('/v1/users/links')
|
8
|
+
Oj.load(response.body, symbol_keys: true)
|
9
|
+
rescue StandardError => _e
|
10
|
+
{}
|
11
|
+
end
|
12
|
+
|
13
|
+
def find(code)
|
14
|
+
@response = conn.get("/v1/users/links/#{code}")
|
15
|
+
Oj.load(response.body, symbol_keys: true)
|
16
|
+
rescue StandardError => _e
|
17
|
+
{}
|
18
|
+
end
|
19
|
+
|
20
|
+
# code: a2e1M
|
21
|
+
# files: Array[String]: ['/path/to/file1', '/path/to/file2', ...]
|
22
|
+
def attach_files(code, files)
|
23
|
+
return unless files.is_a?(Array)
|
24
|
+
|
25
|
+
@files = files
|
26
|
+
|
27
|
+
@response = multipart_conn.post("/v1/users/links/#{code}") do |req|
|
28
|
+
req.body = attach_file_params
|
29
|
+
end
|
30
|
+
Oj.load(response.body, symbol_keys: true)
|
31
|
+
rescue StandardError => _e
|
32
|
+
{}
|
33
|
+
end
|
34
|
+
|
35
|
+
# code: a2e1M
|
36
|
+
# params: Hash: {
|
37
|
+
# attach: Hash: {
|
38
|
+
# password: String: '1234'
|
39
|
+
# password_note: String: 'today'
|
40
|
+
# view_count_limit: Integer: 100
|
41
|
+
# }
|
42
|
+
# post: Hash: {
|
43
|
+
# content: String: 'This is post content'
|
44
|
+
# }
|
45
|
+
# }
|
46
|
+
def update(code, params)
|
47
|
+
@response = conn.put("/v1/users/links/#{code}") do |req|
|
48
|
+
req.body = params.to_json
|
49
|
+
end
|
50
|
+
Oj.load(response.body, symbol_keys: true)
|
51
|
+
rescue StandardError => _e
|
52
|
+
{}
|
53
|
+
end
|
54
|
+
|
55
|
+
# code: a2e1M
|
56
|
+
# params: Hash: {
|
57
|
+
# ip: String: "125.227.100.100",
|
58
|
+
# hostname: String: "125-227-100-100.hinet-ip.hinet.net",
|
59
|
+
# city: String: "Taipei",
|
60
|
+
# region: String: "Taiwan",
|
61
|
+
# country: String: "TW",
|
62
|
+
# loc: String: "25.0418,121.5359",
|
63
|
+
# org: String: "AS3462 Data Communication Business Group",
|
64
|
+
# timezone: String: "Asia/Taipei"
|
65
|
+
# }
|
66
|
+
def update_ip_info(code, params)
|
67
|
+
@response = conn.post("/v1/users/links/#{code}/ip_info") do |req|
|
68
|
+
req.body = params.to_json
|
69
|
+
end
|
70
|
+
Oj.load(response.body, symbol_keys: true)
|
71
|
+
rescue StandardError => _e
|
72
|
+
{}
|
73
|
+
end
|
74
|
+
|
75
|
+
# code: a2e1M
|
76
|
+
def destroy(code)
|
77
|
+
@response = conn.delete("/v1/users/links/#{code}")
|
78
|
+
Oj.load(response.body, symbol_keys: true)
|
79
|
+
rescue StandardError => _e
|
80
|
+
{}
|
81
|
+
end
|
82
|
+
|
83
|
+
private
|
84
|
+
|
85
|
+
def attach_file_params
|
86
|
+
{
|
87
|
+
attach: {
|
88
|
+
files: make_files
|
89
|
+
}
|
90
|
+
}
|
91
|
+
end
|
92
|
+
|
93
|
+
def make_files
|
94
|
+
@files.map do |file|
|
95
|
+
Faraday::Multipart::FilePart.new(make_io(file), 'application/octet-stream')
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
def make_io(path_or_io)
|
100
|
+
if path_or_io.is_a?(String)
|
101
|
+
::File.open(path_or_io, binmode: true)
|
102
|
+
elsif defined?(Pathname) && path_or_io.is_a?(Pathname)
|
103
|
+
path_or_io.open(binmode: true)
|
104
|
+
else
|
105
|
+
path_or_io
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
data/lib/hiya/version.rb
CHANGED
data/lib/hiya.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hiya
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kevin
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-07-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -28,16 +28,16 @@ dependencies:
|
|
28
28
|
name: faraday-multipart
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '0'
|
33
|
+
version: '1.0'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '0'
|
40
|
+
version: '1.0'
|
41
41
|
description: Simple, Fast, Safe, Private URL Shortener
|
42
42
|
email:
|
43
43
|
- service@iiil.io
|
@@ -59,7 +59,10 @@ files:
|
|
59
59
|
- lib/hiya/base.rb
|
60
60
|
- lib/hiya/configuration.rb
|
61
61
|
- lib/hiya/image.rb
|
62
|
+
- lib/hiya/link.rb
|
63
|
+
- lib/hiya/oauth.rb
|
62
64
|
- lib/hiya/url.rb
|
65
|
+
- lib/hiya/users/links.rb
|
63
66
|
- lib/hiya/version.rb
|
64
67
|
- lib/hiya/video.rb
|
65
68
|
- sig/hiya.rbs
|