clicky_me 0.0.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.
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/README.md +24 -0
- data/Rakefile +2 -0
- data/clicky_me.gemspec +21 -0
- data/lib/clicky_me.rb +71 -0
- data/lib/clicky_me/version.rb +3 -0
- metadata +52 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# ClickyMe
|
2
|
+
|
3
|
+
Use the http://clicky.me API to shorten URLs
|
4
|
+
|
5
|
+
### Installation
|
6
|
+
|
7
|
+
gem install clicky_me
|
8
|
+
|
9
|
+
### Non-tracked Usage
|
10
|
+
|
11
|
+
require 'clicky_me'
|
12
|
+
client = ClickyMe.new('username','password')
|
13
|
+
results = client.shorten('http://www.google.com').url
|
14
|
+
|
15
|
+
>> http://clicky.me/5arG
|
16
|
+
|
17
|
+
### Site-based Tracked Usage
|
18
|
+
|
19
|
+
require 'clicky_me'
|
20
|
+
client = ClickyMe.new('username', 'password', 'site_id', 'sitekey_admin')
|
21
|
+
results = client.shorten('http://www.google.com').url
|
22
|
+
|
23
|
+
>> http://clicky.me/5ary
|
24
|
+
|
data/Rakefile
ADDED
data/clicky_me.gemspec
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "clicky_me/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "clicky_me"
|
7
|
+
s.version = ClickyMe::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Eric Berry"]
|
10
|
+
s.email = ["cavneb@gmail.com"]
|
11
|
+
s.homepage = "http://github.com/cavneb/clicky_me"
|
12
|
+
s.summary = %q{Use the clicky.me API to shorten URLs}
|
13
|
+
s.description = %q{Use the clicky.me API to shorten URLs}
|
14
|
+
|
15
|
+
s.rubyforge_project = "clicky_me"
|
16
|
+
|
17
|
+
s.files = `git ls-files`.split("\n")
|
18
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
|
+
s.require_paths = ["lib"]
|
21
|
+
end
|
data/lib/clicky_me.rb
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'uri'
|
3
|
+
require 'net/http'
|
4
|
+
|
5
|
+
module ClickyMe
|
6
|
+
API_URL = 'http://clicky.me/app/api'
|
7
|
+
|
8
|
+
def self.new(username, password, site_id=nil, sitekey_admin=nil)
|
9
|
+
ClickyMe::Client.new(username, password, site_id, sitekey_admin)
|
10
|
+
end
|
11
|
+
|
12
|
+
class Client
|
13
|
+
|
14
|
+
def initialize(username, password, site_id=nil, sitekey_admin=nil)
|
15
|
+
@username = username
|
16
|
+
@password = password
|
17
|
+
@site_id = site_id
|
18
|
+
@sitekey_admin = sitekey_admin
|
19
|
+
end
|
20
|
+
|
21
|
+
def shorten(url, opts={})
|
22
|
+
request = create_url(url, opts)
|
23
|
+
puts request
|
24
|
+
result = get_result(request)
|
25
|
+
return result
|
26
|
+
end
|
27
|
+
|
28
|
+
def create_url(url="", args={})
|
29
|
+
args = args.merge({
|
30
|
+
:username => @username,
|
31
|
+
:password => @password,
|
32
|
+
:url => url
|
33
|
+
})
|
34
|
+
args = args.merge({ :site_id => @site_id }) if @site_id
|
35
|
+
args = args.merge({ :sitekey_admin => @sitekey_admin }) if @sitekey_admin
|
36
|
+
url = URI.join(url, API_URL)
|
37
|
+
url.query = args.map { |k,v| "%s=%s" % [CGI.escape(k.to_s), CGI.escape(v.to_s)] }.join("&")
|
38
|
+
url
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def get_result(request)
|
44
|
+
begin
|
45
|
+
resp = Net::HTTP.get(request)
|
46
|
+
if resp =~ /http:\/\/clicky\.me\/.*/
|
47
|
+
result = {
|
48
|
+
'url' => resp.strip,
|
49
|
+
'errorMessage' => nil,
|
50
|
+
'statusCode' => 'OK'
|
51
|
+
}
|
52
|
+
else
|
53
|
+
result = {
|
54
|
+
'url' => nil,
|
55
|
+
'errorMessage' => resp.strip,
|
56
|
+
'statusCode' => 'ERROR'
|
57
|
+
}
|
58
|
+
end
|
59
|
+
rescue => ex
|
60
|
+
result = {
|
61
|
+
'url' => nil,
|
62
|
+
'errorMessage' => ex.message,
|
63
|
+
'statusCode' => 'ERROR'
|
64
|
+
}
|
65
|
+
end
|
66
|
+
result
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
metadata
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: clicky_me
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Eric Berry
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-06-12 00:00:00.000000000Z
|
13
|
+
dependencies: []
|
14
|
+
description: Use the clicky.me API to shorten URLs
|
15
|
+
email:
|
16
|
+
- cavneb@gmail.com
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- .gitignore
|
22
|
+
- Gemfile
|
23
|
+
- README.md
|
24
|
+
- Rakefile
|
25
|
+
- clicky_me.gemspec
|
26
|
+
- lib/clicky_me.rb
|
27
|
+
- lib/clicky_me/version.rb
|
28
|
+
homepage: http://github.com/cavneb/clicky_me
|
29
|
+
licenses: []
|
30
|
+
post_install_message:
|
31
|
+
rdoc_options: []
|
32
|
+
require_paths:
|
33
|
+
- lib
|
34
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
35
|
+
none: false
|
36
|
+
requirements:
|
37
|
+
- - ! '>='
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
requirements: []
|
47
|
+
rubyforge_project: clicky_me
|
48
|
+
rubygems_version: 1.8.4
|
49
|
+
signing_key:
|
50
|
+
specification_version: 3
|
51
|
+
summary: Use the clicky.me API to shorten URLs
|
52
|
+
test_files: []
|