Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation #204

Merged
merged 14 commits into from
Jan 27, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions .document

This file was deleted.

7 changes: 7 additions & 0 deletions .yardopts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
--no-private
--markup markdown
-
README.md
CHANGELOG.md
LICENSE
EXAMPLES.md
6 changes: 5 additions & 1 deletion changelog.markdown → CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

* Document all methods
* Re-organize modules under Api to match organization in LinkedIn's REST
API documentation

## 0.4.4 - Jan 11, 2014

* Group share add
Expand Down Expand Up @@ -92,4 +96,4 @@

## 0.0.1 - November 24, 2009

* Initial release
* Initial release
198 changes: 198 additions & 0 deletions EXAMPLES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,198 @@
# Linkedin Gem Examples

## OAuth 1.0a Authentication

Here's an example of authenticating with the LinkedIn API

```ruby
require 'rubygems'
require 'linkedin'

# get your api keys at https://www.linkedin.com/secure/developer
client = LinkedIn::Client.new('your_consumer_key', 'your_consumer_secret')

# If you want to use one of the scopes from linkedin you have to pass it in at this point
# You can learn more about it here: http://developer.linkedin.com/documents/authentication
request_token = client.request_token({}, :scope => "r_basicprofile+r_emailaddress")

rtoken = request_token.token
rsecret = request_token.secret

# to test from your desktop, open the following url in your browser
# and record the pin it gives you
request_token.authorize_url
=> "https://api.linkedin.com/uas/oauth/authorize?oauth_token=<generated_token>"

# then fetch your access keys
client.authorize_from_request(rtoken, rsecret, pin)
=> ["OU812", "8675309"] # <= save these for future requests

# or authorize from previously fetched access keys
c.authorize_from_access("OU812", "8675309")

# you're now free to move about the cabin, call any API method
```


## Profile

Here are some examples of accessing a user's profile

```ruby
# AUTHENTICATE FIRST found in examples/authenticate.rb

# client is a LinkedIn::Client

# get the profile for the authenticated user
client.profile

# get a profile for someone found in network via ID
client.profile(:id => 'gNma67_AdI')

# get a profile for someone via their public profile url
client.profile(:url => 'http://www.linkedin.com/in/netherland')

# provides the ability to access authenticated user's company field in the profile
user = client.profile(:fields => %w(positions))
companies = user.positions.all.map{|t| t.company}
# Example: most recent company can be accessed via companies[0]

# Example of a multi-email search against the special email search API
account_exists = client.profile(:email => '[email protected],[email protected]', :fields => ['id'])
```


## Sending a Message

Here's an example of sending a message to two recipients

```ruby
# AUTHENTICATE FIRST found in examples/authenticate.md

# client is a LinkedIn::Client

# send a message to a person in your network. you will need to authenticate the
# user and ask for the "w_messages" permission.
response = client.send_message("subject", "body", ["person_1_id", "person_2_id"])
```


## User's Network

Here are some examples of accessing network updates and connections of
the authenticated user

``` ruby
# AUTHENTICATE FIRST found in examples/authenticate.rb

# client is a LinkedIn::Client

# get network updates for the authenticated user
client.network_updates

# get profile picture changes
client.network_updates(:type => 'PICT')

# view connections for the currently authenticated user
client.connections
```


## Update User's Status

Here's an example of updating the current user's status

```ruby
# AUTHENTICATE FIRST found in examples/authenticate.rb

# client is a LinkedIn::Client

# update status for the authenticated user
client.add_share(:comment => 'is playing with the LinkedIn Ruby gem')
```


## Sinatra App

Here's an example sinatra application that performs authentication,
after which some info about the authenticated user can be retrieved.

```ruby
require "rubygems"
require "haml"
require "sinatra"
require "linkedin"

enable :sessions

helpers do
def login?
!session[:atoken].nil?
end

def profile
linkedin_client.profile unless session[:atoken].nil?
end

def connections
linkedin_client.connections unless session[:atoken].nil?
end

private
def linkedin_client
client = LinkedIn::Client.new(settings.api, settings.secret)
client.authorize_from_access(session[:atoken], session[:asecret])
client
end

end

configure do
# get your api keys at https://www.linkedin.com/secure/developer
set :api, "your_api_key"
set :secret, "your_secret"
end

get "/" do
haml :index
end

get "/auth" do
client = LinkedIn::Client.new(settings.api, settings.secret)
request_token = client.request_token(:oauth_callback => "http://#{request.host}:#{request.port}/auth/callback")
session[:rtoken] = request_token.token
session[:rsecret] = request_token.secret

redirect client.request_token.authorize_url
end

get "/auth/logout" do
session[:atoken] = nil
redirect "/"
end

get "/auth/callback" do
client = LinkedIn::Client.new(settings.api, settings.secret)
if session[:atoken].nil?
pin = params[:oauth_verifier]
atoken, asecret = client.authorize_from_request(session[:rtoken], session[:rsecret], pin)
session[:atoken] = atoken
session[:asecret] = asecret
end
redirect "/"
end


__END__
@@index
-if login?
%p Welcome #{profile.first_name}!
%a{:href => "/auth/logout"} Logout
%p= profile.headline
%br
%div= "You have #{connections.total} connections!"
-connections.all.each do |c|
%div= "#{c.first_name} #{c.last_name} - #{c.headline}"
-else
%a{:href => "/auth"} Login using LinkedIn
```
84 changes: 0 additions & 84 deletions README.markdown

This file was deleted.

43 changes: 43 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# LinkedIn

Ruby wrapper for the [LinkedIn API](http://developer.linkedin.com). The LinkedIn gem provides an easy-to-use wrapper for LinkedIn's REST APIs.

Travis CI : [![Build Status](https://secure.travis-ci.org/hexgnu/linkedin.png)](http://travis-ci.org/hexgnu/linkedin)

## Installation

gem install linkedin

## Documentation

[http://rdoc.info/gems/linkedin](http://rdoc.info/gems/linkedin)

## Usage

[View the Examples](EXAMPLES.md)

## Changelog

[View the Changelog](CHANGELOG.md)

## TODO

* Update and correct test suite
* Change to Faraday for authentication
* Implement Messaging APIs

## Note on Patches/Pull Requests

* Fork the project.
* Make your feature addition or bug fix.
* Add tests for it. This is important so I don't break it in a
future version unintentionally.
* Make sure your test doesn't just check of instance of LinkedIn::Mash :smile:.
* Commit, do not mess with rakefile, version, or history.
(if you want to have your own version, that is fine but
bump version in a commit by itself I can ignore when I pull)
* Send me a pull request. Bonus points for topic branches.

## Copyright

Copyright (c) 2013-Present [Matt Kirk](http://matthewkirk.com) 2009-11 [Wynn Netherland](http://wynnnetherland.com). See LICENSE for details.
9 changes: 2 additions & 7 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@ task :test => :spec
task :default => :spec
load 'vcr/tasks/vcr.rake'

require 'rdoc/task'
require File.expand_path('../lib/linked_in/version', __FILE__)
RDoc::Task.new do |rdoc|
rdoc.rdoc_dir = 'rdoc'
rdoc.title = "linkedin #{LinkedIn::VERSION::STRING}"
rdoc.rdoc_files.include('README*')
rdoc.rdoc_files.include('lib/**/*.rb')
end
require 'yard'
YARD::Rake::YardocTask.new
26 changes: 0 additions & 26 deletions examples/authenticate.rb

This file was deleted.

Loading