atum 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +16 -0
- data/.rspec +2 -0
- data/.rubocop.yml +9 -0
- data/.rubocop_todo.yml +25 -0
- data/.travis.yml +9 -0
- data/Appraisals +9 -0
- data/CHANGELOG.md +5 -0
- data/CONTRIBUTING.md +9 -0
- data/CONTRIBUTORS.md +15 -0
- data/Gemfile +4 -0
- data/Guardfile +23 -0
- data/LICENSE.txt +22 -0
- data/README.md +95 -0
- data/Rakefile +13 -0
- data/TODO +3 -0
- data/atum.gemspec +37 -0
- data/bin/atum +41 -0
- data/circle.yml +7 -0
- data/gemfiles/faraday_0.8.9.gemfile +8 -0
- data/gemfiles/faraday_0.9.gemfile +8 -0
- data/lib/atum.rb +15 -0
- data/lib/atum/core.rb +13 -0
- data/lib/atum/core/client.rb +45 -0
- data/lib/atum/core/errors.rb +20 -0
- data/lib/atum/core/link.rb +77 -0
- data/lib/atum/core/paginator.rb +32 -0
- data/lib/atum/core/request.rb +55 -0
- data/lib/atum/core/resource.rb +15 -0
- data/lib/atum/core/response.rb +53 -0
- data/lib/atum/core/schema.rb +12 -0
- data/lib/atum/core/schema/api_schema.rb +62 -0
- data/lib/atum/core/schema/link_schema.rb +121 -0
- data/lib/atum/core/schema/parameter.rb +27 -0
- data/lib/atum/core/schema/parameter_choice.rb +28 -0
- data/lib/atum/core/schema/resource_schema.rb +51 -0
- data/lib/atum/generation.rb +15 -0
- data/lib/atum/generation/erb_context.rb +17 -0
- data/lib/atum/generation/errors.rb +6 -0
- data/lib/atum/generation/generator_link.rb +39 -0
- data/lib/atum/generation/generator_resource.rb +31 -0
- data/lib/atum/generation/generator_service.rb +73 -0
- data/lib/atum/generation/generators/base_generator.rb +57 -0
- data/lib/atum/generation/generators/client_generator.rb +16 -0
- data/lib/atum/generation/generators/module_generator.rb +17 -0
- data/lib/atum/generation/generators/resource_generator.rb +23 -0
- data/lib/atum/generation/generators/views/client.erb +26 -0
- data/lib/atum/generation/generators/views/module.erb +104 -0
- data/lib/atum/generation/generators/views/resource.erb +33 -0
- data/lib/atum/generation/options_parameter.rb +12 -0
- data/lib/atum/version.rb +3 -0
- data/spec/atum/core/client_spec.rb +26 -0
- data/spec/atum/core/errors_spec.rb +19 -0
- data/spec/atum/core/link_spec.rb +80 -0
- data/spec/atum/core/paginator_spec.rb +72 -0
- data/spec/atum/core/request_spec.rb +110 -0
- data/spec/atum/core/resource_spec.rb +66 -0
- data/spec/atum/core/response_spec.rb +127 -0
- data/spec/atum/core/schema/api_schema_spec.rb +49 -0
- data/spec/atum/core/schema/link_schema_spec.rb +91 -0
- data/spec/atum/core/schema/parameter_choice_spec.rb +40 -0
- data/spec/atum/core/schema/parameter_spec.rb +24 -0
- data/spec/atum/core/schema/resource_schema_spec.rb +24 -0
- data/spec/atum/generation/generator_link_spec.rb +62 -0
- data/spec/atum/generation/generator_resource_spec.rb +44 -0
- data/spec/atum/generation/generator_service_spec.rb +41 -0
- data/spec/atum/generation/generators/base_generator_spec.rb +75 -0
- data/spec/atum/generation/generators/client_generator_spec.rb +30 -0
- data/spec/atum/generation/generators/module_generator_spec.rb +37 -0
- data/spec/atum/generation/generators/resource_generator_spec.rb +46 -0
- data/spec/atum/generation/options_parameter_spec.rb +27 -0
- data/spec/fixtures/fruity_schema.json +161 -0
- data/spec/fixtures/sample_schema.json +139 -0
- data/spec/integration/client_integration_spec.rb +91 -0
- data/spec/spec_helper.rb +11 -0
- metadata +303 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c7c37a12fcdbcf41017d8e62a6c75f8669bdeaf3
|
4
|
+
data.tar.gz: 5434d95df87ef0963ff3515a6e69b75e4104fa5b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: aa8d0da68c90f34cfb93cf9b7dcf3782186584e2e523f3695e8f4e2356d94bfaf6c1c353d26b0de0decf08c02abe748918fc33e27157c9aaf73783f0a6087aad
|
7
|
+
data.tar.gz: 6e2576f7ff46687e1208fae1ee4eee882d08fc52f34ecb55af8b57113eb18eac977db6bcd9580aa3076f4aab27429b15354dfe0dfe065bb3cac3d29704eb041b
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/.rubocop_todo.yml
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# This configuration was generated by `rubocop --auto-gen-config`
|
2
|
+
# on 2014-09-29 16:05:25 +0100 using RuboCop version 0.26.1.
|
3
|
+
# The point is for the user to remove these configuration records
|
4
|
+
# one by one as the offenses are removed from the code base.
|
5
|
+
# Note that changes in the inspected code, or installation of new
|
6
|
+
# versions of RuboCop, may require this file to be generated again.
|
7
|
+
|
8
|
+
# Offense count: 8
|
9
|
+
# Configuration parameters: AllowURI, URISchemes.
|
10
|
+
Metrics/LineLength:
|
11
|
+
Max: 90
|
12
|
+
|
13
|
+
# Configuration parameters: CountComments.
|
14
|
+
Metrics/MethodLength:
|
15
|
+
Max: 15
|
16
|
+
|
17
|
+
# Offense count: 16
|
18
|
+
Style/Documentation:
|
19
|
+
Enabled: false
|
20
|
+
|
21
|
+
# Offense count: 1
|
22
|
+
# Cop supports --auto-correct.
|
23
|
+
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
24
|
+
Style/SignalException:
|
25
|
+
Enabled: false
|
data/.travis.yml
ADDED
data/Appraisals
ADDED
data/CHANGELOG.md
ADDED
data/CONTRIBUTING.md
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
## Contributing
|
2
|
+
|
3
|
+
Atum is a fork of [Heroics](https://github.com/interagent/heroics). It is
|
4
|
+
adapted to consume [JSON API](http://jsonapi.org)-compliant APIs, and output
|
5
|
+
generated clients into a folder rather than a single file.
|
6
|
+
|
7
|
+
We welcome contributions to Atum and discussion about its design and
|
8
|
+
functionality. Please open an issue or pull request on this repository to
|
9
|
+
propose a change.
|
data/CONTRIBUTORS.md
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# Contributors
|
2
|
+
## Original [Heroics](https://github.com/interagent/heroics) contributors:
|
3
|
+
|
4
|
+
Andrea Salicetti <andrea.salicetti@gmail.com>
|
5
|
+
Jamu Kakar <jkakar@kakar.ca>
|
6
|
+
Jonathan Roes <jroes@jroes.net>
|
7
|
+
Mark Fine <mark.fine@gmail.com>
|
8
|
+
Mark McGranaghan <mmcgrana@gmail.com>
|
9
|
+
Neil Middleton <neil@heroku.com>
|
10
|
+
Wesley Beary <geemus+github@gmail.com>
|
11
|
+
|
12
|
+
## Atum contributors
|
13
|
+
|
14
|
+
Pete Hamilton <peterejhamilton@gmail.com>
|
15
|
+
Isaac Seymour <i.seymour@oxon.org>
|
data/Gemfile
ADDED
data/Guardfile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# A sample Guardfile
|
2
|
+
# More info at https://github.com/guard/guard#readme
|
3
|
+
|
4
|
+
# Note: The cmd option is now required due to the increasing number of ways
|
5
|
+
# rspec may be run, below are examples of the most common uses.
|
6
|
+
# * bundler: 'bundle exec rspec'
|
7
|
+
# * bundler binstubs: 'bin/rspec'
|
8
|
+
# * spring: 'bin/rsspec' (This will use spring if running and you have
|
9
|
+
# installed the spring binstubs per the docs)
|
10
|
+
# * zeus: 'zeus rspec' (requires the server to be started separetly)
|
11
|
+
# * 'just' rspec: 'rspec'
|
12
|
+
guard :rspec, cmd: 'bundle exec rspec' do
|
13
|
+
watch(%r{^spec/.+_spec\.rb$})
|
14
|
+
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
|
15
|
+
watch(%r{^lib/.+\.(rb|erb)$}) { 'spec/integration' }
|
16
|
+
watch('spec/spec_helper.rb') { 'spec' }
|
17
|
+
end
|
18
|
+
|
19
|
+
guard :rubocop do
|
20
|
+
watch(%r{.+\.rb$})
|
21
|
+
watch(%r{(?:.+/)?\.rubocop\.yml$}) { |m| File.dirname(m[0]) }
|
22
|
+
watch(%r{(?:.+/)?\.rubocop\_todo\.yml$}) { |m| File.dirname(m[0]) }
|
23
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 geemus
|
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
@@ -0,0 +1,95 @@
|
|
1
|
+
# Atum
|
2
|
+
|
3
|
+
Ruby HTTP client generator for JSON APIs represented with JSON schema, forked
|
4
|
+
from [Heroics](https://github.com/interagent/heroics).
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
gem 'atum'
|
11
|
+
|
12
|
+
And then execute:
|
13
|
+
|
14
|
+
$ bundle install
|
15
|
+
|
16
|
+
Or install it yourself as:
|
17
|
+
|
18
|
+
$ gem install atum
|
19
|
+
|
20
|
+
## Usage
|
21
|
+
|
22
|
+
### Generating a client
|
23
|
+
|
24
|
+
Atum generates an HTTP client from a JSON schema that describes your JSON
|
25
|
+
API. Look at [prmd](https://github.com/interagent/prmd) for tooling to help
|
26
|
+
write a JSON schema. When you have a JSON schema prepared you can generate a
|
27
|
+
client for your API:
|
28
|
+
|
29
|
+
```
|
30
|
+
$ atum MyApp schema.json https://api.myapp.com
|
31
|
+
```
|
32
|
+
|
33
|
+
This will output a client into a new `my_app` folder, in the current directory,
|
34
|
+
unless that folder exists.
|
35
|
+
|
36
|
+
### Passing custom headers
|
37
|
+
|
38
|
+
If your client needs to pass custom headers with each request these can be
|
39
|
+
specified using `-H`:
|
40
|
+
|
41
|
+
```
|
42
|
+
atum -H "Accept: application/vnd.myapp+json; version=3" MyApp schema.json https://api.myapp.com
|
43
|
+
```
|
44
|
+
|
45
|
+
Pass multiple `-H` options if you need more than one custom header.
|
46
|
+
|
47
|
+
### Generating API documentation
|
48
|
+
|
49
|
+
The generated client has [Yard](http://yardoc.org/)-compatible docstrings.
|
50
|
+
You can generate documentation using `yard`:
|
51
|
+
|
52
|
+
__not convinced this is actually correct now it's a directory?__
|
53
|
+
```
|
54
|
+
yard doc -m markdown my_app
|
55
|
+
```
|
56
|
+
|
57
|
+
This will generate HTML in the `docs` directory. Note that Yard creates an
|
58
|
+
`_index.html` page won't be served by Jekyll on GitHub Pages. Add a
|
59
|
+
`.nojekyll` file to your project to prevent GitHub from passing the content
|
60
|
+
through Jekyll.
|
61
|
+
|
62
|
+
### Handling failures
|
63
|
+
|
64
|
+
The client uses [Faraday](https://github.com/lostisland/faraday) for doing the
|
65
|
+
HTTP requests, which chooses the most appropriate library for the runtime and
|
66
|
+
other cool things. As such, you may encounter Faraday errors, which are mostly
|
67
|
+
subclasses of `Faraday::ClientError`.
|
68
|
+
|
69
|
+
```ruby
|
70
|
+
begin
|
71
|
+
client.app.create('name' => 'example')
|
72
|
+
rescue Faraday::ClientError => error
|
73
|
+
puts error
|
74
|
+
end
|
75
|
+
```
|
76
|
+
|
77
|
+
## Supporting Ruby < 2.0.0
|
78
|
+
This gem only directly supports Ruby >= 2.0.0 out of the box due to our use of
|
79
|
+
Enumerable::Lazy for lazy loading of paginated API resources.
|
80
|
+
|
81
|
+
However, support for previous ruby versions can be added using a gem such as
|
82
|
+
[backports](https://github.com/marcandre/backports).
|
83
|
+
|
84
|
+
1. Add backports to your Gemfile
|
85
|
+
```gem 'backports'```
|
86
|
+
2. Require lazy enumerables
|
87
|
+
```require 'backports/2.0.0/enumerable/lazy.rb'```
|
88
|
+
|
89
|
+
## Contributing
|
90
|
+
|
91
|
+
1. [Fork the repository](https://github.com/isaacseymour/atum/fork)
|
92
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
93
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
94
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
95
|
+
5. Create new pull request
|
data/Rakefile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler/setup'
|
3
|
+
require 'bundler/gem_tasks'
|
4
|
+
require 'rake/testtask'
|
5
|
+
|
6
|
+
Rake::TestTask.new do |task|
|
7
|
+
task.verbose = true
|
8
|
+
task.ruby_opts << '-r turn/autorun'
|
9
|
+
task.ruby_opts << '-I test'
|
10
|
+
task.test_files = FileList['test/**/*_test.rb', 'test/**/*_spec.rb']
|
11
|
+
end
|
12
|
+
|
13
|
+
task default: :test
|
data/TODO
ADDED
data/atum.gemspec
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
lib = File.expand_path('../lib', __FILE__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
|
6
|
+
require 'atum/version'
|
7
|
+
|
8
|
+
Gem::Specification.new do |spec|
|
9
|
+
spec.name = 'atum'
|
10
|
+
spec.version = Atum::VERSION
|
11
|
+
spec.authors = %w(isaacseymour petehamilton)
|
12
|
+
spec.email = ['i.seymour@oxon.org', 'peterejhamilton@gmail.com']
|
13
|
+
spec.description = 'A Ruby client generator for JSON APIs described with a JSON schema'
|
14
|
+
spec.summary = 'A Ruby client generator for JSON APIs described with a JSON schema'
|
15
|
+
spec.homepage = 'https://github.com/gocardless/atum'
|
16
|
+
spec.license = 'MIT'
|
17
|
+
|
18
|
+
spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
|
19
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
20
|
+
spec.test_files = spec.files.grep('^(test|spec|features)/')
|
21
|
+
spec.require_paths = ['lib']
|
22
|
+
|
23
|
+
spec.add_development_dependency 'bundler', '~> 1.6'
|
24
|
+
spec.add_development_dependency 'rspec', '~> 3.1'
|
25
|
+
spec.add_development_dependency 'rubocop', '~> 0.26'
|
26
|
+
spec.add_development_dependency 'guard', '~> 2.6'
|
27
|
+
spec.add_development_dependency 'guard-rspec', '~> 4.3'
|
28
|
+
spec.add_development_dependency 'guard-rubocop', '~> 1.1'
|
29
|
+
spec.add_development_dependency 'webmock', '~> 1.18'
|
30
|
+
spec.add_development_dependency 'pry-nav', '~> 0.2'
|
31
|
+
spec.add_development_dependency 'yard', '~> 0.8'
|
32
|
+
spec.add_development_dependency 'appraisal', '~> 1.0.2'
|
33
|
+
|
34
|
+
spec.add_dependency 'erubis', '~> 2.7'
|
35
|
+
spec.add_dependency 'faraday', '>= 0.8.9'
|
36
|
+
spec.add_dependency 'activesupport', '~> 4.1'
|
37
|
+
end
|
data/bin/atum
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'optparse'
|
4
|
+
require 'atum'
|
5
|
+
|
6
|
+
options = { headers: {} }
|
7
|
+
|
8
|
+
option_parser = OptionParser.new do |opts|
|
9
|
+
opts.banner = 'Usage: atum module_name schema_filename url'
|
10
|
+
|
11
|
+
opts.on('-h', '--help', 'Display this screen') do
|
12
|
+
puts opts
|
13
|
+
exit
|
14
|
+
end
|
15
|
+
|
16
|
+
opts.on('-v', '--version', 'Display the version atum is running at') do
|
17
|
+
puts Atum::VERSION
|
18
|
+
exit
|
19
|
+
end
|
20
|
+
|
21
|
+
opts.on('-H', '--header [HEADER]',
|
22
|
+
'Include header with all requests') do |header|
|
23
|
+
header_key, header_value, _ = header.split(':', 0)
|
24
|
+
options[:headers][header_key] = header_value.strip
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
option_parser.parse!
|
29
|
+
|
30
|
+
if ARGV.length != 3
|
31
|
+
puts option_parser
|
32
|
+
exit
|
33
|
+
end
|
34
|
+
|
35
|
+
options = { default_headers: options[:headers] }
|
36
|
+
|
37
|
+
module_name, schema_filename, url = ARGV
|
38
|
+
|
39
|
+
generator = Atum::Generation::GeneratorService.new(module_name, schema_filename,
|
40
|
+
url, options)
|
41
|
+
generator.generate_files
|
data/circle.yml
ADDED
data/lib/atum.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'base64'
|
2
|
+
require 'erubis'
|
3
|
+
require 'faraday'
|
4
|
+
require 'json'
|
5
|
+
require 'uri'
|
6
|
+
require 'zlib'
|
7
|
+
require 'active_support/inflector'
|
8
|
+
|
9
|
+
# Atum is an HTTP client for an API described by a JSON schema.
|
10
|
+
module Atum
|
11
|
+
end
|
12
|
+
|
13
|
+
require 'atum/version'
|
14
|
+
require 'atum/core'
|
15
|
+
require 'atum/generation'
|
data/lib/atum/core.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
module Atum
|
2
|
+
module Core
|
3
|
+
end
|
4
|
+
end
|
5
|
+
|
6
|
+
require 'atum/core/errors'
|
7
|
+
require 'atum/core/client'
|
8
|
+
require 'atum/core/resource'
|
9
|
+
require 'atum/core/link'
|
10
|
+
require 'atum/core/request'
|
11
|
+
require 'atum/core/response'
|
12
|
+
require 'atum/core/paginator'
|
13
|
+
require 'atum/core/schema'
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module Atum
|
2
|
+
module Core
|
3
|
+
class Client
|
4
|
+
class << self
|
5
|
+
# Create an HTTP client from a schema.
|
6
|
+
#
|
7
|
+
# @param schema [ApiSchema] The schema to build an HTTP client for.
|
8
|
+
# @param url [String] The URL the generated client should use
|
9
|
+
# @param options [Hash] Configuration for links. Possible keys include:
|
10
|
+
# - default_headers: Optionally, a set of headers to include in every
|
11
|
+
# request made by the client. Default is no custom headers.
|
12
|
+
# @return [Client] A client with resources and links from the schema
|
13
|
+
def client_from_schema(api_schema, url, options = {})
|
14
|
+
resources = {}
|
15
|
+
api_schema.resource_schemas.each do |resource_schema|
|
16
|
+
links_hash = {}
|
17
|
+
resource_schema.link_schemas.each do |link_schema|
|
18
|
+
links_hash[link_schema.name] = Link.new(url, link_schema, options)
|
19
|
+
end
|
20
|
+
resources[resource_schema.name] = Resource.new(links_hash)
|
21
|
+
end
|
22
|
+
|
23
|
+
new(resources, url)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
# @param resources [Hash<String,Resource>] Methods names -> Resources
|
28
|
+
# @param url [String] The URL used by this client.
|
29
|
+
def initialize(resources, url)
|
30
|
+
@url = url
|
31
|
+
resources.each do |name, resource|
|
32
|
+
define_singleton_method(name) { resource }
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def inspect
|
37
|
+
url = URI.parse(@url)
|
38
|
+
url.password = 'REDACTED' unless url.password.nil?
|
39
|
+
"#<Atum::Client url=\"#{url}\">"
|
40
|
+
end
|
41
|
+
|
42
|
+
alias_method :to_s, :inspect
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|