google-api-client 0.8.7 → 0.9.pre1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +20 -0
- data/.rspec +2 -0
- data/.rubocop.yml +7 -0
- data/.rubocop_todo.yml +63 -0
- data/.travis.yml +21 -0
- data/.yardopts +12 -0
- data/CHANGELOG.md +6 -3
- data/CONTRIBUTING.md +31 -0
- data/Gemfile +28 -2
- data/MIGRATING.md +171 -0
- data/README.md +158 -150
- data/Rakefile +1 -40
- data/api_names.yaml +872 -0
- data/api_names_out.yaml +20843 -0
- data/bin/generate-api +93 -0
- data/generated/google/apis/adexchangebuyer_v1_3.rb +35 -0
- data/generated/google/apis/adexchangebuyer_v1_3/classes.rb +1124 -0
- data/generated/google/apis/adexchangebuyer_v1_3/representations.rb +375 -0
- data/generated/google/apis/adexchangebuyer_v1_3/service.rb +893 -0
- data/generated/google/apis/adexchangeseller_v2_0.rb +38 -0
- data/generated/google/apis/adexchangeseller_v2_0/classes.rb +792 -0
- data/generated/google/apis/adexchangeseller_v2_0/representations.rb +309 -0
- data/generated/google/apis/adexchangeseller_v2_0/service.rb +682 -0
- data/generated/google/apis/admin_directory_v1.rb +89 -0
- data/generated/google/apis/admin_directory_v1/classes.rb +2389 -0
- data/generated/google/apis/admin_directory_v1/representations.rb +780 -0
- data/generated/google/apis/admin_directory_v1/service.rb +2805 -0
- data/generated/google/apis/admin_reports_v1.rb +38 -0
- data/generated/google/apis/admin_reports_v1/classes.rb +582 -0
- data/generated/google/apis/admin_reports_v1/representations.rb +231 -0
- data/generated/google/apis/admin_reports_v1/service.rb +341 -0
- data/generated/google/apis/adsense_v1_4.rb +38 -0
- data/generated/google/apis/adsense_v1_4/classes.rb +1279 -0
- data/generated/google/apis/adsense_v1_4/representations.rb +493 -0
- data/generated/google/apis/adsense_v1_4/service.rb +1752 -0
- data/generated/google/apis/adsensehost_v4_1.rb +35 -0
- data/generated/google/apis/adsensehost_v4_1/classes.rb +834 -0
- data/generated/google/apis/adsensehost_v4_1/representations.rb +327 -0
- data/generated/google/apis/adsensehost_v4_1/service.rb +1190 -0
- data/generated/google/apis/analytics_v3.rb +49 -0
- data/generated/google/apis/analytics_v3/classes.rb +5113 -0
- data/generated/google/apis/analytics_v3/representations.rb +1661 -0
- data/generated/google/apis/analytics_v3/service.rb +3600 -0
- data/generated/google/apis/androidenterprise_v1.rb +34 -0
- data/generated/google/apis/androidenterprise_v1/classes.rb +1162 -0
- data/generated/google/apis/androidenterprise_v1/representations.rb +431 -0
- data/generated/google/apis/androidenterprise_v1/service.rb +1979 -0
- data/generated/google/apis/androidpublisher_v2.rb +34 -0
- data/generated/google/apis/androidpublisher_v2/classes.rb +1374 -0
- data/generated/google/apis/androidpublisher_v2/representations.rb +630 -0
- data/generated/google/apis/androidpublisher_v2/service.rb +2390 -0
- data/generated/google/apis/appsactivity_v1.rb +46 -0
- data/generated/google/apis/appsactivity_v1/classes.rb +392 -0
- data/generated/google/apis/appsactivity_v1/representations.rb +184 -0
- data/generated/google/apis/appsactivity_v1/service.rb +129 -0
- data/generated/google/apis/appstate_v1.rb +34 -0
- data/generated/google/apis/appstate_v1/classes.rb +154 -0
- data/generated/google/apis/appstate_v1/representations.rb +79 -0
- data/generated/google/apis/appstate_v1/service.rb +265 -0
- data/generated/google/apis/autoscaler_v1beta2.rb +38 -0
- data/generated/google/apis/autoscaler_v1beta2/classes.rb +747 -0
- data/generated/google/apis/autoscaler_v1beta2/representations.rb +281 -0
- data/generated/google/apis/autoscaler_v1beta2/service.rb +488 -0
- data/generated/google/apis/bigquery_v2.rb +49 -0
- data/generated/google/apis/bigquery_v2/classes.rb +2255 -0
- data/generated/google/apis/bigquery_v2/representations.rb +754 -0
- data/generated/google/apis/bigquery_v2/service.rb +1003 -0
- data/generated/google/apis/blogger_v3.rb +37 -0
- data/generated/google/apis/blogger_v3/classes.rb +1354 -0
- data/generated/google/apis/blogger_v3/representations.rb +562 -0
- data/generated/google/apis/blogger_v3/service.rb +1620 -0
- data/generated/google/apis/books_v1.rb +34 -0
- data/generated/google/apis/books_v1/classes.rb +3515 -0
- data/generated/google/apis/books_v1/representations.rb +1361 -0
- data/generated/google/apis/books_v1/service.rb +2170 -0
- data/generated/google/apis/calendar_v3.rb +37 -0
- data/generated/google/apis/calendar_v3/classes.rb +1702 -0
- data/generated/google/apis/calendar_v3/representations.rb +566 -0
- data/generated/google/apis/calendar_v3/service.rb +1943 -0
- data/generated/google/apis/civicinfo_v2.rb +31 -0
- data/generated/google/apis/civicinfo_v2/classes.rb +1057 -0
- data/generated/google/apis/civicinfo_v2/representations.rb +374 -0
- data/generated/google/apis/civicinfo_v2/service.rb +284 -0
- data/generated/google/apis/cloudmonitoring_v2beta2.rb +34 -0
- data/generated/google/apis/cloudmonitoring_v2beta2/classes.rb +679 -0
- data/generated/google/apis/cloudmonitoring_v2beta2/representations.rb +311 -0
- data/generated/google/apis/cloudmonitoring_v2beta2/service.rb +458 -0
- data/generated/google/apis/cloudresourcemanager_v1beta1.rb +38 -0
- data/generated/google/apis/cloudresourcemanager_v1beta1/classes.rb +139 -0
- data/generated/google/apis/cloudresourcemanager_v1beta1/representations.rb +65 -0
- data/generated/google/apis/cloudresourcemanager_v1beta1/service.rb +301 -0
- data/generated/google/apis/compute_v1.rb +49 -0
- data/generated/google/apis/compute_v1/classes.rb +6391 -0
- data/generated/google/apis/compute_v1/representations.rb +2209 -0
- data/generated/google/apis/compute_v1/service.rb +6352 -0
- data/generated/google/apis/container_v1beta1.rb +35 -0
- data/generated/google/apis/container_v1beta1/classes.rb +466 -0
- data/generated/google/apis/container_v1beta1/representations.rb +177 -0
- data/generated/google/apis/container_v1beta1/service.rb +394 -0
- data/generated/google/apis/content_v2.rb +35 -0
- data/generated/google/apis/content_v2/classes.rb +3780 -0
- data/generated/google/apis/content_v2/representations.rb +1456 -0
- data/generated/google/apis/content_v2/service.rb +1706 -0
- data/generated/google/apis/coordinate_v1.rb +37 -0
- data/generated/google/apis/coordinate_v1/classes.rb +669 -0
- data/generated/google/apis/coordinate_v1/representations.rb +285 -0
- data/generated/google/apis/coordinate_v1/service.rb +687 -0
- data/{lib/google/api_client/auth/compute_service_account.rb → generated/google/apis/customsearch_v1.rb} +13 -10
- data/generated/google/apis/customsearch_v1/classes.rb +771 -0
- data/generated/google/apis/customsearch_v1/representations.rb +276 -0
- data/generated/google/apis/customsearch_v1/service.rb +208 -0
- data/generated/google/apis/datastore_v1beta2.rb +40 -0
- data/generated/google/apis/datastore_v1beta2/classes.rb +1186 -0
- data/generated/google/apis/datastore_v1beta2/representations.rb +526 -0
- data/generated/google/apis/datastore_v1beta2/service.rb +300 -0
- data/generated/google/apis/deploymentmanager_v2beta2.rb +41 -0
- data/generated/google/apis/deploymentmanager_v2beta2/classes.rb +820 -0
- data/generated/google/apis/deploymentmanager_v2beta2/representations.rb +303 -0
- data/generated/google/apis/deploymentmanager_v2beta2/service.rb +647 -0
- data/generated/google/apis/dfareporting_v2_1.rb +37 -0
- data/generated/google/apis/dfareporting_v2_1/classes.rb +10755 -0
- data/generated/google/apis/dfareporting_v2_1/representations.rb +3438 -0
- data/generated/google/apis/dfareporting_v2_1/service.rb +8775 -0
- data/generated/google/apis/discovery_v1.rb +32 -0
- data/generated/google/apis/discovery_v1/classes.rb +947 -0
- data/generated/google/apis/discovery_v1/representations.rb +355 -0
- data/generated/google/apis/discovery_v1/service.rb +144 -0
- data/generated/google/apis/dns_v1.rb +41 -0
- data/generated/google/apis/dns_v1/classes.rb +406 -0
- data/generated/google/apis/dns_v1/representations.rb +151 -0
- data/generated/google/apis/dns_v1/service.rb +460 -0
- data/{spec/google/api_client/request_spec.rb → generated/google/apis/doubleclickbidmanager_v1.rb} +15 -13
- data/generated/google/apis/doubleclickbidmanager_v1/classes.rb +709 -0
- data/generated/google/apis/doubleclickbidmanager_v1/representations.rb +297 -0
- data/generated/google/apis/doubleclickbidmanager_v1/service.rb +349 -0
- data/generated/google/apis/doubleclicksearch_v2.rb +35 -0
- data/generated/google/apis/doubleclicksearch_v2/classes.rb +947 -0
- data/generated/google/apis/doubleclicksearch_v2/representations.rb +315 -0
- data/generated/google/apis/doubleclicksearch_v2/service.rb +490 -0
- data/generated/google/apis/drive_v2.rb +55 -0
- data/generated/google/apis/drive_v2/classes.rb +2519 -0
- data/generated/google/apis/drive_v2/representations.rb +781 -0
- data/generated/google/apis/drive_v2/service.rb +2685 -0
- data/generated/google/apis/fitness_v1.rb +49 -0
- data/generated/google/apis/fitness_v1/classes.rb +809 -0
- data/generated/google/apis/fitness_v1/representations.rb +295 -0
- data/generated/google/apis/fitness_v1/service.rb +684 -0
- data/generated/google/apis/fusiontables_v2.rb +37 -0
- data/generated/google/apis/fusiontables_v2/classes.rb +1048 -0
- data/generated/google/apis/fusiontables_v2/representations.rb +409 -0
- data/generated/google/apis/fusiontables_v2/service.rb +1496 -0
- data/generated/google/apis/games_configuration_v1configuration.rb +34 -0
- data/generated/google/apis/games_configuration_v1configuration/classes.rb +506 -0
- data/generated/google/apis/games_configuration_v1configuration/representations.rb +206 -0
- data/generated/google/apis/games_configuration_v1configuration/service.rb +578 -0
- data/generated/google/apis/games_v1.rb +40 -0
- data/generated/google/apis/games_v1/classes.rb +4578 -0
- data/generated/google/apis/games_v1/representations.rb +1570 -0
- data/generated/google/apis/games_v1/service.rb +2306 -0
- data/generated/google/apis/gan_v1beta1.rb +31 -0
- data/generated/google/apis/gan_v1beta1/classes.rb +1428 -0
- data/generated/google/apis/gan_v1beta1/representations.rb +428 -0
- data/generated/google/apis/gan_v1beta1/service.rb +692 -0
- data/generated/google/apis/genomics_v1beta2.rb +46 -0
- data/generated/google/apis/genomics_v1beta2/classes.rb +3288 -0
- data/generated/google/apis/genomics_v1beta2/representations.rb +1194 -0
- data/generated/google/apis/genomics_v1beta2/service.rb +2356 -0
- data/generated/google/apis/gmail_v1.rb +49 -0
- data/generated/google/apis/gmail_v1/classes.rb +794 -0
- data/generated/google/apis/gmail_v1/representations.rb +339 -0
- data/generated/google/apis/gmail_v1/service.rb +1502 -0
- data/generated/google/apis/groupsmigration_v1.rb +34 -0
- data/generated/google/apis/groupsmigration_v1/classes.rb +51 -0
- data/generated/google/apis/groupsmigration_v1/representations.rb +38 -0
- data/generated/google/apis/groupsmigration_v1/service.rb +111 -0
- data/generated/google/apis/groupssettings_v1.rb +34 -0
- data/generated/google/apis/groupssettings_v1/classes.rb +221 -0
- data/generated/google/apis/groupssettings_v1/representations.rb +64 -0
- data/generated/google/apis/groupssettings_v1/service.rb +179 -0
- data/generated/google/apis/identitytoolkit_v3.rb +31 -0
- data/generated/google/apis/identitytoolkit_v3/classes.rb +1229 -0
- data/generated/google/apis/identitytoolkit_v3/representations.rb +422 -0
- data/generated/google/apis/identitytoolkit_v3/service.rb +491 -0
- data/generated/google/apis/licensing_v1.rb +34 -0
- data/generated/google/apis/licensing_v1/classes.rb +132 -0
- data/generated/google/apis/licensing_v1/representations.rb +68 -0
- data/generated/google/apis/licensing_v1/service.rb +376 -0
- data/generated/google/apis/logging_v1beta3.rb +35 -0
- data/generated/google/apis/logging_v1beta3/classes.rb +505 -0
- data/generated/google/apis/logging_v1beta3/representations.rb +222 -0
- data/generated/google/apis/logging_v1beta3/service.rb +670 -0
- data/generated/google/apis/manager_v1beta2.rb +50 -0
- data/generated/google/apis/manager_v1beta2/classes.rb +1287 -0
- data/generated/google/apis/manager_v1beta2/representations.rb +536 -0
- data/generated/google/apis/manager_v1beta2/service.rb +380 -0
- data/generated/google/apis/mapsengine_v1.rb +38 -0
- data/generated/google/apis/mapsengine_v1/classes.rb +2873 -0
- data/generated/google/apis/mapsengine_v1/representations.rb +1235 -0
- data/generated/google/apis/mapsengine_v1/service.rb +3465 -0
- data/generated/google/apis/mirror_v1.rb +37 -0
- data/generated/google/apis/mirror_v1/classes.rb +1072 -0
- data/generated/google/apis/mirror_v1/representations.rb +350 -0
- data/generated/google/apis/mirror_v1/service.rb +1001 -0
- data/generated/google/apis/oauth2_v2.rb +43 -0
- data/generated/google/apis/oauth2_v2/classes.rb +245 -0
- data/generated/google/apis/oauth2_v2/representations.rb +94 -0
- data/generated/google/apis/oauth2_v2/service.rb +203 -0
- data/generated/google/apis/pagespeedonline_v2.rb +32 -0
- data/generated/google/apis/pagespeedonline_v2/classes.rb +614 -0
- data/generated/google/apis/pagespeedonline_v2/representations.rb +244 -0
- data/generated/google/apis/pagespeedonline_v2/service.rb +120 -0
- data/generated/google/apis/plus_domains_v1.rb +61 -0
- data/generated/google/apis/plus_domains_v1/classes.rb +2402 -0
- data/generated/google/apis/plus_domains_v1/representations.rb +873 -0
- data/generated/google/apis/plus_domains_v1/service.rb +924 -0
- data/generated/google/apis/plus_v1.rb +43 -0
- data/generated/google/apis/plus_v1/classes.rb +2384 -0
- data/generated/google/apis/plus_v1/representations.rb +812 -0
- data/generated/google/apis/plus_v1/service.rb +616 -0
- data/generated/google/apis/prediction_v1_6.rb +44 -0
- data/generated/google/apis/prediction_v1_6/classes.rb +751 -0
- data/generated/google/apis/prediction_v1_6/representations.rb +327 -0
- data/generated/google/apis/prediction_v1_6/service.rb +388 -0
- data/generated/google/apis/pubsub_v1beta2.rb +37 -0
- data/generated/google/apis/pubsub_v1beta2/classes.rb +824 -0
- data/generated/google/apis/pubsub_v1beta2/representations.rb +366 -0
- data/generated/google/apis/pubsub_v1beta2/service.rb +778 -0
- data/generated/google/apis/qpx_express_v1.rb +31 -0
- data/generated/google/apis/qpx_express_v1/classes.rb +1268 -0
- data/generated/google/apis/qpx_express_v1/representations.rb +424 -0
- data/generated/google/apis/qpx_express_v1/service.rb +101 -0
- data/generated/google/apis/replicapool_v1beta2.rb +41 -0
- data/generated/google/apis/replicapool_v1beta2/classes.rb +621 -0
- data/generated/google/apis/replicapool_v1beta2/representations.rb +235 -0
- data/generated/google/apis/replicapool_v1beta2/service.rb +620 -0
- data/generated/google/apis/replicapoolupdater_v1beta1.rb +41 -0
- data/generated/google/apis/replicapoolupdater_v1beta1/classes.rb +682 -0
- data/generated/google/apis/replicapoolupdater_v1beta1/representations.rb +247 -0
- data/generated/google/apis/replicapoolupdater_v1beta1/service.rb +472 -0
- data/generated/google/apis/reseller_v1.rb +37 -0
- data/generated/google/apis/reseller_v1/classes.rb +502 -0
- data/generated/google/apis/reseller_v1/representations.rb +199 -0
- data/generated/google/apis/reseller_v1/service.rb +637 -0
- data/generated/google/apis/resourceviews_v1beta2.rb +47 -0
- data/generated/google/apis/resourceviews_v1beta2/classes.rb +660 -0
- data/generated/google/apis/resourceviews_v1beta2/representations.rb +269 -0
- data/generated/google/apis/resourceviews_v1beta2/service.rb +574 -0
- data/generated/google/apis/site_verification_v1.rb +37 -0
- data/generated/google/apis/site_verification_v1/classes.rb +185 -0
- data/generated/google/apis/site_verification_v1/representations.rb +101 -0
- data/generated/google/apis/site_verification_v1/service.rb +322 -0
- data/generated/google/apis/sqladmin_v1beta4.rb +37 -0
- data/generated/google/apis/sqladmin_v1beta4/classes.rb +1817 -0
- data/generated/google/apis/sqladmin_v1beta4/representations.rb +688 -0
- data/generated/google/apis/sqladmin_v1beta4/service.rb +1534 -0
- data/generated/google/apis/storage_v1.rb +43 -0
- data/generated/google/apis/storage_v1/classes.rb +1177 -0
- data/generated/google/apis/storage_v1/representations.rb +427 -0
- data/generated/google/apis/storage_v1/service.rb +1920 -0
- data/generated/google/apis/tagmanager_v1.rb +52 -0
- data/generated/google/apis/tagmanager_v1/classes.rb +1226 -0
- data/generated/google/apis/tagmanager_v1/representations.rb +461 -0
- data/generated/google/apis/tagmanager_v1/service.rb +1978 -0
- data/generated/google/apis/taskqueue_v1beta2.rb +37 -0
- data/generated/google/apis/taskqueue_v1beta2/classes.rb +254 -0
- data/generated/google/apis/taskqueue_v1beta2/representations.rb +114 -0
- data/generated/google/apis/taskqueue_v1beta2/service.rb +416 -0
- data/generated/google/apis/tasks_v1.rb +37 -0
- data/generated/google/apis/tasks_v1/classes.rb +296 -0
- data/generated/google/apis/tasks_v1/representations.rb +115 -0
- data/generated/google/apis/tasks_v1/service.rb +657 -0
- data/generated/google/apis/translate_v2.rb +31 -0
- data/generated/google/apis/translate_v2/classes.rb +168 -0
- data/generated/google/apis/translate_v2/representations.rb +109 -0
- data/generated/google/apis/translate_v2/service.rb +185 -0
- data/generated/google/apis/urlshortener_v1.rb +34 -0
- data/generated/google/apis/urlshortener_v1/classes.rb +246 -0
- data/generated/google/apis/urlshortener_v1/representations.rb +111 -0
- data/generated/google/apis/urlshortener_v1/service.rb +179 -0
- data/generated/google/apis/webmasters_v3.rb +37 -0
- data/generated/google/apis/webmasters_v3/classes.rb +563 -0
- data/generated/google/apis/webmasters_v3/representations.rb +250 -0
- data/generated/google/apis/webmasters_v3/service.rb +587 -0
- data/generated/google/apis/youtube_analytics_v1.rb +46 -0
- data/generated/google/apis/youtube_analytics_v1/classes.rb +540 -0
- data/generated/google/apis/youtube_analytics_v1/representations.rb +242 -0
- data/generated/google/apis/youtube_analytics_v1/service.rb +567 -0
- data/generated/google/apis/youtube_v3.rb +49 -0
- data/generated/google/apis/youtube_v3/classes.rb +7225 -0
- data/generated/google/apis/youtube_v3/representations.rb +2529 -0
- data/generated/google/apis/youtube_v3/service.rb +4051 -0
- data/google-api-client.gemspec +27 -39
- data/lib/google/api_client/auth/storage.rb +3 -2
- data/lib/google/api_client/auth/storages/file_store.rb +1 -3
- data/lib/google/api_client/auth/storages/redis_store.rb +6 -2
- data/lib/google/apis.rb +48 -0
- data/lib/google/apis/core/api_command.rb +128 -0
- data/lib/google/apis/core/base_service.rb +314 -0
- data/lib/google/apis/core/batch.rb +222 -0
- data/lib/google/apis/core/download.rb +94 -0
- data/lib/google/apis/core/hashable.rb +44 -0
- data/lib/google/apis/core/http_command.rb +275 -0
- data/lib/google/apis/core/json_representation.rb +122 -0
- data/lib/google/{api_client/version.rb → apis/core/logging.rb} +12 -8
- data/lib/google/apis/core/multipart.rb +173 -0
- data/lib/google/apis/core/upload.rb +275 -0
- data/lib/google/{api_client → apis}/errors.rb +32 -28
- data/lib/google/apis/generator.rb +70 -0
- data/lib/google/apis/generator/annotator.rb +271 -0
- data/lib/google/apis/generator/helpers.rb +74 -0
- data/lib/google/apis/generator/model.rb +130 -0
- data/lib/google/apis/generator/template.rb +124 -0
- data/lib/google/apis/generator/templates/_class.tmpl +40 -0
- data/lib/google/apis/generator/templates/_method.tmpl +90 -0
- data/lib/google/apis/generator/templates/_representation.tmpl +51 -0
- data/lib/google/apis/generator/templates/_representation_stub.tmpl +15 -0
- data/lib/google/apis/generator/templates/_representation_type.tmpl +10 -0
- data/lib/google/{api_client/reference.rb → apis/generator/templates/classes.rb.tmpl} +11 -9
- data/lib/google/apis/generator/templates/module.rb.tmpl +40 -0
- data/lib/google/apis/generator/templates/representations.rb.tmpl +32 -0
- data/lib/google/apis/generator/templates/service.rb.tmpl +60 -0
- data/lib/google/apis/options.rb +79 -0
- data/lib/google/apis/version.rb +39 -0
- data/rakelib/metrics.rake +22 -0
- data/rakelib/rubocop.rake +10 -0
- data/rakelib/spec.rake +11 -0
- data/rakelib/yard.rake +11 -0
- data/samples/calendar/calendar.rb +43 -0
- data/samples/drive/drive.rb +40 -0
- data/samples/pubsub/pubsub.rb +52 -0
- data/{lib/google/api_client/discovery.rb → samples/translate/translate.rb} +14 -5
- data/script/generate +79 -0
- data/script/package +8 -0
- data/script/release +15 -0
- data/spec/fixtures/files/api_names.yaml +3 -0
- data/spec/fixtures/files/auth_stored_credentials.json +8 -0
- data/spec/fixtures/files/client_secrets.json +1 -0
- data/spec/fixtures/files/test.blah +1 -0
- data/spec/fixtures/files/test.txt +1 -0
- data/spec/fixtures/files/test_api.json +440 -0
- data/spec/google/api_client/auth/storage_spec.rb +1 -3
- data/spec/google/api_client/auth/storages/file_store_spec.rb +1 -2
- data/spec/google/api_client/auth/storages/redis_store_spec.rb +1 -3
- data/spec/google/apis/core/api_command_spec.rb +170 -0
- data/spec/google/apis/core/batch_spec.rb +128 -0
- data/spec/google/apis/core/download_spec.rb +90 -0
- data/spec/google/apis/core/hashable_spec.rb +60 -0
- data/spec/google/apis/core/http_command_spec.rb +238 -0
- data/spec/google/apis/core/json_representation_spec.rb +192 -0
- data/spec/google/apis/core/service_spec.rb +247 -0
- data/spec/google/apis/core/upload_spec.rb +238 -0
- data/{lib/google/api_client/service_account.rb → spec/google/apis/generated_spec.rb} +14 -8
- data/spec/google/apis/generator/generator_spec.rb +272 -0
- data/spec/google/apis/logging_spec.rb +45 -0
- data/spec/google/apis/options_spec.rb +40 -0
- data/spec/integration_tests/drive_spec.rb +35 -0
- data/spec/integration_tests/pubsub_spec.rb +48 -0
- data/spec/integration_tests/url_shortener_spec.rb +31 -0
- data/spec/spec_helper.rb +102 -46
- metadata +433 -178
- data/lib/compat/multi_json.rb +0 -19
- data/lib/google/api_client.rb +0 -750
- data/lib/google/api_client/auth/file_storage.rb +0 -59
- data/lib/google/api_client/auth/jwt_asserter.rb +0 -126
- data/lib/google/api_client/auth/key_utils.rb +0 -93
- data/lib/google/api_client/auth/pkcs12.rb +0 -41
- data/lib/google/api_client/batch.rb +0 -326
- data/lib/google/api_client/charset.rb +0 -33
- data/lib/google/api_client/discovery/api.rb +0 -310
- data/lib/google/api_client/discovery/media.rb +0 -77
- data/lib/google/api_client/discovery/method.rb +0 -363
- data/lib/google/api_client/discovery/resource.rb +0 -156
- data/lib/google/api_client/discovery/schema.rb +0 -117
- data/lib/google/api_client/environment.rb +0 -42
- data/lib/google/api_client/gzip.rb +0 -28
- data/lib/google/api_client/logging.rb +0 -32
- data/lib/google/api_client/media.rb +0 -259
- data/lib/google/api_client/railtie.rb +0 -18
- data/lib/google/api_client/request.rb +0 -350
- data/lib/google/api_client/result.rb +0 -255
- data/lib/google/api_client/service.rb +0 -233
- data/lib/google/api_client/service/batch.rb +0 -110
- data/lib/google/api_client/service/request.rb +0 -144
- data/lib/google/api_client/service/resource.rb +0 -40
- data/lib/google/api_client/service/result.rb +0 -162
- data/lib/google/api_client/service/simple_file_store.rb +0 -151
- data/lib/google/api_client/service/stub_generator.rb +0 -61
- data/spec/google/api_client/batch_spec.rb +0 -248
- data/spec/google/api_client/discovery_spec.rb +0 -708
- data/spec/google/api_client/gzip_spec.rb +0 -98
- data/spec/google/api_client/media_spec.rb +0 -178
- data/spec/google/api_client/result_spec.rb +0 -207
- data/spec/google/api_client/service_account_spec.rb +0 -169
- data/spec/google/api_client/service_spec.rb +0 -618
- data/spec/google/api_client/simple_file_store_spec.rb +0 -133
- data/spec/google/api_client_spec.rb +0 -352
@@ -1,18 +0,0 @@
|
|
1
|
-
require 'rails/railtie'
|
2
|
-
require 'google/api_client/logging'
|
3
|
-
|
4
|
-
module Google
|
5
|
-
class APIClient
|
6
|
-
|
7
|
-
##
|
8
|
-
# Optional support class for Rails. Currently replaces the built-in logger
|
9
|
-
# with Rails' application log.
|
10
|
-
#
|
11
|
-
class Railtie < Rails::Railtie
|
12
|
-
initializer 'google-api-client' do |app|
|
13
|
-
logger = app.config.logger || Rails.logger
|
14
|
-
Google::APIClient.logger = logger unless logger.nil?
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
@@ -1,350 +0,0 @@
|
|
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 'faraday'
|
16
|
-
require 'faraday/request/multipart'
|
17
|
-
require 'compat/multi_json'
|
18
|
-
require 'addressable/uri'
|
19
|
-
require 'stringio'
|
20
|
-
require 'google/api_client/discovery'
|
21
|
-
require 'google/api_client/logging'
|
22
|
-
|
23
|
-
module Google
|
24
|
-
class APIClient
|
25
|
-
|
26
|
-
##
|
27
|
-
# Represents an API request.
|
28
|
-
class Request
|
29
|
-
include Google::APIClient::Logging
|
30
|
-
|
31
|
-
MULTIPART_BOUNDARY = "-----------RubyApiMultipartPost".freeze
|
32
|
-
|
33
|
-
# @return [Hash] Request parameters
|
34
|
-
attr_reader :parameters
|
35
|
-
# @return [Hash] Additional HTTP headers
|
36
|
-
attr_reader :headers
|
37
|
-
# @return [Google::APIClient::Method] API method to invoke
|
38
|
-
attr_reader :api_method
|
39
|
-
# @return [Google::APIClient::UploadIO] File to upload
|
40
|
-
attr_accessor :media
|
41
|
-
# @return [#generated_authenticated_request] User credentials
|
42
|
-
attr_accessor :authorization
|
43
|
-
# @return [TrueClass,FalseClass] True if request should include credentials
|
44
|
-
attr_accessor :authenticated
|
45
|
-
# @return [#read, #to_str] Request body
|
46
|
-
attr_accessor :body
|
47
|
-
|
48
|
-
##
|
49
|
-
# Build a request
|
50
|
-
#
|
51
|
-
# @param [Hash] options
|
52
|
-
# @option options [Hash, Array] :parameters
|
53
|
-
# Request parameters for the API method.
|
54
|
-
# @option options [Google::APIClient::Method] :api_method
|
55
|
-
# API method to invoke. Either :api_method or :uri must be specified
|
56
|
-
# @option options [TrueClass, FalseClass] :authenticated
|
57
|
-
# True if request should include credentials. Implicitly true if
|
58
|
-
# unspecified and :authorization present
|
59
|
-
# @option options [#generate_signed_request] :authorization
|
60
|
-
# OAuth credentials
|
61
|
-
# @option options [Google::APIClient::UploadIO] :media
|
62
|
-
# File to upload, if media upload request
|
63
|
-
# @option options [#to_json, #to_hash] :body_object
|
64
|
-
# Main body of the API request. Typically hash or object that can
|
65
|
-
# be serialized to JSON
|
66
|
-
# @option options [#read, #to_str] :body
|
67
|
-
# Raw body to send in POST/PUT requests
|
68
|
-
# @option options [String, Addressable::URI] :uri
|
69
|
-
# URI to request. Either :api_method or :uri must be specified
|
70
|
-
# @option options [String, Symbol] :http_method
|
71
|
-
# HTTP method when requesting a URI
|
72
|
-
def initialize(options={})
|
73
|
-
@parameters = Faraday::Utils::ParamsHash.new
|
74
|
-
@headers = Faraday::Utils::Headers.new
|
75
|
-
|
76
|
-
self.parameters.merge!(options[:parameters]) unless options[:parameters].nil?
|
77
|
-
self.headers.merge!(options[:headers]) unless options[:headers].nil?
|
78
|
-
self.api_method = options[:api_method]
|
79
|
-
self.authenticated = options[:authenticated]
|
80
|
-
self.authorization = options[:authorization]
|
81
|
-
|
82
|
-
# These parameters are handled differently because they're not
|
83
|
-
# parameters to the API method, but rather to the API system.
|
84
|
-
self.parameters['key'] ||= options[:key] if options[:key]
|
85
|
-
self.parameters['userIp'] ||= options[:user_ip] if options[:user_ip]
|
86
|
-
|
87
|
-
if options[:media]
|
88
|
-
self.initialize_media_upload(options)
|
89
|
-
elsif options[:body]
|
90
|
-
self.body = options[:body]
|
91
|
-
elsif options[:body_object]
|
92
|
-
self.headers['Content-Type'] ||= 'application/json'
|
93
|
-
self.body = serialize_body(options[:body_object])
|
94
|
-
else
|
95
|
-
self.body = ''
|
96
|
-
end
|
97
|
-
|
98
|
-
unless self.api_method
|
99
|
-
self.http_method = options[:http_method] || 'GET'
|
100
|
-
self.uri = options[:uri]
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
# @!attribute [r] upload_type
|
105
|
-
# @return [String] protocol used for upload
|
106
|
-
def upload_type
|
107
|
-
return self.parameters['uploadType'] || self.parameters['upload_type']
|
108
|
-
end
|
109
|
-
|
110
|
-
# @!attribute http_method
|
111
|
-
# @return [Symbol] HTTP method if invoking a URI
|
112
|
-
def http_method
|
113
|
-
return @http_method ||= self.api_method.http_method.to_s.downcase.to_sym
|
114
|
-
end
|
115
|
-
|
116
|
-
def http_method=(new_http_method)
|
117
|
-
if new_http_method.kind_of?(Symbol)
|
118
|
-
@http_method = new_http_method.to_s.downcase.to_sym
|
119
|
-
elsif new_http_method.respond_to?(:to_str)
|
120
|
-
@http_method = new_http_method.to_s.downcase.to_sym
|
121
|
-
else
|
122
|
-
raise TypeError,
|
123
|
-
"Expected String or Symbol, got #{new_http_method.class}."
|
124
|
-
end
|
125
|
-
end
|
126
|
-
|
127
|
-
def api_method=(new_api_method)
|
128
|
-
if new_api_method.nil? || new_api_method.kind_of?(Google::APIClient::Method)
|
129
|
-
@api_method = new_api_method
|
130
|
-
else
|
131
|
-
raise TypeError,
|
132
|
-
"Expected Google::APIClient::Method, got #{new_api_method.class}."
|
133
|
-
end
|
134
|
-
end
|
135
|
-
|
136
|
-
# @!attribute uri
|
137
|
-
# @return [Addressable::URI] URI to send request
|
138
|
-
def uri
|
139
|
-
return @uri ||= self.api_method.generate_uri(self.parameters)
|
140
|
-
end
|
141
|
-
|
142
|
-
def uri=(new_uri)
|
143
|
-
@uri = Addressable::URI.parse(new_uri)
|
144
|
-
@parameters.update(@uri.query_values) unless @uri.query_values.nil?
|
145
|
-
end
|
146
|
-
|
147
|
-
|
148
|
-
# Transmits the request with the given connection
|
149
|
-
#
|
150
|
-
# @api private
|
151
|
-
#
|
152
|
-
# @param [Faraday::Connection] connection
|
153
|
-
# the connection to transmit with
|
154
|
-
# @param [TrueValue,FalseValue] is_retry
|
155
|
-
# True if request has been previous sent
|
156
|
-
#
|
157
|
-
# @return [Google::APIClient::Result]
|
158
|
-
# result of API request
|
159
|
-
def send(connection, is_retry = false)
|
160
|
-
self.body.rewind if is_retry && self.body.respond_to?(:rewind)
|
161
|
-
env = self.to_env(connection)
|
162
|
-
logger.debug { "#{self.class} Sending API request #{env[:method]} #{env[:url].to_s} #{env[:request_headers]}" }
|
163
|
-
http_response = connection.app.call(env)
|
164
|
-
result = self.process_http_response(http_response)
|
165
|
-
|
166
|
-
logger.debug { "#{self.class} Result: #{result.status} #{result.headers}" }
|
167
|
-
|
168
|
-
# Resumamble slightly different than other upload protocols in that it requires at least
|
169
|
-
# 2 requests.
|
170
|
-
if result.status == 200 && self.upload_type == 'resumable' && self.media
|
171
|
-
upload = result.resumable_upload
|
172
|
-
unless upload.complete?
|
173
|
-
logger.debug { "#{self.class} Sending upload body" }
|
174
|
-
result = upload.send(connection)
|
175
|
-
end
|
176
|
-
end
|
177
|
-
return result
|
178
|
-
end
|
179
|
-
|
180
|
-
# Convert to an HTTP request. Returns components in order of method, URI,
|
181
|
-
# request headers, and body
|
182
|
-
#
|
183
|
-
# @api private
|
184
|
-
#
|
185
|
-
# @return [Array<(Symbol, Addressable::URI, Hash, [#read,#to_str])>]
|
186
|
-
def to_http_request
|
187
|
-
request = (
|
188
|
-
if self.api_method
|
189
|
-
self.api_method.generate_request(self.parameters, self.body, self.headers)
|
190
|
-
elsif self.uri
|
191
|
-
unless self.parameters.empty?
|
192
|
-
self.uri.query = Addressable::URI.form_encode(self.parameters)
|
193
|
-
end
|
194
|
-
[self.http_method, self.uri.to_s, self.headers, self.body]
|
195
|
-
end)
|
196
|
-
return request
|
197
|
-
end
|
198
|
-
|
199
|
-
##
|
200
|
-
# Hashified verison of the API request
|
201
|
-
#
|
202
|
-
# @return [Hash]
|
203
|
-
def to_hash
|
204
|
-
options = {}
|
205
|
-
if self.api_method
|
206
|
-
options[:api_method] = self.api_method
|
207
|
-
options[:parameters] = self.parameters
|
208
|
-
else
|
209
|
-
options[:http_method] = self.http_method
|
210
|
-
options[:uri] = self.uri
|
211
|
-
end
|
212
|
-
options[:headers] = self.headers
|
213
|
-
options[:body] = self.body
|
214
|
-
options[:media] = self.media
|
215
|
-
unless self.authorization.nil?
|
216
|
-
options[:authorization] = self.authorization
|
217
|
-
end
|
218
|
-
return options
|
219
|
-
end
|
220
|
-
|
221
|
-
##
|
222
|
-
# Prepares the request for execution, building a hash of parts
|
223
|
-
# suitable for sending to Faraday::Connection.
|
224
|
-
#
|
225
|
-
# @api private
|
226
|
-
#
|
227
|
-
# @param [Faraday::Connection] connection
|
228
|
-
# Connection for building the request
|
229
|
-
#
|
230
|
-
# @return [Hash]
|
231
|
-
# Encoded request
|
232
|
-
def to_env(connection)
|
233
|
-
method, uri, headers, body = self.to_http_request
|
234
|
-
http_request = connection.build_request(method) do |req|
|
235
|
-
req.url(uri.to_s)
|
236
|
-
req.headers.update(headers)
|
237
|
-
req.body = body
|
238
|
-
end
|
239
|
-
|
240
|
-
if self.authorization.respond_to?(:generate_authenticated_request)
|
241
|
-
http_request = self.authorization.generate_authenticated_request(
|
242
|
-
:request => http_request,
|
243
|
-
:connection => connection
|
244
|
-
)
|
245
|
-
end
|
246
|
-
|
247
|
-
http_request.to_env(connection)
|
248
|
-
end
|
249
|
-
|
250
|
-
##
|
251
|
-
# Convert HTTP response to an API Result
|
252
|
-
#
|
253
|
-
# @api private
|
254
|
-
#
|
255
|
-
# @param [Faraday::Response] response
|
256
|
-
# HTTP response
|
257
|
-
#
|
258
|
-
# @return [Google::APIClient::Result]
|
259
|
-
# Processed API response
|
260
|
-
def process_http_response(response)
|
261
|
-
Result.new(self, response)
|
262
|
-
end
|
263
|
-
|
264
|
-
protected
|
265
|
-
|
266
|
-
##
|
267
|
-
# Adjust headers & body for media uploads
|
268
|
-
#
|
269
|
-
# @api private
|
270
|
-
#
|
271
|
-
# @param [Hash] options
|
272
|
-
# @option options [Hash, Array] :parameters
|
273
|
-
# Request parameters for the API method.
|
274
|
-
# @option options [Google::APIClient::UploadIO] :media
|
275
|
-
# File to upload, if media upload request
|
276
|
-
# @option options [#to_json, #to_hash] :body_object
|
277
|
-
# Main body of the API request. Typically hash or object that can
|
278
|
-
# be serialized to JSON
|
279
|
-
# @option options [#read, #to_str] :body
|
280
|
-
# Raw body to send in POST/PUT requests
|
281
|
-
def initialize_media_upload(options)
|
282
|
-
self.media = options[:media]
|
283
|
-
case self.upload_type
|
284
|
-
when "media"
|
285
|
-
if options[:body] || options[:body_object]
|
286
|
-
raise ArgumentError, "Can not specify body & body object for simple uploads"
|
287
|
-
end
|
288
|
-
self.headers['Content-Type'] ||= self.media.content_type
|
289
|
-
self.headers['Content-Length'] ||= self.media.length.to_s
|
290
|
-
self.body = self.media
|
291
|
-
when "multipart"
|
292
|
-
unless options[:body_object]
|
293
|
-
raise ArgumentError, "Multipart requested but no body object"
|
294
|
-
end
|
295
|
-
metadata = StringIO.new(serialize_body(options[:body_object]))
|
296
|
-
build_multipart([Faraday::UploadIO.new(metadata, 'application/json', 'file.json'), self.media])
|
297
|
-
when "resumable"
|
298
|
-
file_length = self.media.length
|
299
|
-
self.headers['X-Upload-Content-Type'] = self.media.content_type
|
300
|
-
self.headers['X-Upload-Content-Length'] = file_length.to_s
|
301
|
-
if options[:body_object]
|
302
|
-
self.headers['Content-Type'] ||= 'application/json'
|
303
|
-
self.body = serialize_body(options[:body_object])
|
304
|
-
else
|
305
|
-
self.body = ''
|
306
|
-
end
|
307
|
-
end
|
308
|
-
end
|
309
|
-
|
310
|
-
##
|
311
|
-
# Assemble a multipart message from a set of parts
|
312
|
-
#
|
313
|
-
# @api private
|
314
|
-
#
|
315
|
-
# @param [Array<[#read,#to_str]>] parts
|
316
|
-
# Array of parts to encode.
|
317
|
-
# @param [String] mime_type
|
318
|
-
# MIME type of the message
|
319
|
-
# @param [String] boundary
|
320
|
-
# Boundary for separating each part of the message
|
321
|
-
def build_multipart(parts, mime_type = 'multipart/related', boundary = MULTIPART_BOUNDARY)
|
322
|
-
env = Faraday::Env.new
|
323
|
-
env.request = Faraday::RequestOptions.new
|
324
|
-
env.request.boundary = boundary
|
325
|
-
env.request_headers = {'Content-Type' => "#{mime_type};boundary=#{boundary}"}
|
326
|
-
multipart = Faraday::Request::Multipart.new
|
327
|
-
self.body = multipart.create_multipart(env, parts.map {|part| [nil, part]})
|
328
|
-
self.headers.update(env[:request_headers])
|
329
|
-
end
|
330
|
-
|
331
|
-
##
|
332
|
-
# Serialize body object to JSON
|
333
|
-
#
|
334
|
-
# @api private
|
335
|
-
#
|
336
|
-
# @param [#to_json,#to_hash] body
|
337
|
-
# object to serialize
|
338
|
-
#
|
339
|
-
# @return [String]
|
340
|
-
# JSON
|
341
|
-
def serialize_body(body)
|
342
|
-
return body.to_json if body.respond_to?(:to_json)
|
343
|
-
return MultiJson.dump(body.to_hash) if body.respond_to?(:to_hash)
|
344
|
-
raise TypeError, 'Could not convert body object to JSON.' +
|
345
|
-
'Must respond to :to_json or :to_hash.'
|
346
|
-
end
|
347
|
-
|
348
|
-
end
|
349
|
-
end
|
350
|
-
end
|
@@ -1,255 +0,0 @@
|
|
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
|
-
##
|
19
|
-
# This class wraps a result returned by an API call.
|
20
|
-
class Result
|
21
|
-
extend Forwardable
|
22
|
-
|
23
|
-
##
|
24
|
-
# Init the result
|
25
|
-
#
|
26
|
-
# @param [Google::APIClient::Request] request
|
27
|
-
# The original request
|
28
|
-
# @param [Faraday::Response] response
|
29
|
-
# Raw HTTP Response
|
30
|
-
def initialize(request, response)
|
31
|
-
@request = request
|
32
|
-
@response = response
|
33
|
-
@media_upload = reference if reference.kind_of?(ResumableUpload)
|
34
|
-
end
|
35
|
-
|
36
|
-
# @return [Google::APIClient::Request] Original request object
|
37
|
-
attr_reader :request
|
38
|
-
# @return [Faraday::Response] HTTP response
|
39
|
-
attr_reader :response
|
40
|
-
# @!attribute [r] reference
|
41
|
-
# @return [Google::APIClient::Request] Original request object
|
42
|
-
# @deprecated See {#request}
|
43
|
-
alias_method :reference, :request # For compatibility with pre-beta clients
|
44
|
-
|
45
|
-
# @!attribute [r] status
|
46
|
-
# @return [Fixnum] HTTP status code
|
47
|
-
# @!attribute [r] headers
|
48
|
-
# @return [Hash] HTTP response headers
|
49
|
-
# @!attribute [r] body
|
50
|
-
# @return [String] HTTP response body
|
51
|
-
def_delegators :@response, :status, :headers, :body
|
52
|
-
|
53
|
-
# @!attribute [r] resumable_upload
|
54
|
-
# @return [Google::APIClient::ResumableUpload] For resuming media uploads
|
55
|
-
def resumable_upload
|
56
|
-
@media_upload ||= (
|
57
|
-
options = self.reference.to_hash.merge(
|
58
|
-
:uri => self.headers['location'],
|
59
|
-
:media => self.reference.media
|
60
|
-
)
|
61
|
-
Google::APIClient::ResumableUpload.new(options)
|
62
|
-
)
|
63
|
-
end
|
64
|
-
|
65
|
-
##
|
66
|
-
# Get the content type of the response
|
67
|
-
# @!attribute [r] media_type
|
68
|
-
# @return [String]
|
69
|
-
# Value of content-type header
|
70
|
-
def media_type
|
71
|
-
_, content_type = self.headers.detect do |h, v|
|
72
|
-
h.downcase == 'Content-Type'.downcase
|
73
|
-
end
|
74
|
-
if content_type
|
75
|
-
return content_type[/^([^;]*);?.*$/, 1].strip.downcase
|
76
|
-
else
|
77
|
-
return nil
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
##
|
82
|
-
# Check if request failed
|
83
|
-
#
|
84
|
-
# @!attribute [r] error?
|
85
|
-
# @return [TrueClass, FalseClass]
|
86
|
-
# true if result of operation is an error
|
87
|
-
def error?
|
88
|
-
return self.response.status >= 400
|
89
|
-
end
|
90
|
-
|
91
|
-
##
|
92
|
-
# Check if request was successful
|
93
|
-
#
|
94
|
-
# @!attribute [r] success?
|
95
|
-
# @return [TrueClass, FalseClass]
|
96
|
-
# true if result of operation was successful
|
97
|
-
def success?
|
98
|
-
return !self.error?
|
99
|
-
end
|
100
|
-
|
101
|
-
##
|
102
|
-
# Extracts error messages from the response body
|
103
|
-
#
|
104
|
-
# @!attribute [r] error_message
|
105
|
-
# @return [String]
|
106
|
-
# error message, if available
|
107
|
-
def error_message
|
108
|
-
if self.data?
|
109
|
-
if self.data.respond_to?(:error) &&
|
110
|
-
self.data.error.respond_to?(:message)
|
111
|
-
# You're going to get a terrible error message if the response isn't
|
112
|
-
# parsed successfully as an error.
|
113
|
-
return self.data.error.message
|
114
|
-
elsif self.data['error'] && self.data['error']['message']
|
115
|
-
return self.data['error']['message']
|
116
|
-
end
|
117
|
-
end
|
118
|
-
return self.body
|
119
|
-
end
|
120
|
-
|
121
|
-
##
|
122
|
-
# Check for parsable data in response
|
123
|
-
#
|
124
|
-
# @!attribute [r] data?
|
125
|
-
# @return [TrueClass, FalseClass]
|
126
|
-
# true if body can be parsed
|
127
|
-
def data?
|
128
|
-
!(self.body.nil? || self.body.empty? || self.media_type != 'application/json')
|
129
|
-
end
|
130
|
-
|
131
|
-
##
|
132
|
-
# Return parsed version of the response body.
|
133
|
-
#
|
134
|
-
# @!attribute [r] data
|
135
|
-
# @return [Object, Hash, String]
|
136
|
-
# Object if body parsable from API schema, Hash if JSON, raw body if unable to parse
|
137
|
-
def data
|
138
|
-
return @data ||= (begin
|
139
|
-
if self.data?
|
140
|
-
media_type = self.media_type
|
141
|
-
data = self.body
|
142
|
-
case media_type
|
143
|
-
when 'application/json'
|
144
|
-
data = MultiJson.load(data)
|
145
|
-
# Strip data wrapper, if present
|
146
|
-
data = data['data'] if data.has_key?('data')
|
147
|
-
else
|
148
|
-
raise ArgumentError,
|
149
|
-
"Content-Type not supported for parsing: #{media_type}"
|
150
|
-
end
|
151
|
-
if @request.api_method && @request.api_method.response_schema
|
152
|
-
# Automatically parse using the schema designated for the
|
153
|
-
# response of this API method.
|
154
|
-
data = @request.api_method.response_schema.new(data)
|
155
|
-
data
|
156
|
-
else
|
157
|
-
# Otherwise, return the raw unparsed value.
|
158
|
-
# This value must be indexable like a Hash.
|
159
|
-
data
|
160
|
-
end
|
161
|
-
end
|
162
|
-
end)
|
163
|
-
end
|
164
|
-
|
165
|
-
##
|
166
|
-
# Get the token used for requesting the next page of data
|
167
|
-
#
|
168
|
-
# @!attribute [r] next_page_token
|
169
|
-
# @return [String]
|
170
|
-
# next page token
|
171
|
-
def next_page_token
|
172
|
-
if self.data.respond_to?(:next_page_token)
|
173
|
-
return self.data.next_page_token
|
174
|
-
elsif self.data.respond_to?(:[])
|
175
|
-
return self.data["nextPageToken"]
|
176
|
-
else
|
177
|
-
raise TypeError, "Data object did not respond to #next_page_token."
|
178
|
-
end
|
179
|
-
end
|
180
|
-
|
181
|
-
##
|
182
|
-
# Build a request for fetching the next page of data
|
183
|
-
#
|
184
|
-
# @return [Google::APIClient::Request]
|
185
|
-
# API request for retrieving next page, nil if no page token available
|
186
|
-
def next_page
|
187
|
-
return nil unless self.next_page_token
|
188
|
-
merged_parameters = Hash[self.reference.parameters].merge({
|
189
|
-
self.page_token_param => self.next_page_token
|
190
|
-
})
|
191
|
-
# Because Requests can be coerced to Hashes, we can merge them,
|
192
|
-
# preserving all context except the API method parameters that we're
|
193
|
-
# using for pagination.
|
194
|
-
return Google::APIClient::Request.new(
|
195
|
-
Hash[self.reference].merge(:parameters => merged_parameters)
|
196
|
-
)
|
197
|
-
end
|
198
|
-
|
199
|
-
##
|
200
|
-
# Get the token used for requesting the previous page of data
|
201
|
-
#
|
202
|
-
# @!attribute [r] prev_page_token
|
203
|
-
# @return [String]
|
204
|
-
# previous page token
|
205
|
-
def prev_page_token
|
206
|
-
if self.data.respond_to?(:prev_page_token)
|
207
|
-
return self.data.prev_page_token
|
208
|
-
elsif self.data.respond_to?(:[])
|
209
|
-
return self.data["prevPageToken"]
|
210
|
-
else
|
211
|
-
raise TypeError, "Data object did not respond to #next_page_token."
|
212
|
-
end
|
213
|
-
end
|
214
|
-
|
215
|
-
##
|
216
|
-
# Build a request for fetching the previous page of data
|
217
|
-
#
|
218
|
-
# @return [Google::APIClient::Request]
|
219
|
-
# API request for retrieving previous page, nil if no page token available
|
220
|
-
def prev_page
|
221
|
-
return nil unless self.prev_page_token
|
222
|
-
merged_parameters = Hash[self.reference.parameters].merge({
|
223
|
-
self.page_token_param => self.prev_page_token
|
224
|
-
})
|
225
|
-
# Because Requests can be coerced to Hashes, we can merge them,
|
226
|
-
# preserving all context except the API method parameters that we're
|
227
|
-
# using for pagination.
|
228
|
-
return Google::APIClient::Request.new(
|
229
|
-
Hash[self.reference].merge(:parameters => merged_parameters)
|
230
|
-
)
|
231
|
-
end
|
232
|
-
|
233
|
-
##
|
234
|
-
# Pagination scheme used by this request/response
|
235
|
-
#
|
236
|
-
# @!attribute [r] pagination_type
|
237
|
-
# @return [Symbol]
|
238
|
-
# currently always :token
|
239
|
-
def pagination_type
|
240
|
-
return :token
|
241
|
-
end
|
242
|
-
|
243
|
-
##
|
244
|
-
# Name of the field that contains the pagination token
|
245
|
-
#
|
246
|
-
# @!attribute [r] page_token_param
|
247
|
-
# @return [String]
|
248
|
-
# currently always 'pageToken'
|
249
|
-
def page_token_param
|
250
|
-
return "pageToken"
|
251
|
-
end
|
252
|
-
|
253
|
-
end
|
254
|
-
end
|
255
|
-
end
|