Class: WADL::HTTPMethod
- Inherits:
-
HasDocs
- Object
- CheapSchema
- HasDocs
- WADL::HTTPMethod
- Defined in:
- lib/wadl/http_method.rb
Constant Summary
- OAUTH_HEADER =
'Authorization'- OAUTH_PREFIX =
'OAuth:'
Constants inherited from CheapSchema
Instance Attribute Summary
Attributes inherited from CheapSchema
#attributes, #href, #index_key, #parent
Instance Method Summary (collapse)
Methods inherited from HasDocs
Methods inherited from CheapSchema
as_collection, as_member, contents_are_mixed_data, #dereference, #dereference_with_context, dereferencing_attr_accessor, dereferencing_instance_accessor, #each_attribute, #each_collection, #each_member, from_element, has_attributes, has_many, has_one, has_required, in_document, inherit, inherited, init, #initialize, #matches?, may_be_reference, may_be_reference?, #paths, #to_s
Constructor Details
This class inherits a constructor from WADL::CheapSchema
Instance Method Details
- (Object) call(resource, args = {})
Args:
:path - Values for path parameters
:query - Values for query parameters
:headers - Values for header parameters
:send_representation
:expect_representation
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/wadl/http_method.rb', line 58 def call(resource, args = {}) unless parent.respond_to?(:uri) raise "You can't call a method that's not attached to a resource! (You may have dereferenced a method when you shouldn't have)" end resource ||= parent method = dereference uri = method.request ? method.request.uri(resource, args) : resource.uri(args) headers = uri.headers.dup headers['Accept'] = expect_representation.mediaType if args[:expect_representation] headers['User-Agent'] = 'Ruby WADL client' unless headers['User-Agent'] headers['Content-Type'] = 'application/x-www-form-urlencoded' headers[:method] = name.downcase.to_sym headers[:body] = args[:send_representation] set_oauth_header(headers, uri) response = begin open(uri, headers) rescue OpenURI::HTTPError => err err.io end method.response.build(response) end |
- (Object) set_oauth_header(headers, uri)
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/wadl/http_method.rb', line 86 def set_oauth_header(headers, uri) args = headers[OAUTH_HEADER] or return yaml = args.dup yaml.sub!(/\A#{OAUTH_PREFIX}/, '') or return consumer_key, consumer_secret, access_token, token_secret = YAML.load(yaml) request = OpenURI::Methods[headers[:method]].new(uri.to_s) consumer = OAuth::Consumer.new(consumer_key, consumer_secret) token = OAuth::AccessToken.new(consumer, access_token, token_secret) helper = OAuth::Client::Helper.new(request, :request_uri => request.path, :consumer => consumer, :token => token, :scheme => 'header', :signature_method => 'HMAC-SHA1' ) headers[OAUTH_HEADER] = helper.header end |