Skip to content

Commit

Permalink
added LinkedIn::Base object for other LinkedIn objects to inherit from
Browse files Browse the repository at this point in the history
  • Loading branch information
bcantin committed Jul 30, 2010
1 parent fa5429f commit c576b04
Show file tree
Hide file tree
Showing 18 changed files with 48 additions and 115 deletions.
6 changes: 1 addition & 5 deletions lib/linked_in/api_standard_profile_request.rb
@@ -1,9 +1,5 @@
module LinkedIn
class ApiStandardProfileRequest

def initialize(doc)
@doc = doc
end
class ApiStandardProfileRequest < LinkedIn::Base

def url
@doc.xpath("//api-standard-profile-request/url").text
Expand Down
13 changes: 13 additions & 0 deletions lib/linked_in/base.rb
@@ -0,0 +1,13 @@
module LinkedIn
class Base

def self.from_xml(doc)
new(Nokogiri::XML(doc))
end

def initialize(doc)
@doc = doc
end

end
end
20 changes: 6 additions & 14 deletions lib/linked_in/birthdate.rb
@@ -1,35 +1,27 @@
module LinkedIn
class Birthdate
class Birthdate < LinkedIn::Base

# <date-of-birth>
# <year>1972</year>
# <month>1</month>
# <day>3</day>
# </date-of-birth>

def self.from_xml(doc)
new(Nokogiri::XML(doc))
end

def initialize(doc)
@doc = doc
end


def year
@year ||= @doc.xpath("/person/date-of-birth/year").text.to_i
end

def day
@day ||= @doc.xpath("/person/date-of-birth/day").text.to_i
end

def month
@month ||= @doc.xpath("/person/date-of-birth/month").text.to_i
end

def to_date
Date.civil(y=year,m=month,d=day)
end

end
end
end
8 changes: 4 additions & 4 deletions lib/linked_in/client.rb
@@ -1,6 +1,6 @@
module LinkedIn
class Client

# TODO: @ http://developer.linkedin.com/docs/DOC-1061 && / DOC-1014
# add in client.get("/people/~:(im-accounts)")
# client.get("/people/~:(twitter-accounts)")
Expand Down Expand Up @@ -99,17 +99,17 @@ def connections(options={})

Connections.from_xml(get(path)).profiles
end

##
# usage:
# usage:
# dob = client.birthdate
# returns a birthdate object allowing access to day, month, year
# dob.to_date will return a DATE object
def birthdate
path = "/people/~:(date-of-birth)"
Birthdate.from_xml(get(path))
end

def search(options={})
path = "/people"
options = {:keywords => options} if options.is_a?(String)
Expand Down
6 changes: 1 addition & 5 deletions lib/linked_in/company.rb
@@ -1,9 +1,5 @@
module LinkedIn
class Company

def initialize(doc)
@doc = doc
end
class Company < LinkedIn::Base

%w[type name industry].each do |f|
define_method(f.to_sym) do
Expand Down
10 changes: 1 addition & 9 deletions lib/linked_in/connections.rb
@@ -1,13 +1,5 @@
module LinkedIn
class Connections

def self.from_xml(doc)
new(Nokogiri::XML(doc))
end

def initialize(doc)
@doc = doc
end
class Connections < LinkedIn::Base

def connections
@array ||= begin
Expand Down
6 changes: 1 addition & 5 deletions lib/linked_in/country.rb
@@ -1,9 +1,5 @@
module LinkedIn
class Country

def initialize(doc)
@doc = doc
end
class Country < LinkedIn::Base

def code
@doc.xpath("/person/location/country/code").text
Expand Down
5 changes: 1 addition & 4 deletions lib/linked_in/education.rb
@@ -1,8 +1,5 @@
module LinkedIn
class Education
def initialize(doc)
@doc = doc
end
class Education < LinkedIn::Base

def education
@array ||= begin
Expand Down
9 changes: 1 addition & 8 deletions lib/linked_in/error.rb
@@ -1,12 +1,5 @@
module LinkedIn
class Error
def self.from_xml(doc)
new(Nokogiri::XML(doc))
end

def initialize(doc)
@doc = doc
end
class Error < LinkedIn::Base

def status
@doc.xpath('//status').text.to_i
Expand Down
6 changes: 1 addition & 5 deletions lib/linked_in/group.rb
@@ -1,9 +1,5 @@
module LinkedIn
class Group

def initialize(doc)
@doc = doc
end
class Group < LinkedIn::Base

def groups
@array ||= begin
Expand Down
6 changes: 1 addition & 5 deletions lib/linked_in/location.rb
@@ -1,9 +1,5 @@
module LinkedIn
class Location

def initialize(doc)
@doc = doc
end
class Location < LinkedIn::Base

def name
@doc.xpath("/person/location/name").text
Expand Down
10 changes: 1 addition & 9 deletions lib/linked_in/network.rb
@@ -1,13 +1,5 @@
module LinkedIn
class Network

def self.from_xml(doc)
new(Nokogiri::XML(doc))
end

def initialize(doc)
@doc = doc
end
class Network < LinkedIn::Base

def updates
@array ||= begin
Expand Down
10 changes: 1 addition & 9 deletions lib/linked_in/people.rb
@@ -1,13 +1,5 @@
module LinkedIn
class People

def self.from_xml(doc)
new(Nokogiri::XML(doc))
end

def initialize(doc)
@doc = doc
end
class People < LinkedIn::Base

%w[total start count].each do |f|
define_method(f.to_sym) do
Expand Down
6 changes: 1 addition & 5 deletions lib/linked_in/position.rb
@@ -1,9 +1,5 @@
module LinkedIn
class Position

def initialize(doc)
@doc = doc
end
class Position < LinkedIn::Base

def positions
@arry ||= begin
Expand Down
10 changes: 1 addition & 9 deletions lib/linked_in/profile.rb
@@ -1,5 +1,5 @@
module LinkedIn
class Profile
class Profile < LinkedIn::Base

# xml_reader :three_current_positions, :as => [Position]

Expand All @@ -14,14 +14,6 @@ class Profile
end
end

def self.from_xml(doc)
new(Nokogiri::XML(doc))
end

def initialize(doc)
@doc = doc
end

def location
@location ||= Location.new(@doc)
end
Expand Down
6 changes: 1 addition & 5 deletions lib/linked_in/update.rb
@@ -1,16 +1,12 @@
module LinkedIn
class Update
class Update < LinkedIn::Base

%w[update_key update_type is_commentable?].each do |f|
define_method(f.to_sym) do
@doc.xpath("./update/#{f.gsub(/_/,'-')}").text
end
end

def initialize(doc)
@doc = doc
end

def timestamp
@doc.xpath('./update/timestamp').text.to_i
end
Expand Down
6 changes: 1 addition & 5 deletions lib/linked_in/url_resource.rb
@@ -1,9 +1,5 @@
module LinkedIn
class UrlResource

def initialize(doc)
@doc = doc
end
class UrlResource < LinkedIn::Base

def resources
@array ||= begin
Expand Down
20 changes: 11 additions & 9 deletions lib/linkedin.rb
@@ -1,6 +1,6 @@
# require 'forwardable'
# require 'rubygems'
#
#
gem 'oauth', '~> 0.3.5'
require 'oauth'

Expand Down Expand Up @@ -28,44 +28,46 @@ class General < LinkedInError; end
class Unavailable < StandardError; end
class InformLinkedIn < StandardError; end
class NotFound < StandardError; end

# config/initializers/linkedin.rb (for instance)
#
#
# LinkedIn.configure do |config|
# config.token = 'consumer_token'
# config.secret = 'consumer_secret'
# end
#
#
# elsewhere
#
# client = LinkedIn::Client.new
def self.configure
yield self

LinkedIn.token = token
LinkedIn.secret = secret
true
end

def self.token
@token
end

def self.token=(token)
@token = token
end

def self.secret
@secret
end

def self.secret=(secret)
@secret = secret
end
end

directory = File.expand_path(File.dirname(__FILE__))

require File.join(directory, 'linked_in', 'base')

require File.join(directory, 'linked_in', 'api_standard_profile_request')
require File.join(directory, 'linked_in', 'url_resource')
require File.join(directory, 'linked_in', 'company')
Expand Down

0 comments on commit c576b04

Please sign in to comment.