rapleaf_api 0.1.5 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG ADDED
@@ -0,0 +1,7 @@
1
+ v1.2.0 Bump version number to match User-Agent
2
+
3
+ v0.1.1. Bug fixes
4
+
5
+ v0.1.0. Added support for show_available
6
+
7
+ v0.0.1. Initial version
data/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ * The Rapleaf Personalization API has separate terms and conditions, which can
2
+ be found at http://www.rapleaf.com/developers/api_usage.
3
+ * If you send us code, please keep in mind that it will be distributed under
4
+ the same license as the rest of the project.
5
+ * This code is licensed under the Apache License which follows...
6
+
7
+ Copyright 2011 Rapleaf
8
+
9
+ Licensed under the Apache License, Version 2.0 (the "License");
10
+ you may not use this file except in compliance with the License.
11
+ You may obtain a copy of the License at
12
+
13
+ http://www.apache.org/licenses/LICENSE-2.0
14
+
15
+ Unless required by applicable law or agreed to in writing, software
16
+ distributed under the License is distributed on an "AS IS" BASIS,
17
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
+ See the License for the specific language governing permissions and
19
+ limitations under the License.
data/Manifest ADDED
@@ -0,0 +1,7 @@
1
+ CHANGELOG
2
+ LICENSE
3
+ Manifest
4
+ README.md
5
+ Rakefile
6
+ lib/rapleaf_api.rb
7
+ rapleaf_api.gemspec
data/README.md CHANGED
@@ -1,51 +1,72 @@
1
- # rapleaf_api
2
-
3
- Getting Started
4
- ---------------
5
-
6
- You need to first get an API key found here:
7
-
8
- [http://www.rapleaf.com/developer/](http://www.rapleaf.com/developer/)
9
-
1
+ How to Use
2
+ ==========
10
3
 
11
4
  Installation
12
5
  ------------
6
+ > gem install rapleaf_api
13
7
 
14
- sudo gem install rapleaf_api
8
+ This gem depends on the "json" gem.
15
9
 
16
10
  Usage
17
11
  -----
12
+ > require 'rapleaf_api'
13
+ => true
14
+ > api = RapleafApi::Api.new('my secret API key')
15
+ => #<RapleafApi::Api:0x101b7f5f0 @API_KEY="my secret API key", @CA_PATH=nil, @TIMEOUT=2, @BASE_PATH="/v4/dr?api_key=my secret API key">
16
+ > h = api.query_by_email('test@example.com')
17
+ => {"location"=>"Fakesville, California, United States", "gender"=>"Male", "age"=>"25-34"}
18
+
19
+ Constructor Options
20
+ -------------------
21
+ You can pass in an options hash to the API constructor, like so:
22
+
23
+ > api = RapleafApi::Api.new('my secret API key', :timeout => 10)
24
+ => #<RapleafApi::Api:0x101b7f5f0 @API_KEY="my secret API key", @CA_PATH=nil, @TIMEOUT=10, @BASE_PATH="/v4/dr?api_key=my secret API key">
25
+
26
+ The possible options/keys accepted by the constructor are:
27
+
28
+ - :timeout => The max amount of time to wait for a request to finish. Defaults to 2.
29
+ - :ca_path => Set this to your system-wide root CA cert path if you're having SSL verification issues. Defaults to nil.
30
+
31
+ Query Options
32
+ -------------
33
+ The gem supports several ways to query Rapleaf's API: email, hashed email (either MD5 or SHA1 hash), name and postal (NAP), or name and ZIP+4 (NAZ).
34
+
35
+ ### query_by_email(email, options)
36
+
37
+ This method queries Rapleaf's API with the specified email. The options hash accepts the following keys:
38
+
39
+ - :hash_email => Whether to (SHA1) hash the email before querying Rapleaf's API with it. Defaults to nil.
40
+ - :show_availble => Controls whether the response will include information about available data---i.e., data for fields the API account is not subscribed to but for which Rapleaf has data. If this option is turned on, fields will be filled in with the string "Data Available". Defaults to nil.
41
+
42
+ ### query_by_md5(md5_email, options)
43
+ ### query_by_sha1(sha1_email, options)
44
+
45
+ These methods query Rapleaf's API with the specified email hashes (either MD5 or SHA1, respectively). Both methods accept an options hash with the following keys:
18
46
 
19
- require 'rubygems'
20
- require 'rapleaf_api'
47
+ - :show_available => Controls whether the response will include information about available data. Defaults to nil.
48
+
49
+ ### query_by_nap(first, last, street, city, state, options)
21
50
 
22
- rapAPI = RapleafApi::Api.new("your api key")
23
-
24
- ### Person API
51
+ This method queries Rapleaf's API with a name and postal address: first name, last name, street, city, and state acronym (i.e., the state's 2-character postal code). It also accepts the following options hash:
25
52
 
26
- #by email
27
- person = rapAPI.query({:type => :person, {:email => "email"}})
53
+ - :email => You can include an email in your NAP query to increase the hit rate. Defaults to nil.
54
+ - :show_available => Controls whether the response will include information about available data. Defaults to nil.
28
55
 
29
- #by md5 hash of email
30
- person = rapAPI.query({:type => :person, {:hash => RapleafApi::MD5, :id => "md5 hash of email"}})
56
+ ### query_by_naz(first, last, zip4, options)
31
57
 
32
- #by site id
33
- person = rapAPI.query({:type => :person, {:site => RapleafApi::TWITTER, :id => "twitter username"}})
58
+ This method queries Rapleaf's API with a name and ZIP+4 code. The ZIP+4 is a string with a 5-digit ZIP code and 4-digit extension separated by a dash. This method accepts the following options:
34
59
 
35
- ### Graph API
60
+ - :email => You can include an email in your NAP query to increase the hit rate. Defaults to nil.
61
+ - :show_available => Controls whether the response will include information about available data. Defaults to nil.
36
62
 
37
- #by email (note this query will only work if you have an email set stored with Rapleaf)
38
- friendList = rapAPI.query({:type => :graph, {:id => "email address"}})
39
63
 
40
- #by email, return Rapleaf IDs instead of scoped emails
41
- friendList = rapAPI.query({:type => :graph, {:id => "email address", :return_rapid => true}})
64
+ Contributing
65
+ ============
66
+ If you have suggestions or patches, feel free to email us at
67
+ <developer at rapleaf dot com>. We look forward to hearing from you!
42
68
 
43
- #by Rapleaf ID, this will return a list of Rapleaf IDs
44
- friendList = rapAPI.query({:type => :graph, {:id => "rapleaf id", :by_rapid => true}})
45
-
46
- Authors
47
- -------
48
69
 
49
- * [Adam Coffman](http://github.com/thecoffman) :: coffman.adam@gmail.com
50
- * [Brent Beer](http://github.com/brntbeer) :: brentbeer@gmail.com
51
- * [Mark Sands](http://github.com/marksands) :: marksands07@gmail.com
70
+ Contributors
71
+ ============
72
+ Greg Poulos <greg at rapleaf dot com>
data/Rakefile ADDED
@@ -0,0 +1,13 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'echoe'
4
+
5
+ Echoe.new('rapleaf_api', '1.2.0') do |p|
6
+ p.author = 'Rapleaf'
7
+ p.description = "A library for interacting with Rapleaf's Personalization API."
8
+ p.email = 'developer @nospam@ rapleaf.com'
9
+ p.url = 'http://www.rapleaf.com'
10
+ p.ignore_pattern = ["tmp/*"]
11
+ p.development_dependencies = ['echoe']
12
+ p.runtime_dependencies = ['json']
13
+ end
data/lib/rapleaf_api.rb CHANGED
@@ -1,29 +1,134 @@
1
- require 'rubygems'
2
- require 'net/http'
3
- require 'xmlsimple'
1
+ # Copyright 2010 Rapleaf
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
4
14
 
5
- %w{api.rb person.rb graph.rb errors.rb}.each do |file|
6
- require File.dirname(__FILE__) +"/api/" + file
7
- end
8
-
9
- module RapleafApi
15
+ require "rubygems"
16
+ require "json"
17
+ require "net/https"
18
+ require "timeout"
19
+ require "erb"
20
+ require "digest"
10
21
 
11
- VERSION = '0.1.0'
22
+ include ERB::Util
12
23
 
13
- #Constants for web queries
14
- BEBO = "bebo"
15
- FACEBOOK = "facebook"
16
- FLICKR = "flickr"
17
- FRIENDSTER = "friendster"
18
- HI5 = "hi5"
19
- LINKEDIN = "linkedin"
20
- MYSPACE = "myspace"
21
- PLAXO = "plaxo"
22
- RAPLEAF = "rapleaf"
23
- TWITTER = "twitter"
24
-
25
- #constants for hash types
26
- MD5 = "md5"
27
- SHA1 = "sha1"
24
+ module RapleafApi
25
+ HOST = "personalize.rapleaf.com"
26
+ PORT = 443
27
+ HEADERS = {'User-Agent' => 'RapleafApi/Ruby/1.2.0'}
28
28
 
29
+ class Api
30
+ def initialize(api_key, options = {})
31
+ @API_KEY = api_key
32
+ @BASE_PATH = "/v4/dr?api_key=#{@API_KEY}"
33
+ @TIMEOUT = options[:timeout] || 2
34
+ @CA_PATH = options[:ca_path] # set to your system-wide root ca cert path
35
+ # if you're having ssl verification issues
36
+ end
37
+
38
+ # Takes an e-mail and returns a hash which maps attribute fields onto attributes
39
+ # Options:
40
+ # :hash_email - the email will be hashed before it's sent to Rapleaf
41
+ # :show_available - return the string "Data Available" for fields the API
42
+ # account is not subscribed to but for which Rapleaf has data
43
+ def query_by_email(email, options = {})
44
+ if options[:hash_email]
45
+ query_by_sha1(Digest::SHA1.hexdigest(email), :show_available => options[:show_available])
46
+ else
47
+ get_json_response("#{@BASE_PATH}&email=#{url_encode(email)}", options[:show_available])
48
+ end
49
+ end
50
+
51
+ # Takes an e-mail that has already been hashed by md5
52
+ # and returns a hash which maps attribute fields onto attributes,
53
+ # optionally showing available data in the response
54
+ def query_by_md5(md5_email, options = {})
55
+ get_json_response("#{@BASE_PATH}&md5_email=#{url_encode(md5_email)}", options[:show_available])
56
+ end
57
+
58
+ # Takes an e-mail that has already been hashed by sha1
59
+ # and returns a hash which maps attribute fields onto attributes,
60
+ # optionally showing available data in the response
61
+ def query_by_sha1(sha1_email, options = {})
62
+ get_json_response("#{@BASE_PATH}&sha1_email=#{url_encode(sha1_email)}", options[:show_available])
63
+ end
64
+
65
+ # Takes first name, last name, and postal (street, city, and state acronym),
66
+ # and returns a hash which maps attribute fields onto attributes
67
+ # Options:
68
+ # :email - query with an email to increase the hit rate
69
+ # :show_available - return the string "Data Available" for fields
70
+ # the API account is not subscribed to but for
71
+ # which Rapleaf has data
72
+ def query_by_nap(first, last, street, city, state, options = {})
73
+ if options[:email]
74
+ url = "#{@BASE_PATH}&email=#{url_encode(options[:email])}&first=#{url_encode(first)}&last=#{url_encode(last)}" +
75
+ "&street=#{url_encode(street)}&city=#{url_encode(city)}&state=#{url_encode(state)}"
76
+ else
77
+ url = "#{@BASE_PATH}&first=#{url_encode(first)}&last=#{url_encode(last)}" +
78
+ "&street=#{url_encode(street)}&city=#{url_encode(city)}&state=#{url_encode(state)}"
79
+ end
80
+ get_json_response(url, options[:show_available])
81
+ end
82
+
83
+ # Takes first name, last name, and zip4 code (5-digit zip
84
+ # and 4-digit extension separated by a dash as a string),
85
+ # and returns a hash which maps attribute fields onto attributes
86
+ # Options:
87
+ # :email - query with an email to increase the hit rate
88
+ # :show_available - return the string "Data Available" for fields
89
+ # the API account is not subscribed to but for
90
+ # which Rapleaf has data
91
+ def query_by_naz(first, last, zip4, options = {})
92
+ if options[:email]
93
+ url = "#{@BASE_PATH}&email=#{url_encode(options[:email])}&first=#{url_encode(first)}&last=#{url_encode(last)}&zip4=#{zip4}"
94
+ else
95
+ url = "#{@BASE_PATH}&first=#{url_encode(first)}&last=#{url_encode(last)}&zip4=#{zip4}"
96
+ end
97
+ get_json_response(url, options[:show_available])
98
+ end
99
+
100
+ private
101
+
102
+ # Takes a url and returns a hash mapping attribute fields onto attributes
103
+ # Note that an exception is raised in the case that
104
+ # an HTTP response code other than 200 is sent back
105
+ # The error code and error body are put in the exception's message
106
+ def get_json_response(path, show_available = false)
107
+ path += "&show_available" if show_available
108
+ response = Timeout::timeout(@TIMEOUT) do
109
+ begin
110
+ http_client.get(path, HEADERS)
111
+ rescue EOFError # Connection cut out. Just try a second time.
112
+ http_client.get(path, HEADERS)
113
+ end
114
+ end
115
+ if response.code =~ /^2\d\d/
116
+ (response.body && response.body != "") ? JSON.parse(response.body) : {}
117
+ else
118
+ raise "Error Code #{response.code}: \"#{response.body}\""
119
+ end
120
+ end
121
+
122
+ # Returns http connection to HOST on PORT
123
+ def http_client
124
+ unless defined?(@@http_client)
125
+ @@http_client = Net::HTTP.new(HOST, PORT)
126
+ @@http_client.use_ssl = true
127
+ @@http_client.ca_path = @CA_PATH if @CA_PATH
128
+ @@http_client.verify_mode = OpenSSL::SSL::VERIFY_PEER
129
+ @@http_client.start
130
+ end
131
+ @@http_client
132
+ end
133
+ end
29
134
  end
@@ -0,0 +1,35 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{rapleaf_api}
5
+ s.version = "1.2.0"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Rapleaf"]
9
+ s.date = %q{2011-03-11}
10
+ s.description = %q{A library for interacting with Rapleaf's Personalization API.}
11
+ s.email = %q{developer @nospam@ rapleaf.com}
12
+ s.extra_rdoc_files = ["CHANGELOG", "LICENSE", "README.md", "lib/rapleaf_api.rb"]
13
+ s.files = ["CHANGELOG", "LICENSE", "Manifest", "README.md", "Rakefile", "lib/rapleaf_api.rb", "rapleaf_api.gemspec"]
14
+ s.homepage = %q{http://www.rapleaf.com}
15
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Rapleaf_api", "--main", "README.md"]
16
+ s.require_paths = ["lib"]
17
+ s.rubyforge_project = %q{rapleaf_api}
18
+ s.rubygems_version = %q{1.6.2}
19
+ s.summary = %q{A library for interacting with Rapleaf's Personalization API.}
20
+
21
+ if s.respond_to? :specification_version then
22
+ s.specification_version = 3
23
+
24
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
25
+ s.add_runtime_dependency(%q<json>, [">= 0"])
26
+ s.add_development_dependency(%q<echoe>, [">= 0"])
27
+ else
28
+ s.add_dependency(%q<json>, [">= 0"])
29
+ s.add_dependency(%q<echoe>, [">= 0"])
30
+ end
31
+ else
32
+ s.add_dependency(%q<json>, [">= 0"])
33
+ s.add_dependency(%q<echoe>, [">= 0"])
34
+ end
35
+ end
metadata CHANGED
@@ -1,75 +1,109 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rapleaf_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ hash: 31
5
+ prerelease:
6
+ segments:
7
+ - 1
8
+ - 2
9
+ - 0
10
+ version: 1.2.0
5
11
  platform: ruby
6
12
  authors:
7
- - Adam Coffman
8
- - Brent Beer
9
- - Mark Sands
13
+ - Rapleaf
10
14
  autorequire:
11
15
  bindir: bin
12
16
  cert_chain: []
13
17
 
14
- date: 2010-02-12 00:00:00 -06:00
18
+ date: 2011-03-11 00:00:00 -08:00
15
19
  default_executable:
16
20
  dependencies:
17
21
  - !ruby/object:Gem::Dependency
18
- name: xml-simple
22
+ name: json
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
19
33
  type: :runtime
20
- version_requirement:
21
- version_requirements: !ruby/object:Gem::Requirement
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: echoe
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
22
40
  requirements:
23
41
  - - ">="
24
42
  - !ruby/object:Gem::Version
43
+ hash: 3
44
+ segments:
45
+ - 0
25
46
  version: "0"
26
- version:
27
- description: An interface to Rapleaf's person and graph APIs. Note that this library is not maintained by or affiliated with Rapleaf in any way and you will still need a (free) api key from Rapleaf to use this.
28
- email:
29
- - coffman.adam@gmail.com
30
- - brent.beer@gmail.com
31
- - marksands07@gmail.com
47
+ type: :development
48
+ version_requirements: *id002
49
+ description: A library for interacting with Rapleaf's Personalization API.
50
+ email: developer @nospam@ rapleaf.com
32
51
  executables: []
33
52
 
34
53
  extensions: []
35
54
 
36
- extra_rdoc_files: []
37
-
55
+ extra_rdoc_files:
56
+ - CHANGELOG
57
+ - LICENSE
58
+ - README.md
59
+ - lib/rapleaf_api.rb
38
60
  files:
61
+ - CHANGELOG
62
+ - LICENSE
63
+ - Manifest
39
64
  - README.md
40
- - Manifest.txt
65
+ - Rakefile
41
66
  - lib/rapleaf_api.rb
42
- - lib/api/api.rb
43
- - lib/api/graph.rb
44
- - lib/api/person.rb
45
- - lib/api/errors.rb
67
+ - rapleaf_api.gemspec
46
68
  has_rdoc: true
47
- homepage: http://github.com/thecoffman/rapleaf_api
69
+ homepage: http://www.rapleaf.com
48
70
  licenses: []
49
71
 
50
72
  post_install_message:
51
- rdoc_options: []
52
-
73
+ rdoc_options:
74
+ - --line-numbers
75
+ - --inline-source
76
+ - --title
77
+ - Rapleaf_api
78
+ - --main
79
+ - README.md
53
80
  require_paths:
54
81
  - lib
55
82
  required_ruby_version: !ruby/object:Gem::Requirement
83
+ none: false
56
84
  requirements:
57
85
  - - ">="
58
86
  - !ruby/object:Gem::Version
87
+ hash: 3
88
+ segments:
89
+ - 0
59
90
  version: "0"
60
- version:
61
91
  required_rubygems_version: !ruby/object:Gem::Requirement
92
+ none: false
62
93
  requirements:
63
94
  - - ">="
64
95
  - !ruby/object:Gem::Version
65
- version: "0"
66
- version:
96
+ hash: 11
97
+ segments:
98
+ - 1
99
+ - 2
100
+ version: "1.2"
67
101
  requirements: []
68
102
 
69
- rubyforge_project:
70
- rubygems_version: 1.3.5
103
+ rubyforge_project: rapleaf_api
104
+ rubygems_version: 1.6.2
71
105
  signing_key:
72
106
  specification_version: 3
73
- summary: An interface to Rapleaf's person and graph APIs.
107
+ summary: A library for interacting with Rapleaf's Personalization API.
74
108
  test_files: []
75
109
 
data/Manifest.txt DELETED
@@ -1,8 +0,0 @@
1
- Manifest.txt
2
- README.txt
3
- Rakefile
4
- lib/rapleaf_api.rb
5
- lib/api/api.rb
6
- lib/api/graph.rb
7
- lib/api/person.rb
8
- lib/api/errors.rb
data/lib/api/api.rb DELETED
@@ -1,85 +0,0 @@
1
- module RapleafApi
2
- class Api
3
-
4
- def initialize(api_key)
5
- @API_KEY = "?api_key=#{api_key}"
6
- @PERSON_URL = "http://api.rapleaf.com/v3/person/"
7
- @GRAPH_URL = "http://api.rapleaf.com/v2/graph/"
8
- end
9
-
10
- def query(params)
11
- raise InvalidParams, "Invalid query, please use an :opts hash to specify your options" unless !params[:opts].nil?
12
- case params[:type]
13
- when :person
14
- return Person.new(person_request(params[:opts]))
15
- when :graph
16
- return Graph.new(graph_request(params[:opts]))
17
- else
18
- raise InvalidParams, "Invalid query type, use either :graph or :person"
19
- end
20
- end
21
-
22
- private
23
-
24
- def request(url)
25
- resp = Net::HTTP.get_response(URI.parse(url))
26
- if resp.code == "200"
27
- return resp.body
28
- else
29
- raise_response_errors(resp.code)
30
- end
31
- end
32
-
33
- def person_request(params)
34
- raise InvalidParams, "Your params hash was formatted incorrectly!" unless url = verify_and_build_person_url(params)
35
- request(url)
36
- end
37
-
38
- def graph_request(params)
39
- raise InvalidParams, "Your params hash was formatted incorrectly!" unless url = verify_and_build_graph_url(params)
40
- request(url)
41
- end
42
-
43
- def verify_and_build_person_url(params)
44
- if params.size == 1
45
- return false unless params[:email]
46
- return @PERSON_URL + "email/#{params[:email]}" + @API_KEY
47
- else
48
- return false unless params[:id] && (params[:hash] || params[:site])
49
- return @PERSON_URL + (!params[:hash].nil? ? "hash/#{params[:hash]}/#{params[:id]}" : "web/#{params[:site]}/#{params[:id]}") + @API_KEY
50
- end
51
- end
52
-
53
- def verify_and_build_graph_url(params)
54
- if params.size == 1
55
- return false unless params[:id]
56
- return @GRAPH_URL + params[:id] + @API_KEY
57
- elsif params.size == 2
58
- return false unless params[:id] && (params[:by_rapid] || params[:return_rapid])
59
- return @GRAPH_URL + params[:id] + @API_KEY + "&" + ( !params[:by_rapid].nil? ? "n=2" : "n=1")
60
- else
61
- return false
62
- end
63
- end
64
-
65
- def raise_response_errors(code)
66
- case code
67
- when "202"
68
- raise AcceptedException, "This person is currently being searched. Please check back shortly."
69
- when "400"
70
- raise MalformedRequestException, "Malformed request."
71
- when "401"
72
- raise ApiKeyInvalidException, "API Key invalid"
73
- when "403"
74
- raise RateLimitExceededException, "API Key query limit exceded, please contact developer@rapleaf.com to have your limit increased."
75
- when "404"
76
- raise PersonNotFoundException, "We do not have this person in our system. If you would like better results, consider supplying the email address."
77
- when "500"
78
- 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."
79
- else
80
- raise "Unkown Error"
81
- end
82
- end
83
-
84
- end
85
- end
data/lib/api/errors.rb DELETED
@@ -1,26 +0,0 @@
1
- module RapleafApi
2
-
3
- class InvalidParams < Exception
4
- end
5
-
6
- class AcceptedException < Exception
7
- end
8
-
9
- class MalformedRequestException < Exception
10
- end
11
-
12
- class ApiKeyInvalidException < Exception
13
- end
14
-
15
- class RateLimitExceededException < Exception
16
- end
17
-
18
- class PersonNotFoundException < Exception
19
- end
20
-
21
- class InternalServerError < Exception
22
- end
23
-
24
- end
25
-
26
-
data/lib/api/graph.rb DELETED
@@ -1,17 +0,0 @@
1
- module RapleafApi
2
- class Graph
3
-
4
- def initialize( body )
5
- @body = body
6
- end
7
-
8
- def friends
9
- if @body.include?(",")
10
- @body.split(",")
11
- else
12
- @body.split("\n")
13
- end
14
- end
15
-
16
- end
17
- end
data/lib/api/person.rb DELETED
@@ -1,72 +0,0 @@
1
- module RapleafApi
2
-
3
- class Person
4
-
5
- def initialize(xml)
6
- @xml = XmlSimple.xml_in(xml, {'ForceArray' => false,
7
- 'GroupTags' =>{'primary' => 'membership',
8
- 'supplemental' => 'membership',
9
- 'universities' => 'university',
10
- 'occupations' =>'occupation'}})
11
- end
12
-
13
- def rapleaf_id
14
- @xml["id"]
15
- end
16
-
17
- def basics
18
- @xml["basics"]
19
- end
20
-
21
- def name
22
- @xml["basics"]["name"]
23
- end
24
-
25
- def age
26
- @xml["basics"]["age"]
27
- end
28
-
29
- def gender
30
- @xml["basics"]["gender"]
31
- end
32
-
33
- def location
34
- @xml["basics"]["location"]
35
- end
36
-
37
- def occupations
38
- @xml["basics"]["occupations"]
39
- end
40
-
41
- def universities
42
- @xml["basics"]["universities"]
43
- end
44
-
45
- def earliest_known_activity
46
- @xml["basics"]["earliest_known_activity"]
47
- end
48
-
49
- def last_known_activity
50
- @xml["basics"]["latest_known_activity"]
51
- end
52
-
53
- def num_friends
54
- @xml["basics"]["num_friends"]
55
- end
56
-
57
- def memberships(selection = :all)
58
- if selection == :primary || selection == :all
59
- memberships = (@xml["memberships"]["primary"])
60
- end
61
- if selection == :supplemental || selection == :all
62
- if memberships.nil?
63
- memberships = (@xml["memberships"]["supplemental"])
64
- else
65
- memberships << (@xml["memberships"]["supplemental"])
66
- end
67
- end
68
- memberships.compact
69
- end
70
- end
71
-
72
- end