The main goal of this Gem is to provide an easy access to the XING API. The XING API uses the OAuth1 standard for the access management and offers calls to access data and functions from user accounts. This Gem encapsulates both by providing methods to handle it in a high level way.
Special thanks go to Jan-Oliver Jahner (jojahner) and Björn Jensen (mirouhh).
Tested with ruby 1.9.3p448 and 2.0.0-p0.
# Require the Gem
require('xing_api_client')
# Get a consumer key and secret from https://dev.xing.com/applications and set up the configuration
XingApiClient::Config.set(consumer_key: '12345', consumer_secret: 'abcde')
# Initialize the handshake
request_params = XingApiClient.request_params
puts "Use your browser to open #{request_params[:auth_url]}"
# Verify the pin
puts "Please enter the pin:"
pin = gets.chomp.strip
# Authorize the handshake and get the token and secret
authorized_params = XingApiClient.authorize(request_params[:request_token], pin)
puts authorized_params.inspect # { access_token: 'abcde', secret: '12345' }
# Initialize a client
client = XingApiClient.new(authorized_params[:access_token], authorized_params[:secret])
# Make a request to load your user data
puts client.request.get_users.inspect
Here you can find an minimal example with Sinatra using a callback URL.
To get access to the XING API, you need a consumer key and a consumer secret. To get those you have to login to the Dev-Portal http://dev.xing.com and create a new app. Now you have a test-consumer-key which can use all calls that are listed in the documentation https://dev.xing.com/docs/resources . After you have developed your app, you can request a production-consumer-key by using the ‘Get a production key’-Button on the app management site (https://dev.xing.com/applications).
The default configuration:
{
host: 'https://api.xing.com',
request_token_path: '/v1/request_token',
authorize_path: '/v1/authorize',
access_token_path: '/v1/access_token',
consumer_key: nil,
consumer_secret: nil,
callback_url: nil # The callback URL for the pin. If it is blank, you user hat to enter the pin manually
}
You can add/overwrite configuration values in four different ways:
XingApiClient::Config.set(consumer_key: '12345', host: 'abcde')
XingApiClient::Config.load_file('path/config.yml')
XingApiClient::Config.load_env
Loads this enviroment variables:
- XINGAPICLIENT_HOST
- XINGAPICLIENT_REQUEST_TOKEN_PATH
- XINGAPICLIENT_AUTHORIZE_PATH
- XINGAPICLIENT_ACCESS_TOKEN_PATH
- XINGAPICLIENT_CONSUMER_KEY
- XINGAPICLIENT_CONSUMER_SECRET
- XINGAPICLIENT_CALLBACK_URL
If you set a prefix, it replaces the part 'XINGAPICLIENT'. Empty values will be ignored.
configuration_values = {
consumer_key: '12345',
consumer_secret: 'abcde',
}
XingApiClient.new('access_token', 'access_token_secret', configuration_values)
Here are only the values 'consumer_key' and 'consumer_secret' available.
Before you can start using the gem you need to make the handshake for every developer. There are two different ways:
The user has to enter the pin manually if no callback URL is configured.
# Get a consumer key and secret from https://dev.xing.com/applications and set up the configuration
XingApiClient::Config.set(consumer_key: '12345', consumer_secret: 'abcde')
# Initialize the handshake
request_params = XingApiClient.request_params
puts "Use your browser to open #{request_params[:auth_url]}"
# Verify the pin
puts "Please enter the pin:"
pin = gets.chomp.strip
# Authorize the handshake and get the token and secret
authorized_params = XingApiClient.authorize(request_params[:request_token], pin)
puts authorized_params.inspect # { access_token: 'abcde', secret: '12345' }
If a callback URL is defined this will be use to send the pin as a parameter.
# Get a consumer key and secret from https://dev.xing.com/applications and set up the configuration
XingApiClient::Config.set(consumer_key: '12345', consumer_secret: 'abcde')
request_params = XingApiClient.request_params
# You need to save the token somewhere
session[:token] = request_params[:request_token]
# Initialize the handshake
redirect_to request_params[:auth_url]
The user gets redirected to the handshake dialog. After he has accepted the handshake the url cets called with the parameter 'oauth_verifier' witch contains the pin.
authorized_params = XingApiClient.authorize(session[:token], params[:oauth_verifier])
puts authorized_params.inspect # { access_token: 'abcde', secret: '12345' }
After setting up the configuration and making the handshake you can make calls in the scope of the user.
# Don't forget to configurate your client before you initialize an object
client = XingApiClient.new('ACCESS_TOKEN', 'SECRET')
client.request.call_methods.keys # [:get_users, :get_users_contact_requests, :get_users_contacts, ...]
client.request.get_users(id: 'me')
- GET /v1/users/:id
- GET /v1/users/me
- GET /v1/users/me/id_card
- GET /v1/users/find_by_emails
-
GET /v1/jobs/:id (experimental) -
GET /v1/jobs/find (experimental) -
GET /v1/users/:user_id/jobs/recommendations (experimental)
- GET /v1/users/:user_id/conversations
- POST /v1/users/:user_id/conversations
-
GET /v1/users/me/conversations/valid_recipients/:id (experimental) - GET /v1/users/:user_id/conversations/:id
-
GET /v1/user…ations/:conversation_id/attachments (experimental) -
GET /v1/user…ns/:conversation_id/attachments/:id (experimental) -
POST /v1/user…rsation_id/attachments/:id/download (experimental) - PUT /v1/users/:user_id/conversations/:id/read
-
PUT /v1/user…s/:conversation_id/participants/:id (experimental) - GET /v1/user…ersations/:conversation_id/messages
- GET /v1/user…tions/:conversation_id/messages/:id
- PUT /v1/user…/:conversation_id/messages/:id/read
- DELETE /v1/user…/:conversation_id/messages/:id/read
- POST /v1/user…ersations/:conversation_id/messages
- DELETE /v1/users/:user_id/conversations/:id
- GET /v1/users/:user_id/profile_message
- PUT /v1/users/:user_id/profile_message
- GET /v1/users/:user_id/contacts
-
GET /v1/users/me/contact_ids (experimental) - GET /v1/users/:user_id/contacts/:contact_id/tags
- GET /v1/users/:user_id/contacts/shared
- GET /v1/users/:user_id/contact_requests
- POST /v1/users/:user_id/contact_requests
- DELETE /v1/users/:user_id/contact_requests/:id
- GET /v1/users/:user_id/contact_requests/sent
- PUT /v1/users/:user_id/contact_requests/:id/accept
- GET /v1/users/:user_id/network/:other_user_id/paths
- GET /v1/users/:user_id/bookmarks
- PUT /v1/users/:user_id/bookmarks/:id
- DELETE /v1/users/:user_id/bookmarks/:id
- GET /v1/users/:user_id/network_feed
- GET /v1/users/:id/feed
- POST /v1/users/:id/status_message
-
POST /v1/users/me/share/link (experimental) - GET /v1/activities/:id
- POST /v1/activities/:id/share
- DELETE /v1/activities/:id
- GET /v1/activities/:activity_id/comments
- POST /v1/activities/:activity_id/comments
- DELETE /v1/activities/:activity_id/comments/:id
- GET /v1/activities/:activity_id/likes
- PUT /v1/activities/:activity_id/like
- DELETE /v1/activities/:activity_id/like
- GET /v1/users/:user_id/visits
- POST /v1/users/:user_id/visits
- GET /v1/users/:user_id/network/recommendations
- DELETE /v1/users/:user_id/network/recommendations/user/:id
-
POST /v1/users/invite (experimental)
- GET /v1/users/:user_id/nearby_users
- PUT /v1/users/:user_id/geo_location