14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
# File 'lib/stitches/api_generator.rb', line 14
def bootstrap_api
inject_into_file "Gemfile", after: /^gem ['"]rails['"].*$/ do"\ngem \"apitome\"\ngem \"responders\"\ngem \"rspec_api_documentation\", group: [ :development, :test ]\ngem \"capybara\", group: [ :development, :test ]\n GEM\n end\n inject_into_file \"config/routes.rb\", before: /^end/ do<<-ROUTES\nnamespace :api do\n scope module: :v1, constraints: Stitches::ApiVersionConstraint.new(1) do\nresource 'ping', only: [ :create ]\n# Add your V1 resources here\n end\n scope module: :v2, constraints: Stitches::ApiVersionConstraint.new(2) do\nresource 'ping', only: [ :create ]\n# This is here simply to validate that versioning is working\n# as well as for your client to be able to validate this as well.\n end\nend\napi_docs = Rack::Auth::Basic.new(Apitome::Engine ) do |_,password|\n password == ENV['HTTP_AUTH_PASSWORD']\nend\nmount api_docs, at: \"docs\"\n ROUTES\n end\n\n run 'bundle install'\n\n copy_file \"app/controllers/api.rb\"\n copy_file \"app/controllers/api/api_controller.rb\"\n copy_file \"app/controllers/api/v1.rb\"\n copy_file \"app/controllers/api/v2.rb\"\n copy_file \"app/controllers/api/v1/pings_controller.rb\"\n copy_file \"app/controllers/api/v2/pings_controller.rb\"\n copy_file \"app/models/api_client.rb\"\n copy_file \"config/initializers/stitches.rb\"\n copy_file \"lib/tasks/generate_api_key.rake\"\n template \"spec/features/api_spec.rb.erb\", \"spec/features/api_spec.rb\"\n copy_file \"spec/acceptance/ping_v1_spec.rb\", \"spec/acceptance/ping_v1_spec.rb\"\n\n run 'bundle install'\n\n migration_template \"db/migrate/enable_uuid_ossp_extension.rb\", \"db/migrate/enable_uuid_ossp_extension.rb\"\n sleep 1 # allow clock to tick so we get different numbers\n migration_template \"db/migrate/create_api_clients.rb\", \"db/migrate/create_api_clients.rb\"\n\n inject_into_file 'spec/rails_helper.rb', %q{\nconfig.include RSpec::Rails::RequestExampleGroup, type: :feature\n}, before: /^end/\n\n inject_into_file 'spec/rails_helper.rb', before: /^RSpec.configure/ do<<-REQUIRE\nrequire 'stitches/spec'\n REQUIRE\n end\n\n append_to_file 'spec/rails_helper.rb' do<<-RSPEC_API\nrequire 'rspec_api_documentation'\nRspecApiDocumentation.configure do |config|\nconfig.format = :json\nconfig.request_headers_to_include = %w(\n Accept\n Content-Type\n Authorization\n If-Modified-Since\n)\nconfig.response_headers_to_include = %w(\n Last-Modified\n ETag\n)\nconfig.api_name = \"YOUR SERVICE NAME HERE\"\nend\n RSPEC_API\n end\n run \"rails g apitome:install\"\n gsub_file 'config/initializers/apitome.rb', /config.mount_at = .*$/, \"config.mount_at = nil\"\n gsub_file 'config/initializers/apitome.rb', /config.title = .*$/, \"config.title = 'Service Documentation'\"\n\nend\n"
|