whit_li 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/Gemfile +8 -0
- data/LICENSE +20 -0
- data/README.markdown +56 -0
- data/Rakefile +1 -0
- data/lib/whit_li.rb +16 -0
- data/lib/whit_li/client.rb +77 -0
- data/lib/whit_li/config.rb +9 -0
- data/lib/whit_li/errors.rb +19 -0
- data/lib/whit_li/mash.rb +11 -0
- data/lib/whit_li/version.rb +3 -0
- data/whit_li.gemspec +27 -0
- metadata +96 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2012 Sergey Efremov
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.markdown
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
# WhitLi
|
2
|
+
|
3
|
+
Ruby wrapper for the [WhitLi API](http://developer.whit.li), provides an easy-to-use wrapper for LinkedIn's Oauth/XML APIs. Originally developed for [ResumUP](http://resumup.com)
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Install via rubygems
|
8
|
+
|
9
|
+
[sudo] gem install whit_li
|
10
|
+
|
11
|
+
Or via bundler:
|
12
|
+
|
13
|
+
gem "whit_li"
|
14
|
+
|
15
|
+
|
16
|
+
## Usage
|
17
|
+
|
18
|
+
### Usage examples
|
19
|
+
|
20
|
+
require 'rubygems'
|
21
|
+
require 'whit_li'
|
22
|
+
|
23
|
+
client = WhitLi::Client.new "api_key_from_whitli"
|
24
|
+
|
25
|
+
# import token from facebook
|
26
|
+
client.import_token facebook_id, facebook_token
|
27
|
+
|
28
|
+
# populate data from facebook to whitli
|
29
|
+
client.populate facebook_id
|
30
|
+
|
31
|
+
# manual import data to whitly
|
32
|
+
client.import_generic request_body
|
33
|
+
|
34
|
+
# retrieve vectors for user by facebook_id and key. More about keys read at http://developer.whit.li/docs/read/How_to_Interpret_a_Whitli_Key
|
35
|
+
vectors = client.get facebook_id, key_id
|
36
|
+
|
37
|
+
# compare users in contexts. More about context read at http://developer.whit.li/docs/read/How_to_Interpret_a_Whitli_Key
|
38
|
+
vectors = client.compare facebook_id_1, facebook_id_2, context_id
|
39
|
+
|
40
|
+
|
41
|
+
|
42
|
+
## TODO
|
43
|
+
|
44
|
+
* Add 146% Test coverage
|
45
|
+
* Add vector parser
|
46
|
+
|
47
|
+
## Note on Patches/Pull Requests
|
48
|
+
|
49
|
+
* Fork the project.
|
50
|
+
* Make your feature addition or bug fix.
|
51
|
+
* Commit, do not mess with rakefile, version, or history.
|
52
|
+
* Send me a pull request. Bonus points for topic branches.
|
53
|
+
|
54
|
+
## Copyright
|
55
|
+
|
56
|
+
See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/lib/whit_li.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
module WhitLi
|
2
|
+
class << self
|
3
|
+
attr_accessor :token
|
4
|
+
|
5
|
+
def configure
|
6
|
+
yield self
|
7
|
+
true
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
autoload :Config, "whit_li/config"
|
12
|
+
autoload :Version, "whit_li/version"
|
13
|
+
autoload :Mash, "whit_li/mash"
|
14
|
+
autoload :Errors, "whit_li/errors"
|
15
|
+
autoload :Client, "whit_li/client"
|
16
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
require 'rest_client'
|
2
|
+
|
3
|
+
module WhitLi
|
4
|
+
class Client
|
5
|
+
|
6
|
+
attr_accessor :api_key
|
7
|
+
|
8
|
+
def initialize api_key
|
9
|
+
@api_key = api_key
|
10
|
+
end
|
11
|
+
|
12
|
+
def import_token fb_id, token
|
13
|
+
api_call "user/importToken", "post", { :uid => fb_id, :oauth_token => token }
|
14
|
+
end
|
15
|
+
|
16
|
+
def populate fb_id
|
17
|
+
api_call "user/populate", "get", { :uid => fb_id }
|
18
|
+
end
|
19
|
+
|
20
|
+
def import_generic request_body
|
21
|
+
api_call "user/importGeneric", "put", { :RequestBody => request_body }
|
22
|
+
end
|
23
|
+
|
24
|
+
def get fb_id, key_id, schema = "fb"
|
25
|
+
api_call "key/get", "get", { :uid => fb_id, :key_id => key_id, :schema => schema }
|
26
|
+
end
|
27
|
+
|
28
|
+
def compare fb_id_1, fb_id_2, context_id, schema = "fb"
|
29
|
+
api_call "key/compare", "get", { :uid1 => fb_id_1, :uid2 => fb_id_2, :context_id => context_id, :schema => schema }
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def raise_response_error response
|
35
|
+
#pending
|
36
|
+
end
|
37
|
+
|
38
|
+
def api_call path, method = "get", params = {}
|
39
|
+
params = params.merge({:api_key => @api_key, :format => WhitLi::Config::FORMAT})
|
40
|
+
begin
|
41
|
+
case method
|
42
|
+
when "get"
|
43
|
+
response = RestClient.get [WhitLi::Config::API_URL, path].join("/"), { :params => params }
|
44
|
+
when "put"
|
45
|
+
response = RestClient.put [WhitLi::Config::API_URL, path].join("/"), params, {:accept => :json}
|
46
|
+
when "post"
|
47
|
+
response = RestClient.post [WhitLi::Config::API_URL, path].join("/"), params, {:accept => :json}
|
48
|
+
else
|
49
|
+
response = RestClient.send method, [WhitLi::Config::API_URL, path].join("/"), { :params => params }
|
50
|
+
end
|
51
|
+
|
52
|
+
rescue => e
|
53
|
+
raise_errors e.response
|
54
|
+
end
|
55
|
+
WhitLi::Mash.from_json response.body
|
56
|
+
end
|
57
|
+
|
58
|
+
def raise_errors response
|
59
|
+
case response.code.to_i
|
60
|
+
when 400
|
61
|
+
data = Mash.from_json(response.body)
|
62
|
+
raise WhitLi::Errors::GeneralError.new(data), "(#{data.status}): #{data.message}"
|
63
|
+
when 403
|
64
|
+
raise WhitLi::Errors::AccessDeniedError, "(#{response.code}): #{response.message}"
|
65
|
+
when 405, 401
|
66
|
+
raise WhitLi::Errors::UnauthorizedError, "(#{response.code}): #{response.message}"
|
67
|
+
when 404
|
68
|
+
raise WhitLi::Errors::NotFoundError, "(#{response.code}): #{response.message}"
|
69
|
+
when 500
|
70
|
+
raise WhitLi::Errors::InformWhitLiError, "WhitLi had an internal error. (#{response.code}): #{response.message}"
|
71
|
+
when 502..503
|
72
|
+
raise WhitLi::Errors::UnavailableError, "(#{response.code}): #{response.message}"
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module WhitLi
|
2
|
+
module Errors
|
3
|
+
class WhitLiError < StandardError
|
4
|
+
attr_reader :data
|
5
|
+
def initialize(data)
|
6
|
+
@data = data
|
7
|
+
super
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
class UnauthorizedError < WhitLiError; end
|
12
|
+
class GeneralError < WhitLiError; end
|
13
|
+
class AccessDeniedError < WhitLiError; end
|
14
|
+
|
15
|
+
class UnavailableError < WhitLiError; end
|
16
|
+
class InformLinkedInError < WhitLiError; end
|
17
|
+
class NotFoundError < WhitLiError; end
|
18
|
+
end
|
19
|
+
end
|
data/lib/whit_li/mash.rb
ADDED
data/whit_li.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "whit_li/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "whit_li"
|
7
|
+
s.version = WhitLi::VERSION
|
8
|
+
s.authors = ["Sergey Efremov"]
|
9
|
+
s.email = ["sergey.efremov@resumup.com"]
|
10
|
+
s.homepage = ""
|
11
|
+
s.summary = "Whit.li Ruby wrapper"
|
12
|
+
s.description = "Whit.li Ruby wrapper"
|
13
|
+
|
14
|
+
s.rubyforge_project = "whit_li"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
# specify any dependencies here; for example:
|
22
|
+
# s.add_development_dependency "rspec"
|
23
|
+
# s.add_runtime_dependency "rest-client"
|
24
|
+
s.add_dependency(%q<multi_json>, [">= 0"])
|
25
|
+
s.add_dependency(%q<hashie>, [">= 0"])
|
26
|
+
s.add_dependency(%q<rest-client>, [">= 0"])
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: whit_li
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Sergey Efremov
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-03-09 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: multi_json
|
16
|
+
requirement: &70303889089240 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70303889089240
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: hashie
|
27
|
+
requirement: &70303889088720 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70303889088720
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: rest-client
|
38
|
+
requirement: &70303889088240 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
type: :runtime
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *70303889088240
|
47
|
+
description: Whit.li Ruby wrapper
|
48
|
+
email:
|
49
|
+
- sergey.efremov@resumup.com
|
50
|
+
executables: []
|
51
|
+
extensions: []
|
52
|
+
extra_rdoc_files: []
|
53
|
+
files:
|
54
|
+
- .gitignore
|
55
|
+
- Gemfile
|
56
|
+
- LICENSE
|
57
|
+
- README.markdown
|
58
|
+
- Rakefile
|
59
|
+
- lib/whit_li.rb
|
60
|
+
- lib/whit_li/client.rb
|
61
|
+
- lib/whit_li/config.rb
|
62
|
+
- lib/whit_li/errors.rb
|
63
|
+
- lib/whit_li/mash.rb
|
64
|
+
- lib/whit_li/version.rb
|
65
|
+
- whit_li.gemspec
|
66
|
+
homepage: ''
|
67
|
+
licenses: []
|
68
|
+
post_install_message:
|
69
|
+
rdoc_options: []
|
70
|
+
require_paths:
|
71
|
+
- lib
|
72
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
segments:
|
79
|
+
- 0
|
80
|
+
hash: 2327776953409311588
|
81
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
82
|
+
none: false
|
83
|
+
requirements:
|
84
|
+
- - ! '>='
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
87
|
+
segments:
|
88
|
+
- 0
|
89
|
+
hash: 2327776953409311588
|
90
|
+
requirements: []
|
91
|
+
rubyforge_project: whit_li
|
92
|
+
rubygems_version: 1.8.10
|
93
|
+
signing_key:
|
94
|
+
specification_version: 3
|
95
|
+
summary: Whit.li Ruby wrapper
|
96
|
+
test_files: []
|