kutt 0.0.0 → 0.2

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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/kutt.rb +53 -39
  3. metadata +7 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7568783dd14611cb8ebc5a4267fecf13c4bddc69c6f0419c3f9f2b1aec4cab8d
4
- data.tar.gz: 41755f6f4eaccc40275de553ae4e798fdb1a00961a9f8345f1fce06bb0c7e945
3
+ metadata.gz: 396005f27cb2300a33bfe3e11fee78a5f92504d497defdc9eaef0f2a2ea73c31
4
+ data.tar.gz: f1d7ff7258999aa3f97c11bc0e38123530a360bfdf6454f555f4cca582c9abcf
5
5
  SHA512:
6
- metadata.gz: 93fdf19e4c0272e3e67131867efac3e3853c990f01b27a1b84d471f4dc1aeb78ad5cf3cd50e427077b92a96a259772d3b88505f870a7c0dd97a7fb484b0b4ed8
7
- data.tar.gz: 5e9b30dc90a53a3b184a2ed9259f1ba74305df4cc6455b0e2640e3d9960fa88d915ac43adb7c6c0cf66c04a8cfe2a564b1418373b7b228b7497ef8374a07d3df
6
+ metadata.gz: 1c4752eb6e59d9bcaee2e4c257c545c84a0e805eb1d07bd3342a8bd4c7ff824e691df2b8772bad012ec3ca12fa48033c1881a7b0ca3b641c8f20d6275ddff27b
7
+ data.tar.gz: 982c0e772abb7f58c15e201c14a63d13cb30bcd219b2df5a777cb9facee0acd6c5096588b88eed411a1860289036af48d7ebe66071a0d1b7c00321cc310a8c31
@@ -2,62 +2,76 @@ require 'httparty'
2
2
  require 'json'
3
3
 
4
4
  class Kutt
5
- def initialize(apikey)
6
- @base_url = 'https://kutt.it'
7
- @headers = { 'Content-Type' => 'application/json', 'Accept' => 'application/json', 'X-API-Key' => apikey}
5
+ def initialize(apikey, base_url = 'https://kutt.it')
6
+ @base_url = base_url
7
+ @headers = { 'Content-Type': 'application/json', 'Accept': 'application/json',
8
+ 'X-API-Key': apikey}
8
9
  return true
9
10
  end
10
11
 
11
- def submit(url, customurl=nil, password=nil, reuse=false)
12
+ def submit(url, **args)
12
13
  payload = {}
13
- payload['target'] = url
14
- if customurl
15
- payload['customurl'] = customurl
16
- end
17
- if password
18
- payload['password'] = password
19
- end
20
- if reuse
21
- payload['reuse'] = true
22
- end
14
+ payload['target'] = url
15
+ payload['customurl'] = args[:customurl] if args[:customurl]
16
+ payload['password'] = args[:password] if args[:password]
17
+ payload['reuse'] = 'true' if args[:reuse] == true
23
18
 
24
- r = HTTParty.post(@base_url+'/api/url/submit',
25
- :headers => @headers,
26
- :body => payload.to_json)
19
+ r = HTTParty.post(@base_url + '/api/url/submit',
20
+ headers: @headers,
21
+ body: payload.to_json)
27
22
 
28
23
  return r.code, r.to_hash
29
24
  end
30
25
 
31
26
  def delete(target)
32
- url_array = target.split("/")
27
+ url_array = target.split('/')
33
28
  id = url_array.last
34
-
35
- payload = {'id' => id}
36
-
37
- r = HTTParty.post(@base_url+'/api/url/deleteurl',
38
- :headers => @headers,
39
- :body => payload.to_json)
40
-
29
+
30
+ payload = { 'id': id }
31
+
32
+ r = HTTParty.post(@base_url + '/api/url/deleteurl', headers: @headers,
33
+ body: payload.to_json)
34
+
41
35
  return r.code, r.to_hash
42
36
  end
43
-
37
+
44
38
  def stats(target)
45
- url_array = target.split("/")
39
+ url_array = target.split('/')
46
40
  id = url_array.last
47
-
48
- payload = {'id' => id}
49
-
50
- r = HTTParty.get(@base_url+'/api/url/stats',
51
- :headers => @headers,
52
- :query => payload)
53
-
41
+
42
+ payload = {'id': id }
43
+
44
+ r = HTTParty.get(@base_url + '/api/url/stats',
45
+ headers: @headers,
46
+ query: payload)
47
+
54
48
  return r.code, r.to_hash
55
49
  end
56
-
57
- def list()
58
- r = HTTParty.get(@base_url+'/api/url/geturls',
59
- :headers => @headers)
60
-
50
+
51
+ def count
52
+ r = HTTParty.get(@base_url + '/api/url/geturls?count=0',
53
+ headers: @headers)['countAll']
54
+ return r
55
+ end
56
+
57
+ def list(count = 5, page = 1)
58
+ r = HTTParty.get(@base_url + "/api/url/geturls?count=#{count}&page=
59
+ #{page}",
60
+ headers: @headers)
61
+
61
62
  return r.code, r.to_hash
62
63
  end
64
+
65
+ def list_all
66
+ num_pages = (count.to_f / 50).ceil
67
+ return ''.to_hash if num_pages.zero?
68
+
69
+ full_list = []
70
+ (1..num_pages).each do |page|
71
+ r = HTTParty.get(@base_url + "/api/url/geturls?count=50&page=#{page}",
72
+ :headers => @headers)['list']
73
+ (full_list << r).flatten!
74
+ end
75
+ return r.code, full_list
76
+ end
63
77
  end
metadata CHANGED
@@ -1,23 +1,24 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kutt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: '0.2'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Amirali Esfandiari
8
+ - MalekMFS
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2018-11-09 00:00:00.000000000 Z
12
+ date: 2020-09-30 00:00:00.000000000 Z
12
13
  dependencies: []
13
- description: library for url shorten service kutt.it
14
+ description: library for url shortener service kutt.it
14
15
  email: amiralinull@gmail.com
15
16
  executables: []
16
17
  extensions: []
17
18
  extra_rdoc_files: []
18
19
  files:
19
20
  - lib/kutt.rb
20
- homepage: http://github.com/univa64/kutt.rb/
21
+ homepage: http://github.com/RealAmirali/kutt.rb/
21
22
  licenses:
22
23
  - GPL-3.0+
23
24
  metadata: {}
@@ -36,9 +37,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
36
37
  - !ruby/object:Gem::Version
37
38
  version: '0'
38
39
  requirements: []
39
- rubyforge_project:
40
- rubygems_version: 2.7.6
40
+ rubygems_version: 3.1.2
41
41
  signing_key:
42
42
  specification_version: 4
43
- summary: just a library for kutt in ruby
43
+ summary: Ruby wrapper for kutt.it
44
44
  test_files: []