module LinkedIn::Helpers::Request
Constants
- API_PATH
- DEFAULT_HEADERS
Protected Instance Methods
delete(path, options={})
click to toggle source
# File lib/linked_in/helpers/request.rb, line 32 def delete(path, options={}) response = access_token.delete("#{API_PATH}#{path}", DEFAULT_HEADERS.merge(options)) raise_errors(response) response end
get(path, options={})
click to toggle source
# File lib/linked_in/helpers/request.rb, line 14 def get(path, options={}) response = access_token.get("#{API_PATH}#{path}", DEFAULT_HEADERS.merge(options)) raise_errors(response) response.body end
post(path, body='', options={})
click to toggle source
# File lib/linked_in/helpers/request.rb, line 20 def post(path, body='', options={}) response = access_token.post("#{API_PATH}#{path}", body, DEFAULT_HEADERS.merge(options)) raise_errors(response) response end
put(path, body, options={})
click to toggle source
# File lib/linked_in/helpers/request.rb, line 26 def put(path, body, options={}) response = access_token.put("#{API_PATH}#{path}", body, DEFAULT_HEADERS.merge(options)) raise_errors(response) response end
Private Instance Methods
raise_errors(response)
click to toggle source
# File lib/linked_in/helpers/request.rb, line 40 def raise_errors(response) # Even if the json answer contains the HTTP status code, LinkedIn also sets this code # in the HTTP answer (thankfully). case response.code.to_i when 401 data = Mash.from_json(response.body) raise LinkedIn::Errors::UnauthorizedError.new(data), "(#{data.status}): #{data.message}" when 400 data = Mash.from_json(response.body) raise LinkedIn::Errors::GeneralError.new(data), "(#{data.status}): #{data.message}" when 403 data = Mash.from_json(response.body) raise LinkedIn::Errors::AccessDeniedError.new(data), "(#{data.status}): #{data.message}" when 404 raise LinkedIn::Errors::NotFoundError, "(#{response.code}): #{response.message}" when 500 raise LinkedIn::Errors::InformLinkedInError, "LinkedIn had an internal error. Please let them know in the forum. (#{response.code}): #{response.message}" when 502..503 raise LinkedIn::Errors::UnavailableError, "(#{response.code}): #{response.message}" end end
to_query(params)
click to toggle source
Stolen from Rack::Util.build_query
# File lib/linked_in/helpers/request.rb, line 64 def to_query(params) params.map { |k, v| if v.class == Array to_query(v.map { |x| [k, x] }) else v.nil? ? escape(k) : "#{CGI.escape(k.to_s)}=#{CGI.escape(v.to_s)}" end }.join("&") end
to_uri(path, options)
click to toggle source
# File lib/linked_in/helpers/request.rb, line 74 def to_uri(path, options) uri = URI.parse(path) if options && options != {} uri.query = to_query(options) end uri.to_s end