abrio 0.0.5
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 +7 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +20 -0
- data/LICENSE +20 -0
- data/README.md +70 -0
- data/Rakefile +27 -0
- data/abrio.gemspec +24 -0
- data/lib/abrio.rb +31 -0
- data/lib/abrio/client.rb +40 -0
- data/lib/abrio/error.rb +2 -0
- data/lib/abrio/request.rb +38 -0
- data/lib/abrio/url.rb +39 -0
- data/lib/abrio/version.rb +3 -0
- data/test/abrio/client_test.rb +63 -0
- data/test/abrio/request_test.rb +24 -0
- data/test/abrio/url_test.rb +47 -0
- data/test/abrio_test.rb +27 -0
- data/test/fixtures/shorten_success +29 -0
- data/test/fixtures/xml_response.rb +41 -0
- data/test/test_helper.rb +23 -0
- metadata +124 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
abrio (0.0.5)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: http://rubygems.org/
|
8
|
+
specs:
|
9
|
+
fakeweb (1.3.0)
|
10
|
+
metaclass (0.0.1)
|
11
|
+
mocha (0.10.4)
|
12
|
+
metaclass (~> 0.0.1)
|
13
|
+
|
14
|
+
PLATFORMS
|
15
|
+
ruby
|
16
|
+
|
17
|
+
DEPENDENCIES
|
18
|
+
abrio!
|
19
|
+
fakeweb (~> 1.3.0)
|
20
|
+
mocha (~> 0.10.0)
|
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Roger Leite
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
'Software'), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
17
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
18
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
19
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
20
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
Abrio
|
2
|
+
======
|
3
|
+
|
4
|
+
A Ruby API for http://abr.io
|
5
|
+
|
6
|
+
More information for API here:
|
7
|
+
http://abr.io/pages/api
|
8
|
+
|
9
|
+
Project goals:
|
10
|
+
*Easy to use
|
11
|
+
*Flexible to configure
|
12
|
+
*No external dependencies
|
13
|
+
|
14
|
+
Installation
|
15
|
+
------------
|
16
|
+
|
17
|
+
gem install abrio
|
18
|
+
|
19
|
+
Usage
|
20
|
+
-----
|
21
|
+
|
22
|
+
Case 1:
|
23
|
+
|
24
|
+
require "rubygems"
|
25
|
+
require "abrio"
|
26
|
+
|
27
|
+
client = Abrio::Client.new(:login => "login", :key => "Z_123")
|
28
|
+
url = client.shorten("http://google.com")
|
29
|
+
url.short_url #=> "http://abr.io/11jU"
|
30
|
+
|
31
|
+
Case 2:
|
32
|
+
|
33
|
+
require "rubygems"
|
34
|
+
require "abrio"
|
35
|
+
|
36
|
+
#This is useful to setup config at Rails initializer for example.
|
37
|
+
Abrio.setup do |client|
|
38
|
+
client.uri = "http://abr.io/api/links"
|
39
|
+
client.login = "login"
|
40
|
+
client.key = "key"
|
41
|
+
end
|
42
|
+
url = Abrio.shorten("http://google.com")
|
43
|
+
url.short_url #=> "http://abr.io/18VN"
|
44
|
+
|
45
|
+
Running the Tests
|
46
|
+
-----------------
|
47
|
+
|
48
|
+
Install development dependencies with:
|
49
|
+
|
50
|
+
$ bundle install
|
51
|
+
|
52
|
+
To run the test suite:
|
53
|
+
|
54
|
+
$ rake test
|
55
|
+
|
56
|
+
|
57
|
+
Contributing
|
58
|
+
------------
|
59
|
+
|
60
|
+
Once you've made your great commits:
|
61
|
+
|
62
|
+
1. [Fork][0] abrio
|
63
|
+
2. Create a topic branch - `git checkout -b my_branch`
|
64
|
+
3. Push to your branch - `git push origin my_branch`
|
65
|
+
4. Create an [Issue][1] with a link to your branch
|
66
|
+
5. That's it!
|
67
|
+
|
68
|
+
|
69
|
+
[0]: http://help.github.com/forking/
|
70
|
+
[1]: https://github.com/abril/abrio/issues
|
data/Rakefile
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'rake/testtask'
|
3
|
+
require 'rake/rdoctask'
|
4
|
+
require 'bundler'
|
5
|
+
|
6
|
+
Bundler::GemHelper.install_tasks
|
7
|
+
|
8
|
+
desc 'Generate API documentation to doc/rdocs/index.html'
|
9
|
+
Rake::RDocTask.new do |rd|
|
10
|
+
rd.rdoc_dir = 'doc'
|
11
|
+
rd.main = 'README.md'
|
12
|
+
rd.rdoc_files.include "README.md", "LICENSE", "lib/**/*\.rb"
|
13
|
+
|
14
|
+
rd.options << '--inline-source'
|
15
|
+
rd.options << '--line-numbers'
|
16
|
+
rd.options << '--all'
|
17
|
+
rd.options << '--fileboxes'
|
18
|
+
end
|
19
|
+
|
20
|
+
desc "Run tests"
|
21
|
+
Rake::TestTask.new do |t|
|
22
|
+
t.libs << "test"
|
23
|
+
t.test_files = FileList['test/**/*.rb']
|
24
|
+
t.verbose = true
|
25
|
+
end
|
26
|
+
|
27
|
+
task :default => :test
|
data/abrio.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "abrio/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "abrio"
|
7
|
+
s.version = Abrio::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Roger Leite"]
|
10
|
+
s.email = ["roger.leite@abril.com.br"]
|
11
|
+
s.homepage = ""
|
12
|
+
s.summary = %q{Client ruby para o encurtador http://abr.io}
|
13
|
+
s.description = %q{Client ruby para o encurtador http://abr.io}
|
14
|
+
s.required_ruby_version = ">= 1.8.7"
|
15
|
+
|
16
|
+
#s.rubyforge_project = "abrio"
|
17
|
+
s.add_development_dependency "fakeweb", "~> 1.3.0"
|
18
|
+
s.add_development_dependency "mocha", "~> 0.10.0"
|
19
|
+
|
20
|
+
s.files = `git ls-files`.split("\n")
|
21
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
22
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
23
|
+
s.require_paths = ["lib"]
|
24
|
+
end
|
data/lib/abrio.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
module Abrio
|
2
|
+
autoload :Client, "abrio/client"
|
3
|
+
autoload :Request, "abrio/request"
|
4
|
+
autoload :Url, "abrio/url"
|
5
|
+
autoload :Error, "abrio/error"
|
6
|
+
|
7
|
+
# Useful to set Abrio client parameters.
|
8
|
+
#
|
9
|
+
# Abrio.setup do |client|
|
10
|
+
# client.uri = "http://abr.io/api/links"
|
11
|
+
# client.login = "login"
|
12
|
+
# client.key = "key"
|
13
|
+
# end
|
14
|
+
#
|
15
|
+
def self.setup
|
16
|
+
yield(client) if block_given?
|
17
|
+
end
|
18
|
+
|
19
|
+
# Shortcut to Abrio::Client.shorten
|
20
|
+
def self.shorten(long_url, options = {})
|
21
|
+
client.shorten(long_url, options)
|
22
|
+
end
|
23
|
+
|
24
|
+
protected
|
25
|
+
|
26
|
+
#Returns Abrio::Client instance
|
27
|
+
def self.client
|
28
|
+
@@client ||= Client.new
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
data/lib/abrio/client.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
#Client proxy for Abr.io API.
|
2
|
+
class Abrio::Client
|
3
|
+
|
4
|
+
attr_accessor :uri, :login, :key
|
5
|
+
|
6
|
+
DEFAULT_PARAMS = {:format => "xml", :version => "1.0"}
|
7
|
+
|
8
|
+
#Use the following options to initialize your client:
|
9
|
+
# [uri] - Default: "abr.io/api/links"
|
10
|
+
# [login] - Your login from Zapt.In. See: http://abr.io/pages/api
|
11
|
+
# [key] - Your key from Zapt.In. See: http://abr.io/pages/api
|
12
|
+
def initialize(options = {})
|
13
|
+
@uri = options[:uri] || "http://abr.io/api/links"
|
14
|
+
@login = options[:login]
|
15
|
+
@key = options[:key]
|
16
|
+
end
|
17
|
+
|
18
|
+
#Shorten an url.
|
19
|
+
#[long_url] url you want to shorten.
|
20
|
+
#[options] Optional Hash. You can pass the following keys:
|
21
|
+
# [uri] - Default: "abr.io/api/links"
|
22
|
+
# [login] - Your login from Zapt.In. See: http://abr.io/pages/api
|
23
|
+
# [key] - Your key from Zapt.In. See: http://abr.io/pages/api
|
24
|
+
def shorten(long_url, options = {})
|
25
|
+
return nil if long_url.nil? || long_url == ""
|
26
|
+
|
27
|
+
@uri = options.delete(:uri) || @uri
|
28
|
+
params = {:login => options.delete(:login) || @login,
|
29
|
+
:key => options.delete(:key) || @key}.merge(DEFAULT_PARAMS)
|
30
|
+
params[:longUrl] = long_url
|
31
|
+
|
32
|
+
begin
|
33
|
+
response = Abrio::Request.get("#{self.uri}/shorten", params)
|
34
|
+
Abrio::Url.parse(response)
|
35
|
+
rescue Abrio::Error => e
|
36
|
+
Abrio::Url.new(:status_code => "ERROR", :errorMessage => e.message, :error_code => -1)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
data/lib/abrio/error.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
require "net/http"
|
2
|
+
require "uri"
|
3
|
+
|
4
|
+
#Wrapper responsible for all requests.
|
5
|
+
class Abrio::Request
|
6
|
+
|
7
|
+
#Call get at *uri* with *parameters*.
|
8
|
+
#[uri] Complete url. Example: http://abr.io/api/links/shorten
|
9
|
+
#[parameters] Hash of parameters. Example: {:format => "xml", :version => "1.0"}
|
10
|
+
#
|
11
|
+
#Returns response body, a String.
|
12
|
+
def self.get(uri, parameters)
|
13
|
+
params = build_parameters(parameters)
|
14
|
+
|
15
|
+
begin
|
16
|
+
url = URI.parse(uri)
|
17
|
+
req = Net::HTTP::Get.new("#{url}?#{params}")
|
18
|
+
res = Net::HTTP.start(url.host, url.port) do |http|
|
19
|
+
http.request(req)
|
20
|
+
end
|
21
|
+
res.body
|
22
|
+
rescue StandardError => e
|
23
|
+
raise Abrio::Error.new(e)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
#Receives a Hash.
|
30
|
+
#
|
31
|
+
#Returns a String in format: "key=value&key2=value2"
|
32
|
+
def self.build_parameters(params)
|
33
|
+
array_params = []
|
34
|
+
params.each_pair { |key, value| array_params << "#{key}=#{value}"}
|
35
|
+
array_params.join("&")
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
data/lib/abrio/url.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'rexml/document'
|
2
|
+
|
3
|
+
#Represents Abrio API response.
|
4
|
+
class Abrio::Url
|
5
|
+
|
6
|
+
attr_reader :status_code, :error_message, :error_code
|
7
|
+
attr_reader :short_url
|
8
|
+
|
9
|
+
#Initialize all read-only atributes with Hash.
|
10
|
+
def initialize(attrs = {})
|
11
|
+
attrs.each_pair do |attr, value|
|
12
|
+
self.instance_variable_set("@#{attr}", value)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
#Parses *xml* from Abrio API.
|
17
|
+
#
|
18
|
+
#See documentation at http://abr.io/pages/api
|
19
|
+
def self.parse(xml_body)
|
20
|
+
validates_xml(xml_body)
|
21
|
+
|
22
|
+
doc = REXML::Document.new(xml_body)
|
23
|
+
|
24
|
+
attributes = {:status_code => doc.elements["*/statusCode"].text,
|
25
|
+
:error_message => doc.elements["*/errorMessage"].text,
|
26
|
+
:error_code => doc.elements["*/errorCode"].text}
|
27
|
+
|
28
|
+
if (result = doc.elements["*/results/nodeKeyVal"])
|
29
|
+
attributes.merge!({:short_url => result.elements["shortUrl"].text})
|
30
|
+
end
|
31
|
+
self.new(attributes)
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.validates_xml(xml)
|
35
|
+
raise Abrio::Error.new("XML body cannot be blank") if xml.nil? || xml.empty?
|
36
|
+
raise Abrio::Error.new("Does not appear to be a valid Abrio XML.\n\n#{xml}") unless xml.start_with?("<abrio>")
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class Abrio::ClientTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
include Abrio::Fixtures::XmlResponse
|
6
|
+
DEFAULT_EXPECTED_PARAMS = {:longUrl => 'http://google.com', :version => '1.0', :format => 'xml', :key => 'Z_VALID', :login => 'rogleite'}
|
7
|
+
|
8
|
+
def test_default_configurations
|
9
|
+
assert_equal "http://abr.io/api/links", Abrio::Client.new.uri
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_shorten_with_blank_value
|
13
|
+
client = Abrio::Client.new
|
14
|
+
assert_equal nil, client.shorten(nil)
|
15
|
+
assert_equal nil, client.shorten("")
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_shorten_with_valid_value
|
19
|
+
client = Abrio::Client.new(:login => "rogleite", :key => "Z_VALID")
|
20
|
+
|
21
|
+
Abrio::Request.expects(:get).with("#{client.uri}/shorten", DEFAULT_EXPECTED_PARAMS).returns(abrio_success_xml)
|
22
|
+
|
23
|
+
abrio_url = client.shorten("http://google.com")
|
24
|
+
assert_not_nil abrio_url, "expects a Abrio::Url"
|
25
|
+
assert_equal "http://abr.io/18VN", abrio_url.short_url
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_shorten_options_parameter
|
29
|
+
client = Abrio::Client.new(:login => "rogleite", :key => "Z_VALID")
|
30
|
+
|
31
|
+
expected_params = DEFAULT_EXPECTED_PARAMS.merge({:key => 'Z_OPTION', :login => 'login'})
|
32
|
+
Abrio::Request.expects(:get).with("http://abr.io/api/links/shorten", expected_params).returns(abrio_success_xml)
|
33
|
+
|
34
|
+
abrio_url = client.shorten("http://google.com", :uri => "http://abr.io/api/links", :login => "login", :key => "Z_OPTION")
|
35
|
+
assert_not_nil abrio_url, "expects a Abrio::Url"
|
36
|
+
assert_equal "OK", abrio_url.status_code
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_shorten_failure
|
40
|
+
client = Abrio::Client.new(:login => "rogleite", :key => "Z_INVALID")
|
41
|
+
|
42
|
+
expected_params = DEFAULT_EXPECTED_PARAMS.merge({:key => 'Z_INVALID'})
|
43
|
+
Abrio::Request.expects(:get).with("#{client.uri}/shorten", expected_params).returns(abrio_error_xml)
|
44
|
+
|
45
|
+
abrio_url = client.shorten("http://google.com")
|
46
|
+
assert_not_nil abrio_url, "expects a Abrio::Url"
|
47
|
+
assert_equal "ERROR", abrio_url.status_code
|
48
|
+
assert_nil abrio_url.short_url
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_shorten_net_http_error
|
52
|
+
expected_params = DEFAULT_EXPECTED_PARAMS.merge({:key => 'Z_INVALID'})
|
53
|
+
Abrio::Request.expects(:get).with("http://nonexist/shorten", expected_params).raises(Abrio::Error, "Net fake error")
|
54
|
+
|
55
|
+
client = Abrio::Client.new(:login => "rogleite", :key => "Z_INVALID")
|
56
|
+
abrio_url = client.shorten("http://google.com", :uri => "http://nonexist")
|
57
|
+
|
58
|
+
assert_not_nil abrio_url, "expects a Abrio::Url"
|
59
|
+
assert_equal "ERROR", abrio_url.status_code
|
60
|
+
assert_nil abrio_url.short_url
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class Abrio::RequestTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def test_get_request
|
6
|
+
register_uri("http://abr.io/api/links/shorten?param=value", :fixture => "shorten_success")
|
7
|
+
|
8
|
+
uri = "http://abr.io/api/links/shorten"
|
9
|
+
params = {:param => "value"}
|
10
|
+
|
11
|
+
response_body = Abrio::Request.get(uri, params)
|
12
|
+
assert_match(/<abrio>/, response_body, "Response should start with <abrio>")
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_get_invalid_request
|
16
|
+
|
17
|
+
Net::HTTP.expects(:start).with("invalid.com", 80).raises(ArgumentError)
|
18
|
+
assert_raise Abrio::Error do
|
19
|
+
Abrio::Request.get("http://invalid.com", {})
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class Abrio::UrlTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
include Abrio::Fixtures::XmlResponse
|
6
|
+
|
7
|
+
def assert_success_url(url, attrs)
|
8
|
+
assert_not_nil url
|
9
|
+
assert_equal "0", url.error_code
|
10
|
+
assert_equal "OK", url.status_code
|
11
|
+
assert_equal attrs[:short_url], url.short_url
|
12
|
+
end
|
13
|
+
|
14
|
+
def assert_error_url(url, code, message)
|
15
|
+
assert_not_nil url
|
16
|
+
assert_equal code, url.error_code
|
17
|
+
assert_equal message, url.error_message
|
18
|
+
assert_equal "ERROR", url.status_code
|
19
|
+
assert_equal nil, url.short_url
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_parse_abrio_success_xml
|
23
|
+
url = Abrio::Url.parse(abrio_success_xml)
|
24
|
+
assert_success_url url, :short_url => "http://abr.io/18VN"
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_parse_abrio_error_xml
|
28
|
+
url = Abrio::Url.parse(abrio_error_xml)
|
29
|
+
assert_error_url url, "203", "You must be authenticated to access shorten."
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_parse_blank_xml
|
33
|
+
assert_raise Abrio::Error do
|
34
|
+
Abrio::Url.parse(nil)
|
35
|
+
end
|
36
|
+
assert_raise Abrio::Error do
|
37
|
+
Abrio::Url.parse("")
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_parse_should_check_for_root_tags
|
42
|
+
assert_raise Abrio::Error do
|
43
|
+
Abrio::Url.parse("<h1>Some Error</h1>")
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
data/test/abrio_test.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class AbrioTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def test_setup
|
6
|
+
Abrio.setup do |client|
|
7
|
+
client.uri = "http://abr.io/api/links"
|
8
|
+
client.login = "login"
|
9
|
+
client.key = "key"
|
10
|
+
end
|
11
|
+
|
12
|
+
assert_equal "http://abr.io/api/links", Abrio.client.uri
|
13
|
+
assert_equal "login", Abrio.client.login
|
14
|
+
assert_equal "key", Abrio.client.key
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_shorten
|
18
|
+
client = mock() do
|
19
|
+
expects(:shorten).with("google.com", {}).returns("OK")
|
20
|
+
end
|
21
|
+
Abrio.expects(:client).returns(client)
|
22
|
+
|
23
|
+
result = Abrio.shorten("google.com")
|
24
|
+
assert_equal "OK", result
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
HTTP/1.1 200 OK
|
2
|
+
Server: nginx/0.7.67
|
3
|
+
Date: Fri, 03 Jun 2011 18:17:52 GMT
|
4
|
+
Content-Type: application/xml; charset=utf-8
|
5
|
+
Connection: keep-alive
|
6
|
+
X-Runtime: 33
|
7
|
+
ETag: "96e2aec9b5358bed89d8345f4d94b969"
|
8
|
+
Cache-Control: private, max-age=0, must-revalidate
|
9
|
+
Content-Length: 380
|
10
|
+
X-Varnish: 981428441
|
11
|
+
Age: 0
|
12
|
+
Via: 1.1 varnish
|
13
|
+
|
14
|
+
<abrio>
|
15
|
+
<errorCode>0</errorCode>
|
16
|
+
<errorMessage></errorMessage>
|
17
|
+
<results>
|
18
|
+
<nodeKeyVal>
|
19
|
+
<userHash>11jU</userHash>
|
20
|
+
<shortKeywordUrl></shortKeywordUrl>
|
21
|
+
<hash>9</hash>
|
22
|
+
<nodeKey>
|
23
|
+
<![CDATA[http://google.com]]>
|
24
|
+
</nodeKey>
|
25
|
+
<shortUrl>http://abr.io/11jU</shortUrl>
|
26
|
+
</nodeKeyVal>
|
27
|
+
</results>
|
28
|
+
<statusCode>OK</statusCode>
|
29
|
+
</abrio>
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module Abrio
|
2
|
+
|
3
|
+
module Fixtures
|
4
|
+
|
5
|
+
module XmlResponse
|
6
|
+
|
7
|
+
def abrio_success_xml
|
8
|
+
<<XML
|
9
|
+
<abrio>
|
10
|
+
<errorCode>0</errorCode>
|
11
|
+
<errorMessage></errorMessage>
|
12
|
+
<results>
|
13
|
+
<nodeKeyVal>
|
14
|
+
<userHash>18VN</userHash>
|
15
|
+
<shortKeywordUrl></shortKeywordUrl>
|
16
|
+
<hash>3u</hash>
|
17
|
+
<nodeKey>
|
18
|
+
<![CDATA[http://google.com]]>
|
19
|
+
</nodeKey>
|
20
|
+
<shortUrl>http://abr.io/18VN</shortUrl>
|
21
|
+
</nodeKeyVal>
|
22
|
+
</results>
|
23
|
+
<statusCode>OK</statusCode>
|
24
|
+
</abrio>
|
25
|
+
XML
|
26
|
+
end
|
27
|
+
|
28
|
+
def abrio_error_xml
|
29
|
+
<<XML
|
30
|
+
<abrio>
|
31
|
+
<errorCode>203</errorCode>
|
32
|
+
<errorMessage>You must be authenticated to access shorten.</errorMessage>
|
33
|
+
<statusCode>ERROR</statusCode>
|
34
|
+
</abrio>
|
35
|
+
XML
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
|
3
|
+
require 'test/unit'
|
4
|
+
require 'mocha'
|
5
|
+
require 'fakeweb'
|
6
|
+
|
7
|
+
FakeWeb.allow_net_connect = false
|
8
|
+
|
9
|
+
class Test::Unit::TestCase
|
10
|
+
|
11
|
+
def register_uri(url, options = {})
|
12
|
+
fixture = options.delete(:fixture)
|
13
|
+
FakeWeb.register_uri(:get, url, :response => File.read("test/fixtures/#{fixture}"))
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
require 'abrio'
|
19
|
+
|
20
|
+
module Abrio::Fixtures
|
21
|
+
autoload :XmlResponse, "test/fixtures/xml_response"
|
22
|
+
end
|
23
|
+
|
metadata
ADDED
@@ -0,0 +1,124 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: abrio
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 21
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 5
|
10
|
+
version: 0.0.5
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Roger Leite
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2012-02-17 00:00:00 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: fakeweb
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ~>
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 27
|
29
|
+
segments:
|
30
|
+
- 1
|
31
|
+
- 3
|
32
|
+
- 0
|
33
|
+
version: 1.3.0
|
34
|
+
type: :development
|
35
|
+
version_requirements: *id001
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: mocha
|
38
|
+
prerelease: false
|
39
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ~>
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
hash: 55
|
45
|
+
segments:
|
46
|
+
- 0
|
47
|
+
- 10
|
48
|
+
- 0
|
49
|
+
version: 0.10.0
|
50
|
+
type: :development
|
51
|
+
version_requirements: *id002
|
52
|
+
description: Client ruby para o encurtador http://abr.io
|
53
|
+
email:
|
54
|
+
- roger.leite@abril.com.br
|
55
|
+
executables: []
|
56
|
+
|
57
|
+
extensions: []
|
58
|
+
|
59
|
+
extra_rdoc_files: []
|
60
|
+
|
61
|
+
files:
|
62
|
+
- .gitignore
|
63
|
+
- Gemfile
|
64
|
+
- Gemfile.lock
|
65
|
+
- LICENSE
|
66
|
+
- README.md
|
67
|
+
- Rakefile
|
68
|
+
- abrio.gemspec
|
69
|
+
- lib/abrio.rb
|
70
|
+
- lib/abrio/client.rb
|
71
|
+
- lib/abrio/error.rb
|
72
|
+
- lib/abrio/request.rb
|
73
|
+
- lib/abrio/url.rb
|
74
|
+
- lib/abrio/version.rb
|
75
|
+
- test/abrio/client_test.rb
|
76
|
+
- test/abrio/request_test.rb
|
77
|
+
- test/abrio/url_test.rb
|
78
|
+
- test/abrio_test.rb
|
79
|
+
- test/fixtures/shorten_success
|
80
|
+
- test/fixtures/xml_response.rb
|
81
|
+
- test/test_helper.rb
|
82
|
+
homepage: ""
|
83
|
+
licenses: []
|
84
|
+
|
85
|
+
post_install_message:
|
86
|
+
rdoc_options: []
|
87
|
+
|
88
|
+
require_paths:
|
89
|
+
- lib
|
90
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
91
|
+
none: false
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
hash: 57
|
96
|
+
segments:
|
97
|
+
- 1
|
98
|
+
- 8
|
99
|
+
- 7
|
100
|
+
version: 1.8.7
|
101
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
102
|
+
none: false
|
103
|
+
requirements:
|
104
|
+
- - ">="
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
hash: 3
|
107
|
+
segments:
|
108
|
+
- 0
|
109
|
+
version: "0"
|
110
|
+
requirements: []
|
111
|
+
|
112
|
+
rubyforge_project:
|
113
|
+
rubygems_version: 1.8.15
|
114
|
+
signing_key:
|
115
|
+
specification_version: 3
|
116
|
+
summary: Client ruby para o encurtador http://abr.io
|
117
|
+
test_files:
|
118
|
+
- test/abrio/client_test.rb
|
119
|
+
- test/abrio/request_test.rb
|
120
|
+
- test/abrio/url_test.rb
|
121
|
+
- test/abrio_test.rb
|
122
|
+
- test/fixtures/shorten_success
|
123
|
+
- test/fixtures/xml_response.rb
|
124
|
+
- test/test_helper.rb
|