class Object
Public Instance Methods
build_fields_params(fields)
click to toggle source
# File lib/linked_in/api_resource.rb, line 122 def build_fields_params(fields) if fields.is_a?(Hash) && !fields.empty? fields.map {|v| "(#{build_fields_params(v)})" }.join(',') elsif fields.respond_to?(:each) fields.map {|field| build_fields_params(field) }.join(',') else fields.to_s.gsub("_", "-") end end
format_options_for_query(options)
click to toggle source
Dasherizes the param keys
# File lib/linked_in/api_resource.rb, line 102 def format_options_for_query(options) options.reduce({}) do |list, kv| key, value = kv.first.to_s.gsub("_","-"), kv.last list[key] = value list end end
generate_field_selectors(options)
click to toggle source
# File lib/linked_in/api_resource.rb, line 110 def generate_field_selectors(options) default = LinkedIn.config.default_profile_fields || {} fields = options.delete(:fields) || default if options.delete(:public) return ":public" elsif fields.empty? return "" else return "?projection=(#{fields})" end end
is_self(str)
click to toggle source
# File lib/linked_in/api_resource.rb, line 176 def is_self(str) str == "self" or str == "me" end
multiple_people_path(ids=[], urls=[])
click to toggle source
See syntax here: developer.linkedin.com/documents/field-selectors
# File lib/linked_in/api_resource.rb, line 163 def multiple_people_path(ids=[], urls=[]) if ids.nil? then ids = [] end if urls.nil? then urls = [] end ids = ids.map do |id| if is_self(id) then "me" else "id=#{id}" end end urls = urls.map do |url| if is_self(url) then "me" else "url=#{CGI.escape(url)}" end end return "::(#{(ids+urls).join(",")})" end
parse_modified_since(since)
click to toggle source
Returns a unix time in miliseconds
# File lib/linked_in/people.rb, line 131 def parse_modified_since(since) if since.is_a? ::Fixnum if ::Time.at(since).year < 2050 # Got passed in as seconds. since = since * 1000 end elsif since.is_a? ::String since = utc_parse(since) elsif since.is_a? ::Time since = since.to_i * 1000 end return since end
prepare_connection_params(path, options)
click to toggle source
# File lib/linked_in/api_resource.rb, line 90 def prepare_connection_params(path, options) path = prepend_prefix(path) path += generate_field_selectors(options) headers = options.delete(:headers) || {} params = format_options_for_query(options) return [path, params, headers] end
profile_path(options={}, allow_multiple=true)
click to toggle source
# File lib/linked_in/api_resource.rb, line 132 def profile_path(options={}, allow_multiple=true) path = "/people" id = options.delete(:id) url = options.delete(:url) ids = options.delete(:ids) urls = options.delete(:urls) if options.delete(:email) then raise deprecated end if (id or url) path += single_person_path(id, url) elsif allow_multiple and (ids or urls) path += multiple_people_path(ids, urls) else path = "/me" end end
single_person_path(id=nil, url=nil)
click to toggle source
# File lib/linked_in/api_resource.rb, line 152 def single_person_path(id=nil, url=nil) if id return "/id=#{id}" elsif url return "/url=#{CGI.escape(url)}" else return "/me" end end
utc_parse(since)
click to toggle source
# File lib/linked_in/people.rb, line 145 def utc_parse(since) t = ::Time.parse(since) Time.utc(t.year, t.month, t.day, t.hour, t.min, t.sec).to_i * 1000 end