0.01
No release in over 3 years
Low commit activity in last 3 years
Wrapper for the XING API
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
 Dependencies
 Project Readme

XingApiClient

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).

Requirements

Tested with ruby 1.9.3p448 and 2.0.0-p0.

Build Status Code Climate Coverage Status Dependency Status

Quickstart

Make a handshake

# 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.

Before you start

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).

Configuration

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:

Use a Hash

XingApiClient::Config.set(consumer_key: '12345', host: 'abcde')

Use a YAML-File

XingApiClient::Config.load_file('path/config.yml')

Use Environment variables

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.

Paste some values to the initialization

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.

Handshake

Before you can start using the gem you need to make the handshake for every developer. There are two different ways:

Pin

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' }

Callback

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' }

Make calls

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')

Available calls

User Profiles

  • GET /v1/users/:id
  • GET /v1/users/me
  • GET /v1/users/me/id_card
  • GET /v1/users/find_by_emails

Jobs

  • GET /v1/jobs/:id (experimental)
  • GET /v1/jobs/find (experimental)
  • GET /v1/users/:user_id/jobs/recommendations (experimental)

Messages

  • 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

Profile Messages

  • GET /v1/users/:user_id/profile_message
  • PUT /v1/users/:user_id/profile_message

Contacts

  • 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

Contact Requests

  • 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

Contact Path

  • GET /v1/users/:user_id/network/:other_user_id/paths

Bookmarks

  • GET /v1/users/:user_id/bookmarks
  • PUT /v1/users/:user_id/bookmarks/:id
  • DELETE /v1/users/:user_id/bookmarks/:id

Network Feed

  • 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

Profile Visits

  • GET /v1/users/:user_id/visits
  • POST /v1/users/:user_id/visits

Recommendations

  • GET /v1/users/:user_id/network/recommendations
  • DELETE /v1/users/:user_id/network/recommendations/user/:id

Invitations

  • POST /v1/users/invite (experimental)

Geo Locations

  • GET /v1/users/:user_id/nearby_users
  • PUT /v1/users/:user_id/geo_location