trim-api 0.1 → 0.3

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.
@@ -1,7 +1,12 @@
1
+ === 0.3 / 2009-10-24
2
+
3
+ * Added trim_reference method
4
+ * Added trim_claim method
5
+
1
6
  === 0.1 / 2009-10-23
2
7
 
3
8
  * Added trim_destination method that returns the destination for a trimmed url
4
- * Added authentication (currently only required for trim_destination)
9
+ * Added authentication (currently only required for trim_destination but must be used in initialisation)
5
10
 
6
11
  === 0.0.1 / 2009-10-18
7
12
 
data/README.txt CHANGED
@@ -8,7 +8,8 @@ A simple Ruby library for accessing the tr.im API
8
8
 
9
9
  == FEATURES/PROBLEMS:
10
10
 
11
- Currently only supports the trimming of a URL with limited error checking.
11
+ Supports trimming and expanding of URLS.
12
+ More features coming soon.
12
13
 
13
14
  == REQUIREMENTS:
14
15
 
@@ -26,10 +27,24 @@ gem install trim-api
26
27
  require 'rubygems'
27
28
  require 'trim_api'
28
29
 
29
- api = TrimApi::Trim.new
30
+ * Authentication on the initialisation is only required if you intend to use an API call that requires authentication. For example, to trim a url, no authentication is required.
31
+
32
+ api = TrimApi::Trim.new(:username => "username", :password => "password")
30
33
  api.trim("http://www.google.com/")
31
34
 
32
- Returns the trimmed url as a string.
35
+ Returns the trimmed url as a string in the format http://tr.im/ABCD
36
+
37
+ api.trim_destination("CMo5")
38
+
39
+ Returns the original destination as a string.
40
+
41
+ api.trim_reference("CMo5")
42
+
43
+ Returns the reference for the trimmed url if the authenticated user owns the trimmed url.
44
+
45
+ api.trim_claim("dkajdsakjdamnsdsma")
46
+
47
+ Claims a url identified by the unique reference obtained by trim_reference and attaches it to the authenticated user's account.
33
48
 
34
49
  == LICENSE:
35
50
 
@@ -28,14 +28,14 @@ module TrimApi
28
28
  unless data["status"]["result"] == "OK"
29
29
  raise TrimError.new(data["status"]["code"],data["status"]["message"])
30
30
  else
31
- data["url"]
31
+ "http://tr.im/#{data['url']}"
32
32
  end
33
33
  end
34
34
 
35
35
  def trim_destination(trimmed_url, options = {})
36
36
  raise ArgumentError.new(":trimmed url is required") if trimmed_url.nil?
37
37
  raise ArgumentError.new(":username and password are required") if (username.nil? || password.nil?)
38
- response = @client.get_content(create_url("trim_destination", {:trimpath => trimmed_url, :username => username, :password => password}))
38
+ response = @client.get_content(create_url("trim_destination",options.merge!({:trimpath => trimmed_url, :username => username, :password => password})))
39
39
  data = JSON.parse(response)
40
40
  unless data["status"]["result"] == "OK"
41
41
  raise TrimError.new(data["status"]["code"],data["status"]["message"])
@@ -44,6 +44,30 @@ module TrimApi
44
44
  end
45
45
  end
46
46
 
47
+ def trim_reference(trimmed_url, options = {})
48
+ raise ArgumentError.new(":trimmed url is required") if trimmed_url.nil?
49
+ raise ArgumentError.new(":username and password are required") if (username.nil? || password.nil?)
50
+ response = @client.get_content(create_url("trim_reference", options.merge!({:trimpath => trimmed_url, :username => username, :password => password})))
51
+ data = JSON.parse(response)
52
+ unless data["status"]["result"] == "OK"
53
+ raise TrimError.new(data["status"]["code"],data["status"]["message"])
54
+ else
55
+ data["reference"]
56
+ end
57
+ end
58
+
59
+ def trim_claim(reference, options = {})
60
+ raise ArgumentError.new(":url reference is required. Use trim_reference to obtain this.") if reference.nil?
61
+ raise ArgumentError.new(":username and password are required") if (username.nil? || password.nil?)
62
+ response = @client.get_content(create_url("trim_claim", options.merge!({:reference => reference, :username => username, :password => password})))
63
+ data = JSON.parse(response)
64
+ unless data["status"]["result"] == "OK"
65
+ raise TrimError.new(data["status"]["code"],data["status"]["message"])
66
+ else
67
+ "URL successfully claimed and added to your account"
68
+ end
69
+ end
70
+
47
71
  private
48
72
 
49
73
  def create_url(method, options = {})
@@ -5,5 +5,5 @@ require 'CGI'
5
5
  require 'trim-api/trim-api.rb'
6
6
 
7
7
  module TrimApi
8
- VERSION = '0.1'
8
+ VERSION = '0.3'
9
9
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trim-api
3
3
  version: !ruby/object:Gem::Version
4
- version: "0.1"
4
+ version: "0.3"
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robin Fisher
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-10-23 00:00:00 +01:00
12
+ date: 2009-10-24 00:00:00 +01:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency