grempe-rapleaf 0.1.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/CHANGELOG ADDED
@@ -0,0 +1,3 @@
1
+ CHANGELOG
2
+
3
+ - Nothing to report
data/LICENSE ADDED
@@ -0,0 +1,67 @@
1
+ Copyright (c) 2008 Glenn Rempe
2
+
3
+ This software is distributed under the Ruby License. A copy of which is
4
+ provided below.
5
+
6
+ RUBY LICENSE
7
+
8
+ http://www.ruby-lang.org/en/LICENSE.txt
9
+
10
+ Ruby is copyrighted free software by Yukihiro Matsumoto <matz@netlab.co.jp>.
11
+ You can redistribute it and/or modify it under either the terms of the GPL
12
+ (see COPYING.txt file), or the conditions below:
13
+
14
+ 1. You may make and give away verbatim copies of the source form of the
15
+ software without restriction, provided that you duplicate all of the
16
+ original copyright notices and associated disclaimers.
17
+
18
+ 2. You may modify your copy of the software in any way, provided that
19
+ you do at least ONE of the following:
20
+
21
+ a) place your modifications in the Public Domain or otherwise
22
+ make them Freely Available, such as by posting said
23
+ modifications to Usenet or an equivalent medium, or by allowing
24
+ the author to include your modifications in the software.
25
+
26
+ b) use the modified software only within your corporation or
27
+ organization.
28
+
29
+ c) rename any non-standard executables so the names do not conflict
30
+ with standard executables, which must also be provided.
31
+
32
+ d) make other distribution arrangements with the author.
33
+
34
+ 3. You may distribute the software in object code or executable
35
+ form, provided that you do at least ONE of the following:
36
+
37
+ a) distribute the executables and library files of the software,
38
+ together with instructions (in the manual page or equivalent)
39
+ on where to get the original distribution.
40
+
41
+ b) accompany the distribution with the machine-readable source of
42
+ the software.
43
+
44
+ c) give non-standard executables non-standard names, with
45
+ instructions on where to get the original software distribution.
46
+
47
+ d) make other distribution arrangements with the author.
48
+
49
+ 4. You may modify and include the part of the software into any other
50
+ software (possibly commercial). But some files in the distribution
51
+ are not written by the author, so that they are not under this terms.
52
+
53
+ They are gc.c(partly), utils.c(partly), regex.[ch], st.[ch] and some
54
+ files under the ./missing directory. See each file for the copying
55
+ condition.
56
+
57
+ 5. The scripts and library files supplied as input to or produced as
58
+ output from the software do not automatically fall under the
59
+ copyright of the software, but belong to whomever generated them,
60
+ and may be sold commercially, and may be aggregated with this
61
+ software.
62
+
63
+ 6. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
64
+ IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
65
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
66
+ PURPOSE.
67
+
data/README.rdoc ADDED
@@ -0,0 +1,50 @@
1
+ = Rapleaf Ruby Gem Library
2
+
3
+ = Rapleaf
4
+
5
+ Rapleaf's goal is to make the internet safe and transparent, by allowing you
6
+ to evaluate your web footprint across a variety of user-generated sites.
7
+ See http://www.rapleaf.com for more information.
8
+
9
+
10
+ = Installation
11
+
12
+ Install as a Ruby Gem with:
13
+
14
+ Update to RubyGems 1.2.0 before proceeding!!
15
+
16
+ gem sources -a http://gems.github.com (you only have to do this once)
17
+ sudo gem install grempe-rapleaf
18
+
19
+
20
+ = Examples
21
+
22
+ In order to use this API, you will need to get an API Key from Rapleaf. These
23
+ can be obtained free at http://www.rapleaf.com/.
24
+
25
+ You will need to put your API Key in the examples/person.rb file or the
26
+ examples will fail.
27
+
28
+ To run any of the examples, simply run it like:
29
+
30
+ cd examples
31
+ ruby person.rb
32
+
33
+
34
+ = History & Contributing
35
+
36
+ This library was inspired by the sample code provided by Rapleaf at:
37
+
38
+ http://trac.rapleaf.com/ruby-api-kit/wiki
39
+
40
+ The code was extensively re-written so it would work with the current
41
+ Rapleaf v2 API and is provided for your use. Sorry that no support
42
+ for this library is currently available. However, Git pull requests/patches
43
+ are accepted.
44
+
45
+ http://github.com/grempe/rapleaf
46
+
47
+ Glenn Rempe
48
+ glenn@rempe.us
49
+ July, 2008
50
+
data/Rakefile ADDED
@@ -0,0 +1,30 @@
1
+ require 'rubygems'
2
+ require 'rake/gempackagetask'
3
+ require 'rake/testtask'
4
+ require 'rake/rdoctask'
5
+
6
+ # read the contents of the gemspec, eval it, and assign it to 'spec'
7
+ # this lets us maintain all gemspec info in one place. Nice and DRY.
8
+ spec = eval(IO.read("rapleaf.gemspec"))
9
+
10
+ Rake::GemPackageTask.new(spec) do |pkg|
11
+ pkg.gem_spec = spec
12
+ end
13
+
14
+ desc "Build and install the gem locally."
15
+ task :install => [:package] do
16
+ sh %{sudo gem install pkg/rapleaf-*}
17
+ end
18
+
19
+ Rake::TestTask.new do |t|
20
+ t.libs << "test"
21
+ t.test_files = FileList['test/test*.rb']
22
+ t.verbose = true
23
+ end
24
+
25
+ Rake::RDocTask.new do |rd|
26
+ rd.main = "README.rdoc"
27
+ rd.rdoc_files.include("README.rdoc", "lib/**/*.rb")
28
+ rd.rdoc_dir = 'doc'
29
+ rd.options = spec.rdoc_options
30
+ end
@@ -0,0 +1,65 @@
1
+ require 'rubygems'
2
+ require File.dirname(__FILE__) + '/../lib/rapleaf'
3
+
4
+ # Instanciate a Rapleaf object with your API Key.
5
+ @rapleaf = Rapleaf::Base.new('REPLACE_WITH_YOUR_API_KEY')
6
+
7
+ @person = @rapleaf.person(:email => 'dummy@rapleaf.com')
8
+
9
+ puts "\n\n"
10
+ puts "BASICS"
11
+
12
+ puts "\n@person.basics.name:"
13
+ puts @person.basics.name
14
+
15
+ puts "\n@person.basics.age:"
16
+ puts @person.basics.age
17
+
18
+ puts "\n@person.basics.gender:"
19
+ puts @person.basics.gender
20
+
21
+ puts "\n@person.basics.location:"
22
+ puts @person.basics.location
23
+
24
+ puts "\n@person.basics.occupations:"
25
+ if @person.basics.occupations
26
+ @person.basics.occupations.each do |occupation|
27
+ puts "occupation.job_title"
28
+ puts occupation.job_title
29
+ puts "occupation.company"
30
+ puts occupation.company
31
+ end
32
+ end
33
+
34
+ puts "\n@person.basics.universities:"
35
+ if @person.basics.universities
36
+ @person.basics.universities.each do |university|
37
+ puts "university:"
38
+ puts university
39
+ end
40
+ end
41
+
42
+ puts "\n@person.basics.earliest_known_activity:"
43
+ puts @person.basics.earliest_known_activity
44
+
45
+ puts "\n@person.basics.latest_known_activity:"
46
+ puts @person.basics.latest_known_activity
47
+
48
+ puts "\n@person.basics.num_friends:"
49
+ puts @person.basics.num_friends
50
+
51
+ puts "\nMEMBERSHIPS"
52
+
53
+ puts "\n@person.memberships.inspect"
54
+ puts @person.memberships.inspect
55
+
56
+ puts "\n@person.memberships.primary.inspect"
57
+ puts @person.memberships.primary.inspect
58
+
59
+ puts "\n@person.memberships.primary.membership[0].site"
60
+ puts @person.memberships.primary.membership[0].site
61
+
62
+ # Look up a profile by hashed email address.
63
+ puts "\nLookup by hashed email:"
64
+ @person = @rapleaf.person(:email => '1147e414eec8b785fb760f13f7890a767ffaef6e')
65
+
data/lib/rapleaf.rb ADDED
@@ -0,0 +1,12 @@
1
+ %w[ base64 cgi openssl digest/sha1 net/http builder ostruct ].each { |f| require f }
2
+
3
+ Dir[File.join(File.dirname(__FILE__), 'rapleaf/**/*.rb')].sort.each { |lib| require lib }
4
+
5
+ module Rapleaf
6
+
7
+ # API Constants
8
+ API_HOST = 'api.rapleaf.com'
9
+ API_PORT = 80
10
+ API_VERSION = 'v2'
11
+
12
+ end
@@ -0,0 +1,61 @@
1
+ module Rapleaf
2
+
3
+ # CLIENT SIDE ERRORS
4
+
5
+ # All of our errors are superclassed by Error < RuntimeError
6
+ class Error < RuntimeError #:nodoc:
7
+ end
8
+
9
+ # A client side only argument error
10
+ class ArgumentError < Error #:nodoc:
11
+ end
12
+
13
+ # SERVER SIDE ERRORS
14
+
15
+ # GENERAL API
16
+ # =============================================
17
+
18
+ # 401 Unauthorized
19
+ # API key was not provided or is invalid.
20
+ class AuthFailure < Error #:nodoc:
21
+ end
22
+
23
+ # 403 Forbidden
24
+ # Your query limit has been exceeded.
25
+ class ForbiddenQueryLimitExceeded < Error #:nodoc:
26
+ end
27
+
28
+ # 500 Internal Server Error
29
+ # There was an unexpected error on our server. This should be very
30
+ # rare and if you see it please contact developer@rapleaf.com.
31
+ class InternalServerError < Error #:nodoc:
32
+ end
33
+
34
+
35
+ # PERSON API
36
+ # =============================================
37
+
38
+ # 202 Accepted
39
+ # This person is currently being searched. Check back shortly and we should have data.
40
+ class PersonAccepted < Error #:nodoc:
41
+ end
42
+
43
+ # 400 Bad Request
44
+ # Invalid email address.
45
+ class PersonBadRequestInvalidEmail < Error #:nodoc:
46
+ end
47
+
48
+ # 404 Not Found
49
+ # Only returned for lookup by hash. We do not have this email in our
50
+ # system and are not able to create a person using a hash. If you would
51
+ # like better results, consider supplying the unhashed email address.
52
+ class PersonEmailHashNotFound < Error #:nodoc:
53
+ end
54
+
55
+
56
+ # ABOOK API
57
+ # =============================================
58
+
59
+ # TODO
60
+
61
+ end
@@ -0,0 +1,52 @@
1
+ module Rapleaf
2
+
3
+ class Base
4
+
5
+ def initialize(api_key, options = {})
6
+ options = {
7
+ :api_host => API_HOST,
8
+ :api_port => API_PORT,
9
+ :api_version => API_VERSION
10
+ }.merge(options)
11
+
12
+ @api_key = api_key
13
+ @host = options[:api_host]
14
+ @port = options[:api_port]
15
+ @version = options[:api_version]
16
+ end
17
+
18
+ # This resource is used to retrieve information about a person, identified
19
+ # using an email address or email address hash.
20
+ # Example: person(:email => 'dummy@rapleaf.com')
21
+ 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))
27
+
28
+ case resp.code
29
+ when '200'
30
+ return Response.parse(:xml => resp.body)
31
+ when '202'
32
+ raise PersonAccepted, 'This person is currently being searched. Check back shortly and we should have data.'
33
+ when '400'
34
+ raise PersonBadRequestInvalidEmail, 'Invalid email address.'
35
+ when '401'
36
+ raise AuthFailure, 'API key was not provided or is invalid.'
37
+ when '403'
38
+ raise ForbiddenQueryLimitExceeded, 'Your query limit has been exceeded. Contact developer@rapleaf.com if you would like to increase your limit.'
39
+ when '500'
40
+ 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
+ else
42
+ raise Error, 'Unknown error'
43
+ end
44
+ end
45
+
46
+ def abook( opts = {} )
47
+ # TODO
48
+ end
49
+
50
+ end
51
+
52
+ end
@@ -0,0 +1,142 @@
1
+ module Rapleaf
2
+
3
+ # Credits :
4
+ # I learned the magic of making an OpenStruct object able to respond as a fully Enumerable
5
+ # object (responds to .each, etc.) thanks to a great blog article on Struct and OpenStruct
6
+ # at http://errtheblog.com/post/30
7
+ #
8
+ # Thanks to Sean Knapp for the XmlSimple response patch which greatly simplified the response
9
+ # mechanism for the whole library while making it more accurate and much less brittle to boot!
10
+ #
11
+
12
+ require 'rubygems'
13
+ begin
14
+ require 'xmlsimple' unless defined? XmlSimple
15
+ rescue Exception => e
16
+ require 'xml-simple' unless defined? XmlSimple
17
+ end
18
+
19
+ class Response < OpenStruct
20
+
21
+ include Enumerable
22
+
23
+ def self.parse(options = {})
24
+ options = {
25
+ :xml => "",
26
+ :parse_options => { 'ForceArray' => ['item'], 'SuppressEmpty' => nil }
27
+ }.merge(options)
28
+ response = Response.new(XmlSimple.xml_in(options[:xml], options[:parse_options]))
29
+
30
+ # set the xml attribute of the response object to contain the original XML that was
31
+ # returned. This allows anyone to bypass our parsing if desired and just
32
+ # get right at the raw XML response.
33
+ response.xml = options[:xml]
34
+ return response
35
+ end
36
+
37
+ # Every member of an OpenStruct object has getters and setters, the latter of which
38
+ # has a method ending in "=". Find all of these methods, excluding those defined on
39
+ # parent classes.
40
+ def members
41
+ methods(false).sort.grep(/=/).map { |m| m[0...-1] }
42
+ end
43
+
44
+ # Required by the Enumerable module. Iterate over each item in the members array
45
+ # and pass as a value the block passed to each using yield.
46
+ def each
47
+ members.each do |method|
48
+ yield send(method)
49
+ end
50
+ self
51
+ end
52
+
53
+ # Same as the each method, but with both key and value.
54
+ #
55
+ #Sample Use:
56
+ # obj.each_pair { |k,v| puts "key: #{k}, value: #{v}" }
57
+ def each_pair
58
+ members.each do |method|
59
+ yield method, send(method)
60
+ end
61
+ self
62
+ end
63
+
64
+ # Alternative method for getting members.
65
+ def [](member)
66
+ send(member)
67
+ end
68
+
69
+ # Alternative method for setting members.
70
+ def []=(member, value)
71
+ send("#{member}=", value)
72
+ end
73
+
74
+ # Helper for converting to string which support a long and short version
75
+ # to avoid recursion problems with parents.
76
+ def to_string(short=false)
77
+ s = "#<#{self.class}:0x#{(2 ** 32 + object_id).to_s(16).upcase}"
78
+ if (short)
79
+ s += " ..."
80
+ else
81
+ each_pair { |k,v|
82
+ if (v == self.parent && v.kind_of?(Response))
83
+ v = v.to_string(true)
84
+ elsif (v.kind_of?(String))
85
+ v = "\"#{v.gsub("\"", "\\\"")}\""
86
+ elsif (v.kind_of?(NilClass))
87
+ v = "nil"
88
+ end
89
+ s += " #{k}=#{v}"
90
+ }
91
+ end
92
+ s += ">"
93
+ return s
94
+ end
95
+
96
+ # Override of to string method.
97
+ def to_s
98
+ return to_string
99
+ end
100
+
101
+ private
102
+
103
+ # Initialize the object by passing data to the OpenStruct initialize method
104
+ # and then converting ourself to guarantee we have top-to-bottom data
105
+ # representation as a Response object.
106
+ def initialize(data, parent=nil)
107
+ super(data)
108
+ self.parent = parent
109
+ Response.convert(self, parent)
110
+ end
111
+
112
+ # The "brains" of our Response class. This method takes an arbitray object and
113
+ # depending on its class attempts to convert it.
114
+ def self.convert(obj, parent)
115
+ if (obj.kind_of?(Response))
116
+ # Recursively convert the object.
117
+ obj.each_pair { |k,v|
118
+ if (v != obj.parent)
119
+ obj[k] = convert(v, obj)
120
+ end
121
+ }
122
+ return obj
123
+ elsif (obj.kind_of?(Hash))
124
+ # Hashes make good Responses already thanks to OpenStruct.
125
+ return Response.new(obj, parent)
126
+ elsif (obj.kind_of?(Array))
127
+ # With arrays, make sure each element is appropriately converted.
128
+ new_arr = []
129
+ obj.each { |elem|
130
+ new_arr << convert(elem, parent)
131
+ }
132
+ return new_arr
133
+ else
134
+ # At this point we're out of ideas, so let's hope it is a string.
135
+ return obj
136
+ end
137
+ end
138
+
139
+ end # class Response < OpenStruct
140
+
141
+ end # module
142
+
metadata ADDED
@@ -0,0 +1,89 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: grempe-rapleaf
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ platform: ruby
6
+ authors:
7
+ - Glenn Rempe
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-07-08 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: xml-simple
17
+ version_requirement:
18
+ version_requirements: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: "0"
23
+ version:
24
+ - !ruby/object:Gem::Dependency
25
+ name: builder
26
+ version_requirement:
27
+ version_requirements: !ruby/object:Gem::Requirement
28
+ requirements:
29
+ - - ">="
30
+ - !ruby/object:Gem::Version
31
+ version: "0"
32
+ version:
33
+ description: A Ruby gem library for accessing the rapleaf.com API
34
+ email: glenn@rempe.us
35
+ executables: []
36
+
37
+ extensions: []
38
+
39
+ extra_rdoc_files:
40
+ - README.rdoc
41
+ - CHANGELOG
42
+ - LICENSE
43
+ files:
44
+ - README.rdoc
45
+ - LICENSE
46
+ - CHANGELOG
47
+ - Rakefile
48
+ - examples/person.rb
49
+ - lib/rapleaf
50
+ - lib/rapleaf/exceptions.rb
51
+ - lib/rapleaf/rapleaf.rb
52
+ - lib/rapleaf/responses.rb
53
+ - lib/rapleaf.rb
54
+ has_rdoc: true
55
+ homepage: http://github.com/grempe/rapleaf/
56
+ post_install_message:
57
+ rdoc_options:
58
+ - --quiet
59
+ - --title
60
+ - rapleaf documentation
61
+ - --opname
62
+ - index.html
63
+ - --line-numbers
64
+ - --main
65
+ - README.rdoc
66
+ - --inline-source
67
+ require_paths:
68
+ - lib
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: "0"
74
+ version:
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: "0"
80
+ version:
81
+ requirements: []
82
+
83
+ rubyforge_project:
84
+ rubygems_version: 1.2.0
85
+ signing_key:
86
+ specification_version: 2
87
+ summary: A Ruby gem library for accessing the rapleaf.com API
88
+ test_files: []
89
+