linkedin 0.1.7 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. data/.autotest +14 -0
  2. data/.document +5 -0
  3. data/.gitignore +25 -0
  4. data/Gemfile +3 -0
  5. data/README.markdown +12 -7
  6. data/Rakefile +10 -33
  7. data/VERSION +1 -1
  8. data/changelog.markdown +38 -0
  9. data/examples/authenticate.rb +1 -1
  10. data/lib/linked_in/api_standard_profile_request.rb +14 -6
  11. data/lib/linked_in/authorization_helpers.rb +48 -0
  12. data/lib/linked_in/base.rb +13 -0
  13. data/lib/linked_in/birthdate.rb +21 -0
  14. data/lib/linked_in/client.rb +86 -146
  15. data/lib/linked_in/company.rb +9 -7
  16. data/lib/linked_in/connections.rb +14 -5
  17. data/lib/linked_in/country.rb +7 -5
  18. data/lib/linked_in/current_share.rb +56 -0
  19. data/lib/linked_in/education.rb +40 -14
  20. data/lib/linked_in/error.rb +19 -8
  21. data/lib/linked_in/group.rb +30 -7
  22. data/lib/linked_in/languages.rb +28 -0
  23. data/lib/linked_in/likes.rb +23 -0
  24. data/lib/linked_in/location.rb +11 -6
  25. data/lib/linked_in/message.rb +20 -0
  26. data/lib/linked_in/network.rb +10 -5
  27. data/lib/linked_in/patents.rb +42 -0
  28. data/lib/linked_in/people.rb +16 -8
  29. data/lib/linked_in/person.rb +7 -0
  30. data/lib/linked_in/phone_number.rb +29 -0
  31. data/lib/linked_in/position.rb +45 -14
  32. data/lib/linked_in/profile.rb +81 -28
  33. data/lib/linked_in/publications.rb +40 -0
  34. data/lib/linked_in/recipient.rb +7 -0
  35. data/lib/linked_in/recipients.rb +18 -0
  36. data/lib/linked_in/recommendations.rb +30 -0
  37. data/lib/linked_in/request_helpers.rb +76 -0
  38. data/lib/linked_in/short_profile.rb +13 -0
  39. data/lib/linked_in/skill.rb +33 -0
  40. data/lib/linked_in/to_xml_helpers.rb +53 -0
  41. data/lib/linked_in/update.rb +21 -9
  42. data/lib/linked_in/url_resource.rb +24 -6
  43. data/lib/linkedin.rb +58 -59
  44. data/linkedin.gemspec +52 -0
  45. data/spec/cases/client_spec.rb +281 -0
  46. data/spec/cases/linkedin_spec.rb +37 -0
  47. data/spec/cases/oauth_spec.rb +109 -0
  48. data/{test → spec}/fixtures/blank.xml +0 -0
  49. data/{test → spec}/fixtures/connections.xml +0 -0
  50. data/{test → spec}/fixtures/error.xml +0 -0
  51. data/spec/fixtures/likes.xml +18 -0
  52. data/spec/fixtures/mailbox_items.xml +16 -0
  53. data/{test → spec}/fixtures/network_status_with_group.xml +3 -3
  54. data/{test → spec}/fixtures/network_statuses.xml +18 -0
  55. data/{test → spec}/fixtures/picture_updates.xml +0 -0
  56. data/{test → spec}/fixtures/profile.xml +0 -0
  57. data/{test → spec}/fixtures/profile_full.xml +57 -0
  58. data/{test → spec}/fixtures/profile_with_positions.xml +0 -0
  59. data/{test → spec}/fixtures/search.xml +2 -2
  60. data/spec/fixtures/shares.xml +12 -0
  61. data/{test → spec}/fixtures/status.xml +0 -0
  62. data/spec/spec_helper.rb +49 -0
  63. metadata +160 -76
  64. data/test/client_test.rb +0 -124
  65. data/test/oauth_test.rb +0 -117
  66. data/test/test_helper.rb +0 -51
@@ -1,9 +1,11 @@
1
1
  module LinkedIn
2
- class Company
3
- include ROXML
4
- xml_convention {|val| val.gsub("_","-") }
5
- xml_reader :type
6
- xml_reader :name
7
- xml_reader :industry
2
+ class Company < LinkedIn::Base
3
+
4
+ %w[type name industry].each do |f|
5
+ define_method(f.to_sym) do
6
+ @doc.xpath("./#{f.gsub(/_/,'-')}").text
7
+ end
8
+ end
9
+
8
10
  end
9
- end
11
+ end
@@ -1,7 +1,16 @@
1
1
  module LinkedIn
2
- class Connections
3
- include ROXML
4
- xml_convention {|val| val.gsub("_","-") }
5
- xml_reader :profiles, :as => [Profile], :from => 'person'
2
+ class Connections < LinkedIn::Base
3
+
4
+ def connections
5
+ @connections ||= @doc.xpath('//connections').children.inject([]) do |list, profile|
6
+ list << Profile.new(Nokogiri::XML(profile.to_xml)) unless profile.blank?
7
+ list
8
+ end
9
+ end
10
+
11
+ def profiles
12
+ connections
13
+ end
14
+
6
15
  end
7
- end
16
+ end
@@ -1,7 +1,9 @@
1
1
  module LinkedIn
2
- class Country
3
- include ROXML
4
- xml_convention {|val| val.gsub("_","-") }
5
- xml_reader :code
2
+ class Country < LinkedIn::Base
3
+
4
+ def code
5
+ @doc.xpath("/person/location/country/code").text
6
+ end
7
+
6
8
  end
7
- end
9
+ end
@@ -0,0 +1,56 @@
1
+ module LinkedIn
2
+
3
+ class CurrentShare < LinkedIn::Base
4
+ %w[id comment].each do |f|
5
+ define_method(f.to_sym) do
6
+ @doc.xpath("./#{f.gsub(/_/,'-')}").text
7
+ end
8
+ end
9
+
10
+ def submitted_url
11
+ @doc.xpath('./content/submitted-url').text
12
+ end
13
+
14
+ def resolved_url
15
+ @doc.xpath('./content/resolved-url').text
16
+ end
17
+
18
+ def shortened_url
19
+ @doc.xpath('./content/shortened-url').text
20
+ end
21
+
22
+ def title
23
+ @doc.xpath('./content/title').text
24
+ end
25
+
26
+ def description
27
+ @doc.xpath('./content/description').text
28
+ end
29
+
30
+ def submitted_image_url
31
+ @doc.xpath('./content/submitted-image-url').text
32
+ end
33
+
34
+ def thumbnail_url
35
+ @doc.xpath('./content/thumbnail-url').text
36
+ end
37
+
38
+ def timestamp
39
+ time = @doc.xpath('./timestamp').text.to_i
40
+ Time.at(time / 1000)
41
+ end
42
+
43
+ def visibility
44
+ @doc.xpath('./visibility/code').text
45
+ end
46
+
47
+ def application
48
+ @doc.xpath('./source/application/name').text
49
+ end
50
+
51
+ def author
52
+ @author ||= ShortProfile.new(@doc.xpath('./author'))
53
+ end
54
+ end
55
+
56
+ end
@@ -1,15 +1,41 @@
1
1
  module LinkedIn
2
- class Education
3
- include ROXML
4
- xml_convention {|val| val.gsub("_","-") }
5
- xml_reader :id
6
- xml_reader :school_name
7
- xml_reader :degree
8
- xml_reader :field_of_study
9
- xml_reader :activities
10
- xml_reader :start_year, :from => "start-date/year", :as => Integer
11
- xml_reader :start_month, :from => "start-date/month", :as => Integer
12
- xml_reader :end_year, :from => "end-date/year", :as => Integer
13
- xml_reader :end_month, :from => "end-date/month", :as => Integer
14
- end
15
- end
2
+ class Education < LinkedIn::Base
3
+
4
+ def educations
5
+ @educations ||= @doc.children.inject([]) do |list, edu|
6
+ list << Resource.new(edu) unless edu.blank?
7
+ list
8
+ end
9
+ end
10
+
11
+ class Resource
12
+
13
+ def initialize(education)
14
+ @education = education
15
+ end
16
+
17
+ %w[id school_name degree field_of_study activities notes].each do |f|
18
+ define_method(f.to_sym) do
19
+ @education.xpath("./#{f.gsub(/_/,'-')}").text
20
+ end
21
+ end
22
+
23
+ def start_month
24
+ @education.xpath('./start-date/month').text.to_i
25
+ end
26
+
27
+ def start_year
28
+ @education.xpath('./start-date/year').text.to_i
29
+ end
30
+
31
+ def end_month
32
+ @education.xpath('./end-date/month').text.to_i
33
+ end
34
+
35
+ def end_year
36
+ @education.xpath('./end-date/year').text.to_i
37
+ end
38
+ end # resource class
39
+
40
+ end # education class
41
+ end
@@ -1,10 +1,21 @@
1
1
  module LinkedIn
2
- class Error
3
- include ROXML
4
- xml_convention {|val| val.gsub("_","-") }
5
- xml_reader :status, :as => Integer
6
- xml_reader :timestamp, :as => Integer
7
- xml_reader :code, :as => Integer, :from => "error-code"
8
- xml_reader :message
2
+ class Error < LinkedIn::Base
3
+
4
+ def status
5
+ @doc.xpath('//status').text.to_i
6
+ end
7
+
8
+ def timestamp
9
+ @doc.xpath('//timestamp').text.to_i
10
+ end
11
+
12
+ def code
13
+ @doc.xpath('//error-coce').text.to_i
14
+ end
15
+
16
+ def message
17
+ @doc.xpath('//message').text
18
+ end
19
+
9
20
  end
10
- end
21
+ end
@@ -1,9 +1,32 @@
1
1
  module LinkedIn
2
- class Group
3
- include ROXML
4
- xml_convention {|val| val.gsub("_","-") }
5
- xml_reader :id
6
- xml_reader :name
7
- xml_reader :site_group_request, :as => ApiStandardProfileRequest
2
+ class Group < LinkedIn::Base
3
+
4
+ def groups
5
+ @groups ||= @doc.children.inject([]) do |list, group|
6
+ list << Resource.new(group) unless group.blank?
7
+ list
8
+ end
9
+ end
10
+
11
+ class Resource
12
+
13
+ def initialize(group)
14
+ @group = group
15
+ end
16
+
17
+ def id
18
+ @group.xpath('//member-group/id').text.to_i
19
+ end
20
+
21
+ def name
22
+ @group.xpath('//member-group/name').text
23
+ end
24
+
25
+ def url
26
+ @group.xpath('//member-group/site-group-request/url').text
27
+ end
28
+
29
+ end
30
+
8
31
  end
9
- end
32
+ end
@@ -0,0 +1,28 @@
1
+ module LinkedIn
2
+ class Languages < LinkedIn::Base
3
+
4
+ def languages
5
+ @languages ||= @doc.children.inject([]) do |list, lang|
6
+ list << Resource.new(lang) unless lang.blank?
7
+ list
8
+ end
9
+ end
10
+
11
+ class Resource
12
+ # proficiency level not implemented yet
13
+ # http://developer.linkedin.com/community/apis/blog/2011/01/04/new-profile-fields-are-here
14
+ def initialize(language)
15
+ @language = language
16
+ end
17
+
18
+ def id
19
+ @language.xpath("./id").text
20
+ end
21
+
22
+ def name
23
+ @language.xpath("./language/name").text
24
+ end
25
+ end
26
+
27
+ end
28
+ end
@@ -0,0 +1,23 @@
1
+ module LinkedIn
2
+ class Likes < LinkedIn::Base
3
+
4
+ def likes
5
+ @likes ||= @doc.xpath('//likes').children.inject([]) do |list, like|
6
+ list << Resource.new(like) unless like.blank?
7
+ list
8
+ end
9
+ end
10
+
11
+ class Resource
12
+ def initialize(like)
13
+ @like = like
14
+ end
15
+
16
+ def profile
17
+ Profile.new(Nokogiri::XML(@like.xpath('./person').to_xml))
18
+ end
19
+
20
+ end
21
+
22
+ end
23
+ end
@@ -1,8 +1,13 @@
1
1
  module LinkedIn
2
- class Location
3
- include ROXML
4
- xml_convention {|val| val.gsub("_","-") }
5
- xml_reader :name
6
- xml_reader :country, :as => {:key => :name, :value => :content}
2
+ class Location < LinkedIn::Base
3
+
4
+ def name
5
+ @doc.xpath("/person/location/name").text
6
+ end
7
+
8
+ def country
9
+ @doc.xpath("/person/location/country/code").text
10
+ end
11
+
7
12
  end
8
- end
13
+ end
@@ -0,0 +1,20 @@
1
+ module LinkedIn
2
+ class Message
3
+
4
+ attr_accessor :subject, :body, :recipients
5
+
6
+ def to_xml
7
+ self.to_xml_node(Nokogiri.XML('<root/>', nil, 'UTF-8')).to_xml
8
+ end
9
+
10
+ def to_xml_node(doc)
11
+ node = Nokogiri::XML::DocumentFragment.new(doc, '<mailbox-item><recipients/><subject/><body/></mailbox-item>')
12
+ node.at_css('recipients').add_child(self.recipients.to_xml_nodes(doc))
13
+ node.at_css('subject').content = self.subject
14
+ node.at_css('body').content = self.body
15
+ node
16
+ end
17
+
18
+ end
19
+
20
+ end
@@ -1,7 +1,12 @@
1
1
  module LinkedIn
2
- class Network
3
- include ROXML
4
- xml_convention {|val| val.gsub("_","-") }
5
- xml_reader :updates, :as => [Update]
2
+ class Network < LinkedIn::Base
3
+
4
+ def updates
5
+ @updates ||= @doc.xpath('//updates').children.inject([]) do |list, update|
6
+ list << Update.new(Nokogiri::XML(update.to_xml)) unless update.blank?
7
+ list
8
+ end
9
+ end
10
+
6
11
  end
7
- end
12
+ end
@@ -0,0 +1,42 @@
1
+ module LinkedIn
2
+ class Patents < LinkedIn::Base
3
+
4
+ def patents
5
+ @patents ||= @doc.children.inject([]) do |list, patent|
6
+ list << Resource.new(patent) unless patent.blank?
7
+ list
8
+ end
9
+ end
10
+
11
+ class Resource
12
+
13
+ def initialize(patent)
14
+ @patent = patent
15
+ end
16
+
17
+ %w[id title].each do |f|
18
+ define_method(f.to_sym) do
19
+ @patent.xpath("./#{f.gsub(/_/,'-')}").text
20
+ end
21
+ end
22
+
23
+ def year
24
+ @year ||= @patent.xpath("./date/year").text.to_i
25
+ end
26
+
27
+ def day
28
+ @day ||= @patent.xpath("./date/day").text.to_i
29
+ end
30
+
31
+ def month
32
+ @month ||= @patent.xpath("./date/month").text.to_i
33
+ end
34
+
35
+ def date
36
+ Date.civil(y=year,m=month,d=day)
37
+ end
38
+
39
+ end # resource class
40
+
41
+ end # patent class
42
+ end
@@ -1,10 +1,18 @@
1
1
  module LinkedIn
2
- class People
3
- include ROXML
4
- xml_convention {|val| val.gsub("_","-") }
5
- xml_reader :total, :as => Integer, :from => "@total"
6
- xml_reader :start, :as => Integer, :from => "@start"
7
- xml_reader :count, :as => Integer, :from => "@count"
8
- xml_reader :profiles, :as => [Profile], :from => 'person'
2
+ class People < LinkedIn::Base
3
+
4
+ %w[total start count].each do |f|
5
+ define_method(f.to_sym) do
6
+ @doc.xpath('.//people').first["#{f.gsub(/_/,'-')}"].to_i
7
+ end
8
+ end
9
+
10
+ def profiles
11
+ @profiles ||= @doc.xpath('//people').children.inject([]) do |list, profile|
12
+ list << Profile.new(Nokogiri::XML(profile.to_xml)) unless profile.blank?
13
+ list
14
+ end
15
+ end
16
+
9
17
  end
10
- end
18
+ end
@@ -0,0 +1,7 @@
1
+ module LinkedIn
2
+ class Person
3
+
4
+ attr_accessor :path
5
+
6
+ end
7
+ end
@@ -0,0 +1,29 @@
1
+ module LinkedIn
2
+ class PhoneNumber < LinkedIn::Base
3
+
4
+ def phone_numbers
5
+ @array ||= begin
6
+ @array = []
7
+ @doc.children.each do |pn|
8
+ @array << Resource.new(pn) unless pn.blank?
9
+ end
10
+ @array
11
+ end
12
+ end
13
+
14
+ class Resource
15
+
16
+ def initialize(phone_number)
17
+ @phone_number = phone_number
18
+ end
19
+
20
+ %w[phone_type phone_number].each do |f|
21
+ define_method(f.to_sym) do
22
+ @phone_number.xpath("./#{f.gsub(/_/,'-')}").text
23
+ end
24
+ end
25
+
26
+ end # resource class
27
+
28
+ end # phone_number class
29
+ end