Class: LinkedIn::Client
- Inherits:
-
Object
- Object
- LinkedIn::Client
- Defined in:
- lib/linked_in/client.rb
Instance Attribute Summary collapse
-
#consumer_options ⇒ Object
readonly
Returns the value of attribute consumer_options.
-
#csecret ⇒ Object
readonly
Returns the value of attribute csecret.
-
#ctoken ⇒ Object
readonly
Returns the value of attribute ctoken.
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.
- #clear_status ⇒ Object
- #connections(options = {}) ⇒ Object
- #consumer ⇒ 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
- #profile(options = {}) ⇒ Object
- #put(path, options = {}) ⇒ Object
-
#request_token(options = {}) ⇒ Object
Note: If using oauth with a web app, be sure to provide :oauth_callback.
- #search(options = {}) ⇒ Object
- #set_callback_url(url) ⇒ Object
- #update_status(text) ⇒ Object
-
#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.
6 7 8 9 10 11 12 13 |
# File 'lib/linked_in/client.rb', line 6 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)
Returns the value of attribute consumer_options.
4 5 6 |
# File 'lib/linked_in/client.rb', line 4 def @consumer_options end |
#csecret ⇒ Object (readonly)
Returns the value of attribute csecret.
4 5 6 |
# File 'lib/linked_in/client.rb', line 4 def csecret @csecret end |
#ctoken ⇒ Object (readonly)
Returns the value of attribute ctoken.
4 5 6 |
# File 'lib/linked_in/client.rb', line 4 def ctoken @ctoken end |
Instance Method Details
#access_token ⇒ Object
39 40 41 |
# File 'lib/linked_in/client.rb', line 39 def access_token @access_token ||= ::OAuth::AccessToken.new(consumer, @atoken, @asecret) end |
#authorize_from_access(atoken, asecret) ⇒ Object
43 44 45 |
# File 'lib/linked_in/client.rb', line 43 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.
33 34 35 36 37 |
# File 'lib/linked_in/client.rb', line 33 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 |
#clear_status ⇒ Object
116 117 118 119 |
# File 'lib/linked_in/client.rb', line 116 def clear_status path = "/people/~/current-status" delete(path).code end |
#connections(options = {}) ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/linked_in/client.rb', line 84 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
15 16 17 |
# File 'lib/linked_in/client.rb', line 15 def consumer @consumer ||= ::OAuth::Consumer.new(@ctoken, @csecret, {:site => 'https://api.linkedin.com'}.merge()) end |
#current_status ⇒ Object
106 107 108 109 |
# File 'lib/linked_in/client.rb', line 106 def current_status path = "/people/~/current-status" Crack::XML.parse(get(path))['current_status'] end |
#delete(path, options = {}) ⇒ Object
61 62 63 64 65 66 |
# File 'lib/linked_in/client.rb', line 61 def delete(path, ={}) path = "/v1#{path}" response = access_token.delete(path, ) raise_errors(response) response end |
#get(path, options = {}) ⇒ Object
47 48 49 50 51 52 |
# File 'lib/linked_in/client.rb', line 47 def get(path, ={}) path = "/v1#{path}" response = access_token.get(path, ) raise_errors(response) response.body end |
#network_statuses(options = {}) ⇒ Object
121 122 123 124 |
# File 'lib/linked_in/client.rb', line 121 def network_statuses(={}) [:type] = 'STAT' network_updates() end |
#network_updates(options = {}) ⇒ Object
126 127 128 129 |
# File 'lib/linked_in/client.rb', line 126 def network_updates(={}) path = "/people/~/network" Network.from_xml(get(to_uri(path, ))) end |
#profile(options = {}) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/linked_in/client.rb', line 69 def profile(={}) path = person_path() if [:public] path +=":public" end unless [:fields].nil? path +=":(#{[:fields].map{|f| f.to_s.gsub("_","-")}.join(',')})" end Profile.from_xml(get(path)) end |
#put(path, options = {}) ⇒ Object
54 55 56 57 58 59 |
# File 'lib/linked_in/client.rb', line 54 def put(path, ={}) path = "/v1#{path}" response = access_token.put(path, ) 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
27 28 29 |
# File 'lib/linked_in/client.rb', line 27 def request_token(={}) @request_token ||= consumer.get_request_token() end |
#search(options = {}) ⇒ Object
98 99 100 101 102 103 104 |
# File 'lib/linked_in/client.rb', line 98 def search(={}) path = "/people" = {:keywords => } if .is_a?(String) = () People.from_xml(get(to_uri(path, ))) end |
#set_callback_url(url) ⇒ Object
19 20 21 22 |
# File 'lib/linked_in/client.rb', line 19 def set_callback_url(url) clear_request_token request_token(:oauth_callback => url) end |
#update_status(text) ⇒ Object
111 112 113 114 |
# File 'lib/linked_in/client.rb', line 111 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
136 137 138 139 140 |
# File 'lib/linked_in/client.rb', line 136 def write_fixture(path, filename) file = File.new("test/fixtures/#{filename}", "w") file.puts(access_token.get(path).body) file.close end |