tent-apidoc 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +17 -0
- data/Gemfile +7 -0
- data/LICENSE.txt +22 -0
- data/README.md +3 -0
- data/Rakefile +1 -0
- data/bin/tent-apidoc +12 -0
- data/lib/tent-apidoc.rb +93 -0
- data/lib/tent-apidoc/examples.rb +204 -0
- data/tent-apidoc.gemspec +22 -0
- metadata +135 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Apollic Software, LLC
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/tent-apidoc
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'pathname'
|
4
|
+
bin_file = Pathname.new(__FILE__).realpath
|
5
|
+
$:.unshift File.expand_path("../../lib", bin_file)
|
6
|
+
|
7
|
+
require 'tent-apidoc'
|
8
|
+
require 'yaml'
|
9
|
+
|
10
|
+
data = { :examples => TentApiDoc.examples, :variables => TentApiDoc.variables }
|
11
|
+
|
12
|
+
File.open(ARGV[0] || 'examples.yaml', 'w') { |f| f.write YAML.dump(data) }
|
data/lib/tent-apidoc.rb
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
require 'bundler/setup'
|
2
|
+
require 'tent-client'
|
3
|
+
require 'tentd'
|
4
|
+
require 'rack/utils'
|
5
|
+
|
6
|
+
ENV['TENT_ENTITY'] = 'https://example.org'
|
7
|
+
|
8
|
+
class TentApiDoc
|
9
|
+
class FaradayAdapter < Faraday::Adapter::Rack
|
10
|
+
def call(env)
|
11
|
+
env[:request_body] = env[:body].dup if env[:body]
|
12
|
+
super
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
Faraday.register_middleware :adapter, :tent_rack => FaradayAdapter
|
17
|
+
|
18
|
+
class << self
|
19
|
+
attr_accessor :examples
|
20
|
+
|
21
|
+
def clients
|
22
|
+
@clients ||= begin
|
23
|
+
adapter = [:tent_rack, TentD.new(:database => 'postgres://localhost/tent_doc').tap { DataMapper.auto_migrate! }]
|
24
|
+
TentD.faraday_adapter = adapter # tentception
|
25
|
+
{
|
26
|
+
:base => TentClient.new('https://example.com', :faraday_adapter => adapter)
|
27
|
+
}
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def example(name)
|
32
|
+
(@examples ||= {})[name] = response_to_markdown(yield)
|
33
|
+
end
|
34
|
+
|
35
|
+
def variables
|
36
|
+
@variables ||= {}
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def response_to_markdown(response)
|
42
|
+
return unless response
|
43
|
+
markdown = request_markdown(response.env)
|
44
|
+
markdown += body_markdown(response.env[:request_body])
|
45
|
+
markdown += response_head_markdown(response)
|
46
|
+
markdown += body_markdown(response.body)
|
47
|
+
end
|
48
|
+
|
49
|
+
def request_markdown(env)
|
50
|
+
request = "#{env[:method].to_s.upcase} #{env[:url].request_uri} HTTP/1.1\n"
|
51
|
+
request += header_string(env[:request_headers])
|
52
|
+
fenced_code(request)
|
53
|
+
end
|
54
|
+
|
55
|
+
def response_head_markdown(response)
|
56
|
+
head = "HTTP/1.1 #{response.status} #{Rack::Utils::HTTP_STATUS_CODES[response.status]}\n"
|
57
|
+
response.headers.delete('X-Cascade')
|
58
|
+
head += header_string(response.headers)
|
59
|
+
fenced_code(head)
|
60
|
+
end
|
61
|
+
|
62
|
+
def body_markdown(body)
|
63
|
+
return '' if body.nil? || body.respond_to?(:empty?) && body.empty?
|
64
|
+
body = (body.rewind && body.read) if body.respond_to?(:read)
|
65
|
+
fenced_code(body)
|
66
|
+
end
|
67
|
+
|
68
|
+
def header_string(headers)
|
69
|
+
headers.map { |k,v| "#{k}: #{v}" }.join("\n")
|
70
|
+
end
|
71
|
+
|
72
|
+
def fenced_code(code)
|
73
|
+
language = if code.kind_of?(Hash) || code.kind_of?(Array)
|
74
|
+
code = JSON.pretty_generate(code)
|
75
|
+
'json'
|
76
|
+
elsif code.match(/\A\s*\{/)
|
77
|
+
code = JSON.pretty_generate(JSON.parse(code))
|
78
|
+
'json'
|
79
|
+
else
|
80
|
+
'text'
|
81
|
+
end
|
82
|
+
"\n```#{language}\n#{code}\n```\n"
|
83
|
+
end
|
84
|
+
|
85
|
+
def client_options(authable)
|
86
|
+
authable.auth_details.merge(:faraday_adapter => TentD.faraday_adapter)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
TentApiDoc.clients
|
92
|
+
|
93
|
+
require 'tent-apidoc/examples'
|
@@ -0,0 +1,204 @@
|
|
1
|
+
require 'faker'
|
2
|
+
require 'fabrication'
|
3
|
+
|
4
|
+
class TentApiDoc
|
5
|
+
include TentD::Model
|
6
|
+
|
7
|
+
User.current = User.create
|
8
|
+
|
9
|
+
# hack so tentception works
|
10
|
+
class TentD::Model::User
|
11
|
+
def profile_entity
|
12
|
+
nil
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
ProfileInfo.create(:type_base => 'https://tent.io/types/info/core',
|
17
|
+
:type_version => '0.1.0',
|
18
|
+
:public => true,
|
19
|
+
:content => {
|
20
|
+
:licenses => ['http://creativecommons.org/licenses/by/3.0/'],
|
21
|
+
:entity => 'https://example.org',
|
22
|
+
:servers => ['https://tent.example.com', 'http://eqt5g4fuenphqinx.onion/']
|
23
|
+
})
|
24
|
+
ProfileInfo.create(:type_base => 'https://tent.io/types/info/basic',
|
25
|
+
:type_version => '0.1.0',
|
26
|
+
:public => true,
|
27
|
+
:content => {
|
28
|
+
:name => 'The Tentity',
|
29
|
+
:avatar_url => 'http://example.org/avatar.jpg',
|
30
|
+
:birthdate => '2012-08-23',
|
31
|
+
:location => 'The Internet',
|
32
|
+
:gender => 'Unknown',
|
33
|
+
:bio => Faker::Lorem.sentence
|
34
|
+
})
|
35
|
+
|
36
|
+
example(:get_profile) do
|
37
|
+
clients[:base].profile.get
|
38
|
+
end
|
39
|
+
|
40
|
+
example(:create_app) do
|
41
|
+
clients[:base].app.create(
|
42
|
+
:name => "FooApp",
|
43
|
+
:description => "Does amazing foos with your data",
|
44
|
+
:url => "http://example.com",
|
45
|
+
:icon => "http://example.com/icon.png",
|
46
|
+
:redirect_uris => ["https://app.example.com/tent/callback"],
|
47
|
+
:scopes => {
|
48
|
+
:write_profile => "Uses an app profile section to describe foos",
|
49
|
+
:read_followings => "Calculates foos based on your followings"
|
50
|
+
}).tap {
|
51
|
+
clients[:app] = TentClient.new('https://example.com', client_options(App.last))
|
52
|
+
}
|
53
|
+
end
|
54
|
+
|
55
|
+
example(:app_auth) do
|
56
|
+
app = App.first
|
57
|
+
auth = app.authorizations.create(
|
58
|
+
:scopes => %w(read_posts write_posts import_posts read_profile write_profile read_followers write_followers read_followings write_followings read_groups write_groups read_permissions write_permissions read_apps write_apps follow_ui read_secrets write_secrets),
|
59
|
+
:profile_info_types => ['https://tent.io/types/info/basic/v0.1.0'],
|
60
|
+
:post_types => ['https://tent.io/types/post/status/v0.1.0', 'https://tent.io/types/post/photo/v0.1.0']
|
61
|
+
)
|
62
|
+
variables[:app_code] = auth.token_code
|
63
|
+
variables[:app_id] = app.public_id
|
64
|
+
clients[:app].app.authorization.create(app.public_id, :code => auth.token_code, :token_type => 'mac').tap {
|
65
|
+
clients[:auth] = TentClient.new('https://example.com', client_options(AppAuthorization.last))
|
66
|
+
}
|
67
|
+
end
|
68
|
+
|
69
|
+
example(:create_following) do
|
70
|
+
clients[:auth].following.create('https://example.org')
|
71
|
+
end
|
72
|
+
|
73
|
+
example(:create_follower) do
|
74
|
+
clients[:base].follower.create(
|
75
|
+
:entity => 'https://example.org',
|
76
|
+
:types => ['all'],
|
77
|
+
:notification_path => "notifications/#{Following.last.public_id}",
|
78
|
+
:licenses => ['http://creativecommons.org/licenses/by/3.0/']
|
79
|
+
).tap { |res|
|
80
|
+
clients[:follower] = TentClient.new('https://example.com', client_options(Follower.last))
|
81
|
+
variables[:follower_id] = res.body['id']
|
82
|
+
}
|
83
|
+
end
|
84
|
+
|
85
|
+
example(:get_follower) do
|
86
|
+
clients[:follower].follower.get(variables[:follower_id])
|
87
|
+
end
|
88
|
+
|
89
|
+
example(:update_follower) do
|
90
|
+
follower = Follower.first(:public_id => variables[:follower_id])
|
91
|
+
clients[:follower].follower.update(follower.public_id, follower.attributes.slice(:entity, :licenses).merge(:types => ['https://tent.io/types/post/essay/v0.1.0#full']))
|
92
|
+
end
|
93
|
+
|
94
|
+
example(:get_app) do
|
95
|
+
clients[:app].app.get(App.last.public_id)
|
96
|
+
end
|
97
|
+
|
98
|
+
example(:update_app) do
|
99
|
+
clients[:app].app.update(
|
100
|
+
App.last.public_id,
|
101
|
+
:name => "FooApp",
|
102
|
+
:description => "Does amazing foos with your data",
|
103
|
+
:url => "http://example.com",
|
104
|
+
:icon => "http://example.com/icon.png",
|
105
|
+
:redirect_uris => ["https://app.example.com/tent/callback"],
|
106
|
+
:scopes => {
|
107
|
+
:write_profile => "Uses an app profile section to describe foos",
|
108
|
+
:read_followings => "Calculates foos based on your followings",
|
109
|
+
:write_following => "Follow new users when you click"
|
110
|
+
}
|
111
|
+
)
|
112
|
+
end
|
113
|
+
|
114
|
+
example(:discovery) do
|
115
|
+
clients[:base].http.head('/')
|
116
|
+
end
|
117
|
+
|
118
|
+
example(:update_profile) do
|
119
|
+
clients[:auth].profile.update(
|
120
|
+
'https://tent.io/types/info/basic/v0.1.0',
|
121
|
+
:name => 'The Tentity',
|
122
|
+
:avatar_url => 'http://example.org/avatar.jpg',
|
123
|
+
:birthdate => '2012-08-23',
|
124
|
+
:location => 'The Internet',
|
125
|
+
:gender => 'Unknown',
|
126
|
+
:bio => Faker::Lorem.sentence
|
127
|
+
)
|
128
|
+
end
|
129
|
+
|
130
|
+
example(:create_post) do
|
131
|
+
clients[:auth].post.create(
|
132
|
+
:type => 'https://tent.io/types/post/status/v0.1.0',
|
133
|
+
:published_at => Time.now.to_i,
|
134
|
+
:permissions => { :public => true },
|
135
|
+
:licenses => ['http://creativecommons.org/licenses/by/3.0/'],
|
136
|
+
:content => {
|
137
|
+
:text => "Just landed.",
|
138
|
+
:location => {
|
139
|
+
:type => 'Point',
|
140
|
+
:coordinates => [50.923878, 4.028605]
|
141
|
+
}
|
142
|
+
}
|
143
|
+
).tap { |res| variables[:post_id] = res.body['id'] }
|
144
|
+
end
|
145
|
+
|
146
|
+
example(:create_post_with_attachments) do
|
147
|
+
clients[:auth].post.create(
|
148
|
+
{
|
149
|
+
:type => 'https://tent.io/types/post/photo/v0.1.0',
|
150
|
+
:published_at => Time.now.to_i,
|
151
|
+
:permissions => { :public => true },
|
152
|
+
:licenses => ['http://creativecommons.org/licenses/by/3.0/'],
|
153
|
+
:content => {
|
154
|
+
:caption => 'Some fake photos'
|
155
|
+
}
|
156
|
+
},
|
157
|
+
:attachments => [
|
158
|
+
{ :category => 'photos', :filename => 'fake_photo1.jpg', :data => 'Photo 1 data would go here', :type => 'image/jpeg' },
|
159
|
+
{ :category => 'photos', :filename => 'fake_photo2.jpg', :data => 'Photo 2 data would go here', :type => 'image/jpeg' },
|
160
|
+
]
|
161
|
+
)
|
162
|
+
end
|
163
|
+
|
164
|
+
example(:get_post_attachment) do
|
165
|
+
attachment = PostAttachment.last
|
166
|
+
clients[:auth].post.attachment.get(attachment.post.public_id, attachment.name, attachment.type)
|
167
|
+
end
|
168
|
+
|
169
|
+
example(:get_followings) do
|
170
|
+
clients[:auth].following.list
|
171
|
+
end
|
172
|
+
|
173
|
+
example(:get_following) do
|
174
|
+
clients[:auth].following.get(Following.last.public_id)
|
175
|
+
end
|
176
|
+
|
177
|
+
example(:delete_following) do
|
178
|
+
clients[:auth].following.delete(Following.last.public_id)
|
179
|
+
end
|
180
|
+
|
181
|
+
example(:get_followers) do
|
182
|
+
clients[:auth].follower.list
|
183
|
+
end
|
184
|
+
|
185
|
+
example(:get_posts) do
|
186
|
+
clients[:auth].post.list
|
187
|
+
end
|
188
|
+
|
189
|
+
example(:get_post) do
|
190
|
+
clients[:auth].post.get(variables[:post_id])
|
191
|
+
end
|
192
|
+
|
193
|
+
example(:follower_get_post) do
|
194
|
+
clients[:follower].post.get(variables[:post_id])
|
195
|
+
end
|
196
|
+
|
197
|
+
example(:follower_get_posts) do
|
198
|
+
clients[:follower].post.list
|
199
|
+
end
|
200
|
+
|
201
|
+
example(:delete_follower) do
|
202
|
+
clients[:follower].follower.delete(variables[:follower_id])
|
203
|
+
end
|
204
|
+
end
|
data/tent-apidoc.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |gem|
|
4
|
+
gem.name = "tent-apidoc"
|
5
|
+
gem.version = '0.0.1'
|
6
|
+
gem.authors = ["Jonathan Rudenberg"]
|
7
|
+
gem.email = ["jonathan@titanous.com"]
|
8
|
+
gem.description = "API examples for the Tent protocol documentation"
|
9
|
+
gem.summary = "API examples for the Tent protocol documentation"
|
10
|
+
gem.homepage = "http://tent.io"
|
11
|
+
|
12
|
+
gem.files = `git ls-files`.split($/)
|
13
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
14
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
|
17
|
+
gem.add_runtime_dependency 'tent-client'
|
18
|
+
gem.add_runtime_dependency 'tentd'
|
19
|
+
gem.add_runtime_dependency 'rack-test'
|
20
|
+
gem.add_runtime_dependency 'fabrication'
|
21
|
+
gem.add_runtime_dependency 'faker'
|
22
|
+
end
|
metadata
ADDED
@@ -0,0 +1,135 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: tent-apidoc
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Jonathan Rudenberg
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-09-20 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: tent-client
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: tentd
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rack-test
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: fabrication
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :runtime
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: faker
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
type: :runtime
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
description: API examples for the Tent protocol documentation
|
95
|
+
email:
|
96
|
+
- jonathan@titanous.com
|
97
|
+
executables:
|
98
|
+
- tent-apidoc
|
99
|
+
extensions: []
|
100
|
+
extra_rdoc_files: []
|
101
|
+
files:
|
102
|
+
- .gitignore
|
103
|
+
- Gemfile
|
104
|
+
- LICENSE.txt
|
105
|
+
- README.md
|
106
|
+
- Rakefile
|
107
|
+
- bin/tent-apidoc
|
108
|
+
- lib/tent-apidoc.rb
|
109
|
+
- lib/tent-apidoc/examples.rb
|
110
|
+
- tent-apidoc.gemspec
|
111
|
+
homepage: http://tent.io
|
112
|
+
licenses: []
|
113
|
+
post_install_message:
|
114
|
+
rdoc_options: []
|
115
|
+
require_paths:
|
116
|
+
- lib
|
117
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
118
|
+
none: false
|
119
|
+
requirements:
|
120
|
+
- - ! '>='
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: '0'
|
123
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
124
|
+
none: false
|
125
|
+
requirements:
|
126
|
+
- - ! '>='
|
127
|
+
- !ruby/object:Gem::Version
|
128
|
+
version: '0'
|
129
|
+
requirements: []
|
130
|
+
rubyforge_project:
|
131
|
+
rubygems_version: 1.8.23
|
132
|
+
signing_key:
|
133
|
+
specification_version: 3
|
134
|
+
summary: API examples for the Tent protocol documentation
|
135
|
+
test_files: []
|