Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 27 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -46,5 +53,23 @@ Google.Apis.Maps.TimeZone.get(location: {-33.86,151.20})
# => %{"dstOffset" => 3600, "rawOffset" => 36000, "status" => "OK", "timeZoneId" => "Australia/Sydney", "timeZoneName" => "Australian Eastern Daylight Time"}
Google.Apis.Places.autocomplete("poz", language: "pl")

alias Google.Apis.Analytics.Accounts
Accounts.list("a_valid_oauth_token")

alias Google.Apis.Analytics.WebProperties
WebProperties.get("a_valid_oauth_token", account_id, web_property_id)
WebProperties.insert("a_valid_oauth_token", account_id, resource)
WebProperties.list("a_valid_oauth_token", account_id)
WebProperties.patch("a_valid_oauth_token", account_id, web_property_id, resource)
WebProperties.update("a_valid_oauth_token", account_id, web_property_id, resource)

alias Google.Apis.Analytics.Views
Views.delete("a_valid_oauth_token", account_id, web_property_id, profile_id)
Views.get("a_valid_oauth_token", account_id, web_property_id, profile_id)
Views.insert("a_valid_oauth_token", account_id, web_property_id, resource)
Views.list("a_valid_oauth_token", account_id, web_property_id)
Views.patch("a_valid_oauth_token", account_id, web_property_id, profile_id, resource)
Views.update("a_valid_oauth_token", account_id, web_property_id, profile_id, resource)

Google.Apis.??? # Submit a PR
```
35 changes: 35 additions & 0 deletions fixture/vcr_cassettes/analytics_accounts_error_response.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
]
34 changes: 34 additions & 0 deletions fixture/vcr_cassettes/analytics_accounts_response.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
]
35 changes: 35 additions & 0 deletions fixture/vcr_cassettes/analytics_views_error_response.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
]
35 changes: 35 additions & 0 deletions fixture/vcr_cassettes/analytics_views_get_error_response.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
]
34 changes: 34 additions & 0 deletions fixture/vcr_cassettes/analytics_views_get_response.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
]
35 changes: 35 additions & 0 deletions fixture/vcr_cassettes/analytics_views_insert_error_response.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
]
34 changes: 34 additions & 0 deletions fixture/vcr_cassettes/analytics_views_insert_response.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
]
35 changes: 35 additions & 0 deletions fixture/vcr_cassettes/analytics_views_patch_error_response.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
]
34 changes: 34 additions & 0 deletions fixture/vcr_cassettes/analytics_views_patch_response.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
]
Loading