ruby-rapleaf 0.1.5 → 0.2.2
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/History.txt +38 -3
- data/README.txt +19 -15
- data/lib/rapleaf/rapleaf.rb +90 -10
- data/lib/ruby-rapleaf.rb +6 -5
- data/ruby-rapleaf.gemspec +5 -5
- metadata +53 -18
data/History.txt
CHANGED
@@ -1,6 +1,41 @@
|
|
1
|
-
===
|
1
|
+
=== 0.2.2 / 2010/10/18
|
2
2
|
|
3
|
-
*
|
3
|
+
* Allow specifying the read_timeout to pass through to Net::HTTP.
|
4
|
+
There are a few reasons why you might want to do this. One is that
|
5
|
+
Net::HTTP's read_timeout is implemented using timeout.rb, which is known
|
6
|
+
to have race conditions, and in particular is unsafe to use in
|
7
|
+
EventMachine (because it can sometimes throw exceptions in the main
|
8
|
+
event loop and kill the whole process); so this lets you disable the
|
9
|
+
timeout entirely.
|
4
10
|
|
5
|
-
|
11
|
+
* Ruby 1.9 compatibility tweak (thanks to Justin Ip)
|
6
12
|
|
13
|
+
=== 0.2.1 / 2010/04/27
|
14
|
+
|
15
|
+
* If unexpected response code, exception should include diagnostic info
|
16
|
+
|
17
|
+
=== 0.2.0 / 2010/04/24
|
18
|
+
|
19
|
+
* Support Person API lookup by site profile (e.g. Twitter username) for API v3.
|
20
|
+
|
21
|
+
=== 0.1.7 / 2010-04-14
|
22
|
+
|
23
|
+
* URLencode email addresses before sending them to Rapleaf.
|
24
|
+
|
25
|
+
* Remove workaround for mistakenly diagnosed problem (thought Rapleaf rejected emails containing '+', they just required encoding).
|
26
|
+
|
27
|
+
* Use existing PersonEmailHashNotFound exception for 404 when looking up by hash
|
28
|
+
|
29
|
+
* removed NotFound class added in 0.1.6
|
30
|
+
|
31
|
+
=== 0.1.6 / 2010-03-04
|
32
|
+
|
33
|
+
* Modified by Sam Stokes
|
34
|
+
|
35
|
+
* Support for Rapleaf Person API v3 (which is now the default)
|
36
|
+
|
37
|
+
* Work around Rapleaf bug: they think email addresses containing '+' are malformed, so for those we send them hashes instead.
|
38
|
+
|
39
|
+
=== 0.1.5 / 2008-08-28
|
40
|
+
|
41
|
+
* Original version by Glenn Rempe, with support for Rapleaf Person API v2
|
data/README.txt
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
= ruby-rapleaf
|
2
2
|
|
3
|
-
* http://github.com/
|
3
|
+
* http://github.com/rapportive-oss/ruby-rapleaf
|
4
4
|
|
5
5
|
== DESCRIPTION:
|
6
6
|
|
@@ -14,16 +14,24 @@ This library was inspired by the sample code provided by Rapleaf at:
|
|
14
14
|
|
15
15
|
http://trac.rapleaf.com/ruby-api-kit/wiki
|
16
16
|
|
17
|
-
The code was extensively re-written so it would work with the
|
18
|
-
Rapleaf v2 API and
|
19
|
-
|
20
|
-
|
17
|
+
The code was extensively re-written by Glenn Rempe so it would work with the
|
18
|
+
then-current Rapleaf v2 API, and further modified by Sam Stokes to support the
|
19
|
+
v3 API.
|
20
|
+
|
21
|
+
=== Original (v2 API compatible)
|
21
22
|
|
22
23
|
http://github.com/grempe/ruby-rapleaf
|
23
24
|
|
24
25
|
Glenn Rempe
|
25
26
|
glenn@rempe.us
|
26
27
|
|
28
|
+
=== Updated (v3 API compatible)
|
29
|
+
|
30
|
+
http://github.com/rapportive-oss/ruby-rapleaf
|
31
|
+
|
32
|
+
Sam Stokes
|
33
|
+
sam@rapportive.com
|
34
|
+
|
27
35
|
== SYNOPSIS:
|
28
36
|
|
29
37
|
In order to use this API, you will need to get an API Key from Rapleaf. These
|
@@ -37,6 +45,8 @@ To run any of the examples, simply run it like:
|
|
37
45
|
cd examples
|
38
46
|
ruby person.rb
|
39
47
|
|
48
|
+
(There are some known problems running the examples at the moment... sorry!)
|
49
|
+
|
40
50
|
== REQUIREMENTS:
|
41
51
|
|
42
52
|
The following gems are required for installation of the ruby-rapleaf gem.
|
@@ -46,17 +56,11 @@ The following gems are required for installation of the ruby-rapleaf gem.
|
|
46
56
|
|
47
57
|
== INSTALL:
|
48
58
|
|
49
|
-
|
50
|
-
|
51
|
-
Update to RubyGems 1.2.0 before proceeding!!
|
52
|
-
|
53
|
-
gem sources -a http://gems.github.com (you only have to do this once)
|
54
|
-
|
55
|
-
sudo gem install grempe-ruby-rapleaf
|
59
|
+
Sorry, there's no hosted gem at the moment!
|
56
60
|
|
57
|
-
|
61
|
+
You can build the gem yourself and install as a Ruby Gem with:
|
58
62
|
|
59
|
-
git clone git://github.com/
|
63
|
+
git clone git://github.com/rapportive-oss/ruby-rapleaf.git
|
60
64
|
cd ruby-rapleaf
|
61
65
|
rake gem
|
62
66
|
rake install_gem
|
@@ -68,7 +72,7 @@ provided below.
|
|
68
72
|
|
69
73
|
RUBY LICENSE
|
70
74
|
|
71
|
-
Copyright (c) 2008 Glenn Rempe
|
75
|
+
Copyright (c) 2008-2010 Glenn Rempe, 2010 Sam Stokes, Justin Ip
|
72
76
|
|
73
77
|
http://www.ruby-lang.org/en/LICENSE.txt
|
74
78
|
|
data/lib/rapleaf/rapleaf.rb
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
require 'digest/md5'
|
2
|
+
require 'uri'
|
3
|
+
|
1
4
|
module Rapleaf
|
2
5
|
|
3
6
|
class Base
|
@@ -6,24 +9,26 @@ module Rapleaf
|
|
6
9
|
options = {
|
7
10
|
:api_host => API_HOST,
|
8
11
|
:api_port => API_PORT,
|
9
|
-
:api_version => API_VERSION
|
12
|
+
:api_version => API_VERSION,
|
13
|
+
:api_read_timeout => 30,
|
10
14
|
}.merge(options)
|
11
15
|
|
12
16
|
@api_key = api_key
|
13
17
|
@host = options[:api_host]
|
14
18
|
@port = options[:api_port]
|
15
19
|
@version = options[:api_version]
|
20
|
+
@read_timeout = options[:api_read_timeout]
|
16
21
|
end
|
17
22
|
|
18
23
|
# This resource is used to retrieve information about a person, identified
|
19
24
|
# using an email address or email address hash.
|
20
|
-
#
|
25
|
+
# Examples:
|
26
|
+
# person(:email => 'dummy@rapleaf.com')
|
27
|
+
# person(:site => :twitter, :profile => 'samstokes')
|
28
|
+
# person(:sha1 => Digest::SHA1.hexdigest('dummy@rapleaf.com'))
|
29
|
+
# person(:md5 => Digest::MD5.hexdigest('dummy@rapleaf.com'))
|
21
30
|
def person( opts = {} )
|
22
|
-
|
23
|
-
raise ArgumentError, 'Email address must be provided' if opts[:email].nil? || opts[:email] == ''
|
24
|
-
|
25
|
-
url = "http://#{@host}:#{@port}/#{@version}/person/#{opts[:email]}?api_key=#{@api_key}"
|
26
|
-
resp = Net::HTTP.get_response(URI.parse(url))
|
31
|
+
resp = fetch_response(URI.parse(person_url(opts)))
|
27
32
|
|
28
33
|
case resp.code
|
29
34
|
when '200'
|
@@ -36,15 +41,90 @@ module Rapleaf
|
|
36
41
|
raise AuthFailure, 'API key was not provided or is invalid.'
|
37
42
|
when '403'
|
38
43
|
raise ForbiddenQueryLimitExceeded, 'Your query limit has been exceeded. Contact developer@rapleaf.com if you would like to increase your limit.'
|
44
|
+
when '404'
|
45
|
+
raise PersonEmailHashNotFound, 'We do not have this email in our system and are not able to create a person using a hash. If you would like better results, consider supplying the unhashed email address.'
|
39
46
|
when '500'
|
40
47
|
raise InternalServerError, 'There was an unexpected error on our server. This should be very rare and if you see it please contact developer@rapleaf.com.'
|
41
48
|
else
|
42
|
-
|
49
|
+
msg = resp.body[0,50]
|
50
|
+
msg << "..." if 50 < resp.body.length
|
51
|
+
raise Error, %(Unexpected response code #{resp.code}: "#{msg}")
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
private
|
56
|
+
def fetch_response(uri)
|
57
|
+
# Have to do this a verbose way in order to override Net::HTTP's
|
58
|
+
# default read_timeout
|
59
|
+
|
60
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
61
|
+
if uri.scheme == 'https'
|
62
|
+
http.use_ssl = true
|
63
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
64
|
+
end
|
65
|
+
http.read_timeout = @read_timeout
|
66
|
+
|
67
|
+
http.start { http.get(uri.path + '?' + uri.query) }
|
68
|
+
end
|
69
|
+
|
70
|
+
def person_url(opts)
|
71
|
+
email = opts[:email]
|
72
|
+
|
73
|
+
site_profile = [opts[:site], opts[:profile]]
|
74
|
+
if site_profile.any?
|
75
|
+
raise ArgumentError, 'Require both :site and :profile if either is specified' unless site_profile.all?
|
76
|
+
else
|
77
|
+
site_profile = nil
|
43
78
|
end
|
79
|
+
|
80
|
+
md5 = opts[:md5]
|
81
|
+
sha1 = opts[:sha1]
|
82
|
+
|
83
|
+
# Rapleaf requires email addresses be urlencoded
|
84
|
+
# Pass our own "unsafe regex" as URI.escape's default is too permissive
|
85
|
+
# (lets + through, but Rapleaf rejects it)
|
86
|
+
email = URI.escape(email, /[^a-zA-Z0-9.\-_]/) if email
|
87
|
+
|
88
|
+
selector = [email, site_profile, md5, sha1].compact
|
89
|
+
raise ArgumentError, 'Please provide only one of :email, [:site and :profile], :md5 or :sha1' if selector.size > 1
|
90
|
+
raise ArgumentError, 'Person selector must be provided' if selector.empty? || '' == selector[0]
|
91
|
+
|
92
|
+
case @version
|
93
|
+
when "v2"
|
94
|
+
if site_profile
|
95
|
+
raise ArgumentError, 'Query by website ID requires API v3 or greater'
|
96
|
+
end
|
97
|
+
person_url_v2_by_email_or_hash(email_or_hash[0])
|
98
|
+
when "v3"
|
99
|
+
if email
|
100
|
+
person_url_v3_by_email(email)
|
101
|
+
elsif site_profile
|
102
|
+
person_url_v3_by_site_profile(*site_profile)
|
103
|
+
elsif md5
|
104
|
+
person_url_v3_by_hash(:md5, md5)
|
105
|
+
else
|
106
|
+
person_url_v3_by_hash(:sha1, sha1)
|
107
|
+
end
|
108
|
+
else
|
109
|
+
raise ArgumentError, "Person queries not supported for API version #{@version}"
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
def person_url_v2_by_email_or_hash(email_or_hash)
|
114
|
+
"http://#{@host}:#{@port}/v2/person/#{email_or_hash}?api_key=#{@api_key}"
|
115
|
+
end
|
116
|
+
|
117
|
+
def person_url_v3_by_email(email)
|
118
|
+
"http://#{@host}:#{@port}/v3/person/email/#{email}?api_key=#{@api_key}"
|
119
|
+
end
|
120
|
+
|
121
|
+
def person_url_v3_by_site_profile(site, profile)
|
122
|
+
# TODO validate param formats
|
123
|
+
"http://#{@host}:#{@port}/v3/person/web/#{site}/#{profile}?api_key=#{@api_key}"
|
44
124
|
end
|
45
125
|
|
46
|
-
def
|
47
|
-
|
126
|
+
def person_url_v3_by_hash(algo, hash)
|
127
|
+
"http://#{@host}:#{@port}/v3/person/hash/#{algo}/#{hash}?api_key=#{@api_key}"
|
48
128
|
end
|
49
129
|
|
50
130
|
end
|
data/lib/ruby-rapleaf.rb
CHANGED
@@ -6,18 +6,19 @@ require 'net/http'
|
|
6
6
|
require 'builder'
|
7
7
|
require 'ostruct'
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
require
|
9
|
+
library_files = Dir[File.join(File.dirname(__FILE__), "/rapleaf/**/*.rb")]
|
10
|
+
library_files.each do |file|
|
11
|
+
require file.gsub(/\.rb$/, "")
|
12
|
+
end
|
12
13
|
|
13
14
|
module Rapleaf
|
14
15
|
|
15
|
-
VERSION = '0.
|
16
|
+
VERSION = '0.2.2'
|
16
17
|
|
17
18
|
# API Constants
|
18
19
|
API_HOST = 'api.rapleaf.com'
|
19
20
|
API_PORT = 80
|
20
|
-
API_VERSION = '
|
21
|
+
API_VERSION = 'v3'
|
21
22
|
|
22
23
|
end
|
23
24
|
|
data/ruby-rapleaf.gemspec
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = %q{ruby-rapleaf}
|
3
|
-
s.version = "0.
|
3
|
+
s.version = "0.2.2"
|
4
4
|
|
5
5
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
6
|
-
s.authors = ["Glenn Rempe"]
|
7
|
-
s.date = %q{
|
6
|
+
s.authors = ["Glenn Rempe", "Sam Stokes", "Justin Ip"]
|
7
|
+
s.date = %q{2010-10-18}
|
8
8
|
s.description = %q{Rapleaf's goal is to make the internet safe and transparent, by allowing you to evaluate your web footprint across a variety of user-generated sites. See http://www.rapleaf.com for more information.}
|
9
|
-
s.email = ["glenn@rempe.us"]
|
9
|
+
s.email = ["glenn@rempe.us", "sam@rapportive.com"]
|
10
10
|
s.extra_rdoc_files = ["History.txt", "Manifest.txt", "README.txt"]
|
11
11
|
s.files = ["History.txt", "Manifest.txt", "README.txt", "Rakefile", "examples/person.rb", "lib/ruby-rapleaf.rb", "lib/rapleaf/exceptions.rb", "lib/rapleaf/rapleaf.rb", "lib/rapleaf/responses.rb", "ruby-rapleaf.gemspec"]
|
12
12
|
s.has_rdoc = true
|
13
|
-
s.homepage = %q{http://github.com/
|
13
|
+
s.homepage = %q{http://github.com/rapportive-oss/ruby-rapleaf}
|
14
14
|
s.rdoc_options = ["--main", "README.txt"]
|
15
15
|
s.require_paths = ["lib"]
|
16
16
|
s.rubyforge_project = %q{ruby-rapleaf}
|
metadata
CHANGED
@@ -1,50 +1,77 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-rapleaf
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
hash: 19
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 2
|
9
|
+
- 2
|
10
|
+
version: 0.2.2
|
5
11
|
platform: ruby
|
6
12
|
authors:
|
7
13
|
- Glenn Rempe
|
14
|
+
- Sam Stokes
|
15
|
+
- Justin Ip
|
8
16
|
autorequire:
|
9
17
|
bindir: bin
|
10
18
|
cert_chain: []
|
11
19
|
|
12
|
-
date:
|
20
|
+
date: 2010-10-18 00:00:00 +01:00
|
13
21
|
default_executable:
|
14
22
|
dependencies:
|
15
23
|
- !ruby/object:Gem::Dependency
|
16
24
|
name: xml-simple
|
17
|
-
|
18
|
-
|
19
|
-
|
25
|
+
prerelease: false
|
26
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
27
|
+
none: false
|
20
28
|
requirements:
|
21
29
|
- - ">="
|
22
30
|
- !ruby/object:Gem::Version
|
31
|
+
hash: 1
|
32
|
+
segments:
|
33
|
+
- 1
|
34
|
+
- 0
|
35
|
+
- 11
|
23
36
|
version: 1.0.11
|
24
|
-
|
37
|
+
type: :runtime
|
38
|
+
version_requirements: *id001
|
25
39
|
- !ruby/object:Gem::Dependency
|
26
40
|
name: builder
|
27
|
-
|
28
|
-
|
29
|
-
|
41
|
+
prerelease: false
|
42
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
43
|
+
none: false
|
30
44
|
requirements:
|
31
45
|
- - ">="
|
32
46
|
- !ruby/object:Gem::Version
|
47
|
+
hash: 15
|
48
|
+
segments:
|
49
|
+
- 2
|
50
|
+
- 1
|
51
|
+
- 2
|
33
52
|
version: 2.1.2
|
34
|
-
|
53
|
+
type: :runtime
|
54
|
+
version_requirements: *id002
|
35
55
|
- !ruby/object:Gem::Dependency
|
36
56
|
name: hoe
|
37
|
-
|
38
|
-
|
39
|
-
|
57
|
+
prerelease: false
|
58
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
59
|
+
none: false
|
40
60
|
requirements:
|
41
61
|
- - ">="
|
42
62
|
- !ruby/object:Gem::Version
|
63
|
+
hash: 11
|
64
|
+
segments:
|
65
|
+
- 1
|
66
|
+
- 7
|
67
|
+
- 0
|
43
68
|
version: 1.7.0
|
44
|
-
|
69
|
+
type: :development
|
70
|
+
version_requirements: *id003
|
45
71
|
description: Rapleaf's goal is to make the internet safe and transparent, by allowing you to evaluate your web footprint across a variety of user-generated sites. See http://www.rapleaf.com for more information.
|
46
72
|
email:
|
47
73
|
- glenn@rempe.us
|
74
|
+
- sam@rapportive.com
|
48
75
|
executables: []
|
49
76
|
|
50
77
|
extensions: []
|
@@ -65,7 +92,9 @@ files:
|
|
65
92
|
- lib/rapleaf/responses.rb
|
66
93
|
- ruby-rapleaf.gemspec
|
67
94
|
has_rdoc: true
|
68
|
-
homepage: http://github.com/
|
95
|
+
homepage: http://github.com/rapportive-oss/ruby-rapleaf
|
96
|
+
licenses: []
|
97
|
+
|
69
98
|
post_install_message:
|
70
99
|
rdoc_options:
|
71
100
|
- --main
|
@@ -73,21 +102,27 @@ rdoc_options:
|
|
73
102
|
require_paths:
|
74
103
|
- lib
|
75
104
|
required_ruby_version: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
76
106
|
requirements:
|
77
107
|
- - ">="
|
78
108
|
- !ruby/object:Gem::Version
|
109
|
+
hash: 3
|
110
|
+
segments:
|
111
|
+
- 0
|
79
112
|
version: "0"
|
80
|
-
version:
|
81
113
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
114
|
+
none: false
|
82
115
|
requirements:
|
83
116
|
- - ">="
|
84
117
|
- !ruby/object:Gem::Version
|
118
|
+
hash: 3
|
119
|
+
segments:
|
120
|
+
- 0
|
85
121
|
version: "0"
|
86
|
-
version:
|
87
122
|
requirements: []
|
88
123
|
|
89
124
|
rubyforge_project: ruby-rapleaf
|
90
|
-
rubygems_version: 1.
|
125
|
+
rubygems_version: 1.3.7
|
91
126
|
signing_key:
|
92
127
|
specification_version: 2
|
93
128
|
summary: Rapleaf's goal is to make the internet safe and transparent, by allowing you to evaluate your web footprint across a variety of user-generated sites
|