Skip to content

Commit

Permalink
Support the groups API (through group membership calls and join_group…
Browse files Browse the repository at this point in the history
… call
  • Loading branch information
Enric Ribas committed May 29, 2012
1 parent 134fade commit 209e097
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/linked_in/api/query_methods.rb
Expand Up @@ -23,6 +23,11 @@ def company(options = {})
simple_query(path, options)
end

def group_memberships(options = {})
path = "#{person_path(options)}/group-memberships"
simple_query(path, options)
end

private

def simple_query(path, options={})
Expand All @@ -33,7 +38,7 @@ def simple_query(path, options={})
elsif fields
path +=":(#{fields.map{ |f| f.to_s.gsub("_","-") }.join(',')})"
end

headers = options.delete(:headers) || {}
params = options.map { |k,v| "#{k}=#{v}" }.join("&")
path += "?#{params}" if not params.empty?
Expand Down
6 changes: 6 additions & 0 deletions lib/linked_in/api/update_methods.rb
Expand Up @@ -9,6 +9,12 @@ def add_share(share)
post(path, defaults.merge(share).to_json, "Content-Type" => "application/json")
end

def join_group(group_id)
path = "/people/~/group-memberships/#{group_id}"
body = {'membership-state' => {'code' => 'member' }}
put(path, body.to_json, "Content-Type" => "application/json")
end

# def share(options={})
# path = "/people/~/shares"
# defaults = { :visability => 'anyone' }
Expand Down
17 changes: 17 additions & 0 deletions spec/cases/api_spec.rb
Expand Up @@ -83,6 +83,23 @@
end
end

context "Group API" do

it "should be able to list group memberships for a profile" do
stub_request(:get, "https://api.linkedin.com/v1/people/~/group-memberships").to_return(:body => "{}")
client.group_memberships.should be_an_instance_of(LinkedIn::Mash)
end

it "should be able to join a group" do
stub_request(:put, "https://api.linkedin.com/v1/people/~/group-memberships/123").to_return(:body => "", :status => 201)

response = client.join_group(123)
response.body.should == ""
response.code.should == "201"
end

end

context "Errors" do
it "should raise AccessDeniedError when LinkedIn returns 403 status code" do
stub_request(:get, "https://api.linkedin.com/v1/people-search?first-name=Javan").to_return(:body => "{}", :status => 403)
Expand Down

0 comments on commit 209e097

Please sign in to comment.