From b798688334ec09218f82179ffbc94130374e7e80 Mon Sep 17 00:00:00 2001 From: elkelk Date: Wed, 21 Jun 2017 10:07:13 -0400 Subject: [PATCH 01/10] Ignore key for Oauth methods --- README.md | 11 +++++++++-- lib/google/apis/base.ex | 16 +++++++++++++--- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 4d99f7d..d870b21 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 diff --git a/lib/google/apis/base.ex b/lib/google/apis/base.ex index c51fd34..a2a145f 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,8 +9,18 @@ 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}" + url = "#{unquote(endpoint)}#{url}" + case unquote(oauth_only) do + true -> url + _ -> + api_key = Application.fetch_env!(:google_api_client, :api_key) + uri = URI.parse(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 end end From 8da23f39642d52ef31389f2936309518779449eb Mon Sep 17 00:00:00 2001 From: elkelk Date: Wed, 21 Jun 2017 10:07:37 -0400 Subject: [PATCH 02/10] Fix deprecation warning --- mix.exs | 2 +- mix.lock | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/mix.exs b/mix.exs index e2e070a..a999ada 100644 --- a/mix.exs +++ b/mix.exs @@ -7,7 +7,7 @@ defmodule Google.Mixfile do elixir: "~> 1.3", build_embedded: Mix.env == :prod, start_permanent: Mix.env == :prod, - deps: deps] + deps: deps()] end # Configuration for the OTP application diff --git a/mix.lock b/mix.lock index e29cbbc..9ff0c52 100644 --- a/mix.lock +++ b/mix.lock @@ -1,8 +1,8 @@ %{"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]}]}, + "hackney": {:hex, :hackney, "1.6.3", "d489d7ca2d4323e307bedc4bfe684323a7bf773ecfd77938f3ee8074e488e140", [:mix, :rebar3], [{: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], []}, "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], []}} From 34e11e7fba565f71081d79fd909c085fe3934cc3 Mon Sep 17 00:00:00 2001 From: elkelk Date: Wed, 21 Jun 2017 10:07:52 -0400 Subject: [PATCH 03/10] Add analytics list method --- README.md | 2 ++ lib/google/apis/analytics.ex | 2 ++ lib/google/apis/analytics/accounts.ex | 19 +++++++++++++++++++ 3 files changed, 23 insertions(+) create mode 100644 lib/google/apis/analytics.ex create mode 100644 lib/google/apis/analytics/accounts.ex diff --git a/README.md b/README.md index d870b21..32ed50c 100644 --- a/README.md +++ b/README.md @@ -53,5 +53,7 @@ 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") +Google.Apis.Analytics.Accounts.list("a_valid_oauth_token") + Google.Apis.??? # Submit a PR ``` 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..90ba372 --- /dev/null +++ b/lib/google/apis/analytics/accounts.ex @@ -0,0 +1,19 @@ +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() + + 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 = ["Authorization": "Bearer #{token}"] + get!(URI.encode_query(params), headers).body + end +end From 365a49a3f7fec0a78aed1a2b27a5c64c7fcbeea5 Mon Sep 17 00:00:00 2001 From: elkelk Date: Wed, 21 Jun 2017 11:13:23 -0400 Subject: [PATCH 04/10] Update Analytics doc --- lib/google/apis/analytics/accounts.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/google/apis/analytics/accounts.ex b/lib/google/apis/analytics/accounts.ex index 90ba372..abf6bf2 100644 --- a/lib/google/apis/analytics/accounts.ex +++ b/lib/google/apis/analytics/accounts.ex @@ -5,7 +5,7 @@ defmodule Google.Apis.Analytics.Accounts do Google Analytics, Accounts Management: https://developers.google.com/analytics/devguides/config/mgmt/v3/mgmtReference/management/accounts Usage: - Google.Apis.Analytics.Accounts.list() + Google.Apis.Analytics.Accounts.list(access_token) Available options: max_results: 100, start_index: 0 From 83711a837eeb807996b78c6c1998f336f9cad2d7 Mon Sep 17 00:00:00 2001 From: elkelk Date: Wed, 21 Jun 2017 13:33:11 -0400 Subject: [PATCH 05/10] Add analytics web properties methods --- README.md | 6 ++ lib/google/apis/analytics/accounts.ex | 2 +- lib/google/apis/analytics/web_properties.ex | 72 +++++++++++++++++++++ lib/google/apis/base.ex | 10 ++- 4 files changed, 86 insertions(+), 4 deletions(-) create mode 100644 lib/google/apis/analytics/web_properties.ex diff --git a/README.md b/README.md index 32ed50c..748be36 100644 --- a/README.md +++ b/README.md @@ -55,5 +55,11 @@ Google.Apis.Places.autocomplete("poz", language: "pl") Google.Apis.Analytics.Accounts.list("a_valid_oauth_token") +Google.Apis.Analytics.WebProperties.get("a_valid_oauth_token", account_id, web_property_id) +Google.Apis.Analytics.WebProperties.insert("a_valid_oauth_token", account_id, resource) +Google.Apis.Analytics.WebProperties.list("a_valid_oauth_token", account_id) +Google.Apis.Analytics.WebProperties.patch("a_valid_oauth_token", account_id, web_property_id, resource) +Google.Apis.Analytics.WebProperties.update("a_valid_oauth_token", account_id, web_property_id, resource) + Google.Apis.??? # Submit a PR ``` diff --git a/lib/google/apis/analytics/accounts.ex b/lib/google/apis/analytics/accounts.ex index abf6bf2..e57d2ca 100644 --- a/lib/google/apis/analytics/accounts.ex +++ b/lib/google/apis/analytics/accounts.ex @@ -13,7 +13,7 @@ defmodule Google.Apis.Analytics.Accounts do 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 = ["Authorization": "Bearer #{token}"] + headers = build_auth_headers(token) get!(URI.encode_query(params), headers).body 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..1e4a5ad --- /dev/null +++ b/lib/google/apis/analytics/web_properties.ex @@ -0,0 +1,72 @@ +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, Accounts Management: https://developers.google.com/analytics/devguides/config/mgmt/v3/mgmtReference/management/accounts + """ + + @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).body + 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: resource} |> Poison.encode! + post!("#{account_id}/webproperties", body, headers).body + 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).body + 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: resource} |> Poison.encode! + patch!("#{account_id}/webproperties/#{web_property_id}", body, headers).body + 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: resource} |> Poison.encode! + put!("#{account_id}/webproperties/#{web_property_id}", body, headers).body + end +end diff --git a/lib/google/apis/base.ex b/lib/google/apis/base.ex index a2a145f..9b4a7d5 100644 --- a/lib/google/apis/base.ex +++ b/lib/google/apis/base.ex @@ -9,12 +9,12 @@ defmodule Google.Apis.Base do end defp process_url(url) do - url = "#{unquote(endpoint)}#{url}" + full_url = "#{unquote(endpoint)}#{url}" case unquote(oauth_only) do - true -> url + true -> full_url _ -> api_key = Application.fetch_env!(:google_api_client, :api_key) - uri = URI.parse(url) + uri = URI.parse(full_url) query = URI.decode_query(uri.query || "") |> Map.merge(%{"key" => api_key}) uri @@ -22,6 +22,10 @@ defmodule Google.Apis.Base do |> URI.to_string end end + + defp build_auth_headers(token) do + ["Authorization": "Bearer #{token}", "Content-Type": "application/json"] + end end end end From bf03c8c0f664d43f34e4e897d205b2daa196b287 Mon Sep 17 00:00:00 2001 From: elkelk Date: Mon, 26 Jun 2017 09:45:14 -0400 Subject: [PATCH 06/10] Add rich responses --- lib/google/apis/analytics/accounts.ex | 3 ++- lib/google/apis/analytics/web_properties.ex | 15 ++++++++++----- lib/google/apis/base.ex | 6 ++++++ .../apis/knowledge_graph/knowledge_graph.ex | 3 ++- lib/google/apis/maps/timezone.ex | 3 ++- lib/google/apis/places/places.ex | 3 ++- 6 files changed, 24 insertions(+), 9 deletions(-) diff --git a/lib/google/apis/analytics/accounts.ex b/lib/google/apis/analytics/accounts.ex index e57d2ca..0184aab 100644 --- a/lib/google/apis/analytics/accounts.ex +++ b/lib/google/apis/analytics/accounts.ex @@ -14,6 +14,7 @@ defmodule Google.Apis.Analytics.Accounts do """ def list(token, params \\ [max_results: 100, start_index: 0]) do headers = build_auth_headers(token) - get!(URI.encode_query(params), headers).body + get!(URI.encode_query(params), headers) + |> build_api_response() end end diff --git a/lib/google/apis/analytics/web_properties.ex b/lib/google/apis/analytics/web_properties.ex index 1e4a5ad..0b84409 100644 --- a/lib/google/apis/analytics/web_properties.ex +++ b/lib/google/apis/analytics/web_properties.ex @@ -13,7 +13,8 @@ defmodule Google.Apis.Analytics.WebProperties do """ def get(token, account_id, web_property_id) do headers = build_auth_headers(token) - get!("#{account_id}/webproperties/#{web_property_id}", headers).body + get!("#{account_id}/webproperties/#{web_property_id}", headers) + |> build_api_response() end @doc """ @@ -27,7 +28,8 @@ defmodule Google.Apis.Analytics.WebProperties do def insert(token, account_id, resource) do headers = build_auth_headers(token) body = %{resource: resource} |> Poison.encode! - post!("#{account_id}/webproperties", body, headers).body + post!("#{account_id}/webproperties", body, headers) + |> build_api_response() end @doc """ @@ -38,7 +40,8 @@ defmodule Google.Apis.Analytics.WebProperties do """ def list(token, account_id) do headers = build_auth_headers(token) - get!("#{account_id}/webproperties", headers).body + get!("#{account_id}/webproperties", headers) + |> build_api_response() end @doc """ @@ -52,7 +55,8 @@ defmodule Google.Apis.Analytics.WebProperties do def patch(token, account_id, web_property_id, resource) do headers = build_auth_headers(token) body = %{resource: resource} |> Poison.encode! - patch!("#{account_id}/webproperties/#{web_property_id}", body, headers).body + patch!("#{account_id}/webproperties/#{web_property_id}", body, headers) + |> build_api_response() end @@ -67,6 +71,7 @@ defmodule Google.Apis.Analytics.WebProperties do def update(token, account_id, web_property_id, resource) do headers = build_auth_headers(token) body = %{resource: resource} |> Poison.encode! - put!("#{account_id}/webproperties/#{web_property_id}", body, headers).body + 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 9b4a7d5..d5bbfcf 100644 --- a/lib/google/apis/base.ex +++ b/lib/google/apis/base.ex @@ -26,6 +26,12 @@ defmodule Google.Apis.Base do 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 From 4c14b0ee30bcb537aeecddd31a28f3ddd125f707 Mon Sep 17 00:00:00 2001 From: elkelk Date: Wed, 28 Jun 2017 14:16:10 -0400 Subject: [PATCH 07/10] Add tests to Analytics - install exvcr - update dependencies - fix issue with resource structure --- .../analytics_accounts_error_response.json | 35 ++++++++++ .../analytics_accounts_response.json | 34 ++++++++++ ...alytics_web_properties_error_response.json | 35 ++++++++++ ...ics_web_properties_get_error_response.json | 35 ++++++++++ ...analytics_web_properties_get_response.json | 34 ++++++++++ ..._web_properties_insert_error_response.json | 35 ++++++++++ ...lytics_web_properties_insert_response.json | 34 ++++++++++ ...s_web_properties_patch_error_response.json | 35 ++++++++++ ...alytics_web_properties_patch_response.json | 34 ++++++++++ .../analytics_web_properties_response.json | 34 ++++++++++ ..._web_properties_update_error_response.json | 35 ++++++++++ ...lytics_web_properties_update_response.json | 34 ++++++++++ lib/google/apis/analytics/web_properties.ex | 6 +- mix.exs | 10 ++- mix.lock | 16 +++-- test/google/apis/analytics/accounts_test.exs | 19 ++++++ .../apis/analytics/web_properties_test.exs | 68 +++++++++++++++++++ test/support/api_case.ex | 28 ++++++++ 18 files changed, 552 insertions(+), 9 deletions(-) create mode 100644 fixture/vcr_cassettes/analytics_accounts_error_response.json create mode 100644 fixture/vcr_cassettes/analytics_accounts_response.json create mode 100644 fixture/vcr_cassettes/analytics_web_properties_error_response.json create mode 100644 fixture/vcr_cassettes/analytics_web_properties_get_error_response.json create mode 100644 fixture/vcr_cassettes/analytics_web_properties_get_response.json create mode 100644 fixture/vcr_cassettes/analytics_web_properties_insert_error_response.json create mode 100644 fixture/vcr_cassettes/analytics_web_properties_insert_response.json create mode 100644 fixture/vcr_cassettes/analytics_web_properties_patch_error_response.json create mode 100644 fixture/vcr_cassettes/analytics_web_properties_patch_response.json create mode 100644 fixture/vcr_cassettes/analytics_web_properties_response.json create mode 100644 fixture/vcr_cassettes/analytics_web_properties_update_error_response.json create mode 100644 fixture/vcr_cassettes/analytics_web_properties_update_response.json create mode 100644 test/google/apis/analytics/accounts_test.exs create mode 100644 test/google/apis/analytics/web_properties_test.exs create mode 100644 test/support/api_case.ex 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_web_properties_error_response.json b/fixture/vcr_cassettes/analytics_web_properties_error_response.json new file mode 100644 index 0000000..2c9d7c5 --- /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 17:59:17 GMT", + "Expires": "Wed, 28 Jun 2017 17:59:17 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..86f38ad --- /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/" + }, + "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:03:37 GMT", + "Expires": "Wed, 28 Jun 2017 18:03: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_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/web_properties.ex b/lib/google/apis/analytics/web_properties.ex index 0b84409..7f5ede6 100644 --- a/lib/google/apis/analytics/web_properties.ex +++ b/lib/google/apis/analytics/web_properties.ex @@ -27,7 +27,7 @@ defmodule Google.Apis.Analytics.WebProperties do """ def insert(token, account_id, resource) do headers = build_auth_headers(token) - body = %{resource: resource} |> Poison.encode! + body = resource |> Poison.encode! post!("#{account_id}/webproperties", body, headers) |> build_api_response() end @@ -54,7 +54,7 @@ defmodule Google.Apis.Analytics.WebProperties do """ def patch(token, account_id, web_property_id, resource) do headers = build_auth_headers(token) - body = %{resource: resource} |> Poison.encode! + body = resource |> Poison.encode! patch!("#{account_id}/webproperties/#{web_property_id}", body, headers) |> build_api_response() end @@ -70,7 +70,7 @@ defmodule Google.Apis.Analytics.WebProperties do """ def update(token, account_id, web_property_id, resource) do headers = build_auth_headers(token) - body = %{resource: resource} |> Poison.encode! + body = resource |> Poison.encode! put!("#{account_id}/webproperties/#{web_property_id}", body, headers) |> build_api_response() end diff --git a/mix.exs b/mix.exs index a999ada..cd72732 100644 --- a/mix.exs +++ b/mix.exs @@ -7,6 +7,10 @@ defmodule Google.Mixfile do elixir: "~> 1.3", build_embedded: Mix.env == :prod, start_permanent: Mix.env == :prod, + elixirc_paths: elixirc_paths(Mix.env), + preferred_cli_env: [ + vcr: :test, "vcr.delete": :test, "vcr.check": :test, "vcr.show": :test + ], deps: deps()] end @@ -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 9ff0c52..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", [:mix, :rebar3], [{: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", [:make, :rebar], []}} + "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/web_properties_test.exs b/test/google/apis/analytics/web_properties_test.exs new file mode 100644 index 0000000..d097a49 --- /dev/null +++ b/test/google/apis/analytics/web_properties_test.exs @@ -0,0 +1,68 @@ +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"} + + test "#get 401 response" do + use_cassette "analytics_web_properties_get_error_response" do + assert {:error, %HTTPoison.Response{status_code: 401}} = WebProperties.get(@token, "12345678") + end + end + + test "#get 200 response" do + use_cassette "analytics_web_properties_get_response" do + assert {:ok, %{"id" => _id}} = WebProperties.get(@token, "12345678", "UA-12345678-6") + 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, "12345678", @resource) + end + end + + test "#insert 200 response" do + use_cassette "analytics_web_properties_insert_response" do + assert {:ok, %{"id" => _id}} = WebProperties.insert(@token, "12345678", @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, "12345678") + end + end + + test "#list 200 response" do + use_cassette "analytics_web_properties_response" do + assert {:ok, %{"items" => _items}} = WebProperties.list(@token, "12345678") + 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, "12345678", "UA-12345678-6", @resource) + end + end + + test "#patch 200 response" do + use_cassette "analytics_web_properties_patch_response" do + assert {:ok, %{"id" => _id}} = WebProperties.patch(@token, "12345678", "UA-12345678-6", @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, "12345678", "UA-12345678-6", @resource) + end + end + + test "#update 200 response" do + use_cassette "analytics_web_properties_update_response" do + assert {:ok, %{"id" => _id}} = WebProperties.update(@token, "12345678", "UA-12345678-6", @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 From 5f3aee06643b56b548606fcf8370ae3773e9e914 Mon Sep 17 00:00:00 2001 From: elkelk Date: Wed, 28 Jun 2017 14:36:25 -0400 Subject: [PATCH 08/10] Update WebProperties doc --- lib/google/apis/analytics/web_properties.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/google/apis/analytics/web_properties.ex b/lib/google/apis/analytics/web_properties.ex index 7f5ede6..60565d0 100644 --- a/lib/google/apis/analytics/web_properties.ex +++ b/lib/google/apis/analytics/web_properties.ex @@ -2,7 +2,7 @@ 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, Accounts Management: https://developers.google.com/analytics/devguides/config/mgmt/v3/mgmtReference/management/accounts + Google Analytics, Web Properties Management: https://developers.google.com/analytics/devguides/config/mgmt/v3/mgmtReference/management/webproperties """ @doc """ From b01ef082d1840492dce174a8bb401f7a4c63949f Mon Sep 17 00:00:00 2001 From: elkelk Date: Wed, 28 Jun 2017 16:12:23 -0400 Subject: [PATCH 09/10] Add Analytics.Views methods/tests --- .../analytics_views_error_response.json | 35 ++++++++ .../analytics_views_get_error_response.json | 35 ++++++++ .../analytics_views_get_response.json | 34 +++++++ ...analytics_views_insert_error_response.json | 35 ++++++++ .../analytics_views_insert_response.json | 34 +++++++ .../analytics_views_patch_error_response.json | 35 ++++++++ .../analytics_views_patch_response.json | 34 +++++++ .../analytics_views_response.json | 34 +++++++ ...analytics_views_update_error_response.json | 35 ++++++++ .../analytics_views_update_response.json | 34 +++++++ ...alytics_web_properties_error_response.json | 4 +- ...ics_web_properties_get_error_response.json | 6 +- lib/google/apis/analytics/views.ex | 88 +++++++++++++++++++ test/google/apis/analytics/views_test.exs | 71 +++++++++++++++ .../apis/analytics/web_properties_test.exs | 22 ++--- 15 files changed, 521 insertions(+), 15 deletions(-) create mode 100644 fixture/vcr_cassettes/analytics_views_error_response.json create mode 100644 fixture/vcr_cassettes/analytics_views_get_error_response.json create mode 100644 fixture/vcr_cassettes/analytics_views_get_response.json create mode 100644 fixture/vcr_cassettes/analytics_views_insert_error_response.json create mode 100644 fixture/vcr_cassettes/analytics_views_insert_response.json create mode 100644 fixture/vcr_cassettes/analytics_views_patch_error_response.json create mode 100644 fixture/vcr_cassettes/analytics_views_patch_response.json create mode 100644 fixture/vcr_cassettes/analytics_views_response.json create mode 100644 fixture/vcr_cassettes/analytics_views_update_error_response.json create mode 100644 fixture/vcr_cassettes/analytics_views_update_response.json create mode 100644 lib/google/apis/analytics/views.ex create mode 100644 test/google/apis/analytics/views_test.exs 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 index 2c9d7c5..89ccabb 100644 --- a/fixture/vcr_cassettes/analytics_web_properties_error_response.json +++ b/fixture/vcr_cassettes/analytics_web_properties_error_response.json @@ -17,8 +17,8 @@ "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 17:59:17 GMT", - "Expires": "Wed, 28 Jun 2017 17:59:17 GMT", + "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", diff --git a/fixture/vcr_cassettes/analytics_web_properties_get_error_response.json b/fixture/vcr_cassettes/analytics_web_properties_get_error_response.json index 86f38ad..774ed41 100644 --- a/fixture/vcr_cassettes/analytics_web_properties_get_error_response.json +++ b/fixture/vcr_cassettes/analytics_web_properties_get_error_response.json @@ -9,7 +9,7 @@ "method": "get", "options": [], "request_body": "", - "url": "https://www.googleapis.com/analytics/v3/management/accounts/12345678/webproperties/" + "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\"}}", @@ -17,8 +17,8 @@ "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:03:37 GMT", - "Expires": "Wed, 28 Jun 2017 18:03:37 GMT", + "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", 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/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 index d097a49..8532cae 100644 --- a/test/google/apis/analytics/web_properties_test.exs +++ b/test/google/apis/analytics/web_properties_test.exs @@ -5,64 +5,66 @@ defmodule Google.Apis.Analytics.WebPropertiesTest do @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, "12345678") + 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, "12345678", "UA-12345678-6") + 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, "12345678", @resource) + 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, "12345678", @response) + 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, "12345678") + 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, "12345678") + 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, "12345678", "UA-12345678-6", @resource) + 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, "12345678", "UA-12345678-6", @response) + 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, "12345678", "UA-12345678-6", @resource) + 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, "12345678", "UA-12345678-6", @response) + assert {:ok, %{"id" => _id}} = WebProperties.update(@token, @account_id, @web_property_id, @response) end end end From f34a41674e2e0ff693e36fed25609c77cbb13dd6 Mon Sep 17 00:00:00 2001 From: elkelk Date: Wed, 28 Jun 2017 16:17:22 -0400 Subject: [PATCH 10/10] Update README with Views --- README.md | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 748be36..0781b6c 100644 --- a/README.md +++ b/README.md @@ -53,13 +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") -Google.Apis.Analytics.Accounts.list("a_valid_oauth_token") - -Google.Apis.Analytics.WebProperties.get("a_valid_oauth_token", account_id, web_property_id) -Google.Apis.Analytics.WebProperties.insert("a_valid_oauth_token", account_id, resource) -Google.Apis.Analytics.WebProperties.list("a_valid_oauth_token", account_id) -Google.Apis.Analytics.WebProperties.patch("a_valid_oauth_token", account_id, web_property_id, resource) -Google.Apis.Analytics.WebProperties.update("a_valid_oauth_token", account_id, web_property_id, resource) +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 ```