New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add a demo for one-legged OAuth1 using Noun Project API #548
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
1f6bdcf
add a demo for one-legged OAuth1
cderv 7bacb4d
add to demo index
cderv 419a654
gives precision on adding env var for example
cderv d8de9cd
add news bullet
cderv 129b210
Merge branch 'master' into cderv-fix-542-add-demo
hadley 9863528
Restyle demos
hadley a58ca97
Use askForPassword instead of env vars
hadley 8586693
Fix merge snafu
hadley File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
library(httr) | ||
|
||
# Noun Project has an API secured with OAuth 1.0a One-legged. A client key and a | ||
# secret must be used to sign requests when accessing the API. This is an | ||
# exemple using OAuth 1.0a One legged auth mechanism | ||
# http://oauthbible.com/#oauth-10a-one-legged | ||
|
||
# 1. Register an application to get required keys: | ||
# https://thenounproject.com/accounts/login/?next=/developers/apps/ | ||
nouns_app <- oauth_app("noun_project", | ||
key = rstudioapi::askForPassword(), | ||
secret = rstudioapi::askForPassword() | ||
) | ||
|
||
# 2. Each request must be signed using the app key and secret | ||
# see ?oauth_signature for more information on signature | ||
url <- "http://api.thenounproject.com/icon/15" | ||
signature <- oauth_signature(url, method = "GET", app = nouns_app) | ||
res <- GET(url, oauth_header(signature)) | ||
stop_for_status(res) | ||
content(res) | ||
|
||
# 3. Create a wrapper function to sign each request more easily | ||
get_nouns_api <- function(endpoint, | ||
baseurl = "http://api.thenounproject.com/", | ||
app = nouns_app, | ||
...) { | ||
url <- modify_url(baseurl, path = endpoint) | ||
info <- oauth_signature(url, app = app) | ||
header_oauth <- oauth_header(info) | ||
GET(url, header_oauth, ...) | ||
} | ||
res <- get_nouns_api("collections") | ||
stop_for_status(res) | ||
content(res) | ||
|
||
# 4. Signing request requires the METHOD used. If the API has a POST for | ||
# example, you must take it into account. | ||
url <- "http://api.thenounproject.com/notify/publish?test=1" | ||
signature <- oauth_signature(url, method = "POST", app = nouns_app) | ||
res <- POST(url, oauth_header(signature), body = list(icons = 15), encode = "json") | ||
stop_for_status(res) | ||
content(res) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you mind using the standard tidyverse style here?