Permalink
Browse files

Request bodies now supported!

  • Loading branch information...
Avdi Grimm
Avdi Grimm committed Jan 16, 2012
1 parent 6d0c1b3 commit 0450776fdd55da79fadfcbfb3c1217d9b67d7783
Showing with 2,428 additions and 821 deletions.
  1. +1 −1 lib/leadlight/hyperlinkable.rb
  2. +8 −3 lib/leadlight/request.rb
  3. +2 −1 lib/leadlight/type_map.rb
  4. +282 −0 spec/cassettes/Leadlight/authorized_GitHub_example/adding_and_removing_teams.yml
  5. +56 −23 spec/cassettes/Leadlight/basic_GitHub_example/_root/.yml
  6. +56 −23 spec/cassettes/Leadlight/basic_GitHub_example/_root/__location__/.yml
  7. +56 −23 spec/cassettes/Leadlight/basic_GitHub_example/_root/should_be_a_204_no_content.yml
  8. +56 −23 spec/cassettes/Leadlight/tinted_GitHub_example/_root/.yml
  9. +56 −23 spec/cassettes/Leadlight/tinted_GitHub_example/_root/__location__/.yml
  10. +56 −23 spec/cassettes/Leadlight/tinted_GitHub_example/_root/should_be_a_204_no_content.yml
  11. +118 −46 spec/cassettes/Leadlight/tinted_GitHub_example/_user/has_the_expected_content.yml
  12. +184 −71 spec/cassettes/Leadlight/tinted_GitHub_example/user_followers/.yml
  13. +252 −96 spec/cassettes/Leadlight/tinted_GitHub_example/user_followers/should_be_able_to_follow_next_link.yml
  14. +590 −221 spec/cassettes/Leadlight/tinted_GitHub_example/user_followers/should_be_enumerable.yml
  15. +321 −121 ...ttes/Leadlight/tinted_GitHub_example/user_followers/should_be_enumerable_over_page_boundaries.yml
  16. +184 −71 spec/cassettes/Leadlight/tinted_GitHub_example/user_followers/should_have_next_and_last_links.yml
  17. +56 −23 spec/cassettes/Leadlight/tinted_GitHub_example/user_link/exists.yml
  18. +56 −23 spec/cassettes/Leadlight/tinted_GitHub_example/user_link/links_to_the_expected_URL.yml
  19. +3 −1 spec/leadlight/hyperlinkable_spec.rb
  20. +2 −1 spec/leadlight/link_template_spec.rb
  21. +4 −3 spec/leadlight/request_spec.rb
  22. +6 −0 spec/leadlight/type_map_spec.rb
  23. +23 −1 spec/leadlight_spec.rb
@@ -10,7 +10,7 @@ module Leadlight
module Hyperlinkable
def self.extended(representation)
super(representation)
- representation.add_link(representation.__response__.env[:url],
+ representation.add_link(representation.__location__,
'self', 'self', rev: 'self')
representation.add_links_from_headers
end
View
@@ -51,8 +51,12 @@ def completed?
end
def submit
- connection.run_request(http_method, url, body, {}) do |request|
- request.options[:leadlight_request] = self
+ entity = type_map.to_entity_body(body)
+ entity_body = entity.body
+ content_type = entity.content_type
+ connection.run_request(http_method, url, entity_body, {}) do |request|
+ request.headers['Content-Type'] = content_type if content_type
+ request.options[:leadlight_request] = self
execute_hook(:on_prepare_request, request)
end.on_complete do |env|
synchronize do
@@ -102,9 +106,10 @@ def represent(env)
content_type = env[:response_headers]['Content-Type']
content_type = clean_content_type(content_type)
representation = type_map.to_native(content_type, env[:body])
+ location = Addressable::URI.parse(env[:response_headers].fetch('location'){ env[:url] })
representation.
extend(Representation).
- initialize_representation(env[:leadlight_service], env[:url], env[:response]).
+ initialize_representation(env[:leadlight_service], location, env[:response]).
extend(Hyperlinkable).
apply_all_tints
end
@@ -82,13 +82,14 @@ def initialize(codec)
end
def encode(object, options={})
+ return Entity.new(nil, nil) if object.nil?
content_type = options.delete(:content_type){"application/json"}
body = @codec.encode(content_type, object, options)
Entity.new(content_type, body)
end
def decode(content_type, entity_body, options={})
- case entity_body.size
+ case entity_body.to_s.size
when 0,1 # No valid JSON document is smaller than 2 bytes
Blank.new
else

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
Oops, something went wrong.

0 comments on commit 0450776

Please sign in to comment.