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
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
88
89
90
91
|
# File 'lib/linked_in/client.rb', line 88
def clear_status
path = "/people/~/current-status"
delete(path).code
end
|
#connections(options = {}) ⇒ Object
31
32
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/linked_in/client.rb', line 31
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
52
53
54
55
|
# File 'lib/linked_in/client.rb', line 52
def current_status
path = "/people/~/current-status"
Nokogiri::XML(get(path)).xpath('//current-status').text
end
|
#like(network_key, is_liked = true) ⇒ Object
73
74
75
76
|
# File 'lib/linked_in/client.rb', line 73
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
78
79
80
81
|
# File 'lib/linked_in/client.rb', line 78
def likes(network_key)
path = "/people/~/network/updates/key=#{network_key}/likes"
Likes.from_xml(get(path)).likes
end
|
#network_statuses(options = {}) ⇒ Object
112
113
114
115
|
# File 'lib/linked_in/client.rb', line 112
def network_statuses(options={})
options[:type] = 'STAT'
network_updates(options)
end
|
#network_updates(options = {}) ⇒ Object
117
118
119
120
|
# File 'lib/linked_in/client.rb', line 117
def network_updates(options={})
path = "/people/~/network"
Network.from_xml(get(to_uri(path, options)))
end
|
#profile(options = {}) ⇒ Object
18
19
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/linked_in/client.rb', line 18
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
44
45
46
47
48
49
50
|
# File 'lib/linked_in/client.rb', line 44
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
# File 'lib/linked_in/client.rb', line 93
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
62
63
64
65
66
|
# File 'lib/linked_in/client.rb', line 62
def share(options={})
path = "/people/~/shares"
defaults = { :visability => 'anyone' }
post(path, share_to_xml(defaults.merge(options)))
end
|
68
69
70
71
|
# File 'lib/linked_in/client.rb', line 68
def (network_key, )
path = "/people/~/network/updates/key=#{network_key}/update-comments"
post(path, ())
end
|
#update_network(message) ⇒ Object
83
84
85
86
|
# File 'lib/linked_in/client.rb', line 83
def update_network(message)
path = "/people/~/person-activities"
post(path, network_update_to_xml(message))
end
|
#update_status(text) ⇒ Object
57
58
59
60
|
# File 'lib/linked_in/client.rb', line 57
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
124
125
126
127
128
|
# File 'lib/linked_in/client.rb', line 124
def write_fixture(path, filename)
file = File.new("test/fixtures/#{filename}", "w")
file.puts(access_token.get(path).body)
file.close
end
|