diff --git a/README.md b/README.md index 4d99f7d..0781b6c 100644 --- a/README.md +++ b/README.md @@ -25,14 +25,21 @@ You will need a Google Developers Console project. 1. Go to the [Google Developers Console](https://console.developers.google.com/project). 2. Click Create Project, enter a name, and click Create. 3. Once inside your project, enable access to the Google APIs you want this project to have access to (Library -> Search -> Enable). -4. Create Credentials (API Key) -5. Add the following to your Elixir app's configuration: + +For key based requests: +1. Create Credentials (API Key) +2. Add the following to your Elixir app's configuration: ```elixir config :google_api_client, api_key: "Your API key" ``` +For Ouath based requests: +1. Implement oauth to obtain a user's token (see: + https://developers.google.com/identity/protocols/OAuth2WebServer) +2. Pass the access token to methods which require oauth + ## Usage ```elixir @@ -46,5 +53,23 @@ Google.Apis.Maps.TimeZone.get(location: {-33.86,151.20}) # => %{"dstOffset" => 3600, "rawOffset" => 36000, "status" => "OK", "timeZoneId" => "Australia/Sydney", "timeZoneName" => "Australian Eastern Daylight Time"} Google.Apis.Places.autocomplete("poz", language: "pl") +alias Google.Apis.Analytics.Accounts +Accounts.list("a_valid_oauth_token") + +alias Google.Apis.Analytics.WebProperties +WebProperties.get("a_valid_oauth_token", account_id, web_property_id) +WebProperties.insert("a_valid_oauth_token", account_id, resource) +WebProperties.list("a_valid_oauth_token", account_id) +WebProperties.patch("a_valid_oauth_token", account_id, web_property_id, resource) +WebProperties.update("a_valid_oauth_token", account_id, web_property_id, resource) + +alias Google.Apis.Analytics.Views +Views.delete("a_valid_oauth_token", account_id, web_property_id, profile_id) +Views.get("a_valid_oauth_token", account_id, web_property_id, profile_id) +Views.insert("a_valid_oauth_token", account_id, web_property_id, resource) +Views.list("a_valid_oauth_token", account_id, web_property_id) +Views.patch("a_valid_oauth_token", account_id, web_property_id, profile_id, resource) +Views.update("a_valid_oauth_token", account_id, web_property_id, profile_id, resource) + Google.Apis.??? # Submit a PR ``` diff --git a/fixture/vcr_cassettes/analytics_accounts_error_response.json b/fixture/vcr_cassettes/analytics_accounts_error_response.json new file mode 100644 index 0000000..2d4b790 --- /dev/null +++ b/fixture/vcr_cassettes/analytics_accounts_error_response.json @@ -0,0 +1,35 @@ +[ + { + "request": { + "body": "", + "headers": { + "Authorization": "***", + "Content-Type": "application/json" + }, + "method": "get", + "options": [], + "request_body": "", + "url": "https://www.googleapis.com/analytics/v3/management/accounts?max_results=100&start_index=0" + }, + "response": { + "body": "{\"error\":{\"errors\":[{\"domain\":\"global\",\"reason\":\"authError\",\"message\":\"Invalid Credentials\",\"locationType\":\"header\",\"location\":\"Authorization\"}],\"code\":401,\"message\":\"Invalid Credentials\"}}", + "headers": { + "Vary": "X-Origin", + "WWW-Authenticate": "Bearer realm=\"https://accounts.google.com/\", error=invalid_token", + "Content-Type": "application/json; charset=UTF-8", + "Date": "Wed, 28 Jun 2017 15:18:48 GMT", + "Expires": "Wed, 28 Jun 2017 15:18:48 GMT", + "Cache-Control": "private, max-age=0", + "X-Content-Type-Options": "nosniff", + "X-Frame-Options": "SAMEORIGIN", + "X-XSS-Protection": "1; mode=block", + "Server": "GSE", + "Alt-Svc": "quic=\":443\"; ma=2592000; v=\"39,38,37,36,35\"", + "Accept-Ranges": "none", + "Transfer-Encoding": "chunked" + }, + "status_code": 401, + "type": "ok" + } + } +] \ No newline at end of file diff --git a/fixture/vcr_cassettes/analytics_accounts_response.json b/fixture/vcr_cassettes/analytics_accounts_response.json new file mode 100644 index 0000000..525f0ec --- /dev/null +++ b/fixture/vcr_cassettes/analytics_accounts_response.json @@ -0,0 +1,34 @@ +[ + { + "request": { + "body": "", + "headers": { + "Authorization": "***", + "Content-Type": "application/json" + }, + "method": "get", + "options": [], + "request_body": "", + "url": "https://www.googleapis.com/analytics/v3/management/accounts?max_results=100&start_index=0" + }, + "response": { + "body": "{\"kind\":\"analytics#accounts\",\"username\":\"daniel@testco.com\",\"totalResults\":1,\"startIndex\":1,\"itemsPerPage\":1000,\"items\":[{\"id\":\"12345678\",\"kind\":\"analytics#account\",\"selfLink\":\"https://www.googleapis.com/analytics/v3/management/accounts/12345678\",\"name\":\"Test Labs\",\"permissions\":{\"effective\":[\"COLLABORATE\",\"EDIT\",\"MANAGE_USERS\",\"READ_AND_ANALYZE\"]},\"created\":\"2015-07-11T17:11:47.869Z\",\"updated\":\"2015-08-11T23:25:12.427Z\",\"childLink\":{\"type\":\"analytics#webproperties\",\"href\":\"https://www.googleapis.com/analytics/v3/management/accounts/12345678/webproperties\"}}]}", + "headers": { + "Expires": "Wed, 28 Jun 2017 15:37:21 GMT", + "Date": "Wed, 28 Jun 2017 15:37:21 GMT", + "Cache-Control": "private, max-age=0, must-revalidate, no-transform", + "ETag": "\"f7I_c57UUFPNhe6k9kg6-jYr1TI/JXrKTtqGpZyK4p3csMdODat6cIQ\"", + "Vary": "Origin", + "Content-Type": "application/json; charset=UTF-8", + "X-Content-Type-Options": "nosniff", + "X-Frame-Options": "SAMEORIGIN", + "X-XSS-Protection": "1; mode=block", + "Content-Length": "571", + "Server": "GSE", + "Alt-Svc": "quic=\":443\"; ma=12345678; v=\"39,38,37,36,35\"" + }, + "status_code": 200, + "type": "ok" + } + } +] diff --git a/fixture/vcr_cassettes/analytics_views_error_response.json b/fixture/vcr_cassettes/analytics_views_error_response.json new file mode 100644 index 0000000..6f65ed3 --- /dev/null +++ b/fixture/vcr_cassettes/analytics_views_error_response.json @@ -0,0 +1,35 @@ +[ + { + "request": { + "body": "", + "headers": { + "Authorization": "***", + "Content-Type": "application/json" + }, + "method": "get", + "options": [], + "request_body": "", + "url": "https://www.googleapis.com/analytics/v3/management/accounts/12345678/webproperties/UA-12345678-6/profiles" + }, + "response": { + "body": "{\"error\":{\"errors\":[{\"domain\":\"global\",\"reason\":\"authError\",\"message\":\"Invalid Credentials\",\"locationType\":\"header\",\"location\":\"Authorization\"}],\"code\":401,\"message\":\"Invalid Credentials\"}}", + "headers": { + "Vary": "X-Origin", + "WWW-Authenticate": "Bearer realm=\"https://accounts.google.com/\", error=invalid_token", + "Content-Type": "application/json; charset=UTF-8", + "Date": "Wed, 28 Jun 2017 20:01:38 GMT", + "Expires": "Wed, 28 Jun 2017 20:01:38 GMT", + "Cache-Control": "private, max-age=0", + "X-Content-Type-Options": "nosniff", + "X-Frame-Options": "SAMEORIGIN", + "X-XSS-Protection": "1; mode=block", + "Server": "GSE", + "Alt-Svc": "quic=\":443\"; ma=12345678; v=\"39,38,37,36,35\"", + "Accept-Ranges": "none", + "Transfer-Encoding": "chunked" + }, + "status_code": 401, + "type": "ok" + } + } +] \ No newline at end of file diff --git a/fixture/vcr_cassettes/analytics_views_get_error_response.json b/fixture/vcr_cassettes/analytics_views_get_error_response.json new file mode 100644 index 0000000..2eb1178 --- /dev/null +++ b/fixture/vcr_cassettes/analytics_views_get_error_response.json @@ -0,0 +1,35 @@ +[ + { + "request": { + "body": "", + "headers": { + "Authorization": "***", + "Content-Type": "application/json" + }, + "method": "get", + "options": [], + "request_body": "", + "url": "https://www.googleapis.com/analytics/v3/management/accounts/12345678/webproperties/UA-12345678-6/profiles/A1" + }, + "response": { + "body": "{\"error\":{\"errors\":[{\"domain\":\"global\",\"reason\":\"authError\",\"message\":\"Invalid Credentials\",\"locationType\":\"header\",\"location\":\"Authorization\"}],\"code\":401,\"message\":\"Invalid Credentials\"}}", + "headers": { + "Vary": "X-Origin", + "WWW-Authenticate": "Bearer realm=\"https://accounts.google.com/\", error=invalid_token", + "Content-Type": "application/json; charset=UTF-8", + "Date": "Wed, 28 Jun 2017 20:01:38 GMT", + "Expires": "Wed, 28 Jun 2017 20:01:38 GMT", + "Cache-Control": "private, max-age=0", + "X-Content-Type-Options": "nosniff", + "X-Frame-Options": "SAMEORIGIN", + "X-XSS-Protection": "1; mode=block", + "Server": "GSE", + "Alt-Svc": "quic=\":443\"; ma=12345678; v=\"39,38,37,36,35\"", + "Accept-Ranges": "none", + "Transfer-Encoding": "chunked" + }, + "status_code": 401, + "type": "ok" + } + } +] \ No newline at end of file diff --git a/fixture/vcr_cassettes/analytics_views_get_response.json b/fixture/vcr_cassettes/analytics_views_get_response.json new file mode 100644 index 0000000..ce568bb --- /dev/null +++ b/fixture/vcr_cassettes/analytics_views_get_response.json @@ -0,0 +1,34 @@ +[ + { + "request": { + "body": "", + "headers": { + "Authorization": "***", + "Content-Type": "application/json" + }, + "method": "get", + "options": [], + "request_body": "", + "url": "https://www.googleapis.com/analytics/v3/management/accounts/12345678/webproperties/UA-12345678-6/profiles/A1" + }, + "response": { + "body": "{\"id\":\"12345678\",\"kind\":\"analytics#profile\",\"selfLink\":\"https://www.googleapis.com/analytics/v3/management/accounts/12345678/webproperties/UA-12345678-6/profiles/12345678\",\"accountId\":\"12345678\",\"webPropertyId\":\"UA-12345678-6\",\"internalWebPropertyId\":\"12345678\",\"name\":\"All Web Site Data\",\"currency\":\"USD\",\"timezone\":\"America/New_York\",\"websiteUrl\":\"http://example.tumblr.com/\",\"type\":\"WEB\",\"permissions\":{\"effective\":[\"COLLABORATE\",\"EDIT\",\"MANAGE_USERS\",\"READ_AND_ANALYZE\"]},\"created\":\"2016-02-22T16:41:49.313Z\",\"updated\":\"2016-02-22T16:41:49.313Z\",\"eCommerceTracking\":false,\"parentLink\":{\"type\":\"analytics#webproperty\",\"href\":\"https://www.googleapis.com/analytics/v3/management/accounts/12345678/webproperties/UA-12345678-6\"},\"childLink\":{\"type\":\"analytics#goals\",\"href\":\"https://www.googleapis.com/analytics/v3/management/accounts/12345678/webproperties/UA-12345678-6/profiles/12345678/goals\"}}", + "headers": { + "Expires": "Wed, 28 Jun 2017 20:01:37 GMT", + "Date": "Wed, 28 Jun 2017 20:01:37 GMT", + "Cache-Control": "private, max-age=0, must-revalidate, no-transform", + "ETag": "\"f7I_c57UUFPNhe6k9kg6-jYr1TI/dlR6rEpuGBK8mdVUU-SADk229lM\"", + "Vary": "Origin", + "Content-Type": "application/json; charset=UTF-8", + "X-Content-Type-Options": "nosniff", + "X-Frame-Options": "SAMEORIGIN", + "X-XSS-Protection": "1; mode=block", + "Content-Length": "910", + "Server": "GSE", + "Alt-Svc": "quic=\":443\"; ma=12345678; v=\"39,38,37,36,35\"" + }, + "status_code": 200, + "type": "ok" + } + } +] diff --git a/fixture/vcr_cassettes/analytics_views_insert_error_response.json b/fixture/vcr_cassettes/analytics_views_insert_error_response.json new file mode 100644 index 0000000..0c62d15 --- /dev/null +++ b/fixture/vcr_cassettes/analytics_views_insert_error_response.json @@ -0,0 +1,35 @@ +[ + { + "request": { + "body": "{\"websiteUrl\":\"http://www.examplepetstore.com\",\"name\":\"Example Store\"}", + "headers": { + "Authorization": "***", + "Content-Type": "application/json" + }, + "method": "post", + "options": [], + "request_body": "", + "url": "https://www.googleapis.com/analytics/v3/management/accounts/12345678/webproperties/UA-12345678-6/profiles" + }, + "response": { + "body": "{\"error\":{\"errors\":[{\"domain\":\"global\",\"reason\":\"authError\",\"message\":\"Invalid Credentials\",\"locationType\":\"header\",\"location\":\"Authorization\"}],\"code\":401,\"message\":\"Invalid Credentials\"}}", + "headers": { + "Vary": "X-Origin", + "WWW-Authenticate": "Bearer realm=\"https://accounts.google.com/\", error=invalid_token", + "Content-Type": "application/json; charset=UTF-8", + "Date": "Wed, 28 Jun 2017 20:01:38 GMT", + "Expires": "Wed, 28 Jun 2017 20:01:38 GMT", + "Cache-Control": "private, max-age=0", + "X-Content-Type-Options": "nosniff", + "X-Frame-Options": "SAMEORIGIN", + "X-XSS-Protection": "1; mode=block", + "Server": "GSE", + "Alt-Svc": "quic=\":443\"; ma=12345678; v=\"39,38,37,36,35\"", + "Accept-Ranges": "none", + "Transfer-Encoding": "chunked" + }, + "status_code": 401, + "type": "ok" + } + } +] \ No newline at end of file diff --git a/fixture/vcr_cassettes/analytics_views_insert_response.json b/fixture/vcr_cassettes/analytics_views_insert_response.json new file mode 100644 index 0000000..7769fb4 --- /dev/null +++ b/fixture/vcr_cassettes/analytics_views_insert_response.json @@ -0,0 +1,34 @@ +[ + { + "request": { + "body": "", + "headers": { + "Authorization": "***", + "Content-Type": "application/json" + }, + "method": "post", + "options": [], + "request_body": "{\"websiteUrl\":\"http://www.examplepetstore.com\",\"name\":\"Example Store\"}", + "url": "https://www.googleapis.com/analytics/v3/management/accounts/12345678/webproperties/UA-12345678-6/profiles" + }, + "response": { + "body": "{\"id\":\"UA-12345678-6\",\"kind\":\"analytics#webproperty\",\"selfLink\":\"https://www.googleapis.com/analytics/v3/management/accounts/12345678/webproperties/UA-12345678-6\",\"accountId\":\"12345678\",\"internalWebPropertyId\":\"12345678\",\"name\":\"example.tumblr.com/\",\"websiteUrl\":\"http://example.tumblr.com/\",\"level\":\"STANDARD\",\"profileCount\":1,\"industryVertical\":\"ARTS_AND_ENTERTAINMENT\",\"defaultProfileId\":\"12345678\",\"permissions\":{\"effective\":[\"COLLABORATE\",\"EDIT\",\"MANAGE_USERS\",\"READ_AND_ANALYZE\"]},\"created\":\"2016-02-22T16:41:49.313Z\",\"updated\":\"2016-02-22T16:41:49.313Z\",\"parentLink\":{\"type\":\"analytics#account\",\"href\":\"https://www.googleapis.com/analytics/v3/management/accounts/12345678\"},\"childLink\":{\"type\":\"analytics#profiles\",\"href\":\"https://www.googleapis.com/analytics/v3/management/accounts/12345678/webproperties/UA-12345678-6/profiles\"}}", + "headers": { + "Expires": "Wed, 28 Jun 2017 17:35:32 GMT", + "Date": "Wed, 28 Jun 2017 17:35:32 GMT", + "Cache-Control": "private, max-age=0, must-revalidate, no-transform", + "ETag": "\"f7I_c57UUFPNhe6k9kg6-jYr1TI/JZ1C7QSgraOUpdL0h-V27sbvjWU\"", + "Vary": "Origin", + "Content-Type": "application/json; charset=UTF-8", + "X-Content-Type-Options": "nosniff", + "X-Frame-Options": "SAMEORIGIN", + "X-XSS-Protection": "1; mode=block", + "Content-Length": "858", + "Server": "GSE", + "Alt-Svc": "quic=\":443\"; ma=12345678; v=\"39,38,37,36,35\"" + }, + "status_code": 200, + "type": "ok" + } + } +] diff --git a/fixture/vcr_cassettes/analytics_views_patch_error_response.json b/fixture/vcr_cassettes/analytics_views_patch_error_response.json new file mode 100644 index 0000000..734d9d1 --- /dev/null +++ b/fixture/vcr_cassettes/analytics_views_patch_error_response.json @@ -0,0 +1,35 @@ +[ + { + "request": { + "body": "{\"websiteUrl\":\"http://www.examplepetstore.com\",\"name\":\"Example Store\"}", + "headers": { + "Authorization": "***", + "Content-Type": "application/json" + }, + "method": "patch", + "options": [], + "request_body": "", + "url": "https://www.googleapis.com/analytics/v3/management/accounts/12345678/webproperties/UA-12345678-6/profiles/A1" + }, + "response": { + "body": "{\"error\":{\"errors\":[{\"domain\":\"global\",\"reason\":\"authError\",\"message\":\"Invalid Credentials\",\"locationType\":\"header\",\"location\":\"Authorization\"}],\"code\":401,\"message\":\"Invalid Credentials\"}}", + "headers": { + "Vary": "X-Origin", + "WWW-Authenticate": "Bearer realm=\"https://accounts.google.com/\", error=invalid_token", + "Content-Type": "application/json; charset=UTF-8", + "Date": "Wed, 28 Jun 2017 20:01:37 GMT", + "Expires": "Wed, 28 Jun 2017 20:01:37 GMT", + "Cache-Control": "private, max-age=0", + "X-Content-Type-Options": "nosniff", + "X-Frame-Options": "SAMEORIGIN", + "X-XSS-Protection": "1; mode=block", + "Server": "GSE", + "Alt-Svc": "quic=\":443\"; ma=12345678; v=\"39,38,37,36,35\"", + "Accept-Ranges": "none", + "Transfer-Encoding": "chunked" + }, + "status_code": 401, + "type": "ok" + } + } +] \ No newline at end of file diff --git a/fixture/vcr_cassettes/analytics_views_patch_response.json b/fixture/vcr_cassettes/analytics_views_patch_response.json new file mode 100644 index 0000000..6e82d7b --- /dev/null +++ b/fixture/vcr_cassettes/analytics_views_patch_response.json @@ -0,0 +1,34 @@ +[ + { + "request": { + "body": "", + "headers": { + "Authorization": "***", + "Content-Type": "application/json" + }, + "method": "patch", + "options": [], + "request_body": "{\"websiteUrl\":\"http://www.examplepetstore.com\",\"name\":\"Example Store\"}", + "url": "https://www.googleapis.com/analytics/v3/management/accounts/12345678/webproperties/UA-12345678-6/profiles/A1" + }, + "response": { + "body": "{\"id\":\"UA-12345678-6\",\"kind\":\"analytics#webproperty\",\"selfLink\":\"https://www.googleapis.com/analytics/v3/management/accounts/12345678/webproperties/UA-12345678-6\",\"accountId\":\"12345678\",\"internalWebPropertyId\":\"12345678\",\"name\":\"example.tumblr.com/\",\"websiteUrl\":\"http://example.tumblr.com/\",\"level\":\"STANDARD\",\"profileCount\":1,\"industryVertical\":\"ARTS_AND_ENTERTAINMENT\",\"defaultProfileId\":\"12345678\",\"permissions\":{\"effective\":[\"COLLABORATE\",\"EDIT\",\"MANAGE_USERS\",\"READ_AND_ANALYZE\"]},\"created\":\"2016-02-22T16:41:49.313Z\",\"updated\":\"2016-02-22T16:41:49.313Z\",\"parentLink\":{\"type\":\"analytics#account\",\"href\":\"https://www.googleapis.com/analytics/v3/management/accounts/12345678\"},\"childLink\":{\"type\":\"analytics#profiles\",\"href\":\"https://www.googleapis.com/analytics/v3/management/accounts/12345678/webproperties/UA-12345678-6/profiles\"}}", + "headers": { + "Expires": "Wed, 28 Jun 2017 17:35:32 GMT", + "Date": "Wed, 28 Jun 2017 17:35:32 GMT", + "Cache-Control": "private, max-age=0, must-revalidate, no-transform", + "ETag": "\"f7I_c57UUFPNhe6k9kg6-jYr1TI/JZ1C7QSgraOUpdL0h-V27sbvjWU\"", + "Vary": "Origin", + "Content-Type": "application/json; charset=UTF-8", + "X-Content-Type-Options": "nosniff", + "X-Frame-Options": "SAMEORIGIN", + "X-XSS-Protection": "1; mode=block", + "Content-Length": "858", + "Server": "GSE", + "Alt-Svc": "quic=\":443\"; ma=12345678; v=\"39,38,37,36,35\"" + }, + "status_code": 200, + "type": "ok" + } + } +] diff --git a/fixture/vcr_cassettes/analytics_views_response.json b/fixture/vcr_cassettes/analytics_views_response.json new file mode 100644 index 0000000..20d97a1 --- /dev/null +++ b/fixture/vcr_cassettes/analytics_views_response.json @@ -0,0 +1,34 @@ +[ + { + "request": { + "body": "", + "headers": { + "Authorization": "***", + "Content-Type": "application/json" + }, + "method": "get", + "options": [], + "request_body": "", + "url": "https://www.googleapis.com/analytics/v3/management/accounts/12345678/webproperties/UA-12345678-6/profiles" + }, + "response": { + "body": "{\"kind\":\"analytics#profiles\",\"username\":\"daniel@testco.com\",\"totalResults\":1,\"startIndex\":1,\"itemsPerPage\":1000,\"items\":[{\"id\":\"12345678\",\"kind\":\"analytics#profile\",\"selfLink\":\"https://www.googleapis.com/analytics/v3/management/accounts/12345678/webproperties/UA-12345678-6/profiles/12345678\",\"accountId\":\"12345678\",\"webPropertyId\":\"UA-12345678-6\",\"internalWebPropertyId\":\"12345678\",\"name\":\"All Web Site Data\",\"currency\":\"USD\",\"timezone\":\"America/New_York\",\"websiteUrl\":\"http://example.tumblr.com/\",\"type\":\"WEB\",\"permissions\":{\"effective\":[\"COLLABORATE\",\"EDIT\",\"MANAGE_USERS\",\"READ_AND_ANALYZE\"]},\"created\":\"2016-02-22T16:41:49.313Z\",\"updated\":\"2016-02-22T16:41:49.313Z\",\"eCommerceTracking\":false,\"parentLink\":{\"type\":\"analytics#webproperty\",\"href\":\"https://www.googleapis.com/analytics/v3/management/accounts/12345678/webproperties/UA-12345678-6\"},\"childLink\":{\"type\":\"analytics#goals\",\"href\":\"https://www.googleapis.com/analytics/v3/management/accounts/12345678/webproperties/UA-12345678-6/profiles/12345678/goals\"}}]}", + "headers": { + "Expires": "Wed, 28 Jun 2017 20:01:37 GMT", + "Date": "Wed, 28 Jun 2017 20:01:37 GMT", + "Cache-Control": "private, max-age=0, must-revalidate, no-transform", + "ETag": "\"f7I_c57UUFPNhe6k9kg6-jYr1TI/mFJWAhd1XCMjBDHpBYm9n_UFQLU\"", + "Vary": "Origin", + "Content-Type": "application/json; charset=UTF-8", + "X-Content-Type-Options": "nosniff", + "X-Frame-Options": "SAMEORIGIN", + "X-XSS-Protection": "1; mode=block", + "Content-Length": "1036", + "Server": "GSE", + "Alt-Svc": "quic=\":443\"; ma=12345678; v=\"39,38,37,36,35\"" + }, + "status_code": 200, + "type": "ok" + } + } +] diff --git a/fixture/vcr_cassettes/analytics_views_update_error_response.json b/fixture/vcr_cassettes/analytics_views_update_error_response.json new file mode 100644 index 0000000..78f4375 --- /dev/null +++ b/fixture/vcr_cassettes/analytics_views_update_error_response.json @@ -0,0 +1,35 @@ +[ + { + "request": { + "body": "{\"websiteUrl\":\"http://www.examplepetstore.com\",\"name\":\"Example Store\"}", + "headers": { + "Authorization": "***", + "Content-Type": "application/json" + }, + "method": "put", + "options": [], + "request_body": "", + "url": "https://www.googleapis.com/analytics/v3/management/accounts/12345678/webproperties/UA-12345678-6/profiles/A1" + }, + "response": { + "body": "{\"error\":{\"errors\":[{\"domain\":\"global\",\"reason\":\"authError\",\"message\":\"Invalid Credentials\",\"locationType\":\"header\",\"location\":\"Authorization\"}],\"code\":401,\"message\":\"Invalid Credentials\"}}", + "headers": { + "Vary": "X-Origin", + "WWW-Authenticate": "Bearer realm=\"https://accounts.google.com/\", error=invalid_token", + "Content-Type": "application/json; charset=UTF-8", + "Date": "Wed, 28 Jun 2017 20:01:38 GMT", + "Expires": "Wed, 28 Jun 2017 20:01:38 GMT", + "Cache-Control": "private, max-age=0", + "X-Content-Type-Options": "nosniff", + "X-Frame-Options": "SAMEORIGIN", + "X-XSS-Protection": "1; mode=block", + "Server": "GSE", + "Alt-Svc": "quic=\":443\"; ma=12345678; v=\"39,38,37,36,35\"", + "Accept-Ranges": "none", + "Transfer-Encoding": "chunked" + }, + "status_code": 401, + "type": "ok" + } + } +] \ No newline at end of file diff --git a/fixture/vcr_cassettes/analytics_views_update_response.json b/fixture/vcr_cassettes/analytics_views_update_response.json new file mode 100644 index 0000000..7be80cd --- /dev/null +++ b/fixture/vcr_cassettes/analytics_views_update_response.json @@ -0,0 +1,34 @@ +[ + { + "request": { + "body": "", + "headers": { + "Authorization": "***", + "Content-Type": "application/json" + }, + "method": "put", + "options": [], + "request_body": "{\"websiteUrl\":\"http://www.examplepetstore.com\",\"name\":\"Example Store\"}", + "url": "https://www.googleapis.com/analytics/v3/management/accounts/12345678/webproperties/UA-12345678-6/profiles/A1" + }, + "response": { + "body": "{\"id\":\"UA-12345678-6\",\"kind\":\"analytics#webproperty\",\"selfLink\":\"https://www.googleapis.com/analytics/v3/management/accounts/12345678/webproperties/UA-12345678-6\",\"accountId\":\"12345678\",\"internalWebPropertyId\":\"12345678\",\"name\":\"example.tumblr.com/\",\"websiteUrl\":\"http://example.tumblr.com/\",\"level\":\"STANDARD\",\"profileCount\":1,\"industryVertical\":\"ARTS_AND_ENTERTAINMENT\",\"defaultProfileId\":\"12345678\",\"permissions\":{\"effective\":[\"COLLABORATE\",\"EDIT\",\"MANAGE_USERS\",\"READ_AND_ANALYZE\"]},\"created\":\"2016-02-22T16:41:49.313Z\",\"updated\":\"2016-02-22T16:41:49.313Z\",\"parentLink\":{\"type\":\"analytics#account\",\"href\":\"https://www.googleapis.com/analytics/v3/management/accounts/12345678\"},\"childLink\":{\"type\":\"analytics#profiles\",\"href\":\"https://www.googleapis.com/analytics/v3/management/accounts/12345678/webproperties/UA-12345678-6/profiles\"}}", + "headers": { + "Expires": "Wed, 28 Jun 2017 17:35:32 GMT", + "Date": "Wed, 28 Jun 2017 17:35:32 GMT", + "Cache-Control": "private, max-age=0, must-revalidate, no-transform", + "ETag": "\"f7I_c57UUFPNhe6k9kg6-jYr1TI/JZ1C7QSgraOUpdL0h-V27sbvjWU\"", + "Vary": "Origin", + "Content-Type": "application/json; charset=UTF-8", + "X-Content-Type-Options": "nosniff", + "X-Frame-Options": "SAMEORIGIN", + "X-XSS-Protection": "1; mode=block", + "Content-Length": "858", + "Server": "GSE", + "Alt-Svc": "quic=\":443\"; ma=12345678; v=\"39,38,37,36,35\"" + }, + "status_code": 200, + "type": "ok" + } + } +] diff --git a/fixture/vcr_cassettes/analytics_web_properties_error_response.json b/fixture/vcr_cassettes/analytics_web_properties_error_response.json new file mode 100644 index 0000000..89ccabb --- /dev/null +++ b/fixture/vcr_cassettes/analytics_web_properties_error_response.json @@ -0,0 +1,35 @@ +[ + { + "request": { + "body": "", + "headers": { + "Authorization": "***", + "Content-Type": "application/json" + }, + "method": "get", + "options": [], + "request_body": "", + "url": "https://www.googleapis.com/analytics/v3/management/accounts/12345678/webproperties" + }, + "response": { + "body": "{\"error\":{\"errors\":[{\"domain\":\"global\",\"reason\":\"authError\",\"message\":\"Invalid Credentials\",\"locationType\":\"header\",\"location\":\"Authorization\"}],\"code\":401,\"message\":\"Invalid Credentials\"}}", + "headers": { + "Vary": "X-Origin", + "WWW-Authenticate": "Bearer realm=\"https://accounts.google.com/\", error=invalid_token", + "Content-Type": "application/json; charset=UTF-8", + "Date": "Wed, 28 Jun 2017 20:06:02 GMT", + "Expires": "Wed, 28 Jun 2017 20:06:02 GMT", + "Cache-Control": "private, max-age=0", + "X-Content-Type-Options": "nosniff", + "X-Frame-Options": "SAMEORIGIN", + "X-XSS-Protection": "1; mode=block", + "Server": "GSE", + "Alt-Svc": "quic=\":443\"; ma=12345678; v=\"39,38,37,36,35\"", + "Accept-Ranges": "none", + "Transfer-Encoding": "chunked" + }, + "status_code": 401, + "type": "ok" + } + } +] \ No newline at end of file diff --git a/fixture/vcr_cassettes/analytics_web_properties_get_error_response.json b/fixture/vcr_cassettes/analytics_web_properties_get_error_response.json new file mode 100644 index 0000000..774ed41 --- /dev/null +++ b/fixture/vcr_cassettes/analytics_web_properties_get_error_response.json @@ -0,0 +1,35 @@ +[ + { + "request": { + "body": "", + "headers": { + "Authorization": "***", + "Content-Type": "application/json" + }, + "method": "get", + "options": [], + "request_body": "", + "url": "https://www.googleapis.com/analytics/v3/management/accounts/12345678/webproperties/UA-12345678-6" + }, + "response": { + "body": "{\"error\":{\"errors\":[{\"domain\":\"global\",\"reason\":\"authError\",\"message\":\"Invalid Credentials\",\"locationType\":\"header\",\"location\":\"Authorization\"}],\"code\":401,\"message\":\"Invalid Credentials\"}}", + "headers": { + "Vary": "X-Origin", + "WWW-Authenticate": "Bearer realm=\"https://accounts.google.com/\", error=invalid_token", + "Content-Type": "application/json; charset=UTF-8", + "Date": "Wed, 28 Jun 2017 20:09:16 GMT", + "Expires": "Wed, 28 Jun 2017 20:09:16 GMT", + "Cache-Control": "private, max-age=0", + "X-Content-Type-Options": "nosniff", + "X-Frame-Options": "SAMEORIGIN", + "X-XSS-Protection": "1; mode=block", + "Server": "GSE", + "Alt-Svc": "quic=\":443\"; ma=12345678; v=\"39,38,37,36,35\"", + "Accept-Ranges": "none", + "Transfer-Encoding": "chunked" + }, + "status_code": 401, + "type": "ok" + } + } +] \ No newline at end of file diff --git a/fixture/vcr_cassettes/analytics_web_properties_get_response.json b/fixture/vcr_cassettes/analytics_web_properties_get_response.json new file mode 100644 index 0000000..b097c72 --- /dev/null +++ b/fixture/vcr_cassettes/analytics_web_properties_get_response.json @@ -0,0 +1,34 @@ +[ + { + "request": { + "body": "", + "headers": { + "Authorization": "***", + "Content-Type": "application/json" + }, + "method": "get", + "options": [], + "request_body": "", + "url": "https://www.googleapis.com/analytics/v3/management/accounts/12345678/webproperties/UA-12345678-6" + }, + "response": { + "body": "{\"id\":\"UA-12345678-6\",\"kind\":\"analytics#webproperty\",\"selfLink\":\"https://www.googleapis.com/analytics/v3/management/accounts/12345678/webproperties/UA-12345678-6\",\"accountId\":\"12345678\",\"internalWebPropertyId\":\"12345678\",\"name\":\"example.tumblr.com/\",\"websiteUrl\":\"http://example.tumblr.com/\",\"level\":\"STANDARD\",\"profileCount\":1,\"industryVertical\":\"ARTS_AND_ENTERTAINMENT\",\"defaultProfileId\":\"12345678\",\"permissions\":{\"effective\":[\"COLLABORATE\",\"EDIT\",\"MANAGE_USERS\",\"READ_AND_ANALYZE\"]},\"created\":\"2016-02-22T16:41:49.313Z\",\"updated\":\"2016-02-22T16:41:49.313Z\",\"parentLink\":{\"type\":\"analytics#account\",\"href\":\"https://www.googleapis.com/analytics/v3/management/accounts/12345678\"},\"childLink\":{\"type\":\"analytics#profiles\",\"href\":\"https://www.googleapis.com/analytics/v3/management/accounts/12345678/webproperties/UA-12345678-6/profiles\"}}", + "headers": { + "Expires": "Wed, 28 Jun 2017 17:35:32 GMT", + "Date": "Wed, 28 Jun 2017 17:35:32 GMT", + "Cache-Control": "private, max-age=0, must-revalidate, no-transform", + "ETag": "\"f7I_c57UUFPNhe6k9kg6-jYr1TI/JZ1C7QSgraOUpdL0h-V27sbvjWU\"", + "Vary": "Origin", + "Content-Type": "application/json; charset=UTF-8", + "X-Content-Type-Options": "nosniff", + "X-Frame-Options": "SAMEORIGIN", + "X-XSS-Protection": "1; mode=block", + "Content-Length": "858", + "Server": "GSE", + "Alt-Svc": "quic=\":443\"; ma=12345678; v=\"39,38,37,36,35\"" + }, + "status_code": 200, + "type": "ok" + } + } +] diff --git a/fixture/vcr_cassettes/analytics_web_properties_insert_error_response.json b/fixture/vcr_cassettes/analytics_web_properties_insert_error_response.json new file mode 100644 index 0000000..6d2fd60 --- /dev/null +++ b/fixture/vcr_cassettes/analytics_web_properties_insert_error_response.json @@ -0,0 +1,35 @@ +[ + { + "request": { + "body": "{\"websiteUrl\":[104,116,116,112,58,47,47,119,119,119,46,101,120,97,109,112,108,101,112,101,116,115,116,111,114,101,46,99,111,109],\"name\":\"Example Store\"}", + "headers": { + "Authorization": "***", + "Content-Type": "application/json" + }, + "method": "post", + "options": [], + "request_body": "", + "url": "https://www.googleapis.com/analytics/v3/management/accounts/12345678/webproperties" + }, + "response": { + "body": "{\"error\":{\"errors\":[{\"domain\":\"global\",\"reason\":\"authError\",\"message\":\"Invalid Credentials\",\"locationType\":\"header\",\"location\":\"Authorization\"}],\"code\":401,\"message\":\"Invalid Credentials\"}}", + "headers": { + "Vary": "X-Origin", + "WWW-Authenticate": "Bearer realm=\"https://accounts.google.com/\", error=invalid_token", + "Content-Type": "application/json; charset=UTF-8", + "Date": "Wed, 28 Jun 2017 18:00:10 GMT", + "Expires": "Wed, 28 Jun 2017 18:00:10 GMT", + "Cache-Control": "private, max-age=0", + "X-Content-Type-Options": "nosniff", + "X-Frame-Options": "SAMEORIGIN", + "X-XSS-Protection": "1; mode=block", + "Server": "GSE", + "Alt-Svc": "quic=\":443\"; ma=12345678; v=\"39,38,37,36,35\"", + "Accept-Ranges": "none", + "Transfer-Encoding": "chunked" + }, + "status_code": 401, + "type": "ok" + } + } +] \ No newline at end of file diff --git a/fixture/vcr_cassettes/analytics_web_properties_insert_response.json b/fixture/vcr_cassettes/analytics_web_properties_insert_response.json new file mode 100644 index 0000000..d0775bc --- /dev/null +++ b/fixture/vcr_cassettes/analytics_web_properties_insert_response.json @@ -0,0 +1,34 @@ +[ + { + "request": { + "body": "", + "headers": { + "Authorization": "***", + "Content-Type": "application/json" + }, + "method": "post", + "options": [], + "request_body": "{\"websiteUrl\":\"http://www.examplepetstore.com\",\"name\":\"Example Store\"}", + "url": "https://www.googleapis.com/analytics/v3/management/accounts/12345678/webproperties" + }, + "response": { + "body": "{\"id\":\"UA-12345678-6\",\"kind\":\"analytics#webproperty\",\"selfLink\":\"https://www.googleapis.com/analytics/v3/management/accounts/12345678/webproperties/UA-12345678-6\",\"accountId\":\"12345678\",\"internalWebPropertyId\":\"12345678\",\"name\":\"example.tumblr.com/\",\"websiteUrl\":\"http://example.tumblr.com/\",\"level\":\"STANDARD\",\"profileCount\":1,\"industryVertical\":\"ARTS_AND_ENTERTAINMENT\",\"defaultProfileId\":\"12345678\",\"permissions\":{\"effective\":[\"COLLABORATE\",\"EDIT\",\"MANAGE_USERS\",\"READ_AND_ANALYZE\"]},\"created\":\"2016-02-22T16:41:49.313Z\",\"updated\":\"2016-02-22T16:41:49.313Z\",\"parentLink\":{\"type\":\"analytics#account\",\"href\":\"https://www.googleapis.com/analytics/v3/management/accounts/12345678\"},\"childLink\":{\"type\":\"analytics#profiles\",\"href\":\"https://www.googleapis.com/analytics/v3/management/accounts/12345678/webproperties/UA-12345678-6/profiles\"}}", + "headers": { + "Expires": "Wed, 28 Jun 2017 17:35:32 GMT", + "Date": "Wed, 28 Jun 2017 17:35:32 GMT", + "Cache-Control": "private, max-age=0, must-revalidate, no-transform", + "ETag": "\"f7I_c57UUFPNhe6k9kg6-jYr1TI/JZ1C7QSgraOUpdL0h-V27sbvjWU\"", + "Vary": "Origin", + "Content-Type": "application/json; charset=UTF-8", + "X-Content-Type-Options": "nosniff", + "X-Frame-Options": "SAMEORIGIN", + "X-XSS-Protection": "1; mode=block", + "Content-Length": "858", + "Server": "GSE", + "Alt-Svc": "quic=\":443\"; ma=12345678; v=\"39,38,37,36,35\"" + }, + "status_code": 200, + "type": "ok" + } + } +] diff --git a/fixture/vcr_cassettes/analytics_web_properties_patch_error_response.json b/fixture/vcr_cassettes/analytics_web_properties_patch_error_response.json new file mode 100644 index 0000000..819f428 --- /dev/null +++ b/fixture/vcr_cassettes/analytics_web_properties_patch_error_response.json @@ -0,0 +1,35 @@ +[ + { + "request": { + "body": "{\"websiteUrl\":\"http://www.examplepetstore.com\",\"name\":\"Example Store\"}", + "headers": { + "Authorization": "***", + "Content-Type": "application/json" + }, + "method": "patch", + "options": [], + "request_body": "", + "url": "https://www.googleapis.com/analytics/v3/management/accounts/12345678/webproperties/UA-12345678-6" + }, + "response": { + "body": "{\"error\":{\"errors\":[{\"domain\":\"global\",\"reason\":\"authError\",\"message\":\"Invalid Credentials\",\"locationType\":\"header\",\"location\":\"Authorization\"}],\"code\":401,\"message\":\"Invalid Credentials\"}}", + "headers": { + "Vary": "X-Origin", + "WWW-Authenticate": "Bearer realm=\"https://accounts.google.com/\", error=invalid_token", + "Content-Type": "application/json; charset=UTF-8", + "Date": "Wed, 28 Jun 2017 18:08:20 GMT", + "Expires": "Wed, 28 Jun 2017 18:08:20 GMT", + "Cache-Control": "private, max-age=0", + "X-Content-Type-Options": "nosniff", + "X-Frame-Options": "SAMEORIGIN", + "X-XSS-Protection": "1; mode=block", + "Server": "GSE", + "Alt-Svc": "quic=\":443\"; ma=12345678; v=\"39,38,37,36,35\"", + "Accept-Ranges": "none", + "Transfer-Encoding": "chunked" + }, + "status_code": 401, + "type": "ok" + } + } +] \ No newline at end of file diff --git a/fixture/vcr_cassettes/analytics_web_properties_patch_response.json b/fixture/vcr_cassettes/analytics_web_properties_patch_response.json new file mode 100644 index 0000000..69fe8cc --- /dev/null +++ b/fixture/vcr_cassettes/analytics_web_properties_patch_response.json @@ -0,0 +1,34 @@ +[ + { + "request": { + "body": "", + "headers": { + "Authorization": "***", + "Content-Type": "application/json" + }, + "method": "patch", + "options": [], + "request_body": "{\"websiteUrl\":\"http://www.examplepetstore.com\",\"name\":\"Example Store\"}", + "url": "https://www.googleapis.com/analytics/v3/management/accounts/12345678/webproperties/UA-12345678-6" + }, + "response": { + "body": "{\"id\":\"UA-12345678-6\",\"kind\":\"analytics#webproperty\",\"selfLink\":\"https://www.googleapis.com/analytics/v3/management/accounts/12345678/webproperties/UA-12345678-6\",\"accountId\":\"12345678\",\"internalWebPropertyId\":\"12345678\",\"name\":\"example.tumblr.com/\",\"websiteUrl\":\"http://example.tumblr.com/\",\"level\":\"STANDARD\",\"profileCount\":1,\"industryVertical\":\"ARTS_AND_ENTERTAINMENT\",\"defaultProfileId\":\"12345678\",\"permissions\":{\"effective\":[\"COLLABORATE\",\"EDIT\",\"MANAGE_USERS\",\"READ_AND_ANALYZE\"]},\"created\":\"2016-02-22T16:41:49.313Z\",\"updated\":\"2016-02-22T16:41:49.313Z\",\"parentLink\":{\"type\":\"analytics#account\",\"href\":\"https://www.googleapis.com/analytics/v3/management/accounts/12345678\"},\"childLink\":{\"type\":\"analytics#profiles\",\"href\":\"https://www.googleapis.com/analytics/v3/management/accounts/12345678/webproperties/UA-12345678-6/profiles\"}}", + "headers": { + "Expires": "Wed, 28 Jun 2017 17:35:32 GMT", + "Date": "Wed, 28 Jun 2017 17:35:32 GMT", + "Cache-Control": "private, max-age=0, must-revalidate, no-transform", + "ETag": "\"f7I_c57UUFPNhe6k9kg6-jYr1TI/JZ1C7QSgraOUpdL0h-V27sbvjWU\"", + "Vary": "Origin", + "Content-Type": "application/json; charset=UTF-8", + "X-Content-Type-Options": "nosniff", + "X-Frame-Options": "SAMEORIGIN", + "X-XSS-Protection": "1; mode=block", + "Content-Length": "858", + "Server": "GSE", + "Alt-Svc": "quic=\":443\"; ma=12345678; v=\"39,38,37,36,35\"" + }, + "status_code": 200, + "type": "ok" + } + } +] diff --git a/fixture/vcr_cassettes/analytics_web_properties_response.json b/fixture/vcr_cassettes/analytics_web_properties_response.json new file mode 100644 index 0000000..924bf2d --- /dev/null +++ b/fixture/vcr_cassettes/analytics_web_properties_response.json @@ -0,0 +1,34 @@ +[ + { + "request": { + "body": "", + "headers": { + "Authorization": "***", + "Content-Type": "application/json" + }, + "method": "get", + "options": [], + "request_body": "", + "url": "https://www.googleapis.com/analytics/v3/management/accounts/12345678/webproperties" + }, + "response": { + "body": "{\"kind\":\"analytics#webproperties\",\"username\":\"daniel@testco.com\",\"totalResults\":6,\"startIndex\":1,\"itemsPerPage\":1000,\"items\":[{\"id\":\"UA-12345678-1\",\"kind\":\"analytics#webproperty\",\"selfLink\":\"https://www.googleapis.com/analytics/v3/management/accounts/12345678/webproperties/UA-12345678-1\",\"accountId\":\"12345678\",\"internalWebPropertyId\":\"12345678\",\"name\":\"example.net\",\"websiteUrl\":\"http://example.net\",\"level\":\"STANDARD\",\"profileCount\":1,\"industryVertical\":\"INTERNET_AND_TELECOM\",\"permissions\":{\"effective\":[\"COLLABORATE\",\"EDIT\",\"MANAGE_USERS\",\"READ_AND_ANALYZE\"]},\"created\":\"2015-07-11T17:11:47.869Z\",\"updated\":\"2015-07-13T15:04:19.566Z\",\"parentLink\":{\"type\":\"analytics#account\",\"href\":\"https://www.googleapis.com/analytics/v3/management/accounts/12345678\"},\"childLink\":{\"type\":\"analytics#profiles\",\"href\":\"https://www.googleapis.com/analytics/v3/management/accounts/12345678/webproperties/UA-12345678-1/profiles\"}},{\"id\":\"UA-12345678-2\",\"kind\":\"analytics#webproperty\",\"selfLink\":\"https://www.googleapis.com/analytics/v3/management/accounts/12345678/webproperties/UA-12345678-2\",\"accountId\":\"12345678\",\"internalWebPropertyId\":\"12345678\",\"name\":\"example.us\",\"websiteUrl\":\"https://example.us\",\"level\":\"STANDARD\",\"profileCount\":1,\"industryVertical\":\"INTERNET_AND_TELECOM\",\"defaultProfileId\":\"12345678\",\"permissions\":{\"effective\":[\"COLLABORATE\",\"EDIT\",\"MANAGE_USERS\",\"READ_AND_ANALYZE\"]},\"created\":\"2015-07-16T21:45:49.823Z\",\"updated\":\"2015-07-16T21:45:59.832Z\",\"parentLink\":{\"type\":\"analytics#account\",\"href\":\"https://www.googleapis.com/analytics/v3/management/accounts/12345678\"},\"childLink\":{\"type\":\"analytics#profiles\",\"href\":\"https://www.googleapis.com/analytics/v3/management/accounts/12345678/webproperties/UA-12345678-2/profiles\"}},{\"id\":\"UA-12345678-3\",\"kind\":\"analytics#webproperty\",\"selfLink\":\"https://www.googleapis.com/analytics/v3/management/accounts/12345678/webproperties/UA-12345678-3\",\"accountId\":\"12345678\",\"internalWebPropertyId\":\"12345678\",\"name\":\"example.com\",\"websiteUrl\":\"https://www.example.com\",\"level\":\"STANDARD\",\"profileCount\":1,\"industryVertical\":\"HEALTHCARE\",\"defaultProfileId\":\"12345678\",\"permissions\":{\"effective\":[\"COLLABORATE\",\"EDIT\",\"MANAGE_USERS\",\"READ_AND_ANALYZE\"]},\"created\":\"2015-07-20T20:47:21.236Z\",\"updated\":\"2015-07-22T05:28:30.793Z\",\"parentLink\":{\"type\":\"analytics#account\",\"href\":\"https://www.googleapis.com/analytics/v3/management/accounts/12345678\"},\"childLink\":{\"type\":\"analytics#profiles\",\"href\":\"https://www.googleapis.com/analytics/v3/management/accounts/12345678/webproperties/UA-12345678-3/profiles\"}},{\"id\":\"UA-12345678-4\",\"kind\":\"analytics#webproperty\",\"selfLink\":\"https://www.googleapis.com/analytics/v3/management/accounts/12345678/webproperties/UA-12345678-4\",\"accountId\":\"12345678\",\"internalWebPropertyId\":\"12345678\",\"name\":\"example1.net\",\"websiteUrl\":\"http://www.example1.net\",\"level\":\"STANDARD\",\"profileCount\":1,\"industryVertical\":\"COMPUTERS_AND_ELECTRONICS\",\"defaultProfileId\":\"12345678\",\"permissions\":{\"effective\":[\"COLLABORATE\",\"EDIT\",\"MANAGE_USERS\",\"READ_AND_ANALYZE\"]},\"created\":\"2015-07-22T01:37:14.928Z\",\"updated\":\"2015-07-22T01:37:17.204Z\",\"parentLink\":{\"type\":\"analytics#account\",\"href\":\"https://www.googleapis.com/analytics/v3/management/accounts/12345678\"},\"childLink\":{\"type\":\"analytics#profiles\",\"href\":\"https://www.googleapis.com/analytics/v3/management/accounts/12345678/webproperties/UA-12345678-4/profiles\"}},{\"id\":\"UA-12345678-5\",\"kind\":\"analytics#webproperty\",\"selfLink\":\"https://www.googleapis.com/analytics/v3/management/accounts/12345678/webproperties/UA-12345678-5\",\"accountId\":\"12345678\",\"internalWebPropertyId\":\"12345678\",\"name\":\"example2.net\",\"websiteUrl\":\"http://www.example2.net\",\"level\":\"STANDARD\",\"profileCount\":1,\"industryVertical\":\"COMPUTERS_AND_ELECTRONICS\",\"defaultProfileId\":\"12345678\",\"permissions\":{\"effective\":[\"COLLABORATE\",\"EDIT\",\"MANAGE_USERS\",\"READ_AND_ANALYZE\"]},\"created\":\"2015-07-22T17:35:50.478Z\",\"updated\":\"2015-07-22T17:50:29.010Z\",\"parentLink\":{\"type\":\"analytics#account\",\"href\":\"https://www.googleapis.com/analytics/v3/management/accounts/12345678\"},\"childLink\":{\"type\":\"analytics#profiles\",\"href\":\"https://www.googleapis.com/analytics/v3/management/accounts/12345678/webproperties/UA-12345678-5/profiles\"}},{\"id\":\"UA-12345678-6\",\"kind\":\"analytics#webproperty\",\"selfLink\":\"https://www.googleapis.com/analytics/v3/management/accounts/12345678/webproperties/UA-12345678-6\",\"accountId\":\"12345678\",\"internalWebPropertyId\":\"12345678\",\"name\":\"example.tumblr.com/\",\"websiteUrl\":\"http://example.tumblr.com/\",\"level\":\"STANDARD\",\"profileCount\":1,\"industryVertical\":\"ARTS_AND_ENTERTAINMENT\",\"defaultProfileId\":\"12345678\",\"permissions\":{\"effective\":[\"COLLABORATE\",\"EDIT\",\"MANAGE_USERS\",\"READ_AND_ANALYZE\"]},\"created\":\"2016-02-22T16:41:49.313Z\",\"updated\":\"2016-02-22T16:41:49.313Z\",\"parentLink\":{\"type\":\"analytics#account\",\"href\":\"https://www.googleapis.com/analytics/v3/management/accounts/12345678\"},\"childLink\":{\"type\":\"analytics#profiles\",\"href\":\"https://www.googleapis.com/analytics/v3/management/accounts/12345678/webproperties/UA-12345678-6/profiles\"}}]}", + "headers": { + "Expires": "Wed, 28 Jun 2017 17:28:32 GMT", + "Date": "Wed, 28 Jun 2017 17:28:32 GMT", + "Cache-Control": "private, max-age=0, must-revalidate, no-transform", + "ETag": "\"f7I_c57UUFPNhe6k9kg6-jYr1TI/Qb2SEa01cJVDTHrfdfv-j7dJiK4\"", + "Vary": "Origin", + "Content-Type": "application/json; charset=UTF-8", + "X-Content-Type-Options": "nosniff", + "X-Frame-Options": "SAMEORIGIN", + "X-XSS-Protection": "1; mode=block", + "Content-Length": "5129", + "Server": "GSE", + "Alt-Svc": "quic=\":443\"; ma=12345678; v=\"39,38,37,36,35\"" + }, + "status_code": 200, + "type": "ok" + } + } +] diff --git a/fixture/vcr_cassettes/analytics_web_properties_update_error_response.json b/fixture/vcr_cassettes/analytics_web_properties_update_error_response.json new file mode 100644 index 0000000..2a12f24 --- /dev/null +++ b/fixture/vcr_cassettes/analytics_web_properties_update_error_response.json @@ -0,0 +1,35 @@ +[ + { + "request": { + "body": "{\"websiteUrl\":\"http://www.examplepetstore.com\",\"name\":\"Example Store\"}", + "headers": { + "Authorization": "***", + "Content-Type": "application/json" + }, + "method": "put", + "options": [], + "request_body": "", + "url": "https://www.googleapis.com/analytics/v3/management/accounts/12345678/webproperties/UA-12345678-6" + }, + "response": { + "body": "{\"error\":{\"errors\":[{\"domain\":\"global\",\"reason\":\"authError\",\"message\":\"Invalid Credentials\",\"locationType\":\"header\",\"location\":\"Authorization\"}],\"code\":401,\"message\":\"Invalid Credentials\"}}", + "headers": { + "Vary": "X-Origin", + "WWW-Authenticate": "Bearer realm=\"https://accounts.google.com/\", error=invalid_token", + "Content-Type": "application/json; charset=UTF-8", + "Date": "Wed, 28 Jun 2017 18:11:47 GMT", + "Expires": "Wed, 28 Jun 2017 18:11:47 GMT", + "Cache-Control": "private, max-age=0", + "X-Content-Type-Options": "nosniff", + "X-Frame-Options": "SAMEORIGIN", + "X-XSS-Protection": "1; mode=block", + "Server": "GSE", + "Alt-Svc": "quic=\":443\"; ma=12345678; v=\"39,38,37,36,35\"", + "Accept-Ranges": "none", + "Transfer-Encoding": "chunked" + }, + "status_code": 401, + "type": "ok" + } + } +] \ No newline at end of file diff --git a/fixture/vcr_cassettes/analytics_web_properties_update_response.json b/fixture/vcr_cassettes/analytics_web_properties_update_response.json new file mode 100644 index 0000000..302d8f5 --- /dev/null +++ b/fixture/vcr_cassettes/analytics_web_properties_update_response.json @@ -0,0 +1,34 @@ +[ + { + "request": { + "body": "", + "headers": { + "Authorization": "***", + "Content-Type": "application/json" + }, + "method": "put", + "options": [], + "request_body": "{\"websiteUrl\":\"http://www.examplepetstore.com\",\"name\":\"Example Store\"}", + "url": "https://www.googleapis.com/analytics/v3/management/accounts/12345678/webproperties/UA-12345678-6" + }, + "response": { + "body": "{\"id\":\"UA-12345678-6\",\"kind\":\"analytics#webproperty\",\"selfLink\":\"https://www.googleapis.com/analytics/v3/management/accounts/12345678/webproperties/UA-12345678-6\",\"accountId\":\"12345678\",\"internalWebPropertyId\":\"12345678\",\"name\":\"example.tumblr.com/\",\"websiteUrl\":\"http://example.tumblr.com/\",\"level\":\"STANDARD\",\"profileCount\":1,\"industryVertical\":\"ARTS_AND_ENTERTAINMENT\",\"defaultProfileId\":\"12345678\",\"permissions\":{\"effective\":[\"COLLABORATE\",\"EDIT\",\"MANAGE_USERS\",\"READ_AND_ANALYZE\"]},\"created\":\"2016-02-22T16:41:49.313Z\",\"updated\":\"2016-02-22T16:41:49.313Z\",\"parentLink\":{\"type\":\"analytics#account\",\"href\":\"https://www.googleapis.com/analytics/v3/management/accounts/12345678\"},\"childLink\":{\"type\":\"analytics#profiles\",\"href\":\"https://www.googleapis.com/analytics/v3/management/accounts/12345678/webproperties/UA-12345678-6/profiles\"}}", + "headers": { + "Expires": "Wed, 28 Jun 2017 17:35:32 GMT", + "Date": "Wed, 28 Jun 2017 17:35:32 GMT", + "Cache-Control": "private, max-age=0, must-revalidate, no-transform", + "ETag": "\"f7I_c57UUFPNhe6k9kg6-jYr1TI/JZ1C7QSgraOUpdL0h-V27sbvjWU\"", + "Vary": "Origin", + "Content-Type": "application/json; charset=UTF-8", + "X-Content-Type-Options": "nosniff", + "X-Frame-Options": "SAMEORIGIN", + "X-XSS-Protection": "1; mode=block", + "Content-Length": "858", + "Server": "GSE", + "Alt-Svc": "quic=\":443\"; ma=12345678; v=\"39,38,37,36,35\"" + }, + "status_code": 200, + "type": "ok" + } + } +] diff --git a/lib/google/apis/analytics.ex b/lib/google/apis/analytics.ex new file mode 100644 index 0000000..639e59e --- /dev/null +++ b/lib/google/apis/analytics.ex @@ -0,0 +1,2 @@ +defmodule Google.Apis.Analytics do +end diff --git a/lib/google/apis/analytics/accounts.ex b/lib/google/apis/analytics/accounts.ex new file mode 100644 index 0000000..0184aab --- /dev/null +++ b/lib/google/apis/analytics/accounts.ex @@ -0,0 +1,20 @@ +defmodule Google.Apis.Analytics.Accounts do + use Google.Apis.Base, endpoint: "https://www.googleapis.com/analytics/v3/management/accounts?", oauth_only: true + + @doc """ + Google Analytics, Accounts Management: https://developers.google.com/analytics/devguides/config/mgmt/v3/mgmtReference/management/accounts + + Usage: + Google.Apis.Analytics.Accounts.list(access_token) + + Available options: + max_results: 100, start_index: 0 + + See https://developers.google.com/analytics/devguides/config/mgmt/v3/mgmtReference/management/accounts/list + """ + def list(token, params \\ [max_results: 100, start_index: 0]) do + headers = build_auth_headers(token) + get!(URI.encode_query(params), headers) + |> build_api_response() + end +end diff --git a/lib/google/apis/analytics/views.ex b/lib/google/apis/analytics/views.ex new file mode 100644 index 0000000..ac0f31a --- /dev/null +++ b/lib/google/apis/analytics/views.ex @@ -0,0 +1,88 @@ +defmodule Google.Apis.Analytics.Views do + use Google.Apis.Base, endpoint: "https://www.googleapis.com/analytics/v3/management/accounts/", oauth_only: true + + @moduledoc """ + Google Analytics, Views Management: https://developers.google.com/analytics/devguides/config/mgmt/v3/mgmtReference/management/profiles + """ + + @doc """ + Usage: + Google.Apis.Analytics.Views.delete(token, account_id, web_property_id, profile_id) + + See https://developers.google.com/analytics/devguides/config/mgmt/v3/mgmtReference/management/profiles/delete + """ + def update(token, account_id, web_property_id, profile_id) do + headers = build_auth_headers(token) + delete!("#{account_id}/webproperties/#{web_property_id}/profiles/#{profile_id}", "", headers) + |> build_api_response() + end + + @doc """ + Usage: + Google.Apis.Analytics.Views.get(token, account_id, web_property_id, profile_id) + + See https://developers.google.com/analytics/devguides/config/mgmt/v3/mgmtReference/management/profiles/get + """ + def get(token, account_id, web_property_id, profile_id) do + headers = build_auth_headers(token) + get!("#{account_id}/webproperties/#{web_property_id}/profiles/#{profile_id}", headers) + |> build_api_response() + end + + @doc """ + Usage: + Google.Apis.Analytics.Views.insert(token, account_id, web_property_id, resource) + + Resource is a management profiles resource: https://developers.google.com/analytics/devguides/config/mgmt/v3/mgmtReference/management/profiles#resource + + See https://developers.google.com/analytics/devguides/config/mgmt/v3/mgmtReference/management/profiles/insert + """ + def insert(token, account_id, web_property_id, resource) do + headers = build_auth_headers(token) + body = resource |> Poison.encode! + post!("#{account_id}/webproperties/#{web_property_id}/profiles", body, headers) + |> build_api_response() + end + + @doc """ + Usage: + Google.Apis.Analytics.Views.list(token, account_id, web_property_id) + + See: https://developers.google.com/analytics/devguides/config/mgmt/v3/mgmtReference/management/profiles/list + """ + def list(token, account_id, web_property_id) do + headers = build_auth_headers(token) + get!("#{account_id}/webproperties/#{web_property_id}/profiles", headers) + |> build_api_response() + end + + @doc """ + Usage: + Google.Apis.Analytics.Views.patch(token, account_id, web_property_id, profile_id, resource) + + Resource is a management profiles resource: https://developers.google.com/analytics/devguides/config/mgmt/v3/mgmtReference/management/profiles#resource + + See https://developers.google.com/analytics/devguides/config/mgmt/v3/mgmtReference/management/profiles/patch + """ + def patch(token, account_id, web_property_id, profile_id, resource) do + headers = build_auth_headers(token) + body = resource |> Poison.encode! + patch!("#{account_id}/webproperties/#{web_property_id}/profiles/#{profile_id}", body, headers) + |> build_api_response() + end + + @doc """ + Usage: + Google.Apis.Analytics.Views.update(token, account_id, web_property_id, profile_id, resource) + + Resource is a management profiles resource: https://developers.google.com/analytics/devguides/config/mgmt/v3/mgmtReference/management/profiles#resource + + See https://developers.google.com/analytics/devguides/config/mgmt/v3/mgmtReference/management/profiles/update + """ + def update(token, account_id, web_property_id, profile_id, resource) do + headers = build_auth_headers(token) + body = resource |> Poison.encode! + put!("#{account_id}/webproperties/#{web_property_id}/profiles/#{profile_id}", body, headers) + |> build_api_response() + end +end diff --git a/lib/google/apis/analytics/web_properties.ex b/lib/google/apis/analytics/web_properties.ex new file mode 100644 index 0000000..60565d0 --- /dev/null +++ b/lib/google/apis/analytics/web_properties.ex @@ -0,0 +1,77 @@ +defmodule Google.Apis.Analytics.WebProperties do + use Google.Apis.Base, endpoint: "https://www.googleapis.com/analytics/v3/management/accounts/", oauth_only: true + + @moduledoc """ + Google Analytics, Web Properties Management: https://developers.google.com/analytics/devguides/config/mgmt/v3/mgmtReference/management/webproperties + """ + + @doc """ + Usage: + Google.Apis.Analytics.WebProperties.get(token, account_id, web_property_id) + + See https://developers.google.com/analytics/devguides/config/mgmt/v3/mgmtReference/management/webproperties/get + """ + def get(token, account_id, web_property_id) do + headers = build_auth_headers(token) + get!("#{account_id}/webproperties/#{web_property_id}", headers) + |> build_api_response() + end + + @doc """ + Usage: + Google.Apis.Analytics.WebProperties.insert(token, account_id, resource) + + Resource is a management web properties resource: https://developers.google.com/analytics/devguides/config/mgmt/v3/mgmtReference/management/webproperties#resource + + See https://developers.google.com/analytics/devguides/config/mgmt/v3/mgmtReference/management/webproperties/insert + """ + def insert(token, account_id, resource) do + headers = build_auth_headers(token) + body = resource |> Poison.encode! + post!("#{account_id}/webproperties", body, headers) + |> build_api_response() + end + + @doc """ + Usage: + Google.Apis.Analytics.WebProperties.list(token, account_id) + + See: https://developers.google.com/analytics/devguides/config/mgmt/v3/mgmtReference/management/webproperties/list + """ + def list(token, account_id) do + headers = build_auth_headers(token) + get!("#{account_id}/webproperties", headers) + |> build_api_response() + end + + @doc """ + Usage: + Google.Apis.Analytics.WebProperties.patch(token, account_id, web_property_id, resource) + + Resource is a management web properties resource: https://developers.google.com/analytics/devguides/config/mgmt/v3/mgmtReference/management/webproperties#resource + + See https://developers.google.com/analytics/devguides/config/mgmt/v3/mgmtReference/management/webproperties/patch + """ + def patch(token, account_id, web_property_id, resource) do + headers = build_auth_headers(token) + body = resource |> Poison.encode! + patch!("#{account_id}/webproperties/#{web_property_id}", body, headers) + |> build_api_response() + end + + + @doc """ + Usage: + Google.Apis.Analytics.WebProperties.update(token, account_id, web_property_id, resource) + + Resource is a management web properties resource: https://developers.google.com/analytics/devguides/config/mgmt/v3/mgmtReference/management/webproperties#resource + + See https://developers.google.com/analytics/devguides/config/mgmt/v3/mgmtReference/management/webproperties/update + """ + def update(token, account_id, web_property_id, resource) do + headers = build_auth_headers(token) + body = resource |> Poison.encode! + put!("#{account_id}/webproperties/#{web_property_id}", body, headers) + |> build_api_response() + end +end diff --git a/lib/google/apis/base.ex b/lib/google/apis/base.ex index c51fd34..d5bbfcf 100644 --- a/lib/google/apis/base.ex +++ b/lib/google/apis/base.ex @@ -1,6 +1,6 @@ defmodule Google.Apis.Base do defmacro __using__(opts) do - quote bind_quoted: [endpoint: opts[:endpoint]] do + quote bind_quoted: [endpoint: opts[:endpoint], oauth_only: opts[:oauth_only]] do use HTTPoison.Base defp process_response_body(body) do @@ -9,9 +9,29 @@ defmodule Google.Apis.Base do end defp process_url(url) do - api_key = Application.fetch_env!(:google_api_client, :api_key) - "#{unquote(endpoint)}" <> url <> "&key=#{api_key}" + full_url = "#{unquote(endpoint)}#{url}" + case unquote(oauth_only) do + true -> full_url + _ -> + api_key = Application.fetch_env!(:google_api_client, :api_key) + uri = URI.parse(full_url) + query = URI.decode_query(uri.query || "") + |> Map.merge(%{"key" => api_key}) + uri + |> Map.put(:query, URI.encode_query(query)) + |> URI.to_string + end end + + defp build_auth_headers(token) do + ["Authorization": "Bearer #{token}", "Content-Type": "application/json"] + end + + defp build_api_response(%HTTPoison.Response{body: body, status_code: status_code}) when status_code > 199 and status_code < 300 do + {:ok, body} + end + + defp build_api_response(%HTTPoison.Response{} = response), do: {:error, response} end end end diff --git a/lib/google/apis/knowledge_graph/knowledge_graph.ex b/lib/google/apis/knowledge_graph/knowledge_graph.ex index ab97b2c..6757cfb 100644 --- a/lib/google/apis/knowledge_graph/knowledge_graph.ex +++ b/lib/google/apis/knowledge_graph/knowledge_graph.ex @@ -15,6 +15,7 @@ defmodule Google.Apis.KnowledgeGraph do """ def search(query, params \\ [indent: false, prefix: false, limit: 10]) do params = [query: query] ++ params - get!(URI.encode_query(params)).body + get!(URI.encode_query(params)) + |> build_api_response() end end diff --git a/lib/google/apis/maps/timezone.ex b/lib/google/apis/maps/timezone.ex index 8823e39..8433fb8 100644 --- a/lib/google/apis/maps/timezone.ex +++ b/lib/google/apis/maps/timezone.ex @@ -23,6 +23,7 @@ defmodule Google.Apis.Maps.TimeZone do def get(params \\ [location: {}, timestamp: DateTime.to_unix(DateTime.utc_now)]) do params = Keyword.update!(params, :location, fn(l) -> Enum.join(Tuple.to_list(l), ",") end) params = Keyword.put_new(params, :timestamp, DateTime.to_unix(DateTime.utc_now)) - get!(URI.encode_query(params)).body + get!(URI.encode_query(params)) + |> build_api_response() end end diff --git a/lib/google/apis/places/places.ex b/lib/google/apis/places/places.ex index c277109..96d13a1 100644 --- a/lib/google/apis/places/places.ex +++ b/lib/google/apis/places/places.ex @@ -15,6 +15,7 @@ defmodule Google.Apis.Places do def autocomplete(input, params \\ []) do params = [input: input] ++ params - get!(URI.encode_query(params)).body + get!(URI.encode_query(params)) + |> build_api_response() end end diff --git a/mix.exs b/mix.exs index e2e070a..cd72732 100644 --- a/mix.exs +++ b/mix.exs @@ -7,7 +7,11 @@ defmodule Google.Mixfile do elixir: "~> 1.3", build_embedded: Mix.env == :prod, start_permanent: Mix.env == :prod, - deps: deps] + elixirc_paths: elixirc_paths(Mix.env), + preferred_cli_env: [ + vcr: :test, "vcr.delete": :test, "vcr.check": :test, "vcr.show": :test + ], + deps: deps()] end # Configuration for the OTP application @@ -29,7 +33,11 @@ defmodule Google.Mixfile do defp deps do [ {:httpoison, "~> 0.8"}, - {:poison, "~> 1.5 or ~> 2.0"} + {:poison, "~> 1.5 or ~> 2.0"}, + {:exvcr, "~> 0.8", only: :test} ] end + + defp elixirc_paths(:test), do: ["lib", "test/support"] + defp elixirc_paths(_), do: ["lib"] end diff --git a/mix.lock b/mix.lock index e29cbbc..c4381a7 100644 --- a/mix.lock +++ b/mix.lock @@ -1,8 +1,14 @@ -%{"certifi": {:hex, :certifi, "0.7.0", "861a57f3808f7eb0c2d1802afeaae0fa5de813b0df0979153cbafcd853ababaf", [:rebar3], []}, - "hackney": {:hex, :hackney, "1.6.3", "d489d7ca2d4323e307bedc4bfe684323a7bf773ecfd77938f3ee8074e488e140", [:rebar3, :mix], [{:certifi, "0.7.0", [hex: :certifi, optional: false]}, {:idna, "1.2.0", [hex: :idna, optional: false]}, {:metrics, "1.0.1", [hex: :metrics, optional: false]}, {:mimerl, "1.0.2", [hex: :mimerl, optional: false]}, {:ssl_verify_fun, "1.1.1", [hex: :ssl_verify_fun, optional: false]}]}, - "httpoison": {:hex, :httpoison, "0.10.0", "4727b3a5e57e9a4ff168a3c2883e20f1208103a41bccc4754f15a9366f49b676", [:mix], [{:hackney, "~> 1.6.3", [hex: :hackney, optional: false]}]}, - "idna": {:hex, :idna, "1.2.0", "ac62ee99da068f43c50dc69acf700e03a62a348360126260e87f2b54eced86b2", [:rebar3], []}, +%{"certifi": {:hex, :certifi, "1.2.1", "c3904f192bd5284e5b13f20db3ceac9626e14eeacfbb492e19583cf0e37b22be", [:rebar3], []}, + "exactor": {:hex, :exactor, "2.2.3", "a6972f43bb6160afeb73e1d8ab45ba604cd0ac8b5244c557093f6e92ce582786", [:mix], []}, + "exjsx": {:hex, :exjsx, "3.2.1", "1bc5bf1e4fd249104178f0885030bcd75a4526f4d2a1e976f4b428d347614f0f", [:mix], [{:jsx, "~> 2.8.0", [hex: :jsx, optional: false]}]}, + "exvcr": {:hex, :exvcr, "0.8.10", "17090dea4758eb2349146746084a7c422c77f36b922611df6a46fef40a4bf94c", [:mix], [{:exactor, "~> 2.2", [hex: :exactor, optional: false]}, {:exjsx, "~> 3.2", [hex: :exjsx, optional: false]}, {:httpoison, "~> 0.11", [hex: :httpoison, optional: true]}, {:httpotion, "~> 3.0", [hex: :httpotion, optional: true]}, {:ibrowse, "~> 4.2.2", [hex: :ibrowse, optional: true]}, {:meck, "~> 0.8.3", [hex: :meck, optional: false]}]}, + "hackney": {:hex, :hackney, "1.8.6", "21a725db3569b3fb11a6af17d5c5f654052ce9624219f1317e8639183de4a423", [:rebar3], [{:certifi, "1.2.1", [hex: :certifi, optional: false]}, {:idna, "5.0.2", [hex: :idna, optional: false]}, {:metrics, "1.0.1", [hex: :metrics, optional: false]}, {:mimerl, "1.0.2", [hex: :mimerl, optional: false]}, {:ssl_verify_fun, "1.1.1", [hex: :ssl_verify_fun, optional: false]}]}, + "httpoison": {:hex, :httpoison, "0.11.2", "9e59f17a473ef6948f63c51db07320477bad8ba88cf1df60a3eee01150306665", [:mix], [{:hackney, "~> 1.8.0", [hex: :hackney, optional: false]}]}, + "idna": {:hex, :idna, "5.0.2", "ac203208ada855d95dc591a764b6e87259cb0e2a364218f215ad662daa8cd6b4", [:rebar3], [{:unicode_util_compat, "0.2.0", [hex: :unicode_util_compat, optional: false]}]}, + "jsx": {:hex, :jsx, "2.8.2", "7acc7d785b5abe8a6e9adbde926a24e481f29956dd8b4df49e3e4e7bcc92a018", [:mix, :rebar3], []}, + "meck": {:hex, :meck, "0.8.6", "af92a4d3e1525173a7162ed25e9ba6c6c7874e054900b8ae4a23fe71290890e0", [:make, :rebar3], []}, "metrics": {:hex, :metrics, "1.0.1", "25f094dea2cda98213cecc3aeff09e940299d950904393b2a29d191c346a8486", [:rebar3], []}, "mimerl": {:hex, :mimerl, "1.0.2", "993f9b0e084083405ed8252b99460c4f0563e41729ab42d9074fd5e52439be88", [:rebar3], []}, "poison": {:hex, :poison, "2.2.0", "4763b69a8a77bd77d26f477d196428b741261a761257ff1cf92753a0d4d24a63", [:mix], []}, - "ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.1", "28a4d65b7f59893bc2c7de786dec1e1555bd742d336043fe644ae956c3497fbe", [:rebar, :make], []}} + "ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.1", "28a4d65b7f59893bc2c7de786dec1e1555bd742d336043fe644ae956c3497fbe", [:make, :rebar], []}, + "unicode_util_compat": {:hex, :unicode_util_compat, "0.2.0", "dbbccf6781821b1c0701845eaf966c9b6d83d7c3bfc65ca2b78b88b8678bfa35", [:rebar3], []}} diff --git a/test/google/apis/analytics/accounts_test.exs b/test/google/apis/analytics/accounts_test.exs new file mode 100644 index 0000000..c1c66e6 --- /dev/null +++ b/test/google/apis/analytics/accounts_test.exs @@ -0,0 +1,19 @@ +defmodule Google.Apis.Analytics.AccountsTest do + use Google.ApiCase + doctest Google.Apis.Analytics.Accounts + alias Google.Apis.Analytics.Accounts + + @token "abc123" + + test "#list 401 response" do + use_cassette "analytics_accounts_error_response" do + assert {:error, %HTTPoison.Response{status_code: 401}} = Accounts.list(@token) + end + end + + test "#list 200 response" do + use_cassette "analytics_accounts_response" do + assert {:ok, %{"items" => _items}} = Accounts.list(@token) + end + end +end diff --git a/test/google/apis/analytics/views_test.exs b/test/google/apis/analytics/views_test.exs new file mode 100644 index 0000000..12a6219 --- /dev/null +++ b/test/google/apis/analytics/views_test.exs @@ -0,0 +1,71 @@ +defmodule Google.Apis.Analytics.ViewsTest do + use Google.ApiCase + doctest Google.Apis.Analytics.Views + alias Google.Apis.Analytics.Views + + @token "abc123" + @resource %{websiteUrl: "http://www.examplepetstore.com", name: "Example Store"} + @account_id "12345678" + @web_property_id "UA-12345678-6" + @profile_id "A1" + + test "#get 401 response" do + use_cassette "analytics_views_get_error_response" do + assert {:error, %HTTPoison.Response{status_code: 401}} = Views.get(@token, @account_id, @web_property_id, @profile_id) + end + end + + test "#get 200 response" do + use_cassette "analytics_views_get_response" do + assert {:ok, %{"id" => _id}} = Views.get(@token, @account_id, @web_property_id, @profile_id) + end + end + + test "#insert 401 response" do + use_cassette "analytics_views_insert_error_response" do + assert {:error, %HTTPoison.Response{status_code: 401}} = Views.insert(@token, @account_id, @web_property_id, @resource) + end + end + + test "#insert 200 response" do + use_cassette "analytics_views_insert_response" do + assert {:ok, %{"id" => _id}} = Views.insert(@token, @account_id, @web_property_id, @response) + end + end + + test "#list 401 response" do + use_cassette "analytics_views_error_response" do + assert {:error, %HTTPoison.Response{status_code: 401}} = Views.list(@token, @account_id, @web_property_id) + end + end + + test "#list 200 response" do + use_cassette "analytics_views_response" do + assert {:ok, %{"items" => _items}} = Views.list(@token, @account_id, @web_property_id) + end + end + + test "#patch 401 response" do + use_cassette "analytics_views_patch_error_response" do + assert {:error, %HTTPoison.Response{status_code: 401}} = Views.patch(@token, @account_id, @web_property_id, @profile_id, @resource) + end + end + + test "#patch 200 response" do + use_cassette "analytics_views_patch_response" do + assert {:ok, %{"id" => _id}} = Views.patch(@token, @account_id, @web_property_id, @profile_id, @response) + end + end + + test "#update 401 response" do + use_cassette "analytics_views_update_error_response" do + assert {:error, %HTTPoison.Response{status_code: 401}} = Views.update(@token, @account_id, @web_property_id, @profile_id, @resource) + end + end + + test "#update 200 response" do + use_cassette "analytics_views_update_response" do + assert {:ok, %{"id" => _id}} = Views.update(@token, @account_id, @web_property_id, @profile_id, @response) + end + end +end diff --git a/test/google/apis/analytics/web_properties_test.exs b/test/google/apis/analytics/web_properties_test.exs new file mode 100644 index 0000000..8532cae --- /dev/null +++ b/test/google/apis/analytics/web_properties_test.exs @@ -0,0 +1,70 @@ +defmodule Google.Apis.Analytics.WebPropertiesTest do + use Google.ApiCase + doctest Google.Apis.Analytics.WebProperties + alias Google.Apis.Analytics.WebProperties + + @token "abc123" + @resource %{websiteUrl: "http://www.examplepetstore.com", name: "Example Store"} + @account_id "12345678" + @web_property_id "UA-12345678-6" + + test "#get 401 response" do + use_cassette "analytics_web_properties_get_error_response" do + assert {:error, %HTTPoison.Response{status_code: 401}} = WebProperties.get(@token, @account_id, @web_property_id) + end + end + + test "#get 200 response" do + use_cassette "analytics_web_properties_get_response" do + assert {:ok, %{"id" => _id}} = WebProperties.get(@token, @account_id, @web_property_id) + end + end + + test "#insert 401 response" do + use_cassette "analytics_web_properties_insert_error_response" do + assert {:error, %HTTPoison.Response{status_code: 401}} = WebProperties.insert(@token, @account_id, @resource) + end + end + + test "#insert 200 response" do + use_cassette "analytics_web_properties_insert_response" do + assert {:ok, %{"id" => _id}} = WebProperties.insert(@token, @account_id, @response) + end + end + + test "#list 401 response" do + use_cassette "analytics_web_properties_error_response" do + assert {:error, %HTTPoison.Response{status_code: 401}} = WebProperties.list(@token, @account_id) + end + end + + test "#list 200 response" do + use_cassette "analytics_web_properties_response" do + assert {:ok, %{"items" => _items}} = WebProperties.list(@token, @account_id) + end + end + + test "#patch 401 response" do + use_cassette "analytics_web_properties_patch_error_response" do + assert {:error, %HTTPoison.Response{status_code: 401}} = WebProperties.patch(@token, @account_id, @web_property_id, @resource) + end + end + + test "#patch 200 response" do + use_cassette "analytics_web_properties_patch_response" do + assert {:ok, %{"id" => _id}} = WebProperties.patch(@token, @account_id, @web_property_id, @response) + end + end + + test "#update 401 response" do + use_cassette "analytics_web_properties_update_error_response" do + assert {:error, %HTTPoison.Response{status_code: 401}} = WebProperties.update(@token, @account_id, @web_property_id, @resource) + end + end + + test "#update 200 response" do + use_cassette "analytics_web_properties_update_response" do + assert {:ok, %{"id" => _id}} = WebProperties.update(@token, @account_id, @web_property_id, @response) + end + end +end diff --git a/test/support/api_case.ex b/test/support/api_case.ex new file mode 100644 index 0000000..83d5b78 --- /dev/null +++ b/test/support/api_case.ex @@ -0,0 +1,28 @@ +defmodule Google.ApiCase do + @moduledoc """ + This module defines the test case to be used by + api tests. + + You may define functions here to be used as helpers in + your api tests. + """ + + use ExUnit.CaseTemplate + + using do + quote do + use ExUnit.Case + use ExVCR.Mock, adapter: ExVCR.Adapter.Hackney + end + end + + setup do + ExVCR.Config.cassette_library_dir("fixture/vcr_cassettes") + # replace emails + ExVCR.Config.filter_sensitive_data("[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}", "daniel@testco.com") + # replace ids + ExVCR.Config.filter_sensitive_data("[0-9]{6,20}", "12345678") + ExVCR.Config.filter_request_headers("Authorization") + :ok + end +end