module LinkedIn

Constants

DEFAULT_TIMEOUT_SECONDS
VERSION

Attributes

config[RW]

Public Class Methods

configure() { |config| ... } click to toggle source
# File lib/linkedin-v2.rb, line 49
def self.configure
  yield self.config
end

Public Instance Methods

brand_path(options) click to toggle source
# File lib/linked_in/organizations.rb, line 212
def brand_path(options)
  path = '/organizationBrands'

  if id = options.delete(:id)
    path += "/#{id}"
  elsif vanity_name = options.delete(:vanity_name)
    path += ">q=vanityName&vanityName=#{CGI.escape(vanity_name)}"
  elsif parent_id = options.delete(:parent_id)
    path = "/organizations?q=parentOrganization&parent=#{CGI.escape(parent_id)}"
  else
    path += "/me"
  end
end
check_access_code_url!(options={}) click to toggle source
# File lib/linked_in/oauth2.rb, line 176
def check_access_code_url!(options={})
  check_redirect_uri!(options)
  if options[:redirect_uri] != @redirect_uri
    raise redirect_uri_mismatch
  end
end
check_credentials!(client_id, client_secret) click to toggle source
# File lib/linked_in/oauth2.rb, line 205
def check_credentials!(client_id, client_secret)
  if client_id.nil? or client_secret.nil?
    raise credential_error
  end
end
check_for_code!(code) click to toggle source
# File lib/linked_in/oauth2.rb, line 183
def check_for_code!(code)
  if code.nil?
    msg = ErrorMessages.no_auth_code
    raise InvalidRequest.new(msg)
  end
end
check_redirect_uri!(options={}) click to toggle source
# File lib/linked_in/oauth2.rb, line 190
def check_redirect_uri!(options={})
  if options[:redirect_uri].nil?
    raise redirect_uri_error
  end
end
convert_key(key) click to toggle source

overload the convert_key mash method so that the LinkedIn keys are made a little more ruby-ish

# File lib/linked_in/mash.rb, line 41
def convert_key(key)
  case key.to_s
  when '_key'
    'id'
  when '_total'
    'total'
  when 'values'
    'all'
  when 'numResults'
    'total_results'
  else
    underscore(key)
  end
end
credential_error() click to toggle source
# File lib/linked_in/oauth2.rb, line 215
def credential_error
  InvalidRequest.new ErrorMessages.credentials_missing
end
default_auth_code_url_options(custom_options={}) click to toggle source
# File lib/linked_in/oauth2.rb, line 152
def default_auth_code_url_options(custom_options={})
  custom_options ||= {}
  options = {raise_errors: true}

  if not LinkedIn.config.redirect_uri.nil?
    options[:redirect_uri] = LinkedIn.config.redirect_uri
  end
  if not LinkedIn.config.scope.nil?
    options[:scope] = LinkedIn.config.scope
  end

  options = options.merge custom_options

  if options[:state].nil?
    options[:state] = generate_csrf_token
  end

  return options
end
default_headers() click to toggle source
# File lib/linked_in/api.rb, line 90
def default_headers
  # https://developer.linkedin.com/documents/api-requests-json
  return {"x-li-format" => "json", "Authorization" => "Bearer #{@access_token.token}"}
end
default_oauth_options(custom_options={}) click to toggle source
# File lib/linked_in/oauth2.rb, line 196
def default_oauth_options(custom_options={})
  custom_options ||= {}
  options = {}
  options[:site] = LinkedIn.config.site
  options[:token_url] = LinkedIn.config.token_url
  options[:authorize_url] = LinkedIn.config.authorize_url
  return options.merge custom_options
end
default_params() click to toggle source
# File lib/linked_in/api.rb, line 83
def default_params
  # LIv2 TODO - Probably can just remove?
  # https//developer.linkedin.com/documents/authentication
  #return { oauth2_access_token: @access_token.token }
  {}
end
delete(path=nil, body=nil, headers=nil, &block) click to toggle source
# File lib/linked_in/api_resource.rb, line 72
def delete(path=nil, body=nil, headers=nil, &block)
  # @connection.delete(prepend_prefix(path), params, headers, &block)
  # To be able to DELETE with a body:
  response = @connection.run_request(:delete, prepend_prefix(path), body, headers, &block)

  Mash.from_json(response.body)
end
deprecated() click to toggle source
# File lib/linked_in/api_resource.rb, line 80
def deprecated
  LinkedIn::Deprecated.new(LinkedIn::ErrorMessages.deprecated)
end
generate_csrf_token() click to toggle source
# File lib/linked_in/oauth2.rb, line 172
def generate_csrf_token
  SecureRandom.base64(32)
end
no_access_token_error() click to toggle source
# File lib/linked_in/api.rb, line 109
def no_access_token_error
  msg = LinkedIn::ErrorMessages.no_access_token
  LinkedIn::InvalidRequest.new(msg)
end
parse_access_token(access_token) click to toggle source
# File lib/linked_in/api.rb, line 101
def parse_access_token(access_token)
  if access_token.is_a? LinkedIn::AccessToken
    return access_token
  elsif access_token.is_a? String
    return LinkedIn::AccessToken.new(access_token)
  end
end
post(path=nil, body=nil, headers=nil, &block) click to toggle source
# File lib/linked_in/api_resource.rb, line 63
def post(path=nil, body=nil, headers=nil, &block)
  @connection.post(prepend_prefix(path), body, headers, &block)
end
put(path=nil, body=nil, headers=nil, &block) click to toggle source
# File lib/linked_in/api_resource.rb, line 67
def put(path=nil, body=nil, headers=nil, &block)
  @connection.put(prepend_prefix(path), body, headers, &block)
  Mash.from_json(response.body)
end
redirect_uri_error() click to toggle source
# File lib/linked_in/oauth2.rb, line 211
def redirect_uri_error
  InvalidRequest.new ErrorMessages.redirect_uri
end
redirect_uri_mismatch() click to toggle source
# File lib/linked_in/oauth2.rb, line 219
def redirect_uri_mismatch
  InvalidRequest.new ErrorMessages.redirect_uri_mismatch
end
underscore(camel_cased_word) click to toggle source

borrowed from ActiveSupport no need require an entire lib when we only need one method

# File lib/linked_in/mash.rb, line 58
def underscore(camel_cased_word)
  word = camel_cased_word.to_s.dup
  word.gsub!(/::/, '/')
  word.gsub!(/([A-Z]+)([A-Z][a-z])/,'\1_\2')
  word.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
  word.tr!("-", "_")
  word.downcase!
  word
end
verify_access_token!(access_token) click to toggle source
# File lib/linked_in/api.rb, line 95
def verify_access_token!(access_token)
  if not access_token.is_a? LinkedIn::AccessToken
    raise no_access_token_error
  end
end