clnk_api 0.0.3 → 0.0.5
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/CHANGELOG.md +42 -0
- data/CLAUDE.md +112 -0
- data/README.md +13 -0
- data/clnk_api-0.0.4.gem +0 -0
- data/clnk_api.gemspec +7 -7
- data/lib/clnk_api/clnk.rb +15 -6
- data/lib/clnk_api/link.rb +33 -11
- data/lib/clnk_api/version.rb +1 -1
- metadata +34 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: aadd78f740df8828fa1f9c8c9b07eca199178d6a0b737932ad004a027df836bb
|
4
|
+
data.tar.gz: 2ef777e85b8783dd1a3fc3f7e0cb3432a8205f9014a55238308d10b1103bcc31
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 54b80490dff6e20b0e70f1586acd9e133f20c18f4740a93412dfc979801d1655700bf73538b2337c5bf9ee71bd5b6f8cccd81ec3171aa2f5e99a8a933994a7b1
|
7
|
+
data.tar.gz: cbac5854628067c65699f6387218b5a10edd9255f01429e64634c05189598406e0d914af66e1dcbde79d230cec4aa10b67d988cb0bec1762aad03f59693f92dc
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
All notable changes to this project will be documented in this file.
|
4
|
+
|
5
|
+
## [0.0.5] - 2024-10-08
|
6
|
+
|
7
|
+
### Changed
|
8
|
+
- Relaxed HTTParty dependency from `~> 0.17.3` to `>= 0.13.0` for better compatibility
|
9
|
+
- Relaxed multi_json dependency from `~> 1.11.2` to `>= 1.10` for better compatibility
|
10
|
+
- This allows the gem to work with newer versions of HTTParty (tested up to 0.23.x) and multi_json (tested up to 1.15.x)
|
11
|
+
- Resolves Bundler dependency conflicts with other gems that require different versions of these libraries
|
12
|
+
|
13
|
+
## [0.0.4] - 2024-10-08
|
14
|
+
|
15
|
+
### Added
|
16
|
+
- Support for custom base URI configuration
|
17
|
+
- Users can now specify alternative API endpoints when initializing the client
|
18
|
+
- Example: `ClnkApi::Clnk.new("token", "https://custom.api.example.com")`
|
19
|
+
|
20
|
+
### Changed
|
21
|
+
- Updated Clnk initializer to accept optional base_uri parameter
|
22
|
+
- Updated Link class to use configurable base URI
|
23
|
+
|
24
|
+
## [0.0.3] - 2014-11-14
|
25
|
+
|
26
|
+
### Changed
|
27
|
+
- Updated to use HTTPS instead of HTTP for API endpoints
|
28
|
+
|
29
|
+
## [0.0.2] - 2014-11-11
|
30
|
+
|
31
|
+
### Changed
|
32
|
+
- Updated HTTParty gem version
|
33
|
+
|
34
|
+
## [0.0.1] - 2014-11-11
|
35
|
+
|
36
|
+
### Added
|
37
|
+
- Initial release
|
38
|
+
- URL shortening functionality
|
39
|
+
- URL expansion functionality
|
40
|
+
- URL info retrieval
|
41
|
+
- Bulk URL operations
|
42
|
+
- Error handling for API responses
|
data/CLAUDE.md
ADDED
@@ -0,0 +1,112 @@
|
|
1
|
+
# CLAUDE.md
|
2
|
+
|
3
|
+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
|
4
|
+
|
5
|
+
## Project Overview
|
6
|
+
|
7
|
+
ClnkApi is a Ruby gem that provides a client library for interacting with the Clnk URL shortening service API. It supports URL shortening, expansion, info retrieval, and bulk operations.
|
8
|
+
|
9
|
+
## Development Commands
|
10
|
+
|
11
|
+
### Essential Commands
|
12
|
+
```bash
|
13
|
+
# Install dependencies
|
14
|
+
bundle install
|
15
|
+
|
16
|
+
# Build the gem
|
17
|
+
gem build clnk_api.gemspec
|
18
|
+
|
19
|
+
# Install the gem locally
|
20
|
+
gem install ./clnk_api-0.0.3.gem
|
21
|
+
|
22
|
+
# Run console with gem loaded
|
23
|
+
irb -r ./lib/clnk_api
|
24
|
+
|
25
|
+
# Release new version
|
26
|
+
rake release
|
27
|
+
```
|
28
|
+
|
29
|
+
## Architecture Overview
|
30
|
+
|
31
|
+
### Core Components
|
32
|
+
|
33
|
+
- **`lib/clnk_api/clnk.rb`**: Main client class that handles API authentication and provides high-level methods
|
34
|
+
- **`lib/clnk_api/link.rb`**: Low-level API operations and HTTP request handling
|
35
|
+
- **`lib/clnk_api/errors.rb`**: Custom error classes mapped to HTTP status codes
|
36
|
+
|
37
|
+
### API Operations
|
38
|
+
|
39
|
+
The gem supports four main operations:
|
40
|
+
|
41
|
+
1. **Shorten**: Convert long URLs to short Clnk URLs
|
42
|
+
2. **Expand**: Retrieve original URL from short code
|
43
|
+
3. **Info**: Get detailed information about a shortened URL
|
44
|
+
4. **Bulk**: Process multiple URLs in a single request
|
45
|
+
|
46
|
+
### Key Implementation Details
|
47
|
+
|
48
|
+
#### URL Validation
|
49
|
+
- Accepts String, Array, or Hash inputs
|
50
|
+
- Validates URLs against URI.regexp for HTTP/HTTPS protocols
|
51
|
+
- Automatically adds "http://" prefix if protocol is missing
|
52
|
+
|
53
|
+
#### Error Handling
|
54
|
+
Maps HTTP status codes to specific error classes:
|
55
|
+
- 401 → `Unauthorized` (invalid API key)
|
56
|
+
- 400 → `General` (validation errors)
|
57
|
+
- 404 → `NotFound` (invalid short code)
|
58
|
+
- 500 → `InformClnk` (server error)
|
59
|
+
- 503 → `Unavailable` (service down)
|
60
|
+
|
61
|
+
#### API Configuration
|
62
|
+
- Base URI: `https://api.clnk.in`
|
63
|
+
- Authentication via access token in request headers
|
64
|
+
- Uses HTTParty for HTTP client functionality
|
65
|
+
- JSON parsing with multi_json gem
|
66
|
+
|
67
|
+
## Testing Approach
|
68
|
+
|
69
|
+
Currently no test suite is implemented. When adding tests:
|
70
|
+
```bash
|
71
|
+
# Recommended test framework setup
|
72
|
+
bundle add rspec --group test
|
73
|
+
bundle exec rspec --init
|
74
|
+
|
75
|
+
# Run tests (once implemented)
|
76
|
+
bundle exec rspec
|
77
|
+
```
|
78
|
+
|
79
|
+
## Usage Examples
|
80
|
+
|
81
|
+
```ruby
|
82
|
+
# Initialize client
|
83
|
+
clnk = ClnkApi::Clnk.new("your_access_token")
|
84
|
+
|
85
|
+
# Shorten URL
|
86
|
+
short_url = clnk.shorten("https://example.com/very/long/url")
|
87
|
+
|
88
|
+
# Expand short code
|
89
|
+
original_url = clnk.expand("abc123")
|
90
|
+
|
91
|
+
# Get URL info
|
92
|
+
info = clnk.info("https://clnk.in/abc123")
|
93
|
+
|
94
|
+
# Bulk operations
|
95
|
+
urls = ["https://example1.com", "https://example2.com"]
|
96
|
+
results = clnk.bulk(urls)
|
97
|
+
```
|
98
|
+
|
99
|
+
## External Dependencies
|
100
|
+
|
101
|
+
- **HTTParty (~> 0.17.3)**: HTTP client library
|
102
|
+
- **multi_json (~> 1.11.2)**: JSON parsing
|
103
|
+
- **bundler (~> 1.7)**: Dependency management
|
104
|
+
- **rake (~> 10.0)**: Task automation
|
105
|
+
|
106
|
+
## Version Management
|
107
|
+
|
108
|
+
Current version is defined in `lib/clnk_api/version.rb`. To release a new version:
|
109
|
+
1. Update version number in `lib/clnk_api/version.rb`
|
110
|
+
2. Update CHANGELOG if present
|
111
|
+
3. Commit changes
|
112
|
+
4. Run `rake release` to build, tag, and push to RubyGems
|
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-0.0.4.gem
ADDED
Binary file
|
data/clnk_api.gemspec
CHANGED
@@ -6,11 +6,11 @@ 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 = ["
|
11
|
-
spec.summary = %q{
|
12
|
-
spec.description = %q{
|
13
|
-
spec.homepage = ""
|
9
|
+
spec.authors = ["mothirajha"]
|
10
|
+
spec.email = ["rajha12@gmail.com"]
|
11
|
+
spec.summary = %q{Ruby client for Cuelinks URL shortening API}
|
12
|
+
spec.description = %q{A Ruby gem that provides a client library for interacting with the Cuelinks URL shortening service. Supports URL shortening, expansion, info retrieval, bulk operations, and custom base URIs.}
|
13
|
+
spec.homepage = "https://github.com/cuelinks/clnk_api"
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
16
16
|
spec.files = `git ls-files -z`.split("\x0")
|
@@ -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.13.0", "< 1.0"
|
24
|
+
spec.add_dependency "multi_json", ">= 1.10", "< 2.0"
|
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,14 +1,27 @@
|
|
1
1
|
module ClnkApi
|
2
2
|
class Link
|
3
3
|
include HTTParty
|
4
|
-
|
5
|
-
|
6
|
-
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)
|
7
6
|
@api_key = api_key
|
7
|
+
@base_uri = base_uri || 'https://api.clnk.in'
|
8
|
+
self.class.base_uri @base_uri
|
8
9
|
end
|
9
10
|
|
10
|
-
def validate_url(
|
11
|
-
|
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
|
+
|
12
25
|
end
|
13
26
|
|
14
27
|
def info(url)
|
@@ -26,25 +39,31 @@ module ClnkApi
|
|
26
39
|
handle_response(response)
|
27
40
|
end
|
28
41
|
|
29
|
-
|
30
|
-
|
31
42
|
def shorten(url)
|
32
43
|
validate_url(url)
|
33
44
|
long_url = url
|
34
45
|
options = {:body=>{ :long_url=> long_url,:access_token=> @api_key} }
|
35
46
|
response = self.class.post("/api/v1/links/shorten", options)
|
36
47
|
handle_response(response)
|
37
|
-
|
38
|
-
|
39
|
-
|
40
48
|
end
|
41
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
|
42
56
|
|
43
57
|
def handle_response(response)
|
44
58
|
raise_errors(response)
|
45
59
|
build_response(response)
|
46
60
|
end
|
47
61
|
|
62
|
+
def handle_bulk_response(response)
|
63
|
+
raise_errors(response)
|
64
|
+
bulk_response(response)
|
65
|
+
end
|
66
|
+
|
48
67
|
def raise_errors(response)
|
49
68
|
code = response.code.to_i
|
50
69
|
case code
|
@@ -68,10 +87,13 @@ module ClnkApi
|
|
68
87
|
self.short_url ||= url_data["short_url"]
|
69
88
|
self.short_code ||= url_data["short_code"]
|
70
89
|
self.clicks ||= url_data["clicks"]
|
71
|
-
|
72
90
|
end
|
73
91
|
end
|
74
92
|
|
93
|
+
def bulk_response(response)
|
94
|
+
self.bulk_urls = response.body
|
95
|
+
end
|
96
|
+
|
75
97
|
end
|
76
98
|
end
|
77
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.5
|
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-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -44,51 +44,68 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
48
|
-
|
47
|
+
version: 0.13.0
|
48
|
+
- - "<"
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: '1.0'
|
51
|
+
type: :runtime
|
49
52
|
prerelease: false
|
50
53
|
version_requirements: !ruby/object:Gem::Requirement
|
51
54
|
requirements:
|
52
55
|
- - ">="
|
53
56
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
57
|
+
version: 0.13.0
|
58
|
+
- - "<"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '1.0'
|
55
61
|
- !ruby/object:Gem::Dependency
|
56
62
|
name: multi_json
|
57
63
|
requirement: !ruby/object:Gem::Requirement
|
58
64
|
requirements:
|
59
65
|
- - ">="
|
60
66
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
62
|
-
|
67
|
+
version: '1.10'
|
68
|
+
- - "<"
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '2.0'
|
71
|
+
type: :runtime
|
63
72
|
prerelease: false
|
64
73
|
version_requirements: !ruby/object:Gem::Requirement
|
65
74
|
requirements:
|
66
75
|
- - ">="
|
67
76
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
69
|
-
|
77
|
+
version: '1.10'
|
78
|
+
- - "<"
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '2.0'
|
81
|
+
description: A Ruby gem that provides a client library for interacting with the Cuelinks
|
82
|
+
URL shortening service. Supports URL shortening, expansion, info retrieval, bulk
|
83
|
+
operations, and custom base URIs.
|
70
84
|
email:
|
71
|
-
-
|
85
|
+
- rajha12@gmail.com
|
72
86
|
executables: []
|
73
87
|
extensions: []
|
74
88
|
extra_rdoc_files: []
|
75
89
|
files:
|
76
90
|
- ".gitignore"
|
91
|
+
- CHANGELOG.md
|
92
|
+
- CLAUDE.md
|
77
93
|
- Gemfile
|
78
94
|
- LICENSE.txt
|
79
95
|
- README.md
|
80
96
|
- Rakefile
|
97
|
+
- clnk_api-0.0.4.gem
|
81
98
|
- clnk_api.gemspec
|
82
99
|
- lib/clnk_api.rb
|
83
100
|
- lib/clnk_api/clnk.rb
|
84
101
|
- lib/clnk_api/errors.rb
|
85
102
|
- lib/clnk_api/link.rb
|
86
103
|
- lib/clnk_api/version.rb
|
87
|
-
homepage:
|
104
|
+
homepage: https://github.com/cuelinks/clnk_api
|
88
105
|
licenses:
|
89
106
|
- MIT
|
90
107
|
metadata: {}
|
91
|
-
post_install_message:
|
108
|
+
post_install_message:
|
92
109
|
rdoc_options: []
|
93
110
|
require_paths:
|
94
111
|
- lib
|
@@ -103,9 +120,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
103
120
|
- !ruby/object:Gem::Version
|
104
121
|
version: '0'
|
105
122
|
requirements: []
|
106
|
-
|
107
|
-
|
108
|
-
signing_key:
|
123
|
+
rubygems_version: 3.4.10
|
124
|
+
signing_key:
|
109
125
|
specification_version: 4
|
110
|
-
summary:
|
126
|
+
summary: Ruby client for Cuelinks URL shortening API
|
111
127
|
test_files: []
|