forked from gflores/viadeo
/
query_methods.rb
48 lines (40 loc) · 1.15 KB
/
query_methods.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
module Viadeo
module Api
module QueryMethods
def profile(access_token)
simple_query(access_token, "/me", {})
end
def search_user(access_token, args)
args = {} if args.nil?
simple_query(access_token, "/search/users", args)
end
def simple_query(access_token, path, args)
url = "#{DEFAULT_OAUTH_OPTIONS[:api_base]}#{path}?access_token=#{access_token}"
args.each {|key, value| url += "&#{key}=#{CGI.escape(value.to_s)}"}
uri = URI.parse(url)
begin
(1..3).each do
connection = Net::HTTP.new(uri.host, 443)
connection.use_ssl = true
connection.verify_mode = OpenSSL::SSL::VERIFY_NONE
resp = connection.request_get(uri.path + '?' + uri.query)
return Mash.from_json resp.body if resp.code == '200'
end
rescue
puts "Error: #{$!}"
end
return nil
end
def person_path(options)
path = "/people/"
if options[:id]
path += "id=#{options[:id]}"
elsif options[:url]
path += "url=#{CGI.escape(options[:url])}"
else
path += "~"
end
end
end
end
end