Class: LinkedIn::Client
Instance Attribute Summary collapse
Instance Method Summary
collapse
#access_token, #authorize_from_access, #authorize_from_request, #consumer, #request_token, #set_callback_url
#delete, #get, #post, #put, #raise_errors, #to_query, #to_uri
Constructor Details
#initialize(ctoken = LinkedIn.token, csecret = LinkedIn.secret, options = {}) ⇒ Client
Returns a new instance of Client.
9
10
11
12
13
14
15
16
|
# File 'lib/linked_in/client.rb', line 9
def initialize(ctoken=LinkedIn.token, csecret=LinkedIn.secret, options={})
opts = {
:request_token_path => "/uas/oauth/requestToken",
:access_token_path => "/uas/oauth/accessToken",
:authorize_path => "/uas/oauth/authorize"
}
@ctoken, @csecret, @consumer_options = ctoken, csecret, opts.merge(options)
end
|
Instance Attribute Details
#consumer_options ⇒ Object
Returns the value of attribute consumer_options.
7
8
9
|
# File 'lib/linked_in/client.rb', line 7
def consumer_options
@consumer_options
end
|
#csecret ⇒ Object
Returns the value of attribute csecret.
7
8
9
|
# File 'lib/linked_in/client.rb', line 7
def csecret
@csecret
end
|
#ctoken ⇒ Object
Returns the value of attribute ctoken.
7
8
9
|
# File 'lib/linked_in/client.rb', line 7
def ctoken
@ctoken
end
|
Instance Method Details
#clear_status ⇒ Object
97
98
99
100
|
# File 'lib/linked_in/client.rb', line 97
def clear_status
path = "/people/~/current-status"
delete(path).code
end
|
#company_search(options = {}) ⇒ Object
53
54
55
56
57
58
59
|
# File 'lib/linked_in/client.rb', line 53
def company_search(options={})
path = "/company-search:(facets,companies:(id,name,website-url,logo-url,employee-count-range,twitter-id,founded-year))"
options = { :keywords => options } if options.is_a?(String)
options = format_options_for_query(options)
CompanySearch.from_xml(get(to_uri(path, options)))
end
|
#connections(options = {}) ⇒ Object
32
33
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/linked_in/client.rb', line 32
def connections(options={})
path = "#{person_path(options)}/connections"
fields = options[:fields] || LinkedIn.default_profile_fields
if options[:public]
path +=":public"
elsif fields
path +=":(#{fields.map{ |f| f.to_s.gsub("_","-") }.join(',')})"
end
Connections.from_xml(get(path)).profiles
end
|
#current_status ⇒ Object
61
62
63
64
|
# File 'lib/linked_in/client.rb', line 61
def current_status
path = "/people/~/current-status"
Nokogiri::XML(get(path)).xpath('//current-status').text
end
|
139
140
141
142
143
144
145
146
147
|
# File 'lib/linked_in/client.rb', line 139
def format_options_for_query(opts)
opts.keys.each do |key|
value = opts.delete(key)
value = value.join("+") if value.is_a?(Array)
value = value.gsub(" ", "+") if value.is_a?(String)
opts[key.to_s.gsub("_","-")] = value
end
opts
end
|
#like(network_key, is_liked = true) ⇒ Object
82
83
84
85
|
# File 'lib/linked_in/client.rb', line 82
def like(network_key, is_liked=true)
path = "/people/~/network/updates/key=#{network_key}/is-liked"
put(path, is_liked_to_xml(is_liked))
end
|
#likes(network_key) ⇒ Object
87
88
89
90
|
# File 'lib/linked_in/client.rb', line 87
def likes(network_key)
path = "/people/~/network/updates/key=#{network_key}/likes"
Likes.from_xml(get(path)).likes
end
|
#network_statuses(options = {}) ⇒ Object
121
122
123
124
|
# File 'lib/linked_in/client.rb', line 121
def network_statuses(options={})
options[:type] = 'STAT'
network_updates(options)
end
|
#network_updates(options = {}) ⇒ Object
126
127
128
129
|
# File 'lib/linked_in/client.rb', line 126
def network_updates(options={})
path = "/people/~/network"
Network.from_xml(get(to_uri(path, options)))
end
|
#person_path(options) ⇒ Object
149
150
151
152
153
154
155
156
157
158
|
# File 'lib/linked_in/client.rb', line 149
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
|
#profile(options = {}) ⇒ Object
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/linked_in/client.rb', line 19
def profile(options={})
path = person_path(options)
fields = options[:fields] || LinkedIn.default_profile_fields
if options[:public]
path +=":public"
elsif fields
path +=":(#{fields.map{ |f| f.to_s.gsub("_","-") }.join(',')})"
end
Profile.from_xml(get(path))
end
|
#search(options = {}) ⇒ Object
45
46
47
48
49
50
51
|
# File 'lib/linked_in/client.rb', line 45
def search(options={})
path = "/people"
options = { :keywords => options } if options.is_a?(String)
options = format_options_for_query(options)
People.from_xml(get(to_uri(path, options)))
end
|
#send_message(subject, body, recipient_paths) ⇒ Object
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
|
# File 'lib/linked_in/client.rb', line 102
def send_message(subject, body, recipient_paths)
path = "/people/~/mailbox"
message = LinkedIn::Message.new
message.subject = subject
message.body = body
recipients = LinkedIn::Recipients.new
recipients.recipients = recipient_paths.map do |profile_path|
recipient = LinkedIn::Recipient.new
recipient.person = LinkedIn::Person.new
recipient.person.path = "/people/#{profile_path}"
recipient
end
message.recipients = recipients
post(path, message_to_xml(message)).code
end
|
#share(options = {}) ⇒ Object
71
72
73
74
75
|
# File 'lib/linked_in/client.rb', line 71
def share(options={})
path = "/people/~/shares"
defaults = { :visability => 'anyone' }
post(path, share_to_xml(defaults.merge(options)))
end
|
77
78
79
80
|
# File 'lib/linked_in/client.rb', line 77
def (network_key, )
path = "/people/~/network/updates/key=#{network_key}/update-comments"
post(path, ())
end
|
#update_network(message) ⇒ Object
92
93
94
95
|
# File 'lib/linked_in/client.rb', line 92
def update_network(message)
path = "/people/~/person-activities"
post(path, network_update_to_xml(message))
end
|
#update_status(text) ⇒ Object
66
67
68
69
|
# File 'lib/linked_in/client.rb', line 66
def update_status(text)
path = "/people/~/current-status"
put(path, status_to_xml(text))
end
|
#write_fixture(path, filename) ⇒ Object
helpful in making authenticated calls and writing the raw xml to a fixture file
133
134
135
136
137
|
# File 'lib/linked_in/client.rb', line 133
def write_fixture(path, filename)
file = File.new("test/fixtures/#{filename}", "w")
file.puts(access_token.get(path).body)
file.close
end
|