peoplegraph 0.0.1 → 0.0.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 82cbabcf6214a65a90bc0ae6abce7d223836ab2d
4
- data.tar.gz: 50f63e2a329f85e7d39d928c80774a2a11a232d8
3
+ metadata.gz: 1375b3ab66907c9ab9b9dc40516d05120090a0e2
4
+ data.tar.gz: cf785efc8febdbcc107c57ca08fbb9993dd39d70
5
5
  SHA512:
6
- metadata.gz: 6422890de68607a735cdcffbd2500b5f0aedebcab365d0212f33bb0c555a76133b8f52f4a8e216af0f382127454fe9e3b11dcfb9c300ce66fd6c245382bdc198
7
- data.tar.gz: 6fef1880ba997e6fc018ad644fe8fd9fe8ce30adad9bf1a5b968eba7f09d1a924110bd7a39551f1293f8af2c49ab396db0439691b96b8189787a73fec338fb6a
6
+ metadata.gz: 487f410c825cd15075a876baeec0c74d16065c5837bd83e0a10d734073cdcbf37317c8940cb6e42a621205974dec270a5cada4a4e16379df5921171b47fd2f49
7
+ data.tar.gz: e22eccc7d86202a22c847c11719b5f8fc4fd626f81615847d0cc8fef60bf2919789c66a0db5d5dd72e48954b9890c252ba23d58076455f4b80d0799ab0531d1b
@@ -0,0 +1,3 @@
1
+ # encoding: utf-8
2
+ require 'peoplegraph/error'
3
+ require 'peoplegraph/client'
@@ -0,0 +1,62 @@
1
+ # encoding: utf-8
2
+
3
+ require 'faraday'
4
+ require 'multi_json'
5
+ require 'ostruct'
6
+ require 'peoplegraph'
7
+
8
+ module PeopleGraph
9
+ class Client
10
+ attr_reader :api_key, :connection
11
+
12
+ def initialize(api_key = ENV['PEOPLEGRAPH_API_KEY'], options = nil)
13
+ @api_key = api_key
14
+ # /lookup?email=razvan@3desk.com&apiKey=hYxSdRmEif0GN7jwlmeQtVQbE3T1kBb1
15
+ url = ENV['PEOPLEGRAPH_API_URL'] || 'https://api.peoplegraph.io'
16
+ block = block_given? ? Proc.new : nil
17
+ @connection = Faraday.new(url, options, &block)
18
+ end
19
+
20
+ def search(email = nil, url = nil, name = nil, company = nil, options = nil)
21
+ profile = lookup(email, url, name, company, options)
22
+ return nil if profile.nil?
23
+ OpenStruct.new(profile)
24
+ end
25
+
26
+ protected
27
+ def lookup(email = nil, url = nil, name = nil, company = nil, options = nil)
28
+ response = connection.get do |request|
29
+ request.url '/v2/lookup'
30
+ request.params['apiKey'] = api_key
31
+ request.params['email'] = email unless email.nil?
32
+ request.params['url'] = url unless url.nil?
33
+ request.params['name'] = name unless name.nil?
34
+ request.params['company'] = company unless company.nil?
35
+ request.headers['accept'] = 'application/json'
36
+ end
37
+
38
+ status = response.status.to_i
39
+ response = MultiJson.decode(response.body)
40
+
41
+ if status == 200
42
+ return response['result']
43
+ elsif status == 202
44
+ error = PeopleGraph::Error::RequestAccepted
45
+ elsif status == 400
46
+ error = PeopleGraph::Error::BadRequest
47
+ elsif status == 401
48
+ error = PeopleGraph::Error::NotAuthorized
49
+ elsif status == 404
50
+ return nil
51
+ elsif status == 429
52
+ error = PeopleGraph::Error::TooManyRequests
53
+ elsif status == 500
54
+ error = PeopleGraph::Error::ServerError
55
+ else
56
+ error = PeopleGraph::Error::UnknownError
57
+ end
58
+
59
+ fail(error, response['message'], caller)
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,23 @@
1
+ # encoding: utf-8
2
+
3
+ module PeopleGraph
4
+ module Error
5
+ class NotAuthorized < StandardError
6
+ end
7
+
8
+ class BadRequest < StandardError
9
+ end
10
+
11
+ class RequestAccepted < StandardError
12
+ end
13
+
14
+ class ServerError < StandardError
15
+ end
16
+
17
+ class TooManyRequests < StandardError
18
+ end
19
+
20
+ class UnknownError < StandardError
21
+ end
22
+ end
23
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: peoplegraph
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stefano Fontanelli
@@ -10,6 +10,46 @@ bindir: bin
10
10
  cert_chain: []
11
11
  date: 2015-05-27 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.9.1
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 0.9.1
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: 0.9.1
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 0.9.1
33
+ - !ruby/object:Gem::Dependency
34
+ name: multi_json
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: 1.11.0
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: 1.11.0
43
+ type: :runtime
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: 1.11.0
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: 1.11.0
13
53
  - !ruby/object:Gem::Dependency
14
54
  name: rake
15
55
  requirement: !ruby/object:Gem::Requirement
@@ -30,7 +70,10 @@ email:
30
70
  executables: []
31
71
  extensions: []
32
72
  extra_rdoc_files: []
33
- files: []
73
+ files:
74
+ - lib/peoplegraph.rb
75
+ - lib/peoplegraph/client.rb
76
+ - lib/peoplegraph/error.rb
34
77
  homepage: https://github.com/stefanofontanelli/peoplegraph
35
78
  licenses: []
36
79
  metadata: {}