grempe-ruby-rapleaf 0.1.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/History.txt ADDED
@@ -0,0 +1,6 @@
1
+ === 1.0.0 / 2008-08-27
2
+
3
+ * 1 major enhancement
4
+
5
+ * Birthday!
6
+
data/Manifest.txt ADDED
@@ -0,0 +1,10 @@
1
+ History.txt
2
+ Manifest.txt
3
+ README.txt
4
+ Rakefile
5
+ examples/person.rb
6
+ lib/ruby-rapleaf.rb
7
+ lib/rapleaf/exceptions.rb
8
+ lib/rapleaf/rapleaf.rb
9
+ lib/rapleaf/responses.rb
10
+ ruby-rapleaf.gemspec
data/README.txt ADDED
@@ -0,0 +1,131 @@
1
+ = ruby-rapleaf
2
+
3
+ * http://github.com/grempe/ruby-rapleaf
4
+
5
+ == DESCRIPTION:
6
+
7
+ Rapleaf's goal is to make the internet safe and transparent, by allowing you
8
+ to evaluate your web footprint across a variety of user-generated sites.
9
+ See http://www.rapleaf.com for more information.
10
+
11
+ == FEATURES/PROBLEMS:
12
+
13
+ This library was inspired by the sample code provided by Rapleaf at:
14
+
15
+ http://trac.rapleaf.com/ruby-api-kit/wiki
16
+
17
+ The code was extensively re-written so it would work with the current
18
+ Rapleaf v2 API and is provided for your use. Sorry that no support
19
+ for this library is currently available. However, Git pull requests/patches
20
+ are accepted.
21
+
22
+ http://github.com/grempe/ruby-rapleaf
23
+
24
+ Glenn Rempe
25
+ glenn@rempe.us
26
+
27
+ == SYNOPSIS:
28
+
29
+ In order to use this API, you will need to get an API Key from Rapleaf. These
30
+ can be obtained free at http://www.rapleaf.com/.
31
+
32
+ To run the samples you will need to put your API Key in the
33
+ examples/person.rb file or the examples will fail.
34
+
35
+ To run any of the examples, simply run it like:
36
+
37
+ cd examples
38
+ ruby person.rb
39
+
40
+ == REQUIREMENTS:
41
+
42
+ The following gems are required for installation of the ruby-rapleaf gem.
43
+
44
+ * xml-simple
45
+ * builder
46
+
47
+ == INSTALL:
48
+
49
+ Install as a Ruby Gem with:
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
56
+
57
+ # OR
58
+
59
+ git clone git://github.com/grempe/ruby-rapleaf.git
60
+ cd ruby-rapleaf
61
+ rake gem
62
+ rake install_gem
63
+
64
+ == LICENSE:
65
+
66
+ This software is distributed under the Ruby License. A copy of which is
67
+ provided below.
68
+
69
+ RUBY LICENSE
70
+
71
+ Copyright (c) 2008 Glenn Rempe
72
+
73
+ http://www.ruby-lang.org/en/LICENSE.txt
74
+
75
+ Ruby is copyrighted free software by Yukihiro Matsumoto <matz@netlab.co.jp>.
76
+ You can redistribute it and/or modify it under either the terms of the GPL
77
+ (see COPYING.txt file), or the conditions below:
78
+
79
+ 1. You may make and give away verbatim copies of the source form of the
80
+ software without restriction, provided that you duplicate all of the
81
+ original copyright notices and associated disclaimers.
82
+
83
+ 2. You may modify your copy of the software in any way, provided that
84
+ you do at least ONE of the following:
85
+
86
+ a) place your modifications in the Public Domain or otherwise
87
+ make them Freely Available, such as by posting said
88
+ modifications to Usenet or an equivalent medium, or by allowing
89
+ the author to include your modifications in the software.
90
+
91
+ b) use the modified software only within your corporation or
92
+ organization.
93
+
94
+ c) rename any non-standard executables so the names do not conflict
95
+ with standard executables, which must also be provided.
96
+
97
+ d) make other distribution arrangements with the author.
98
+
99
+ 3. You may distribute the software in object code or executable
100
+ form, provided that you do at least ONE of the following:
101
+
102
+ a) distribute the executables and library files of the software,
103
+ together with instructions (in the manual page or equivalent)
104
+ on where to get the original distribution.
105
+
106
+ b) accompany the distribution with the machine-readable source of
107
+ the software.
108
+
109
+ c) give non-standard executables non-standard names, with
110
+ instructions on where to get the original software distribution.
111
+
112
+ d) make other distribution arrangements with the author.
113
+
114
+ 4. You may modify and include the part of the software into any other
115
+ software (possibly commercial). But some files in the distribution
116
+ are not written by the author, so that they are not under this terms.
117
+
118
+ They are gc.c(partly), utils.c(partly), regex.[ch], st.[ch] and some
119
+ files under the ./missing directory. See each file for the copying
120
+ condition.
121
+
122
+ 5. The scripts and library files supplied as input to or produced as
123
+ output from the software do not automatically fall under the
124
+ copyright of the software, but belong to whomever generated them,
125
+ and may be sold commercially, and may be aggregated with this
126
+ software.
127
+
128
+ 6. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
129
+ IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
130
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
131
+ PURPOSE.
data/Rakefile ADDED
@@ -0,0 +1,28 @@
1
+ # -*- ruby -*-
2
+
3
+ require 'rubygems'
4
+ require 'hoe'
5
+ require './lib/ruby-rapleaf.rb'
6
+
7
+ Hoe.new('ruby-rapleaf', Rapleaf::VERSION) do |p|
8
+ p.rubyforge_name = 'ruby-rapleaf' # if different than lowercase project name
9
+ p.developer('Glenn Rempe', 'glenn@rempe.us')
10
+ p.extra_deps = [['xml-simple', '>= 1.0.11'], ['builder', '>= 2.1.2']]
11
+ end
12
+
13
+ namespace :manifest do
14
+ desc 'Recreate Manifest.txt to include ALL files'
15
+ task :refresh do
16
+ `rake check_manifest | patch -p0 > Manifest.txt`
17
+ end
18
+ end
19
+
20
+ namespace :gemspec do
21
+ desc 'Refresh the gemspec file'
22
+ task :refresh do
23
+ `rake debug_gem > ruby-rapleaf.gemspec`
24
+ # remove the first line from the file which is an artifact of the gemspec generation
25
+ `perl -pi -e '$_ = "" if ($. == 1);' ruby-rapleaf.gemspec`
26
+ end
27
+ end
28
+
@@ -0,0 +1,65 @@
1
+ require 'rubygems'
2
+ require File.dirname(__FILE__) + '/../lib/ruby-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
+
@@ -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
+
@@ -0,0 +1,23 @@
1
+ require 'base64'
2
+ require 'cgi'
3
+ require 'openssl'
4
+ require 'digest/sha1'
5
+ require 'net/http'
6
+ require 'builder'
7
+ require 'ostruct'
8
+
9
+ require 'rapleaf/rapleaf.rb'
10
+ require 'rapleaf/exceptions.rb'
11
+ require 'rapleaf/responses.rb'
12
+
13
+ module Rapleaf
14
+
15
+ VERSION = '0.1.5'
16
+
17
+ # API Constants
18
+ API_HOST = 'api.rapleaf.com'
19
+ API_PORT = 80
20
+ API_VERSION = 'v2'
21
+
22
+ end
23
+
@@ -0,0 +1,38 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = %q{ruby-rapleaf}
3
+ s.version = "0.1.5"
4
+
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{2008-08-27}
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"]
10
+ s.extra_rdoc_files = ["History.txt", "Manifest.txt", "README.txt"]
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
+ s.has_rdoc = true
13
+ s.homepage = %q{http://github.com/grempe/ruby-rapleaf}
14
+ s.rdoc_options = ["--main", "README.txt"]
15
+ s.require_paths = ["lib"]
16
+ s.rubyforge_project = %q{ruby-rapleaf}
17
+ s.rubygems_version = %q{1.2.0}
18
+ s.summary = %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}
19
+
20
+ if s.respond_to? :specification_version then
21
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
22
+ s.specification_version = 2
23
+
24
+ if current_version >= 3 then
25
+ s.add_runtime_dependency(%q<xml-simple>, [">= 1.0.11"])
26
+ s.add_runtime_dependency(%q<builder>, [">= 2.1.2"])
27
+ s.add_development_dependency(%q<hoe>, [">= 1.7.0"])
28
+ else
29
+ s.add_dependency(%q<xml-simple>, [">= 1.0.11"])
30
+ s.add_dependency(%q<builder>, [">= 2.1.2"])
31
+ s.add_dependency(%q<hoe>, [">= 1.7.0"])
32
+ end
33
+ else
34
+ s.add_dependency(%q<xml-simple>, [">= 1.0.11"])
35
+ s.add_dependency(%q<builder>, [">= 2.1.2"])
36
+ s.add_dependency(%q<hoe>, [">= 1.7.0"])
37
+ end
38
+ end
metadata ADDED
@@ -0,0 +1,92 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: grempe-ruby-rapleaf
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.5
5
+ platform: ruby
6
+ authors:
7
+ - Glenn Rempe
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-08-27 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: 1.0.11
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: 2.1.2
32
+ version:
33
+ - !ruby/object:Gem::Dependency
34
+ name: hoe
35
+ version_requirement:
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 1.7.0
41
+ version:
42
+ 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.
43
+ email:
44
+ - glenn@rempe.us
45
+ executables: []
46
+
47
+ extensions: []
48
+
49
+ extra_rdoc_files:
50
+ - History.txt
51
+ - Manifest.txt
52
+ - README.txt
53
+ files:
54
+ - History.txt
55
+ - Manifest.txt
56
+ - README.txt
57
+ - Rakefile
58
+ - examples/person.rb
59
+ - lib/ruby-rapleaf.rb
60
+ - lib/rapleaf/exceptions.rb
61
+ - lib/rapleaf/rapleaf.rb
62
+ - lib/rapleaf/responses.rb
63
+ - ruby-rapleaf.gemspec
64
+ has_rdoc: true
65
+ homepage: http://github.com/grempe/ruby-rapleaf
66
+ post_install_message:
67
+ rdoc_options:
68
+ - --main
69
+ - README.txt
70
+ require_paths:
71
+ - lib
72
+ required_ruby_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: "0"
77
+ version:
78
+ required_rubygems_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: "0"
83
+ version:
84
+ requirements: []
85
+
86
+ rubyforge_project: ruby-rapleaf
87
+ rubygems_version: 1.2.0
88
+ signing_key:
89
+ specification_version: 2
90
+ 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
91
+ test_files: []
92
+