-
Notifications
You must be signed in to change notification settings - Fork 401
Expand file tree
/
Copy pathquery_helpers.rb
More file actions
86 lines (74 loc) · 2.24 KB
/
query_helpers.rb
File metadata and controls
86 lines (74 loc) · 2.24 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
module LinkedIn
module Api
module QueryHelpers
private
def group_path(options)
path = "groups"
if id = options.delete(:id)
path += "/#{id}"
end
end
def simple_query(path, options={})
fields = options.delete(:fields) || LinkedIn.default_profile_fields
if options.delete(:public)
path +=":public"
elsif fields
path +=":(#{build_fields_params(fields)})"
end
headers = options.delete(:headers) || {}
# params = to_query(options)
# path += "#{path.include?("?") ? "&" : "?"}#{params}" if !params.empty?
get(path, options, headers)
end
def build_fields_params(fields)
if fields.is_a?(Hash) && !fields.empty?
fields.map {|index,value| "#{index}:(#{build_fields_params(value)})" }.join(',')
elsif fields.respond_to?(:each)
fields.map {|field| build_fields_params(field) }.join(',')
else
fields.to_s.gsub("_", "-")
end
end
def person_path(options)
path = "people"
if id = options.delete(:id)
path += "/id=#{id}"
elsif url = options.delete(:url)
path += "/url=#{CGI.escape(url)}"
elsif email = options.delete(:email)
path += "::(#{email})"
else
path += "/~"
end
end
def company_path(options)
path = "companies"
if domain = options.delete(:domain)
path += "?email-domain=#{CGI.escape(domain)}"
elsif id = options.delete(:id)
path += "/id=#{id}"
elsif url = options.delete(:url)
path += "/url=#{CGI.escape(url)}"
elsif name = options.delete(:name)
path += "/universal-name=#{CGI.escape(name)}"
elsif is_admin = options.delete(:is_admin)
path += "?is-company-admin=#{CGI.escape(is_admin)}"
else
path += "/~"
end
end
def picture_urls_path(options)
path = person_path(options)
path += "/picture-urls"
end
def jobs_path(options)
path = "jobs"
if id = options.delete(:id)
path += "/id=#{id}"
else
path += "/~"
end
end
end
end
end