From 5e53054d4f5b58dcbba7e290ac824058f1597cd2 Mon Sep 17 00:00:00 2001 From: Matt Kirk Date: Fri, 15 Nov 2013 11:26:21 -0800 Subject: [PATCH 1/3] Taking out options mangling for Search --- lib/linked_in/search.rb | 29 ++++++++++++++++++++++------- spec/cases/search_spec.rb | 13 +++++++++++-- 2 files changed, 33 insertions(+), 9 deletions(-) diff --git a/lib/linked_in/search.rb b/lib/linked_in/search.rb index 2cf3f821..c9093b07 100644 --- a/lib/linked_in/search.rb +++ b/lib/linked_in/search.rb @@ -1,6 +1,7 @@ module LinkedIn module Search + REJECT_KEYS = [:fields] # Retrieve search results of the given object type # @@ -21,11 +22,18 @@ def search(options={}, type='people') path = "/#{type.to_s}-search" if options.is_a?(Hash) - fields = options.delete(:fields) - path += field_selector(fields) if fields + fields = options.fetch(:fields, []) + if !fields.empty? + path += field_selector(fields) + else + + end + elsif options.is_a?(String) + options = {:keywords => options} + else + end - options = { :keywords => options } if options.is_a?(String) options = format_options_for_query(options) result_json = get(to_uri(path, options)) @@ -36,11 +44,18 @@ def search(options={}, type='people') private def format_options_for_query(opts) - opts.inject({}) do |list, kv| - key, value = kv.first.to_s.gsub("_","-"), kv.last - list[key] = sanitize_value(value) - list + query_hash = {} + + opts.each do |k, value| + if REJECT_KEYS.include?(k) + next + else + key = k.to_s.gsub("_", "-") + query_hash[key] = sanitize_value(value) + end end + + query_hash end def sanitize_value(value) diff --git a/spec/cases/search_spec.rb b/spec/cases/search_spec.rb index 652274c0..5f112f6a 100644 --- a/spec/cases/search_spec.rb +++ b/spec/cases/search_spec.rb @@ -80,9 +80,18 @@ describe "by keywords options with fields" do use_vcr_cassette :record => :new_episodes + let(:fields) { [{:companies => [:id, :name, :industries, :description, :specialties]}, :num_results] } + let(:options) { {:keywords => 'apple', :fields => fields} } + let(:results) do - fields = [{:companies => [:id, :name, :industries, :description, :specialties]}, :num_results] - client.search({:keywords => 'apple', :fields => fields}, 'company') + client.search(options, 'company') + end + + it "doesn't change the original options" do + original_options = options.dup + client.search(options, 'company') + + options.should == original_options end it "should perform a search" do From f0769ebe65c66c8c3342489743a4a3472393ea70 Mon Sep 17 00:00:00 2001 From: Matt Kirk Date: Fri, 15 Nov 2013 11:41:12 -0800 Subject: [PATCH 2/3] Take out group path delete(:id) --- lib/linked_in/helpers/request.rb | 1 - spec/cases/api_spec.rb | 23 +++++++++++++++++++---- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/lib/linked_in/helpers/request.rb b/lib/linked_in/helpers/request.rb index 94f66592..1495a0ae 100644 --- a/lib/linked_in/helpers/request.rb +++ b/lib/linked_in/helpers/request.rb @@ -59,7 +59,6 @@ def raise_errors(response) end end - # Stolen from Rack::Util.build_query def to_query(params) params.map { |k, v| diff --git a/spec/cases/api_spec.rb b/spec/cases/api_spec.rb index 7346ce2a..ba153405 100644 --- a/spec/cases/api_spec.rb +++ b/spec/cases/api_spec.rb @@ -252,10 +252,25 @@ response.code.should == "201" end - it "should be able to list a group profile" do - stub_request(:get, "https://api.linkedin.com/v1/groups/123").to_return(:body => '{"id": "123"}') - response = client.group_profile(:id => 123) - response.id.should == '123' + context '#group_profile' do + let(:options) do + {:id => 123} + end + + before do + stub_request(:get, "https://api.linkedin.com/v1/groups/123").to_return(:body => '{"id": "123"}') + 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 + response = client.group_profile(options) + response.id.should == options.fetch(:id).to_s + end end it "should be able to list group posts" do From ff888e2ee139bbd1c21e049ebe1d692286402895 Mon Sep 17 00:00:00 2001 From: Matt Kirk Date: Fri, 15 Nov 2013 11:53:42 -0800 Subject: [PATCH 3/3] Taking out some comments --- lib/linked_in/client.rb | 27 --------------------------- 1 file changed, 27 deletions(-) diff --git a/lib/linked_in/client.rb b/lib/linked_in/client.rb index 645f196d..cd4705dc 100644 --- a/lib/linked_in/client.rb +++ b/lib/linked_in/client.rb @@ -1,7 +1,6 @@ require 'cgi' module LinkedIn - class Client include Helpers::Request include Helpers::Authorization @@ -21,31 +20,5 @@ def initialize(ctoken=LinkedIn.token, csecret=LinkedIn.secret, options={}) @consumer_secret = csecret @consumer_options = options end - - # - # def current_status - # path = "/people/~/current-status" - # Crack::XML.parse(get(path))['current_status'] - # end - # - # def network_statuses(options={}) - # options[:type] = 'STAT' - # network_updates(options) - # end - # - # def network_updates(options={}) - # path = "/people/~/network" - # Network.from_xml(get(to_uri(path, options))) - # end - # - # # helpful in making authenticated calls and writing the - # # raw xml to a fixture file - # def write_fixture(path, filename) - # file = File.new("test/fixtures/#{filename}", "w") - # file.puts(access_token.get(path).body) - # file.close - # end - end - end