Skip to content

Commit c15530e

Browse files
committed
Add dynamic tokens to docs
1 parent fea46c5 commit c15530e

File tree

8 files changed

+328
-19
lines changed

8 files changed

+328
-19
lines changed

content/docs/guides/create-a-post.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Using [adnpy](/docs/libraries#python)
2121
import adnpy
2222

2323
# Set the default access token for API calls.
24-
adnpy.api.add_authorization_token('your access token here')
24+
adnpy.api.add_authorization_token('<YOUR ACCESS TOKEN>')
2525

2626
# Create a post
2727
post = adnpy.api.create_post(data={'text':'Hello App.net from Python!'})
@@ -32,7 +32,7 @@ Or with the [adn](/docs/libraries#ruby) Ruby gem:
3232
~~~ ruby
3333
require 'adn'
3434

35-
ADN.token = 'your access token here'
35+
ADN.token = '<YOUR ACCESS TOKEN>'
3636
post = ADN::Post.send_post(:text => "Hello App.net from Ruby!")
3737
~~~
3838

content/docs/guides/send-a-broadcast.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Once you've installed the ADNPy library, it's as simple as:
3131
import adnpy
3232

3333
# Set the default access token for API calls.
34-
adnpy.api.add_authorization_token('your access token here')
34+
adnpy.api.add_authorization_token('<YOUR ACCESS TOKEN>')
3535

3636
# Send a broadcast with the BroadcastMessageBuilder recipe.
3737
builder = adnpy.recipes.BroadcastMessageBuilder(adnpy.api)
@@ -54,7 +54,7 @@ Or with the [adn](https://github.com/adn-rb/adn) Ruby gem:
5454
~~~ ruby
5555
require 'adn'
5656

57-
ADN.token = 'your access token here'
57+
ADN.token = '<YOUR ACCESS TOKEN>'
5858

5959
builder = ADN::Recipes::BroadcastMessageBuilder.new
6060
builder.channel_id = 24204

content/reference/authentication/index.md

+5-6
Original file line numberDiff line numberDiff line change
@@ -91,32 +91,31 @@ All requests to the API—authenticated or not—must be made over HTTPS.
9191

9292
When making a call to one of our API resources, there are three ways to include authentication information.
9393

94-
> In all of these examples, `[access token]` is the user's access token, free of any JSON framing or query string parameters.
94+
> In all of these examples, `<YOUR ACCESS TOKEN>` is the user's access token, free of any JSON framing or query string parameters.
9595
9696
* Adding an Authorization header (**preferred**)
9797

9898
Add the following header to your request:
99-
`Authorization: Bearer [access token]`
100-
where `[access token]` is the value of the user's access token.
99+
`Authorization: Bearer <YOUR ACCESS TOKEN>`
100+
where `<YOUR ACCESS TOKEN>` is the value of the user's access token.
101101

102102
Here's an example:
103103

104104
<%= curl_example(:post, "posts", :none, {
105105
:data => {"text" => "Test post"},
106106
:content_type => nil,
107-
:token => "[access token]"
108107
}) %>
109108

110109
* Add `access_token` to query string
111110

112-
<%= curl_example(:get, "posts/1?access_token=[access token]", :none, {:data => "text=Test post", :content_type => nil, :token => nil}) %>
111+
<%= curl_example(:get, "posts/1?access_token=<YOUR ACCESS TOKEN>", :none, {:data => "text=Test post", :content_type => nil, :token => nil}) %>
113112

114113
* Add `access_token` to HTTP body.
115114

116115
> Note: this method will only work with the `PUT`, `POST`, and `PATCH` methods. `GET` and `DELETE` do not accept an HTTP body.
117116
118117
<%= curl_example(:post, "posts", :none, {
119-
:data => {"text" => "Test post", "access_token" => "[access token]"},
118+
:data => {"text" => "Test post", "access_token" => "<YOUR ACCESS TOKEN>"},
120119
:content_type => nil,
121120
:token => nil
122121
}) %>

layouts/default.html

+2
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@
4848
</div>
4949

5050
<script type="text/javascript" src="/assets/js/jquery-1.8.3.min.js"></script>
51+
<script type="text/javascript" src="/assets/js/purl.js"></script>
5152
<script type="text/javascript" src="/assets/js/bootstrap.js"></script>
53+
<script type="text/javascript" src="/assets/js/app.js"></script>
5254
<script type="text/javascript">
5355
ADN.write_extra_js();
5456
</script>

lib/helpers.rb

+25-7
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,27 @@ def local_hostname()
7272
ENV['LOCAL_HOSTNAME'] || 'localhost'
7373
end
7474

75+
def login_url(text)
76+
base_domain = "https://account.app.net"
77+
scopes = ["basic"]
78+
client_id = "gvfM7pVsPBAkVmFWeCDF22uLTyTuMzdd"
79+
redirect_uri = "<script>document.write(window.location);</script>"
80+
path = "/oauth/authenticate?response_type=token"
81+
82+
url = "#{base_domain}#{path}&scope=#{scopes.join(' ')}&client_id=#{client_id}&redirect_uri="
83+
link = "\"<a href='#{url}\" + window.location + \"'>#{text}</a>\""
84+
85+
"<script>document.write(#{link})</script>"
86+
end
87+
88+
def access_token_banner()
89+
login_url = login_url("Authorize the App.net docs")
90+
"<div class=\"alert alert-success alert-block authorize-prompt hide\">
91+
#{login_url} to see more complete examples.
92+
</div>
93+
"
94+
end
95+
7596
def curl_example(method, path, response_key, options = {}, &block)
7697
# things left to figure out
7798
# - some quoting/escaping stuff
@@ -109,9 +130,7 @@ def curl_example(method, path, response_key, options = {}, &block)
109130
paginated_response(response_key, &block)
110131
when :raw
111132
options[:pretty_json] = false
112-
%{<pre><code class="language-#{options[:response_syntax]}">
113-
#{CGI.escapeHTML(response_key)}
114-
</code></pre>
133+
%{<pre><code class="language-#{options[:response_syntax]}">#{CGI.escapeHTML(response_key)}</code></pre>
115134
}
116135
when :none
117136
""
@@ -192,10 +211,9 @@ def curl_example(method, path, response_key, options = {}, &block)
192211
end
193212
curl_lines << cur_line.strip
194213

195-
# use pre, code instead of a fenced code block so I can use these insted of markdown lists. Fenced code blocks don't work in md lists
196-
%{<pre><code class="language-sh">
197-
#{curl_lines.join(" \\\n ")}
198-
</code></pre>
214+
# use pre, code instead of a fenced code block so I can use these inside of markdown lists. Fenced code blocks don't work in md lists
215+
%{#{access_token_banner}
216+
<pre><code class="language-sh">#{curl_lines.join(" \\\n ")}</code></pre>
199217
#{response}
200218
}
201219
end

lib/sample_objects.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def get_hash(key)
1919
end
2020

2121
def json_output(hash)
22-
"\n<pre><code class='language-js'>\n" + CGI.escapeHTML(JSON.pretty_generate(hash)) + "\n</code></pre>\n"
22+
"\n<pre><code class='language-js'>" + CGI.escapeHTML(JSON.pretty_generate(hash)) + "</code></pre>\n"
2323
end
2424

2525
def process_json(key, &block)
@@ -298,7 +298,7 @@ def paginated_response(key, &block)
298298
"user" => "...user object...",
299299
"created_at" => "2012-07-16T17:25:47Z",
300300
"text" => "@berg FIRST post on this new site #newsocialnetwork",
301-
"html" => "<span itemscope=\"https://app.net/schemas/Post\"><span itemprop=\"mention\" data-mention-name=\"berg\" data-mention-id=\"2\">@berg</span> FIRST post on <a href=\"https://join.app.net\" rel=\"nofollow\">this new site</a> <span itemprop=\"hashtag\" data-hashtag-name=\"newsocialnetwork\">#newsocialnetwork</span>.</span",
301+
"html" => "<span itemscope=\"https://app.net/schemas/Post\"><span itemprop=\"mention\" data-mention-name=\"berg\" data-mention-id=\"2\">@berg</span> FIRST post on <a href=\"https://join.app.net\" rel=\"nofollow\">this new site</a> <span itemprop=\"hashtag\" data-hashtag-name=\"newsocialnetwork\">#newsocialnetwork</span>.</span>",
302302
"source" => {
303303
"name" => "Clientastic for iOS",
304304
"link" => "http://app.net",

static/js/app.js

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
$(function() {
2+
3+
var token = null;
4+
var new_token = $.url(window.location).fparam('access_token');
5+
if (new_token) {
6+
token = {
7+
user_token: new_token
8+
};
9+
localStorage.token = JSON.stringify(token);
10+
} else if (typeof(localStorage.token) !== 'undefined') {
11+
token = JSON.parse(localStorage.token);
12+
}
13+
14+
if (token && token.user_token) {
15+
var needle = "&lt;YOUR ACCESS TOKEN&gt;";
16+
$('pre code').each(function () {
17+
var el = $(this);
18+
el.html(el.html().replace(needle, token.user_token));
19+
});
20+
} else {
21+
$('.authorize-prompt').removeClass('hide');
22+
}
23+
});

0 commit comments

Comments
 (0)