Class: LinkedIn::Client
- Inherits:
-
Object
- Object
- LinkedIn::Client
- Defined in:
- lib/linked_in/client.rb
Instance Attribute Summary collapse
-
#consumer_options ⇒ Object
readonly
TODO: @ developer.linkedin.com/docs/DOC-1061 && / DOC-1014 add in client.get(“/people/~:(im-accounts)”) client.get(“/people/~:(twitter-accounts)”) client.get(“/people/~:(date-of-birth)”) client.get(“/people/~:(main-address)”).
-
#csecret ⇒ Object
readonly
TODO: @ developer.linkedin.com/docs/DOC-1061 && / DOC-1014 add in client.get(“/people/~:(im-accounts)”) client.get(“/people/~:(twitter-accounts)”) client.get(“/people/~:(date-of-birth)”) client.get(“/people/~:(main-address)”).
-
#ctoken ⇒ Object
readonly
TODO: @ developer.linkedin.com/docs/DOC-1061 && / DOC-1014 add in client.get(“/people/~:(im-accounts)”) client.get(“/people/~:(twitter-accounts)”) client.get(“/people/~:(date-of-birth)”) client.get(“/people/~:(main-address)”).
Instance Method Summary collapse
- #access_token ⇒ Object
- #authorize_from_access(atoken, asecret) ⇒ Object
-
#authorize_from_request(rtoken, rsecret, verifier_or_pin) ⇒ Object
For web apps use params, for desktop apps, use the verifier is the pin that LinkedIn gives users.
-
#birthdate ⇒ Object
usage: dob = client.birthdate returns a birthdate object allowing access to day, month, year dob.to_date will return a DATE object.
- #clear_status ⇒ Object
- #connections(options = {}) ⇒ Object
- #consumer ⇒ Object
- #create_network_update(text) ⇒ Object
- #current_status ⇒ Object
- #delete(path, options = {}) ⇒ Object
- #get(path, options = {}) ⇒ Object
-
#initialize(ctoken = LinkedIn.token, csecret = LinkedIn.secret, options = {}) ⇒ Client
constructor
A new instance of Client.
- #network_statuses(options = {}) ⇒ Object
- #network_updates(options = {}) ⇒ Object
- #post(path, body = '', options = {}) ⇒ Object
- #profile(options = {}) ⇒ Object
- #put(path, body, options = {}) ⇒ Object
-
#request_token(options = {}) ⇒ Object
Note: If using oauth with a web app, be sure to provide :oauth_callback.
- #search(options = {}) ⇒ Object
- #send_invite(subject, body, recipient_paths) ⇒ Object
- #send_message(subject, body, recipient_paths) ⇒ Object
- #set_callback_url(url) ⇒ Object
- #update_comment(network_key, comment) ⇒ Object
-
#update_status(text) ⇒ Object
NOTE: this is a deprecated API.
-
#write_fixture(path, filename) ⇒ Object
helpful in making authenticated calls and writing the raw xml to a fixture file.
Constructor Details
#initialize(ctoken = LinkedIn.token, csecret = LinkedIn.secret, options = {}) ⇒ Client
Returns a new instance of Client.
11 12 13 14 15 16 17 18 |
# File 'lib/linked_in/client.rb', line 11 def initialize(ctoken=LinkedIn.token, csecret=LinkedIn.secret, ={}) 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() end |
Instance Attribute Details
#consumer_options ⇒ Object (readonly)
TODO: @ developer.linkedin.com/docs/DOC-1061 && / DOC-1014 add in client.get(“/people/~:(im-accounts)”)
client.get("/people/~:(twitter-accounts)")
client.get("/people/~:(date-of-birth)")
client.get("/people/~:(main-address)")
9 10 11 |
# File 'lib/linked_in/client.rb', line 9 def @consumer_options end |
#csecret ⇒ Object (readonly)
TODO: @ developer.linkedin.com/docs/DOC-1061 && / DOC-1014 add in client.get(“/people/~:(im-accounts)”)
client.get("/people/~:(twitter-accounts)")
client.get("/people/~:(date-of-birth)")
client.get("/people/~:(main-address)")
9 10 11 |
# File 'lib/linked_in/client.rb', line 9 def csecret @csecret end |
#ctoken ⇒ Object (readonly)
TODO: @ developer.linkedin.com/docs/DOC-1061 && / DOC-1014 add in client.get(“/people/~:(im-accounts)”)
client.get("/people/~:(twitter-accounts)")
client.get("/people/~:(date-of-birth)")
client.get("/people/~:(main-address)")
9 10 11 |
# File 'lib/linked_in/client.rb', line 9 def ctoken @ctoken end |
Instance Method Details
#access_token ⇒ Object
44 45 46 |
# File 'lib/linked_in/client.rb', line 44 def access_token @access_token ||= ::OAuth::AccessToken.new(consumer, @atoken, @asecret) end |
#authorize_from_access(atoken, asecret) ⇒ Object
48 49 50 |
# File 'lib/linked_in/client.rb', line 48 def (atoken, asecret) @atoken, @asecret = atoken, asecret end |
#authorize_from_request(rtoken, rsecret, verifier_or_pin) ⇒ Object
For web apps use params, for desktop apps, use the verifier is the pin that LinkedIn gives users.
38 39 40 41 42 |
# File 'lib/linked_in/client.rb', line 38 def (rtoken, rsecret, verifier_or_pin) request_token = ::OAuth::RequestToken.new(consumer, rtoken, rsecret) access_token = request_token.get_access_token(:oauth_verifier => verifier_or_pin) @atoken, @asecret = access_token.token, access_token.secret end |
#birthdate ⇒ Object
usage:
dob = client.birthdate
returns a birthdate object allowing access to day, month, year
dob.to_date will return a DATE object
118 119 120 121 |
# File 'lib/linked_in/client.rb', line 118 def birthdate path = "/people/~:(date-of-birth)" Birthdate.from_xml(get(path)) end |
#clear_status ⇒ Object
153 154 155 156 |
# File 'lib/linked_in/client.rb', line 153 def clear_status path = "/people/~/current-status" delete(path).code end |
#connections(options = {}) ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/linked_in/client.rb', line 99 def connections(={}) path = "#{person_path()}/connections" unless [:fields].nil? if [:public] path +=":public" else path +=":(#{[:fields].map{|f| f.to_s.gsub("_","-")}.join(',')})" end end Connections.from_xml(get(path)).profiles end |
#consumer ⇒ Object
20 21 22 |
# File 'lib/linked_in/client.rb', line 20 def consumer @consumer ||= ::OAuth::Consumer.new(@ctoken, @csecret, {:site => 'https://api.linkedin.com'}.merge(@consumer_options)) end |
#create_network_update(text) ⇒ Object
131 132 133 134 |
# File 'lib/linked_in/client.rb', line 131 def create_network_update(text) path = "/people/~/person-activities" post(path, network_update_to_xml(CGI.escapeHTML(text)), {"Content-Type" => "text/xml"}) end |
#current_status ⇒ Object
136 137 138 139 |
# File 'lib/linked_in/client.rb', line 136 def current_status path = "/people/~/current-status" Crack::XML.parse(get(path))['current_status'] end |
#delete(path, options = {}) ⇒ Object
76 77 78 79 80 81 |
# File 'lib/linked_in/client.rb', line 76 def delete(path, ={}) path = "/v1#{path}" response = access_token.delete(path, ) raise_errors(response) response end |
#get(path, options = {}) ⇒ Object
52 53 54 55 56 57 |
# File 'lib/linked_in/client.rb', line 52 def get(path, ={}) path = "/v1#{path}" response = access_token.get(path, ) raise_errors(response) response.body end |
#network_statuses(options = {}) ⇒ Object
216 217 218 219 |
# File 'lib/linked_in/client.rb', line 216 def network_statuses(={}) [:type] = 'STAT' network_updates() end |
#network_updates(options = {}) ⇒ Object
221 222 223 224 |
# File 'lib/linked_in/client.rb', line 221 def network_updates(={}) path = "/people/~/network" Network.from_xml(get(to_uri(path, ))) end |
#post(path, body = '', options = {}) ⇒ Object
60 61 62 63 64 65 66 67 |
# File 'lib/linked_in/client.rb', line 60 def post(path, body='', ={}) path = "/v1#{path}" response = access_token.post(path, body, ) puts 'response:' puts response raise_errors(response) response end |
#profile(options = {}) ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/linked_in/client.rb', line 84 def profile(={}) path = person_path() unless [:fields].nil? if [:public] path +=":public" else path +=":(#{[:fields].map{|f| f.to_s.gsub("_","-")}.join(',')})" end end Profile.from_xml(get(path)) end |
#put(path, body, options = {}) ⇒ Object
69 70 71 72 73 74 |
# File 'lib/linked_in/client.rb', line 69 def put(path, body, ={}) path = "/v1#{path}" response = access_token.put(path, body, ) raise_errors(response) response end |
#request_token(options = {}) ⇒ Object
Note: If using oauth with a web app, be sure to provide :oauth_callback. Options:
:oauth_callback => String, url that LinkedIn should redirect to
32 33 34 |
# File 'lib/linked_in/client.rb', line 32 def request_token(={}) @request_token ||= consumer.get_request_token() end |
#search(options = {}) ⇒ Object
123 124 125 126 127 128 129 |
# File 'lib/linked_in/client.rb', line 123 def search(={}) path = "/people" = {:keywords => } if .is_a?(String) = () People.from_xml(get(to_uri(path, ))) end |
#send_invite(subject, body, recipient_paths) ⇒ Object
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 |
# File 'lib/linked_in/client.rb', line 184 def send_invite(subject, body, recipient_paths) path = "/people/~/mailbox" = LinkedIn::InviteMessage.new .subject = subject .body = body recipients = LinkedIn::Recipients.new recipients.recipients = recipient_paths.map do |recipient_hash| email = recipient_hash[:email] first = recipient_hash[:first] last = recipient_hash[:last] recipient = LinkedIn::Recipient.new recipient.person = LinkedIn::Person.new recipient.person.path = "\"/people/email=#{email}\"" recipient.person.first_name = first recipient.person.last_name = last recipient end .recipients = recipients puts 'sending in send_message:' puts path puts () post(path, (), { "Content-Type" => "text/xml" }).code end |
#send_message(subject, body, recipient_paths) ⇒ Object
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
# File 'lib/linked_in/client.rb', line 158 def (subject, body, recipient_paths) path = "/people/~/mailbox" = LinkedIn::Message.new .subject = subject .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 .recipients = recipients puts 'sending in send_message:' puts path puts () post(path, (), { "Content-Type" => "text/xml" }).code end |
#set_callback_url(url) ⇒ Object
24 25 26 27 |
# File 'lib/linked_in/client.rb', line 24 def set_callback_url(url) clear_request_token request_token(:oauth_callback => url) end |
#update_comment(network_key, comment) ⇒ Object
148 149 150 151 |
# File 'lib/linked_in/client.rb', line 148 def update_comment(network_key, comment) path = "/people/~/network/updates/key=#{network_key}/update-comments" post(path,comment_to_xml(comment),{'Content-Type' => 'application/xml'}) end |
#update_status(text) ⇒ Object
NOTE: this is a deprecated API. Please use the Share API,
which is not currently implemented
143 144 145 146 |
# File 'lib/linked_in/client.rb', line 143 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
228 229 230 231 232 |
# File 'lib/linked_in/client.rb', line 228 def write_fixture(path, filename) file = File.new("test/fixtures/#{filename}", "w") file.puts(access_token.get(path).body) file.close end |