ezlinkedin 0.2.2 → 0.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 732cfd1e0e6434f0a3cafe87bd6e6196c4537442
4
- data.tar.gz: af17d9ba544c77223fe0c81bf016c45a9dbbca58
3
+ metadata.gz: 026514954030db6836bac2efd36665279e3f3c3e
4
+ data.tar.gz: ad1c5b6f9db60dcbcffc3858657e799abc6f9717
5
5
  SHA512:
6
- metadata.gz: 358ee684769177036991aab5cb8b22dcab1f1df0267aec93b6ebf8939729d31ef79594012682e026cbf47620c26a46435bae809567de1d67d942cc8cd900c1a6
7
- data.tar.gz: 83813e8d1f536d4e8380a12248b13e3053e43e619e4cf329991ad3e18c8e7eb786b9df133d9ebe6d2fe6417e1c861b2e78854ecc4daedecf98d38912df1ecb09
6
+ metadata.gz: fc0bf270a371ce6d82bba6a1c983dcb233cb024844768280aad2b9595cdfb7940a0d7dd957428270c70b7165daaec6a9d9d340b1b6cca588d0391f935cad1dac
7
+ data.tar.gz: 87ec5eb125cc43d65dc446394598143770a30ac507f7a00000bb321822ca6bcd2f18ff60fb32b1bb6596dc1523db8ce14b5684bdd9b313fb5407c35948989a2d
@@ -164,4 +164,4 @@ module EzLinkedin
164
164
  end
165
165
 
166
166
  end
167
- end
167
+ end
@@ -5,6 +5,7 @@ module EzLinkedin
5
5
  include Request
6
6
  include Api::QueryMethods
7
7
  include Api::UpdateMethods
8
+ include Search
8
9
 
9
10
  attr_reader :consumer_key, :consumer_secret, :access_token, :client
10
11
  attr_accessor :consumer_options
@@ -1,5 +1,4 @@
1
1
  module EzLinkedin
2
-
3
2
  module Request
4
3
  DEFAULT_HEADERS = {
5
4
  'x-li-format' => 'json'
@@ -52,5 +51,4 @@ module EzLinkedin
52
51
  end
53
52
 
54
53
  end
55
-
56
54
  end
@@ -0,0 +1,58 @@
1
+ module EzLinkedin
2
+ module Search
3
+
4
+ #
5
+ # Search linkedin based on keywords or fields
6
+ # @param options [Hash or String] Hash of search criteria or
7
+ # a string of keyword(s).
8
+ # In order to specify fields for a resource(companies or people):
9
+ # pass in the fields as a hash of arrays.
10
+ # client.search(:people => ['id', 'first-name'], fields: ['num-results'])
11
+ # client.search(:companies => ['id', 'name'])
12
+ # @param type="people" [String or symbol] :people or :company search?
13
+ #
14
+ # @return [Mash] hash of results
15
+ def search(options, type="people")
16
+ path = "/#{type.to_s}-search"
17
+
18
+ if options.is_a?(Hash)
19
+ if type_fields = options.delete(type.to_sym)
20
+ if type != 'people'
21
+ path += ":(companies:(#{type_fields.join(',')})#{search_fields(options)})"
22
+ else
23
+ path += ":(people:(#{type_fields.join(',')})#{search_fields(options)})"
24
+ end
25
+ end
26
+ path += configure_fields(options)
27
+ elsif options.is_a?(String)
28
+ path += configure_fields({keywords: options})
29
+ options = {}
30
+ end
31
+
32
+ Mash.from_json(get(path, options))
33
+ end
34
+
35
+ private
36
+
37
+ def search_fields(options)
38
+ if fields = options.delete(:fields)
39
+ ",#{fields.join(',')}"
40
+ end
41
+ end
42
+
43
+ def configure_fields(options)
44
+ path = ""
45
+ options.each do |k, v|
46
+ key = format_for_query(k.to_s)
47
+ path += "#{key}=#{URI::encode(v)}"
48
+ options.delete(k)
49
+ end
50
+ path = "?#{path}" unless path.empty?
51
+ path
52
+ end
53
+
54
+ def format_for_query(key)
55
+ key.gsub("_", "-")
56
+ end
57
+ end
58
+ end
@@ -1,3 +1,3 @@
1
1
  module Ezlinkedin
2
- VERSION = "0.2.2"
2
+ VERSION = "0.4.2"
3
3
  end
data/lib/ezlinkedin.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require "ezlinkedin/version"
2
2
  require 'ezlinkedin/request'
3
3
  require 'ezlinkedin/api'
4
+ require 'ezlinkedin/search'
4
5
  require 'ezlinkedin/mash'
5
6
  require 'ezlinkedin/client'
6
7
  require 'ezlinkedin/errors'
data/spec/api_spec.rb CHANGED
@@ -45,29 +45,35 @@ describe EzLinkedin::Api do
45
45
  # client.share_likes("network_update_key").should be_an_instance_of(EzLinkedin::Mash)
46
46
  # end
47
47
  #
48
- # it "should be able to search with a keyword if given a String" do
49
- # stub_request(:get, "https://api.linkedin.com/v1/people-search?keywords=business").to_return(:body => "{}")
50
- # client.search("business").should be_an_instance_of(EzLinkedin::Mash)
51
- # end
52
- #
53
- # it "should be able to search with an option" do
54
- # stub_request(:get, "https://api.linkedin.com/v1/people-search?first-name=Javan").to_return(:body => "{}")
55
- # client.search(:first_name => "Javan").should be_an_instance_of(EzLinkedin::Mash)
56
- # end
57
- #
58
- # it "should be able to search with an option and fetch specific fields" do
59
- # stub_request(:get, "https://api.linkedin.com/v1/people-search:(num-results,total)?first-name=Javan").to_return(
60
- # :body => "{}")
61
- # client.search(:first_name => "Javan", :fields => ["num_results", "total"]).should be_an_instance_of(EzLinkedin::Mash)
62
- # end
63
- #
48
+ it "should be able to search with a keyword if given a String" do
49
+ stub_request(:get, "https://api.linkedin.com/v1/people-search?keywords=business").to_return(:body => "{}")
50
+ client.search("business").should be_an_instance_of(EzLinkedin::Mash)
51
+ end
52
+
53
+ it "should be able to search with an option" do
54
+ stub_request(:get, "https://api.linkedin.com/v1/people-search?first-name=Javan").to_return(:body => "{}")
55
+ client.search(:first_name => "Javan").should be_an_instance_of(EzLinkedin::Mash)
56
+ end
57
+
58
+ it "should be able to search with an option and fetch specific fields" do
59
+ stub_request(:get, "https://api.linkedin.com/v1/people-search:(people:(id,first-name),num-results)?first-name=Javan").to_return(
60
+ :body => "{}")
61
+ client.search(:first_name => "Javan", :people => ["id", "first-name"], :fields => ['num-results']).should be_an_instance_of(EzLinkedin::Mash)
62
+ end
63
+
64
+ it "should be able to search companies" do
65
+ stub_request(:get, "https://api.linkedin.com/v1/company-search:(companies:(id,name),num-results)?keywords=apple").to_return(
66
+ :body => "{}")
67
+ client.search({:keywords => "apple", :company => ["id", "name"], :fields => ['num-results']}, "company").should be_an_instance_of(EzLinkedin::Mash)
68
+ end
69
+
64
70
  it "should be able to post a share" do
65
71
  stub_request(:post, "https://api.linkedin.com/v1/people/~/shares").to_return(:body => "", :status => 201)
66
72
  response = client.post_share({:comment => "Testing, 1, 2, 3"})
67
73
  response.body.should == nil
68
74
  response.code.should == "201"
69
75
  end
70
- #
76
+
71
77
  # it "should be able to comment on network update" do
72
78
  # stub_request(:post, "https://api.linkedin.com/v1/people/~/network/updates/key=SOMEKEY/update-comments").to_return(
73
79
  # :body => "", :status => 201)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ezlinkedin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - akonwi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-06-03 00:00:00.000000000 Z
11
+ date: 2013-06-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: oauth
@@ -187,6 +187,7 @@ files:
187
187
  - lib/ezlinkedin/errors.rb
188
188
  - lib/ezlinkedin/mash.rb
189
189
  - lib/ezlinkedin/request.rb
190
+ - lib/ezlinkedin/search.rb
190
191
  - lib/ezlinkedin/version.rb
191
192
  - spec/api_spec.rb
192
193
  - spec/client_spec.rb