Class: LinkedIn::Client

Inherits:
Object
  • Object
show all
Includes:
AuthorizationHelpers, RequestHelpers, ToXmlHelpers
Defined in:
lib/linked_in/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from AuthorizationHelpers

#access_token, #authorize_from_access, #authorize_from_request, #consumer, #request_token, #set_callback_url

Methods included from RequestHelpers

#delete, #get, #post, #put

Constructor Details

#initialize(ctoken = LinkedIn.token, csecret = LinkedIn.secret, options = {}) ⇒ Client

Returns a new instance of Client.



9
10
11
12
13
14
15
16
# File 'lib/linked_in/client.rb', line 9

def initialize(ctoken=LinkedIn.token, csecret=LinkedIn.secret, options={})
  opts = {
    :request_token_path => "/uas/oauth/requestToken",
    :access_token_path  => "/uas/oauth/accessToken",
    :authorize_path     => "/uas/oauth/authorize"
  }
  @ctoken, @csecret, @consumer_options = ctoken, csecret, opts.merge(options)
end

Instance Attribute Details

#consumer_optionsObject (readonly)

Returns the value of attribute consumer_options.



7
8
9
# File 'lib/linked_in/client.rb', line 7

def consumer_options
  @consumer_options
end

#csecretObject (readonly)

Returns the value of attribute csecret.



7
8
9
# File 'lib/linked_in/client.rb', line 7

def csecret
  @csecret
end

#ctokenObject (readonly)

Returns the value of attribute ctoken.



7
8
9
# File 'lib/linked_in/client.rb', line 7

def ctoken
  @ctoken
end

Instance Method Details

#clear_statusObject



89
90
91
92
# File 'lib/linked_in/client.rb', line 89

def clear_status
  path = "/people/~/current-status"
  delete(path).code
end

#connections(options = {}) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/linked_in/client.rb', line 32

def connections(options={})
  path = "#{person_path(options)}/connections"
  fields = options[:fields] || LinkedIn.default_profile_fields

  if options[:public]
    path +=":public"
  elsif fields
    path +=":(#{fields.map{ |f| f.to_s.gsub("_","-") }.join(',')})"
  end

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

#current_statusObject



53
54
55
56
# File 'lib/linked_in/client.rb', line 53

def current_status
  path = "/people/~/current-status"
  Nokogiri::XML(get(path)).xpath('//current-status').text
end

#like(network_key, is_liked = true) ⇒ Object



74
75
76
77
# File 'lib/linked_in/client.rb', line 74

def like(network_key, is_liked=true)
  path = "/people/~/network/updates/key=#{network_key}/is-liked"
  put(path, is_liked_to_xml(is_liked))
end

#likes(network_key) ⇒ Object



79
80
81
82
# File 'lib/linked_in/client.rb', line 79

def likes(network_key)
  path = "/people/~/network/updates/key=#{network_key}/likes"
  Likes.from_xml(get(path)).likes
end

#network_statuses(options = {}) ⇒ Object



113
114
115
116
# File 'lib/linked_in/client.rb', line 113

def network_statuses(options={})
  options[:type] = 'STAT'
  network_updates(options)
end

#network_updates(options = {}) ⇒ Object



118
119
120
121
# File 'lib/linked_in/client.rb', line 118

def network_updates(options={})
  path = "/people/~/network"
  Network.from_xml(get(to_uri(path, options)))
end

#profile(options = {}) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/linked_in/client.rb', line 19

def profile(options={})
  path   = person_path(options)
  fields = options[:fields] || LinkedIn.default_profile_fields

  if options[:public]
    path +=":public"
  elsif fields
    path +=":(#{fields.map{ |f| f.to_s.gsub("_","-") }.join(',')})"
  end

  Profile.from_xml(get(path))
end

#search(options = {}) ⇒ Object



45
46
47
48
49
50
51
# File 'lib/linked_in/client.rb', line 45

def search(options={})
  path = "/people"
  options = { :keywords => options } if options.is_a?(String)
  options = format_options_for_query(options)

  People.from_xml(get(to_uri(path, options)))
end

#send_message(subject, body, recipient_paths) ⇒ Object



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/linked_in/client.rb', line 94

def send_message(subject, body, recipient_paths)
  path = "/people/~/mailbox"

  message         = LinkedIn::Message.new
  message.subject = subject
  message.body    = body
  recipients      = LinkedIn::Recipients.new

  recipients.recipients = recipient_paths.map do |profile_path|
    recipient             = LinkedIn::Recipient.new
    recipient.person      = LinkedIn::Person.new
    recipient.person.path = "/people/#{profile_path}"
    recipient
  end

  message.recipients = recipients
  post(path, message_to_xml(message)).code
end

#share(options = {}) ⇒ Object



63
64
65
66
67
# File 'lib/linked_in/client.rb', line 63

def share(options={})
  path = "/people/~/shares"
  defaults = { :visability => 'anyone' }
  post(path, share_to_xml(defaults.merge(options)))
end

#update_comment(network_key, comment) ⇒ Object



69
70
71
72
# File 'lib/linked_in/client.rb', line 69

def update_comment(network_key, comment)
  path = "/people/~/network/updates/key=#{network_key}/update-comments"
  post(path, comment_to_xml(comment))
end

#update_network(message) ⇒ Object



84
85
86
87
# File 'lib/linked_in/client.rb', line 84

def update_network(message)
  path = "/people/~/person-activities"
  post(path, network_update_to_xml(message))
end

#update_status(text) ⇒ Object



58
59
60
61
# File 'lib/linked_in/client.rb', line 58

def update_status(text)
  path = "/people/~/current-status"
  put(path, status_to_xml(text))
end

#write_fixture(path, filename) ⇒ Object

helpful in making authenticated calls and writing the raw xml to a fixture file



125
126
127
128
129
# File 'lib/linked_in/client.rb', line 125

def write_fixture(path, filename)
  file = File.new("test/fixtures/#{filename}", "w")
  file.puts(access_token.get(path).body)
  file.close
end