arvados-google-api-client 0.8.7.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +178 -0
  3. data/Gemfile +9 -0
  4. data/LICENSE +202 -0
  5. data/README.md +218 -0
  6. data/Rakefile +41 -0
  7. data/google-api-client.gemspec +43 -0
  8. data/lib/cacerts.pem +2183 -0
  9. data/lib/compat/multi_json.rb +19 -0
  10. data/lib/google/api_client.rb +750 -0
  11. data/lib/google/api_client/auth/compute_service_account.rb +28 -0
  12. data/lib/google/api_client/auth/file_storage.rb +59 -0
  13. data/lib/google/api_client/auth/installed_app.rb +126 -0
  14. data/lib/google/api_client/auth/jwt_asserter.rb +126 -0
  15. data/lib/google/api_client/auth/key_utils.rb +93 -0
  16. data/lib/google/api_client/auth/pkcs12.rb +41 -0
  17. data/lib/google/api_client/auth/storage.rb +102 -0
  18. data/lib/google/api_client/auth/storages/file_store.rb +58 -0
  19. data/lib/google/api_client/auth/storages/redis_store.rb +54 -0
  20. data/lib/google/api_client/batch.rb +326 -0
  21. data/lib/google/api_client/charset.rb +33 -0
  22. data/lib/google/api_client/client_secrets.rb +179 -0
  23. data/lib/google/api_client/discovery.rb +19 -0
  24. data/lib/google/api_client/discovery/api.rb +310 -0
  25. data/lib/google/api_client/discovery/media.rb +77 -0
  26. data/lib/google/api_client/discovery/method.rb +363 -0
  27. data/lib/google/api_client/discovery/resource.rb +156 -0
  28. data/lib/google/api_client/discovery/schema.rb +117 -0
  29. data/lib/google/api_client/environment.rb +42 -0
  30. data/lib/google/api_client/errors.rb +65 -0
  31. data/lib/google/api_client/gzip.rb +28 -0
  32. data/lib/google/api_client/logging.rb +32 -0
  33. data/lib/google/api_client/media.rb +259 -0
  34. data/lib/google/api_client/railtie.rb +18 -0
  35. data/lib/google/api_client/reference.rb +27 -0
  36. data/lib/google/api_client/request.rb +350 -0
  37. data/lib/google/api_client/result.rb +255 -0
  38. data/lib/google/api_client/service.rb +233 -0
  39. data/lib/google/api_client/service/batch.rb +110 -0
  40. data/lib/google/api_client/service/request.rb +144 -0
  41. data/lib/google/api_client/service/resource.rb +40 -0
  42. data/lib/google/api_client/service/result.rb +162 -0
  43. data/lib/google/api_client/service/simple_file_store.rb +151 -0
  44. data/lib/google/api_client/service/stub_generator.rb +61 -0
  45. data/lib/google/api_client/service_account.rb +21 -0
  46. data/lib/google/api_client/version.rb +26 -0
  47. data/spec/google/api_client/auth/storage_spec.rb +122 -0
  48. data/spec/google/api_client/auth/storages/file_store_spec.rb +40 -0
  49. data/spec/google/api_client/auth/storages/redis_store_spec.rb +70 -0
  50. data/spec/google/api_client/batch_spec.rb +248 -0
  51. data/spec/google/api_client/client_secrets_spec.rb +53 -0
  52. data/spec/google/api_client/discovery_spec.rb +708 -0
  53. data/spec/google/api_client/gzip_spec.rb +98 -0
  54. data/spec/google/api_client/media_spec.rb +178 -0
  55. data/spec/google/api_client/request_spec.rb +29 -0
  56. data/spec/google/api_client/result_spec.rb +207 -0
  57. data/spec/google/api_client/service_account_spec.rb +169 -0
  58. data/spec/google/api_client/service_spec.rb +618 -0
  59. data/spec/google/api_client/simple_file_store_spec.rb +133 -0
  60. data/spec/google/api_client_spec.rb +352 -0
  61. data/spec/spec_helper.rb +66 -0
  62. metadata +339 -0
@@ -0,0 +1,40 @@
1
+ # Copyright 2013 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
+ module Google
16
+ class APIClient
17
+ class Service
18
+ ##
19
+ # Handles an API resource.
20
+ # Simple class that contains API methods and/or child resources.
21
+ class Resource
22
+ include Google::APIClient::Service::StubGenerator
23
+
24
+ ##
25
+ # Build a resource.
26
+ # This class should not be directly instantiated in user code; resources
27
+ # are instantiated by the stub generation mechanism on Service creation.
28
+ #
29
+ # @param [Google::APIClient::Service] service
30
+ # The Service instance this resource belongs to.
31
+ # @param [Google::APIClient::API, Google::APIClient::Resource] root
32
+ # The node corresponding to this resource.
33
+ def initialize(service, root)
34
+ @service = service
35
+ generate_call_stubs(service, root)
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,162 @@
1
+ # Copyright 2013 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
+ module Google
16
+ class APIClient
17
+ class Service
18
+ ##
19
+ # Handles an API result.
20
+ # Wraps around the Google::APIClient::Result class, making it easier to
21
+ # handle the result (e.g. pagination) and keeping it in line with the rest
22
+ # of the Service programming interface.
23
+ class Result
24
+ extend Forwardable
25
+
26
+ ##
27
+ # Init the result.
28
+ #
29
+ # @param [Google::APIClient::Service::Request] request
30
+ # The original request
31
+ # @param [Google::APIClient::Result] base_result
32
+ # The base result to be wrapped
33
+ def initialize(request, base_result)
34
+ @request = request
35
+ @base_result = base_result
36
+ end
37
+
38
+ # @!attribute [r] status
39
+ # @return [Fixnum] HTTP status code
40
+ # @!attribute [r] headers
41
+ # @return [Hash] HTTP response headers
42
+ # @!attribute [r] body
43
+ # @return [String] HTTP response body
44
+ def_delegators :@base_result, :status, :headers, :body
45
+
46
+ # @return [Google::APIClient::Service::Request] Original request object
47
+ attr_reader :request
48
+
49
+ ##
50
+ # Get the content type of the response
51
+ # @!attribute [r] media_type
52
+ # @return [String]
53
+ # Value of content-type header
54
+ def_delegators :@base_result, :media_type
55
+
56
+ ##
57
+ # Check if request failed
58
+ #
59
+ # @!attribute [r] error?
60
+ # @return [TrueClass, FalseClass]
61
+ # true if result of operation is an error
62
+ def_delegators :@base_result, :error?
63
+
64
+ ##
65
+ # Check if request was successful
66
+ #
67
+ # @!attribute [r] success?
68
+ # @return [TrueClass, FalseClass]
69
+ # true if result of operation was successful
70
+ def_delegators :@base_result, :success?
71
+
72
+ ##
73
+ # Extracts error messages from the response body
74
+ #
75
+ # @!attribute [r] error_message
76
+ # @return [String]
77
+ # error message, if available
78
+ def_delegators :@base_result, :error_message
79
+
80
+ ##
81
+ # Check for parsable data in response
82
+ #
83
+ # @!attribute [r] data?
84
+ # @return [TrueClass, FalseClass]
85
+ # true if body can be parsed
86
+ def_delegators :@base_result, :data?
87
+
88
+ ##
89
+ # Return parsed version of the response body.
90
+ #
91
+ # @!attribute [r] data
92
+ # @return [Object, Hash, String]
93
+ # Object if body parsable from API schema, Hash if JSON, raw body if unable to parse
94
+ def_delegators :@base_result, :data
95
+
96
+ ##
97
+ # Pagination scheme used by this request/response
98
+ #
99
+ # @!attribute [r] pagination_type
100
+ # @return [Symbol]
101
+ # currently always :token
102
+ def_delegators :@base_result, :pagination_type
103
+
104
+ ##
105
+ # Name of the field that contains the pagination token
106
+ #
107
+ # @!attribute [r] page_token_param
108
+ # @return [String]
109
+ # currently always 'pageToken'
110
+ def_delegators :@base_result, :page_token_param
111
+
112
+ ##
113
+ # Get the token used for requesting the next page of data
114
+ #
115
+ # @!attribute [r] next_page_token
116
+ # @return [String]
117
+ # next page tokenx =
118
+ def_delegators :@base_result, :next_page_token
119
+
120
+ ##
121
+ # Get the token used for requesting the previous page of data
122
+ #
123
+ # @!attribute [r] prev_page_token
124
+ # @return [String]
125
+ # previous page token
126
+ def_delegators :@base_result, :prev_page_token
127
+
128
+ # @!attribute [r] resumable_upload
129
+ def resumable_upload
130
+ # TODO(sgomes): implement resumable_upload for Service::Result
131
+ raise NotImplementedError
132
+ end
133
+
134
+ ##
135
+ # Build a request for fetching the next page of data
136
+ #
137
+ # @return [Google::APIClient::Service::Request]
138
+ # API request for retrieving next page
139
+ def next_page
140
+ request = @request.clone
141
+ # Make a deep copy of the parameters.
142
+ request.parameters = Marshal.load(Marshal.dump(request.parameters))
143
+ request.parameters[page_token_param] = self.next_page_token
144
+ return request
145
+ end
146
+
147
+ ##
148
+ # Build a request for fetching the previous page of data
149
+ #
150
+ # @return [Google::APIClient::Service::Request]
151
+ # API request for retrieving previous page
152
+ def prev_page
153
+ request = @request.clone
154
+ # Make a deep copy of the parameters.
155
+ request.parameters = Marshal.load(Marshal.dump(request.parameters))
156
+ request.parameters[page_token_param] = self.prev_page_token
157
+ return request
158
+ end
159
+ end
160
+ end
161
+ end
162
+ end
@@ -0,0 +1,151 @@
1
+ # Copyright 2013 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
+ module Google
16
+ class APIClient
17
+ class Service
18
+
19
+ # Simple file store to be used in the event no ActiveSupport cache store
20
+ # is provided. This is not thread-safe, and does not support a number of
21
+ # features (such as expiration), but it's useful for the simple purpose of
22
+ # caching discovery documents to disk.
23
+ # Implements the basic cache methods of ActiveSupport::Cache::Store in a
24
+ # limited fashion.
25
+ class SimpleFileStore
26
+
27
+ # Creates a new SimpleFileStore.
28
+ #
29
+ # @param [String] file_path
30
+ # The path to the cache file on disk.
31
+ # @param [Object] options
32
+ # The options to be used with this SimpleFileStore. Not implemented.
33
+ def initialize(file_path, options = nil)
34
+ @file_path = file_path.to_s
35
+ end
36
+
37
+ # Returns true if a key exists in the cache.
38
+ #
39
+ # @param [String] name
40
+ # The name of the key. Will always be converted to a string.
41
+ # @param [Object] options
42
+ # The options to be used with this query. Not implemented.
43
+ def exist?(name, options = nil)
44
+ read_file
45
+ @cache.nil? ? nil : @cache.include?(name.to_s)
46
+ end
47
+
48
+ # Fetches data from the cache and returns it, using the given key.
49
+ # If the key is missing and no block is passed, returns nil.
50
+ # If the key is missing and a block is passed, executes the block, sets
51
+ # the key to its value, and returns it.
52
+ #
53
+ # @param [String] name
54
+ # The name of the key. Will always be converted to a string.
55
+ # @param [Object] options
56
+ # The options to be used with this query. Not implemented.
57
+ # @yield [String]
58
+ # optional block with the default value if the key is missing
59
+ def fetch(name, options = nil)
60
+ read_file
61
+ if block_given?
62
+ entry = read(name.to_s, options)
63
+ if entry.nil?
64
+ value = yield name.to_s
65
+ write(name.to_s, value)
66
+ return value
67
+ else
68
+ return entry
69
+ end
70
+ else
71
+ return read(name.to_s, options)
72
+ end
73
+ end
74
+
75
+ # Fetches data from the cache, using the given key.
76
+ # Returns nil if the key is missing.
77
+ #
78
+ # @param [String] name
79
+ # The name of the key. Will always be converted to a string.
80
+ # @param [Object] options
81
+ # The options to be used with this query. Not implemented.
82
+ def read(name, options = nil)
83
+ read_file
84
+ @cache.nil? ? nil : @cache[name.to_s]
85
+ end
86
+
87
+ # Writes the value to the cache, with the key.
88
+ #
89
+ # @param [String] name
90
+ # The name of the key. Will always be converted to a string.
91
+ # @param [Object] value
92
+ # The value to be written.
93
+ # @param [Object] options
94
+ # The options to be used with this query. Not implemented.
95
+ def write(name, value, options = nil)
96
+ read_file
97
+ @cache = {} if @cache.nil?
98
+ @cache[name.to_s] = value
99
+ write_file
100
+ return nil
101
+ end
102
+
103
+ # Deletes an entry in the cache.
104
+ # Returns true if an entry is deleted.
105
+ #
106
+ # @param [String] name
107
+ # The name of the key. Will always be converted to a string.
108
+ # @param [Object] options
109
+ # The options to be used with this query. Not implemented.
110
+ def delete(name, options = nil)
111
+ read_file
112
+ return nil if @cache.nil?
113
+ if @cache.include? name.to_s
114
+ @cache.delete name.to_s
115
+ write_file
116
+ return true
117
+ else
118
+ return nil
119
+ end
120
+ end
121
+
122
+ protected
123
+
124
+ # Read the entire cache file from disk.
125
+ # Will avoid reading if there have been no changes.
126
+ def read_file
127
+ if !File.exist? @file_path
128
+ @cache = nil
129
+ else
130
+ # Check for changes after our last read or write.
131
+ if @last_change.nil? || File.mtime(@file_path) > @last_change
132
+ File.open(@file_path) do |file|
133
+ @cache = Marshal.load(file)
134
+ @last_change = file.mtime
135
+ end
136
+ end
137
+ end
138
+ return @cache
139
+ end
140
+
141
+ # Write the entire cache contents to disk.
142
+ def write_file
143
+ File.open(@file_path, 'w') do |file|
144
+ Marshal.dump(@cache, file)
145
+ end
146
+ @last_change = File.mtime(@file_path)
147
+ end
148
+ end
149
+ end
150
+ end
151
+ end
@@ -0,0 +1,61 @@
1
+ # Copyright 2013 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
+ require 'active_support/inflector'
16
+
17
+ module Google
18
+ class APIClient
19
+ class Service
20
+ ##
21
+ # Auxiliary mixin to generate resource and method stubs.
22
+ # Used by the Service and Service::Resource classes to generate both
23
+ # top-level and nested resources and methods.
24
+ module StubGenerator
25
+ def generate_call_stubs(service, root)
26
+ metaclass = (class << self; self; end)
27
+
28
+ # Handle resources.
29
+ root.discovered_resources.each do |resource|
30
+ method_name = ActiveSupport::Inflector.underscore(resource.name).to_sym
31
+ if !self.respond_to?(method_name)
32
+ metaclass.send(:define_method, method_name) do
33
+ Google::APIClient::Service::Resource.new(service, resource)
34
+ end
35
+ end
36
+ end
37
+
38
+ # Handle methods.
39
+ root.discovered_methods.each do |method|
40
+ method_name = ActiveSupport::Inflector.underscore(method.name).to_sym
41
+ if !self.respond_to?(method_name)
42
+ metaclass.send(:define_method, method_name) do |*args|
43
+ if args.length > 1
44
+ raise ArgumentError,
45
+ "wrong number of arguments (#{args.length} for 1)"
46
+ elsif !args.first.respond_to?(:to_hash) && !args.first.nil?
47
+ raise ArgumentError,
48
+ "expected parameter Hash, got #{args.first.class}"
49
+ else
50
+ return Google::APIClient::Service::Request.new(
51
+ service, method, args.first
52
+ )
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,21 @@
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
+ require 'google/api_client/auth/pkcs12'
16
+ require 'google/api_client/auth/jwt_asserter'
17
+ require 'google/api_client/auth/key_utils'
18
+ require 'google/api_client/auth/compute_service_account'
19
+ require 'google/api_client/auth/storage'
20
+ require 'google/api_client/auth/storages/redis_store'
21
+ require 'google/api_client/auth/storages/file_store'
@@ -0,0 +1,26 @@
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
+ module Google
17
+ class APIClient
18
+ module VERSION
19
+ MAJOR = 0
20
+ MINOR = 8
21
+ TINY = 7
22
+ PATCH = 2
23
+ STRING = [MAJOR, MINOR, TINY, PATCH].compact.join('.')
24
+ end
25
+ end
26
+ end