hiya 0.1.1 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 53ce4a25c6148d9b5168d36cb88829557b7cc0c20ffd8323e1f982c90d7136ab
4
- data.tar.gz: e57e02fae1295f88f89038f91773ba1727ffef4b61ca175d4dc977f837b93b98
3
+ metadata.gz: 7d1fc4cb1040d3d524e1c74618d351932f67dcbef1a9c685836c825f0ca1882c
4
+ data.tar.gz: 8701f20b40b0590c95bd95cd901c6bd205bc9b886c863f818f7019b077565efd
5
5
  SHA512:
6
- metadata.gz: 5251f018c62c47456969d1f6c4acea95263b9d661bd620b348f884ba9f1e3b3586c1151c9f1e57959b729be28f3367f7f54f94416106e82977943057c39d38ba
7
- data.tar.gz: a09c5451763dd253f5ddddb642fcb3f11122053f4531835e00bafed3be05d35b840423e3ff9d93d420aa6ea4daa48acdbdbb1222af83cabb9063af70ad4def0c
6
+ metadata.gz: f58479c142f89a29a14f970c7e0cffd1f330792e05f1a01b465b9df55783f44803d7539ec5a49adf59d709307483abc45c443abf1e7ac1ccec99967907f7bff4
7
+ data.tar.gz: 8596cf477196b15a3b4dc424d52fbf2367adab1aefa2aee24d51cf28e5418b5f8620db378d43506f8ff99b14c9a67d91db70113ebfdd99315be4158c371aee08
data/Gemfile.lock CHANGED
@@ -1,9 +1,9 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- hiya (0.1.0)
4
+ hiya (0.2.1)
5
5
  faraday (~> 2.0)
6
- faraday-multipart
6
+ faraday-multipart (~> 1.0)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -35,44 +35,164 @@ Hiya::Url.new.create(links)
35
35
  ### Image - create images short link
36
36
 
37
37
  ``` ruby
38
- paths = [
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(paths, {
44
- attach: { password: '1234', password_note: 'today', expired_num: 300, view_count_limit: 100 },
45
- post: { content: "haha\nhttps://www.google.com" }
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
- paths = [
59
+ files = [
53
60
  '/Users/username/Desktop/aaa.mp4',
54
61
  '/Users/username/Desktop/bbb.mp4'
55
62
  ]
56
- Hiya::Video.new.create(paths, {
57
- attach: { password: '1234', password_note: 'today', expired_num: 300, view_count_limit: 100 },
58
- post: { content: "yoyo\nhttps://www.google.com" }
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
- paths = [
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(paths, {
71
- attach: { password: '1234', password_note: 'today', expired_num: 300, view_count_limit: 100 },
72
- post: { content: "yoyo\nhttps://www.google.com" }
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
+ ### Get link analytic
142
+
143
+ ``` ruby
144
+ Hiya::Users::Links.new(response[:token]).analytic(code)
145
+ ```
146
+
147
+ ### Append files attach to link
148
+
149
+ ``` ruby
150
+ files = [
151
+ '/Users/username/Desktop/aaa.jpg',
152
+ '/Users/username/Desktop/bbb.png',
153
+ '/Users/username/Desktop/ccc.gif'
154
+ ]
155
+ Hiya::Users::Links.new(response[:token]).attach_files(code, files)
156
+ ```
157
+
158
+ ### Update attach to link
159
+
160
+ ``` ruby
161
+ params = {
162
+ attach: {
163
+ password: 'kopi',
164
+ password_note: 'こぴ / kopi',
165
+ view_count_limit: 9999
166
+ },
167
+ post: {
168
+ content: "こぴ / kopi\nhttps://youtu.be/kmPgjr0EL64"
169
+ }
170
+ }
171
+ Hiya::Users::Links.new(response[:token]).update(code, params)
172
+ ```
173
+
174
+ ### Update IP info to link
175
+
176
+ ``` ruby
177
+ params = {
178
+ ip: String: "125.227.100.100",
179
+ hostname: String: "125-227-100-100.hinet-ip.hinet.net",
180
+ city: String: "Taipei",
181
+ region: String: "Taiwan",
182
+ country: String: "TW",
183
+ loc: String: "25.0418,121.5359",
184
+ org: String: "AS3462 Data Communication Business Group",
185
+ timezone: String: "Asia/Taipei"
186
+ }
187
+ Hiya::Users::Links.new(response[:token]).update_ip_info(code, params)
188
+ ```
189
+
190
+ ### Destroy link
191
+
192
+ ``` ruby
193
+ Hiya::Users::Links.new(response[:token]).destroy(code)
194
+ ```
195
+
76
196
  ## Development
77
197
 
78
198
  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.
@@ -22,7 +22,7 @@ module Hiya
22
22
  @files = files
23
23
  @opts = opts
24
24
 
25
- response = multipart_conn.post(url) do |req|
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)
data/lib/hiya/base.rb CHANGED
@@ -6,13 +6,13 @@ require 'faraday'
6
6
 
7
7
  module Hiya
8
8
  class Base
9
- def initialize(token = nil)
10
- @token = token
9
+ def initialize(bearer_token = nil)
10
+ @bearer_token = bearer_token
11
11
 
12
12
  setup
13
13
  end
14
14
 
15
- attr_reader :source, :api_url, :token
15
+ attr_reader :source, :api_url, :bearer_token, :response
16
16
 
17
17
  private
18
18
 
@@ -32,14 +32,14 @@ module Hiya
32
32
 
33
33
  def conn
34
34
  @conn ||= Faraday.new(api_url) do |f|
35
- f.request :authorization, 'Bearer', -> { token }
35
+ f.request :authorization, 'Bearer', -> { bearer_token }
36
36
  f.request :json
37
37
  end
38
38
  end
39
39
 
40
40
  def multipart_conn
41
41
  @multipart_conn ||= Faraday.new(api_url) do |f|
42
- f.request :authorization, 'Bearer', -> { token }
42
+ f.request :authorization, 'Bearer', -> { bearer_token }
43
43
  f.request :multipart
44
44
  end
45
45
  end
data/lib/hiya/link.rb CHANGED
@@ -18,7 +18,7 @@ module Hiya
18
18
  # }
19
19
  # }
20
20
  def update(code, params)
21
- response = conn.put("/v1/links/#{code}") do |req|
21
+ @response = conn.put("/v1/links/#{code}") do |req|
22
22
  req.body = params.to_json
23
23
  end
24
24
  Oj.load(response.body, symbol_keys: true)
@@ -31,7 +31,7 @@ module Hiya
31
31
  # token: String(required),
32
32
  # }
33
33
  def destroy(code, params)
34
- response = conn.delete("/v1/links/#{code}") do |req|
34
+ @response = conn.delete("/v1/links/#{code}") do |req|
35
35
  req.body = params.to_json
36
36
  end
37
37
  Oj.load(response.body, symbol_keys: true)
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,7 +6,7 @@ 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)
@@ -0,0 +1,117 @@
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
+ def analytics(code)
21
+ @response = conn.get("/v1/users/links/#{code}/analytics")
22
+ Oj.load(response.body, symbol_keys: true)
23
+ rescue StandardError => _e
24
+ {}
25
+ end
26
+
27
+ # code: a2e1M
28
+ # files: Array[String]: ['/path/to/file1', '/path/to/file2', ...]
29
+ def attach_files(code, files)
30
+ return unless files.is_a?(Array)
31
+
32
+ @files = files
33
+
34
+ @response = multipart_conn.post("/v1/users/links/#{code}") do |req|
35
+ req.body = attach_file_params
36
+ end
37
+ Oj.load(response.body, symbol_keys: true)
38
+ rescue StandardError => _e
39
+ {}
40
+ end
41
+
42
+ # code: a2e1M
43
+ # params: Hash: {
44
+ # attach: Hash: {
45
+ # password: String: '1234'
46
+ # password_note: String: 'today'
47
+ # view_count_limit: Integer: 100
48
+ # }
49
+ # post: Hash: {
50
+ # content: String: 'This is post content'
51
+ # }
52
+ # }
53
+ def update(code, params)
54
+ @response = conn.put("/v1/users/links/#{code}") do |req|
55
+ req.body = params.to_json
56
+ end
57
+ Oj.load(response.body, symbol_keys: true)
58
+ rescue StandardError => _e
59
+ {}
60
+ end
61
+
62
+ # code: a2e1M
63
+ # params: Hash: {
64
+ # ip: String: "125.227.100.100",
65
+ # hostname: String: "125-227-100-100.hinet-ip.hinet.net",
66
+ # city: String: "Taipei",
67
+ # region: String: "Taiwan",
68
+ # country: String: "TW",
69
+ # loc: String: "25.0418,121.5359",
70
+ # org: String: "AS3462 Data Communication Business Group",
71
+ # timezone: String: "Asia/Taipei"
72
+ # }
73
+ def update_ip_info(code, params)
74
+ @response = conn.post("/v1/users/links/#{code}/ip_info") do |req|
75
+ req.body = params.to_json
76
+ end
77
+ Oj.load(response.body, symbol_keys: true)
78
+ rescue StandardError => _e
79
+ {}
80
+ end
81
+
82
+ # code: a2e1M
83
+ def destroy(code)
84
+ @response = conn.delete("/v1/users/links/#{code}")
85
+ Oj.load(response.body, symbol_keys: true)
86
+ rescue StandardError => _e
87
+ {}
88
+ end
89
+
90
+ private
91
+
92
+ def attach_file_params
93
+ {
94
+ attach: {
95
+ files: make_files
96
+ }
97
+ }
98
+ end
99
+
100
+ def make_files
101
+ @files.map do |file|
102
+ Faraday::Multipart::FilePart.new(make_io(file), 'application/octet-stream')
103
+ end
104
+ end
105
+
106
+ def make_io(path_or_io)
107
+ if path_or_io.is_a?(String)
108
+ ::File.open(path_or_io, binmode: true)
109
+ elsif defined?(Pathname) && path_or_io.is_a?(Pathname)
110
+ path_or_io.open(binmode: true)
111
+ else
112
+ path_or_io
113
+ end
114
+ end
115
+ end
116
+ end
117
+ end
data/lib/hiya/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Hiya
4
- VERSION = '0.1.1'
4
+ VERSION = '0.2.1'
5
5
  end
data/lib/hiya.rb CHANGED
@@ -8,6 +8,8 @@ require_relative 'hiya/url'
8
8
  require_relative 'hiya/image'
9
9
  require_relative 'hiya/video'
10
10
  require_relative 'hiya/audio'
11
+ require_relative 'hiya/oauth'
12
+ require_relative 'hiya/users/links'
11
13
 
12
14
  module Hiya
13
15
  class Error < StandardError; end
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.1.1
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-06-30 00:00:00.000000000 Z
11
+ date: 2023-07-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -60,7 +60,9 @@ files:
60
60
  - lib/hiya/configuration.rb
61
61
  - lib/hiya/image.rb
62
62
  - lib/hiya/link.rb
63
+ - lib/hiya/oauth.rb
63
64
  - lib/hiya/url.rb
65
+ - lib/hiya/users/links.rb
64
66
  - lib/hiya/version.rb
65
67
  - lib/hiya/video.rb
66
68
  - sig/hiya.rbs