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

Remove deletes #186

Open
wants to merge 3 commits 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
27 changes: 0 additions & 27 deletions lib/linked_in/client.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
require 'cgi'

module LinkedIn

class Client
include Helpers::Request
include Helpers::Authorization
Expand All @@ -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
1 change: 0 additions & 1 deletion lib/linked_in/helpers/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ def raise_errors(response)
end
end


# Stolen from Rack::Util.build_query
def to_query(params)
params.map { |k, v|
Expand Down
29 changes: 22 additions & 7 deletions lib/linked_in/search.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module LinkedIn

module Search
REJECT_KEYS = [:fields]

# Retrieve search results of the given object type
#
Expand All @@ -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))
Expand All @@ -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)
Expand Down
23 changes: 19 additions & 4 deletions spec/cases/api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 11 additions & 2 deletions spec/cases/search_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down