clnk_api 0.0.2 → 0.0.4
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 +5 -5
- data/README.md +13 -0
- data/clnk_api.gemspec +4 -4
- data/lib/clnk_api/clnk.rb +15 -6
- data/lib/clnk_api/link.rb +33 -12
- data/lib/clnk_api/version.rb +1 -1
- metadata +18 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 91aa142d923c07b8831899fa64292bf25bdc7ff454c6f99b9fc40c77b38a589e
|
4
|
+
data.tar.gz: 1f72e6007cd1250669d8b6c2e8beb3001d99c384e29749cb3624052fc8da1d63
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9b04461f444b7ac02b8ccdad3f6c76249e5cc6a8e254de72ddb174002b2736045f0fb0558f228dd8b3bfb4b9788e5c6e38047533cdcd8776f4250774acc66996
|
7
|
+
data.tar.gz: 5b63abd0f1af786612143073c3dfae7979b829f16d029bbfcd08e03ff3eec9af55240282fd485e2801b1e8b0b2a82136590fc89518695fb5b7fb65b61a320c60
|
data/README.md
CHANGED
@@ -20,11 +20,24 @@ Or install it yourself as:
|
|
20
20
|
|
21
21
|
## Usage
|
22
22
|
|
23
|
+
### Basic Usage
|
24
|
+
|
23
25
|
clnk = ClnkApi::Clnk.new("AccessToken")
|
24
26
|
# Clnk::Link contains :short_url,:long_url,short_code
|
25
27
|
link = clnk.shorten(url) # return ClnkApi::Link
|
26
28
|
link = clnk.expand("shortcode") # return ClnkApi::Link
|
27
29
|
link = clnk.info("shorturl") # return ClnkApi::Link
|
30
|
+
link = clnk.bulk(urls) # where urls can be Array or Hash
|
31
|
+
|
32
|
+
### Using Custom Base URI (v0.0.4+)
|
33
|
+
|
34
|
+
You can now specify a custom base URI when initializing the client:
|
35
|
+
|
36
|
+
# Use custom base URI
|
37
|
+
clnk = ClnkApi::Clnk.new("AccessToken", "https://custom.api.example.com")
|
38
|
+
|
39
|
+
# The default base URI (https://api.clnk.in) is used if not specified
|
40
|
+
clnk = ClnkApi::Clnk.new("AccessToken")
|
28
41
|
|
29
42
|
|
30
43
|
## Contributing
|
data/clnk_api.gemspec
CHANGED
@@ -6,8 +6,8 @@ require 'clnk_api/version'
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "clnk_api"
|
8
8
|
spec.version = ClnkApi::VERSION
|
9
|
-
spec.authors = ["
|
10
|
-
spec.email = ["
|
9
|
+
spec.authors = ["mothirajha"]
|
10
|
+
spec.email = ["rajha12@gmail.com"]
|
11
11
|
spec.summary = %q{Clnk Client API}
|
12
12
|
spec.description = %q{Clnk Client API}
|
13
13
|
spec.homepage = ""
|
@@ -20,6 +20,6 @@ Gem::Specification.new do |spec|
|
|
20
20
|
|
21
21
|
spec.add_development_dependency "bundler", "~> 1.7"
|
22
22
|
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
-
spec.
|
24
|
-
spec.
|
23
|
+
spec.add_dependency "httparty", "~> 0.17.3"
|
24
|
+
spec.add_dependency "multi_json", "~> 1.11.2"
|
25
25
|
end
|
data/lib/clnk_api/clnk.rb
CHANGED
@@ -1,26 +1,35 @@
|
|
1
1
|
module ClnkApi
|
2
2
|
class Clnk
|
3
3
|
|
4
|
-
attr_accessor :api_key
|
5
|
-
def initialize(api_key)
|
4
|
+
attr_accessor :api_key, :base_uri
|
5
|
+
def initialize(api_key, base_uri = nil)
|
6
6
|
@api_key = api_key
|
7
|
+
@base_uri = base_uri || 'https://api.clnk.in'
|
7
8
|
end
|
8
9
|
|
9
10
|
def shorten(url)
|
10
|
-
link = ClnkApi::Link.new(@api_key)
|
11
|
+
link = ClnkApi::Link.new(@api_key, @base_uri)
|
11
12
|
link.shorten(url)
|
12
13
|
link
|
13
14
|
end
|
14
15
|
|
15
16
|
def info(url)
|
16
|
-
link = ClnkApi::Link.new(@api_key)
|
17
|
+
link = ClnkApi::Link.new(@api_key, @base_uri)
|
17
18
|
link.info(url)
|
18
19
|
link
|
19
20
|
end
|
21
|
+
|
20
22
|
def expand(url)
|
21
|
-
link = ClnkApi::Link.new(@api_key)
|
23
|
+
link = ClnkApi::Link.new(@api_key, @base_uri)
|
22
24
|
link.expand(url)
|
23
25
|
link
|
24
26
|
end
|
27
|
+
|
28
|
+
def bulk(urls)
|
29
|
+
link = ClnkApi::Link.new(@api_key, @base_uri)
|
30
|
+
link.bulk_shorten(urls)
|
31
|
+
link
|
32
|
+
end
|
33
|
+
|
25
34
|
end
|
26
|
-
end
|
35
|
+
end
|
data/lib/clnk_api/link.rb
CHANGED
@@ -1,15 +1,27 @@
|
|
1
|
-
require 'pry'
|
2
1
|
module ClnkApi
|
3
2
|
class Link
|
4
3
|
include HTTParty
|
5
|
-
|
6
|
-
|
7
|
-
def initialize(api_key)
|
4
|
+
attr_accessor :long_url, :short_url, :short_code,:api_key,:clicks, :bulk_urls
|
5
|
+
def initialize(api_key, base_uri = nil)
|
8
6
|
@api_key = api_key
|
7
|
+
@base_uri = base_uri || 'https://api.clnk.in'
|
8
|
+
self.class.base_uri @base_uri
|
9
9
|
end
|
10
10
|
|
11
|
-
def validate_url(
|
12
|
-
|
11
|
+
def validate_url(urls)
|
12
|
+
case urls.class.to_s
|
13
|
+
when "String"
|
14
|
+
raise ClnkApi::General.new("Url is invalid.") unless urls =~ /\A#{URI::regexp(['http', 'https'])}\z/
|
15
|
+
when "Array"
|
16
|
+
urls.each do |url|
|
17
|
+
raise ClnkApi::General.new("Url is invalid.") unless url =~ /\A#{URI::regexp(['http', 'https'])}\z/
|
18
|
+
end
|
19
|
+
when "Hash"
|
20
|
+
urls.each do |k, url|
|
21
|
+
raise ClnkApi::General.new("Url is invalid.") unless url =~ /\A#{URI::regexp(['http', 'https'])}\z/
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
13
25
|
end
|
14
26
|
|
15
27
|
def info(url)
|
@@ -27,25 +39,31 @@ module ClnkApi
|
|
27
39
|
handle_response(response)
|
28
40
|
end
|
29
41
|
|
30
|
-
|
31
|
-
|
32
42
|
def shorten(url)
|
33
43
|
validate_url(url)
|
34
44
|
long_url = url
|
35
45
|
options = {:body=>{ :long_url=> long_url,:access_token=> @api_key} }
|
36
46
|
response = self.class.post("/api/v1/links/shorten", options)
|
37
47
|
handle_response(response)
|
38
|
-
|
39
|
-
|
40
|
-
|
41
48
|
end
|
42
49
|
|
50
|
+
def bulk_shorten(urls)
|
51
|
+
validate_url(urls)
|
52
|
+
options = {:body=>{:urls=> urls.to_json,:access_token=>@api_key} }
|
53
|
+
response = self.class.post("/api/v1/links/bulk_shorten", options)
|
54
|
+
handle_bulk_response(response)
|
55
|
+
end
|
43
56
|
|
44
57
|
def handle_response(response)
|
45
58
|
raise_errors(response)
|
46
59
|
build_response(response)
|
47
60
|
end
|
48
61
|
|
62
|
+
def handle_bulk_response(response)
|
63
|
+
raise_errors(response)
|
64
|
+
bulk_response(response)
|
65
|
+
end
|
66
|
+
|
49
67
|
def raise_errors(response)
|
50
68
|
code = response.code.to_i
|
51
69
|
case code
|
@@ -69,10 +87,13 @@ module ClnkApi
|
|
69
87
|
self.short_url ||= url_data["short_url"]
|
70
88
|
self.short_code ||= url_data["short_code"]
|
71
89
|
self.clicks ||= url_data["clicks"]
|
72
|
-
|
73
90
|
end
|
74
91
|
end
|
75
92
|
|
93
|
+
def bulk_response(response)
|
94
|
+
self.bulk_urls = response.body
|
95
|
+
end
|
96
|
+
|
76
97
|
end
|
77
98
|
end
|
78
99
|
|
data/lib/clnk_api/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: clnk_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
8
|
-
autorequire:
|
7
|
+
- mothirajha
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2025-10-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -42,33 +42,33 @@ dependencies:
|
|
42
42
|
name: httparty
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
48
|
-
type: :
|
47
|
+
version: 0.17.3
|
48
|
+
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
54
|
+
version: 0.17.3
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: multi_json
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - "
|
59
|
+
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
62
|
-
type: :
|
61
|
+
version: 1.11.2
|
62
|
+
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - "
|
66
|
+
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
68
|
+
version: 1.11.2
|
69
69
|
description: Clnk Client API
|
70
70
|
email:
|
71
|
-
-
|
71
|
+
- rajha12@gmail.com
|
72
72
|
executables: []
|
73
73
|
extensions: []
|
74
74
|
extra_rdoc_files: []
|
@@ -88,7 +88,7 @@ homepage: ''
|
|
88
88
|
licenses:
|
89
89
|
- MIT
|
90
90
|
metadata: {}
|
91
|
-
post_install_message:
|
91
|
+
post_install_message:
|
92
92
|
rdoc_options: []
|
93
93
|
require_paths:
|
94
94
|
- lib
|
@@ -103,9 +103,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
103
103
|
- !ruby/object:Gem::Version
|
104
104
|
version: '0'
|
105
105
|
requirements: []
|
106
|
-
|
107
|
-
|
108
|
-
signing_key:
|
106
|
+
rubygems_version: 3.4.10
|
107
|
+
signing_key:
|
109
108
|
specification_version: 4
|
110
109
|
summary: Clnk Client API
|
111
110
|
test_files: []
|