21700: Install Bundler system-wide in Rails postinst
[arvados.git] / sdk / ruby-google-api-client / lib / google / api_client / discovery / media.rb
1 # Copyright 2010 Google Inc.
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 #      http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15
16 require 'addressable/uri'
17 require 'addressable/template'
18
19 require 'google/api_client/errors'
20
21
22 module Google
23   class APIClient
24     ##
25     # Media upload elements for discovered methods
26     class MediaUpload
27
28       ##
29       # Creates a description of a particular method.
30       #
31       # @param [Google::APIClient::API] api
32       #    Base discovery document for the API
33       # @param [Addressable::URI] method_base
34       #   The base URI for the service.
35       # @param [Hash] discovery_document
36       #   The media upload section of the discovery document.
37       #
38       # @return [Google::APIClient::Method] The constructed method object.
39       def initialize(api, method_base, discovery_document)
40         @api = api
41         @method_base = method_base
42         @discovery_document = discovery_document
43       end
44
45       ##
46       # List of acceptable mime types
47       #
48       # @return [Array]
49       #   List of acceptable mime types for uploaded content
50       def accepted_types
51         @discovery_document['accept']
52       end
53
54       ##
55       # Maximum size of an uplad
56       # TODO: Parse & convert to numeric value
57       #
58       # @return [String]
59       def max_size
60         @discovery_document['maxSize']
61       end
62
63       ##
64       # Returns the URI template for the method.  A parameter list can be
65       # used to expand this into a URI.
66       #
67       # @return [Addressable::Template] The URI template.
68       def uri_template
69         return @uri_template ||= Addressable::Template.new(
70           @api.method_base.join(Addressable::URI.parse(@discovery_document['protocols']['simple']['path']))
71         )
72       end
73
74     end
75
76   end
77 end