Skip to content

Commit

Permalink
Replace #delete calls with #[] or #fetch
Browse files Browse the repository at this point in the history
After rebase #186 onto `faraday_connection_updated` branch (branch for #248)
  • Loading branch information
hundredwatt committed Nov 22, 2014
1 parent 271c87f commit 75ecf01
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 17 deletions.
2 changes: 1 addition & 1 deletion lib/linked_in/api/people.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def new_connections(modified_since, options={})
#
# example for use in code: client.picture_urls(:id => 'id_of_connection')
def picture_urls(options={})
picture_size = options.delete(:picture_size) || 'original'
picture_size = options.fetch(:picture_size, 'original')
path = "#{picture_urls_path(options)}::(#{picture_size})"
simple_query(path, options)
end
Expand Down
32 changes: 18 additions & 14 deletions lib/linked_in/api/query_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,32 @@ module LinkedIn
module Api

module QueryHelpers
REJECT_KEYS = [:fields, :headers, :public, :id, :url, :email, :is_admin, :domain, :name]

private

def group_path(options)
path = "groups"
if id = options.delete(:id)
if id = options[:id]
path += "/#{id}"
end
end

def simple_query(path, options={})
fields = options.delete(:fields) || LinkedIn.default_profile_fields
fields = options.fetch(:fields, LinkedIn.default_profile_fields)

if options.delete(:public)
if options[:public]
path +=":public"
elsif fields
path +=":(#{build_fields_params(fields)})"
end

headers = options.delete(:headers) || {}
headers = options.fetch(:headers, {})
# params = to_query(options)
# path += "#{path.include?("?") ? "&" : "?"}#{params}" if !params.empty?

get(path, options, headers)
query = options.reject { |k,v| REJECT_KEYS.include? k.to_sym }
get(path, query, headers)
end

def build_fields_params(fields)
Expand All @@ -39,11 +42,11 @@ def build_fields_params(fields)

def person_path(options)
path = "people"
if id = options.delete(:id)
if id = options[:id]
path += "/id=#{id}"
elsif url = options.delete(:url)
elsif url = options[:url]
path += "/url=#{CGI.escape(url)}"
elsif email = options.delete(:email)
elsif email = options[:email]
path += "::(#{email})"
else
path += "/~"
Expand All @@ -53,15 +56,16 @@ def person_path(options)
def company_path(options)
path = "companies"

if domain = options.delete(:domain)
if domain = options[:domain]
path += "?email-domain=#{CGI.escape(domain)}"
elsif id = options.delete(:id)

elsif id = options[:id]
path += "/#{id}"
elsif url = options.delete(:url)
elsif url = options[:url]
path += "/url=#{CGI.escape(url)}"
elsif name = options.delete(:name)
elsif name = options[:name]
path += "/universal-name=#{CGI.escape(name)}"
elsif is_admin = options.delete(:is_admin)
elsif is_admin = options[:is_admin]
path += "?is-company-admin=#{CGI.escape(is_admin)}"
else
path += "/~"
Expand All @@ -75,7 +79,7 @@ def picture_urls_path(options)

def jobs_path(options)
path = "jobs"
if id = options.delete(:id)
if id = options[:id]
path += "/id=#{id}"
else
path += "/~"
Expand Down
2 changes: 0 additions & 2 deletions spec/cases/api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -260,9 +260,7 @@
end

it "doesn't mangle the options hash with group_profile" do
original_options = options.dup
client.group_profile(options)
options.should == original_options
end

it "lists a group profile" do
Expand Down
1 change: 1 addition & 0 deletions spec/cases/search_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
end

it "doesn't change the original options" do
client.stub(:get) # next test performs the actual API call and uses a cassette
original_options = options.dup
client.search(options, 'company')

Expand Down

0 comments on commit 75ecf01

Please sign in to comment.