Module: LinkedIn::RequestHelpers
- Included in:
- Client
- Defined in:
- lib/linked_in/request_helpers.rb
Instance Method Summary collapse
- #delete(path, options = {}) ⇒ Object
- #get(path, options = {}) ⇒ Object
- #post(path, body = '', options = {}) ⇒ Object
- #put(path, body, options = {}) ⇒ Object
- #raise_errors(response) ⇒ Object
- #to_query(options) ⇒ Object
- #to_uri(path, options) ⇒ Object
Instance Method Details
#delete(path, options = {}) ⇒ Object
27 28 29 30 31 32 |
# File 'lib/linked_in/request_helpers.rb', line 27 def delete(path, ={}) path = "/v1#{path}" response = access_token.delete(path, ) raise_errors(response) response end |
#get(path, options = {}) ⇒ Object
5 6 7 8 9 10 |
# File 'lib/linked_in/request_helpers.rb', line 5 def get(path, ={}) path = "/v1#{path}" response = access_token.get(path, ) raise_errors(response) response.body end |
#post(path, body = '', options = {}) ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/linked_in/request_helpers.rb', line 12 def post(path, body='', ={}) path = "/v1#{path}" = { 'Content-Type' => 'application/xml' } response = access_token.post(path, body, .merge()) raise_errors(response) response end |
#put(path, body, options = {}) ⇒ Object
20 21 22 23 24 25 |
# File 'lib/linked_in/request_helpers.rb', line 20 def put(path, body, ={}) path = "/v1#{path}" response = access_token.put(path, body, ) raise_errors(response) response end |
#raise_errors(response) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/linked_in/request_helpers.rb', line 35 def raise_errors(response) # Even if the XML answer contains the HTTP status code, LinkedIn also sets this code # in the HTTP answer (thankfully). if response.code.to_i >= 400 data = LinkedIn::Error.from_xml(response.body) = "(#{response.code}): #{data.} - #{data.code}" case response.code.to_i when 400 raise BadRequest.new(data), when 401 raise Unauthorized.new(data), when 403 raise Forbidden.new(data), when 404 raise NotFound.new(data), when 500 raise InformLinkedIn, "LinkedIn had an internal error. Please let them know in the forum. #{}" when 502..503 raise Unavailable, end end end |
#to_query(options) ⇒ Object
59 60 61 62 63 64 65 |
# File 'lib/linked_in/request_helpers.rb', line 59 def to_query() query_string = .inject([]) do |collection, opt| collection << "#{opt[0]}=#{opt[1]}" collection end * '&' URI.escape(query_string) end |
#to_uri(path, options) ⇒ Object
67 68 69 70 71 72 73 74 |
# File 'lib/linked_in/request_helpers.rb', line 67 def to_uri(path, ) uri = URI.parse(path) if && != {} uri.query = to_query() end uri.to_s end |