isgd 1.0.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.
Files changed (4) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +4 -0
  3. data/lib/isgd.rb +49 -0
  4. metadata +61 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d0a71f4c1c3c22e6407a90bdfbd6b83085196de0
4
+ data.tar.gz: ca561870e4ea6b3d14057dfbbf48575fe2d28793
5
+ SHA512:
6
+ metadata.gz: 6e32a2a3cc6b109f0fa9451a3f6eda0ebb73a74020b5e33abd45ad4ac1f64e2c33c5b31c3fd7c45a05d46e94ae4b625f62b52368cdef9b480505d1a604cf3890
7
+ data.tar.gz: ce9a3ac6801dfd283910e235d59f2b945251b6dc461157932791b1919626b0972721a219c4e25ccda68fb70991050161801d1efd8a7a5039cd7b27c56e82fec0
@@ -0,0 +1,4 @@
1
+ # Changelog
2
+ ## Version 1
3
+ ### 1.0.0
4
+ * Initial release.
@@ -0,0 +1,49 @@
1
+ require 'httpclient'
2
+ require 'json'
3
+
4
+ module ISGD
5
+ module_function
6
+
7
+ # Shortens a URL using ISGD.
8
+ # @param url [String] The URL to shorten.
9
+ # @param short [String] The custom short URL to use as the shortened link. This cannot be shorter than 5, or more
10
+ # than 30.
11
+ # @see http://is.gd/apishorteningreference.php ISGD Shortening API Documentation
12
+ # @since 1.0.0
13
+ # @return [String] The error message.
14
+ # @return [String] The shortened URL.
15
+ def shorten(url, short = nil)
16
+ params = {
17
+ format: 'json',
18
+ url: url
19
+ }
20
+ params[:shorturl] = short if !short.nil? && 30 < short.length < 5
21
+ @client = HTTPClient.new if @client.nil?
22
+
23
+ response = JSON.parse(@client.get(URI.parse('http://is.gd/create.php'), params).body)
24
+
25
+ return response['errormessage'] if response.key?('errormessage')
26
+
27
+ response['shorturl']
28
+ end
29
+
30
+ # Looks up a short URL's original long URL.
31
+ # @param url [String] The shortened URL to look up.
32
+ # @see http://is.gd/apilookupreference.php ISGD Lookup API Documentation
33
+ # @since 1.0.0
34
+ # @return [String] The error message.
35
+ # @return [String] The long URL.
36
+ def lookup(url)
37
+ params = {
38
+ format: 'json',
39
+ shorturl: url
40
+ }
41
+ @client = HTTPClient.new if @client.nil?
42
+
43
+ response = JSON.parse(@client.get(URI.parse('http://is.gd/forward.php'), params).body)
44
+
45
+ return response['errormessage'] if response.key?('errormessage')
46
+
47
+ response['url']
48
+ end
49
+ end
metadata ADDED
@@ -0,0 +1,61 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: isgd
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Eli Foster
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-01-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: httpclient
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '='
18
+ - !ruby/object:Gem::Version
19
+ version: 2.6.0.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: 2.6.0.1
27
+ description: Accessing the isgd API through HTTPClient.
28
+ email: elifosterwy@gmail.com
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - CHANGELOG.md
34
+ - lib/isgd.rb
35
+ homepage: https://github.com/elifoster/isgd-rb
36
+ licenses:
37
+ - CC-BY-NC-ND-4.0
38
+ metadata:
39
+ issue_tracker: https://github.com/elifoster/isgdrb/issues
40
+ post_install_message:
41
+ rdoc_options: []
42
+ require_paths:
43
+ - lib
44
+ required_ruby_version: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ required_rubygems_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ requirements: []
55
+ rubyforge_project:
56
+ rubygems_version: 2.4.5.1
57
+ signing_key:
58
+ specification_version: 4
59
+ summary: A Ruby gem for interacting with the isgd API.
60
+ test_files: []
61
+ has_rdoc: