yourls 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README ADDED
@@ -0,0 +1 @@
1
+ Shorten URLs with a custom Yourls installation
data/lib/yourls.rb ADDED
@@ -0,0 +1,4 @@
1
+ require 'httparty'
2
+ require 'yourls/yourls'
3
+ require 'yourls/client'
4
+ require 'yourls/url'
@@ -0,0 +1,42 @@
1
+ require 'digest/md5'
2
+
3
+ module Yourls
4
+ class Client
5
+ include HTTParty
6
+
7
+ def initialize(host, api_key)
8
+ @host, @api_key = host, api_key
9
+ @base_uri = File.join(host, 'yourls-api.php')
10
+ end
11
+
12
+ def stats(options = {})
13
+ response = get('stats', options)
14
+ response.parsed_response
15
+ end
16
+
17
+ def expand(short_url, options = {})
18
+ Yourls::Url.new(get('expand', options.merge!(:shorturl => short_url)).parsed_response)
19
+ end
20
+
21
+ def shorten(long_url, options = {})
22
+ Yourls::Url.new(get('shorturl', options.merge!(:url => long_url)).parsed_response)
23
+ end
24
+
25
+ def get(action, query = {})
26
+ # Prepare the signature
27
+ timestamp = Time.now.to_i
28
+ signature = Digest::MD5.hexdigest(timestamp.to_s + @api_key)
29
+
30
+ query ||= {}
31
+ query.merge!(:timestamp => timestamp, :signature => signature, :action => action, :format => 'json')
32
+
33
+ response = self.class.get(@base_uri, :query => query)
34
+
35
+ if response.code == 200
36
+ return response
37
+ else
38
+ raise YourlsError.new(response.message, response.code)
39
+ end
40
+ end
41
+ end
42
+ end
data/lib/yourls/url.rb ADDED
@@ -0,0 +1,14 @@
1
+ module Yourls
2
+ class Url
3
+ attr_reader :short_url, :long_url, :keyword
4
+
5
+ def initialize(options = {})
6
+ if options
7
+ url = options['url'] || Hash.new('')
8
+ @short_url = options['shorturl']
9
+ @long_url = options['longurl'] || url['url']
10
+ @keyword = options['keyword'] || url['keyword']
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,14 @@
1
+ module Yourls
2
+ def self.new(host, api_key)
3
+ Yourls::Client.new(host, api_key)
4
+ end
5
+ end
6
+
7
+ class YourlsError < StandardError
8
+ attr_reader :code
9
+ alias :msg :message
10
+ def initialize(msg, code)
11
+ @code = code
12
+ super("#{msg} - '#{code}'")
13
+ end
14
+ end
data/yourls.gemspec ADDED
@@ -0,0 +1,29 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = 'yourls'
5
+ s.version = File.read(File.dirname(__FILE__) + '/VERSION').strip
6
+ s.authors = ['Justin Rhinesmith']
7
+ s.email = 'jrhinesmith@threestage.com'
8
+ s.summary = 'Use the Yourls API to shorten or expand URLs'
9
+ s.description = 'Use the Yourls API to shorten or expand URLs'
10
+
11
+ s.files = ["yourls.gemspec", "lib/yourls.rb", "lib/yourls/yourls.rb", "lib/yourls/client.rb", "lib/yourls/url.rb", "README"]
12
+ s.require_paths = ["lib"]
13
+
14
+ if s.respond_to? :specification_version then
15
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
16
+ s.specification_version = 3
17
+
18
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
19
+ s.add_runtime_dependency(%q<crack>, [">= 0.1.4"])
20
+ s.add_runtime_dependency(%q<httparty>, [">= 0.5.2"])
21
+ else
22
+ s.add_dependency(%q<crack>, [">= 0.1.4"])
23
+ s.add_dependency(%q<httparty>, [">= 0.5.2"])
24
+ end
25
+ else
26
+ s.add_dependency(%q<crack>, [">= 0.1.4"])
27
+ s.add_dependency(%q<httparty>, [">= 0.5.2"])
28
+ end
29
+ end
metadata ADDED
@@ -0,0 +1,103 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: yourls
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - Justin Rhinesmith
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-10-19 00:00:00 -04:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: crack
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 19
30
+ segments:
31
+ - 0
32
+ - 1
33
+ - 4
34
+ version: 0.1.4
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: httparty
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ hash: 15
46
+ segments:
47
+ - 0
48
+ - 5
49
+ - 2
50
+ version: 0.5.2
51
+ type: :runtime
52
+ version_requirements: *id002
53
+ description: Use the Yourls API to shorten or expand URLs
54
+ email: jrhinesmith@threestage.com
55
+ executables: []
56
+
57
+ extensions: []
58
+
59
+ extra_rdoc_files: []
60
+
61
+ files:
62
+ - yourls.gemspec
63
+ - lib/yourls.rb
64
+ - lib/yourls/yourls.rb
65
+ - lib/yourls/client.rb
66
+ - lib/yourls/url.rb
67
+ - README
68
+ has_rdoc: true
69
+ homepage:
70
+ licenses: []
71
+
72
+ post_install_message:
73
+ rdoc_options: []
74
+
75
+ require_paths:
76
+ - lib
77
+ required_ruby_version: !ruby/object:Gem::Requirement
78
+ none: false
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ hash: 3
83
+ segments:
84
+ - 0
85
+ version: "0"
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ none: false
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ hash: 3
92
+ segments:
93
+ - 0
94
+ version: "0"
95
+ requirements: []
96
+
97
+ rubyforge_project:
98
+ rubygems_version: 1.3.7
99
+ signing_key:
100
+ specification_version: 3
101
+ summary: Use the Yourls API to shorten or expand URLs
102
+ test_files: []
103
+