rubervu 0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README +55 -0
- data/lib/rubervu/ubervu.rb +95 -0
- data/lib/rubervu/ubervu_resource.rb +57 -0
- data/lib/rubervu.rb +19 -0
- metadata +65 -0
data/README
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
= Rubervu: Gem for accessing the UberVU.com API.
|
2
|
+
|
3
|
+
See http://rubervu.rubyforge.org/ for more information.
|
4
|
+
|
5
|
+
Version 0.1.
|
6
|
+
|
7
|
+
== Basic Usage
|
8
|
+
|
9
|
+
|
10
|
+
=== Installation
|
11
|
+
gem install rubervu
|
12
|
+
|
13
|
+
=== Usage
|
14
|
+
|
15
|
+
ubervu = Rubervu::Ubervu.new('API_KEY')
|
16
|
+
|
17
|
+
# Get information about a specific URL
|
18
|
+
result = ubervu.resources.show(url)
|
19
|
+
|
20
|
+
# Add a new resource
|
21
|
+
result = ubervu.resources.create(url)
|
22
|
+
|
23
|
+
# Add a batch of new resources
|
24
|
+
result = ubervu.resources.create_batch([ url1, url2, url3 ])
|
25
|
+
|
26
|
+
== License
|
27
|
+
|
28
|
+
Copyright (c) 2009, Radu Spineanu
|
29
|
+
All rights reserved.
|
30
|
+
|
31
|
+
Redistribution and use in source and binary forms, with or without modification,
|
32
|
+
are permitted provided that the following conditions are met:
|
33
|
+
|
34
|
+
Redistributions of source code must retain the above copyright notice,
|
35
|
+
this list of conditions and the following disclaimer.
|
36
|
+
|
37
|
+
Redistributions in binary form must reproduce the above copyright notice,
|
38
|
+
this list of conditions and the following disclaimer in the documentation
|
39
|
+
and/or other materials provided with the distribution.
|
40
|
+
|
41
|
+
Neither the name of the original author nor the names of contributors
|
42
|
+
may be used to endorse or promote products derived from this software
|
43
|
+
without specific prior written permission.
|
44
|
+
|
45
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
46
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
47
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
48
|
+
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
49
|
+
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
50
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
51
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
52
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
53
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
54
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
55
|
+
|
@@ -0,0 +1,95 @@
|
|
1
|
+
# Copyright (c) 2009 Radu Spineanu
|
2
|
+
# You can redistribute it and/or modify it under the same terms as Ruby.
|
3
|
+
#
|
4
|
+
|
5
|
+
module Rubervu
|
6
|
+
|
7
|
+
# Main Ubervu Class
|
8
|
+
# You use it by doing the following:
|
9
|
+
# ubervu = Rubervu::Ubervu.new('API_KEY')
|
10
|
+
#
|
11
|
+
# Next you can call the Ubervu subclasses like:
|
12
|
+
# result = ubervu.resources.show(url)
|
13
|
+
#
|
14
|
+
class Ubervu
|
15
|
+
# Initializes the Ubervu Class.
|
16
|
+
def initialize(api_key, api_url = 'http://api.ubervu.com')
|
17
|
+
@api_key = api_key
|
18
|
+
@api_url = api_url
|
19
|
+
end
|
20
|
+
|
21
|
+
# Maps UbervuResource. See UbervuResource for more information about methods.
|
22
|
+
def resources
|
23
|
+
UbervuResource.new(@api_key, @api_url)
|
24
|
+
end
|
25
|
+
|
26
|
+
# Processes the request. Creates the API call and returns a JSON parsed result.
|
27
|
+
def request(resource, function, params, method = 'get', post_data = nil, api_key = @api_key, api_url = @api_url)
|
28
|
+
rq = "#{api_url}/#{API_VER}/#{resource}/#{function}?apikey=#{CGI.escape api_key}&format=#{CGI.escape FORMAT}"
|
29
|
+
|
30
|
+
if params and params.size > 0
|
31
|
+
params.each_pair do |key, value|
|
32
|
+
rq += "&#{key}=#{CGI.escape value}"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
new_post_data = []
|
37
|
+
if post_data and post_data.size > 0
|
38
|
+
post_data.each_pair do |key, value|
|
39
|
+
new_post_data.push("#{key}=#{CGI.escape value}")
|
40
|
+
end
|
41
|
+
end
|
42
|
+
post_data = new_post_data.join('&')
|
43
|
+
|
44
|
+
result = case method
|
45
|
+
when 'get'
|
46
|
+
get(rq)
|
47
|
+
when 'post'
|
48
|
+
post(rq, post_data)
|
49
|
+
when 'put'
|
50
|
+
put(rq, post_data)
|
51
|
+
when 'delete'
|
52
|
+
delete(rq)
|
53
|
+
end
|
54
|
+
|
55
|
+
case result
|
56
|
+
when Net::HTTPSuccess
|
57
|
+
JSON.parse(result.body)
|
58
|
+
else
|
59
|
+
result.error!
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
private
|
64
|
+
|
65
|
+
def delete(uri)
|
66
|
+
call(Net::HTTP::Delete.new(uri), uri)
|
67
|
+
end
|
68
|
+
|
69
|
+
def get(uri)
|
70
|
+
call(Net::HTTP::Get.new(uri), uri)
|
71
|
+
end
|
72
|
+
|
73
|
+
def put(uri, post_data)
|
74
|
+
req = Net::HTTP::Put.new(uri)
|
75
|
+
req.body = post_data
|
76
|
+
call(req, uri)
|
77
|
+
end
|
78
|
+
|
79
|
+
def post(uri, post_data)
|
80
|
+
req = Net::HTTP::Post.new(uri)
|
81
|
+
req.body = post_data
|
82
|
+
call(req, uri)
|
83
|
+
end
|
84
|
+
|
85
|
+
def call(req, uri)
|
86
|
+
uri = URI.parse(uri)
|
87
|
+
res = Net::HTTP.start(uri.host, uri.port) do |http|
|
88
|
+
http.request(req)
|
89
|
+
end
|
90
|
+
|
91
|
+
res
|
92
|
+
end
|
93
|
+
|
94
|
+
end
|
95
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# Copyright (c) 2009 Radu Spineanu
|
2
|
+
# You can redistribute it and/or modify it under the same terms as Ruby.
|
3
|
+
#
|
4
|
+
|
5
|
+
module Rubervu
|
6
|
+
|
7
|
+
# This class creates API calls for different Resource functions.
|
8
|
+
# How to Use:
|
9
|
+
# ubervu = Rubervu::Ubervu.new('API_KEY')
|
10
|
+
# result = ubervu.resources.show(url)
|
11
|
+
#
|
12
|
+
class UbervuResource < Ubervu
|
13
|
+
|
14
|
+
# Initializes the UbervuResource Class.
|
15
|
+
def initialize(api_key, api_url = 'http://api.ubervu.com')
|
16
|
+
@api_key = api_key
|
17
|
+
@api_url = api_url
|
18
|
+
@resource = 'resources'
|
19
|
+
end
|
20
|
+
|
21
|
+
# Get information about a specific URL
|
22
|
+
# http://developer.ubervu.com/docs/api_methods/Get_information_about_a_specific_URL
|
23
|
+
# url:String
|
24
|
+
def show url
|
25
|
+
function = ''
|
26
|
+
|
27
|
+
params = {}
|
28
|
+
params[:url] = url
|
29
|
+
|
30
|
+
request(@resource, function, params)
|
31
|
+
end
|
32
|
+
|
33
|
+
# Add a new resource
|
34
|
+
# http://developer.ubervu.com/docs/api_methods/Add_a_new_resource
|
35
|
+
# url:String
|
36
|
+
def create url
|
37
|
+
function = ''
|
38
|
+
|
39
|
+
post_data = {}
|
40
|
+
post_data[:url] = url
|
41
|
+
|
42
|
+
request(@resource, function, nil, 'post', post_data)
|
43
|
+
end
|
44
|
+
|
45
|
+
# Add a batch of new resources
|
46
|
+
# http://developer.ubervu.com/docs/api_methods/Add_a_batch_of_new_resources
|
47
|
+
# urls:Array of urls
|
48
|
+
def create_batch urls
|
49
|
+
function = 'batch/'
|
50
|
+
|
51
|
+
post_data = {}
|
52
|
+
post_data[:urls] = urls.join(',')
|
53
|
+
|
54
|
+
request(@resource, function, nil, 'post', post_data)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
data/lib/rubervu.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# Copyright (c) 2009 Radu Spineanu
|
2
|
+
# You can redistribute it and/or modify it under the same terms as Ruby.
|
3
|
+
#
|
4
|
+
|
5
|
+
require 'rubygems'
|
6
|
+
require 'digest/md5'
|
7
|
+
require "cgi"
|
8
|
+
require 'net/http'
|
9
|
+
require 'json'
|
10
|
+
require 'json/ext'
|
11
|
+
|
12
|
+
# Rubervu module contains a Rubervu connection class and different Rubervu Classes
|
13
|
+
module Rubervu
|
14
|
+
FORMAT = "json"
|
15
|
+
API_VER = "1.0"
|
16
|
+
end
|
17
|
+
|
18
|
+
require 'rubervu/ubervu'
|
19
|
+
require 'rubervu/ubervu_resource'
|
metadata
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rubervu
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: "0.1"
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Radu Spineanu
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-05-08 00:00:00 +03:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: json
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
version:
|
25
|
+
description:
|
26
|
+
email: radu @nospam@ rdconcept.ro
|
27
|
+
executables: []
|
28
|
+
|
29
|
+
extensions: []
|
30
|
+
|
31
|
+
extra_rdoc_files:
|
32
|
+
- README
|
33
|
+
files:
|
34
|
+
- lib/rubervu.rb
|
35
|
+
- lib/rubervu/ubervu.rb
|
36
|
+
- lib/rubervu/ubervu_resource.rb
|
37
|
+
- README
|
38
|
+
has_rdoc: true
|
39
|
+
homepage:
|
40
|
+
post_install_message:
|
41
|
+
rdoc_options: []
|
42
|
+
|
43
|
+
require_paths:
|
44
|
+
- lib
|
45
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: "0"
|
50
|
+
version:
|
51
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: "0"
|
56
|
+
version:
|
57
|
+
requirements: []
|
58
|
+
|
59
|
+
rubyforge_project:
|
60
|
+
rubygems_version: 1.3.1
|
61
|
+
signing_key:
|
62
|
+
specification_version: 2
|
63
|
+
summary: Gem for accessing the UberVU.com API.
|
64
|
+
test_files: []
|
65
|
+
|