tags4free 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +6 -0
- data/lib/tags_4_free.rb +9 -5
- data/spec/spec_helper.rb +1 -1
- data/spec/tags_4_free_spec.rb +3 -2
- data.tar.gz.sig +0 -0
- metadata +1 -1
- metadata.gz.sig +0 -0
data/History.txt
CHANGED
data/lib/tags_4_free.rb
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
module Tags4Free
|
2
2
|
require 'rubygems'
|
3
|
+
require 'net/http'
|
3
4
|
require 'httparty'
|
4
5
|
include HTTParty
|
5
6
|
|
6
|
-
VERSION = '0.1.
|
7
|
+
VERSION = '0.1.2'
|
7
8
|
|
8
|
-
class YahooApiError <
|
9
|
+
class YahooApiError < StandardError; end
|
9
10
|
|
10
11
|
class YahooApiFormatError < ArgumentError
|
11
12
|
def initialize(content, result_set)
|
@@ -23,9 +24,12 @@ module Tags4Free
|
|
23
24
|
#
|
24
25
|
# tags = Tags4Free.for('The content that should be tagged')
|
25
26
|
def self.for(content)
|
26
|
-
|
27
|
-
|
28
|
-
|
27
|
+
begin
|
28
|
+
result_set = get(SERVICE_URL, :query => {:appid => APPID, :context => content})
|
29
|
+
rescue Net::HTTPServerException => e
|
30
|
+
raise YahooApiError
|
31
|
+
end
|
32
|
+
|
29
33
|
raise YahooApiFormatError.new(content, result_set) unless result_set['ResultSet']
|
30
34
|
|
31
35
|
result_set['ResultSet']['Result'] || []
|
data/spec/spec_helper.rb
CHANGED
data/spec/tags_4_free_spec.rb
CHANGED
@@ -8,12 +8,13 @@ describe Tags4Free do
|
|
8
8
|
end
|
9
9
|
|
10
10
|
it "should raise an exception if Yahoo! reports an error" do
|
11
|
-
Tags4Free.
|
11
|
+
def Tags4Free.get(*args)
|
12
|
+
raise Net::HTTPForbidden.new(403,'Forbidden','').error!
|
13
|
+
end
|
12
14
|
|
13
15
|
begin
|
14
16
|
Tags4Free.for("Erroneous content")
|
15
17
|
rescue Tags4Free::YahooApiError => e
|
16
|
-
e.message.should include('invalid value: context')
|
17
18
|
else
|
18
19
|
violated('YahooApiError should be raised!')
|
19
20
|
end
|
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
metadata.gz.sig
CHANGED
Binary file
|