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

Add support for tokens from the Mobile SDK #39

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
19 changes: 15 additions & 4 deletions lib/linked_in/api.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
module LinkedIn
class API

attr_accessor :access_token
attr_accessor :access_token, :options

def initialize(access_token=nil)
def initialize(access_token=nil, options={})
access_token = parse_access_token(access_token)
verify_access_token!(access_token)
@access_token = access_token
@options = options

@connection = LinkedIn::Connection.new params: default_params,
headers: default_headers
Expand Down Expand Up @@ -60,6 +61,10 @@ def initialize(access_token=nil)
:update_comment,
:network_updates

def mobile_sdk?
!!(options[:is_mobile_sdk] || options["is_mobile_sdk"])
end

private ##############################################################

def initialize_endpoints
Expand All @@ -74,12 +79,18 @@ def initialize_endpoints

def default_params
# https//developer.linkedin.com/documents/authentication
return {oauth2_access_token: @access_token.token}
mobile_sdk? ? {} : {oauth2_access_token: @access_token.token}
end

def default_headers
# https://developer.linkedin.com/documents/api-requests-json
return {"x-li-format" => "json"}
mobile_sdk? ?
{
"x-li-format" => "json",
"x-li-src" => "msdk",
"Authorization": "Bearer #{@access_token.token}"
} :
{"x-li-format" => "json"}
end

def verify_access_token!(access_token)
Expand Down
9 changes: 9 additions & 0 deletions spec/linked_in/api/api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,13 @@

include_examples "test access token"
end

context "With a string access token and `is_mobil_sdk` turned on" do
let(:access_token) { "dummy_access_token" }
let(:options) {{ is_mobile_sdk: true }}

subject {LinkedIn::API.new(access_token, options)}

include_examples "test access token"
end
end