oak-api 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/LICENSE.txt +1 -1
- data/README.md +24 -37
- data/exe/oak +1 -1
- data/lib/oak/easter_egg.rb +7 -7
- data/lib/oak/errors.rb +2 -1
- data/lib/oak/monkey.rb +8 -0
- data/lib/oak/version.rb +1 -1
- data/lib/oak_api.rb +106 -25
- metadata +3 -5
- data/bin/console +0 -15
- data/bin/setup +0 -8
- data/lib/oak/api.rb +0 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b76688f0f340c45b69ee2ecd0a979d357fe5079d6e0c4af0e233d1dd63c1b499
|
4
|
+
data.tar.gz: 07aade4191b0334d2adde947bacc897cc27fe673593fbed84a06458da03aefef
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d2b05cb1a62d437db88eab0d4d229e981a3e5c8da10529c16092f84fd188f7a0bdfc277b55e85efaa0050ff6a79f2c2b79433bc360b5048f7c2e45c9058e9739
|
7
|
+
data.tar.gz: 58e207df921218b6deac9215f72736343ca8bda5d37a21fc48e4d1611cf5e3c143d9b911787ab6914cffb5c8f3b9e4d833c154709c02e85aaf483a756623b0b0
|
data/.gitignore
CHANGED
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -1,39 +1,26 @@
|
|
1
|
-
# Oak
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
1
|
+
# Oak API tool
|
2
|
+
|
3
|
+
This gem looks for your API key in the `OAK_API_KEY` shell variable.
|
4
|
+
|
5
|
+
After setting such variable let the magic begin:
|
6
|
+
|
7
|
+
```bash
|
8
|
+
# list available API endpoints
|
9
|
+
$ oak -l
|
10
|
+
["/api/docs/?",
|
11
|
+
"/api/blog/ids/?",
|
12
|
+
"/api/endpoints",
|
13
|
+
...
|
14
|
+
|
15
|
+
# get a blog post data
|
16
|
+
$ oak g blog/3
|
17
|
+
{"post_title"=>"Third Post",
|
18
|
+
"post_markdown"=>"Testing 3",
|
19
|
+
"post_slug"=>"third-post",
|
20
|
+
"post_draft"=>false,
|
21
|
+
"post_categories"=>"cook",
|
22
|
+
"post_created_at"=>"2021-03-13",
|
23
|
+
"post_prev"=>"second-post",
|
24
|
+
"post_next"=>"starting-the-oak-blog"}
|
13
25
|
```
|
14
26
|
|
15
|
-
And then execute:
|
16
|
-
|
17
|
-
$ bundle install
|
18
|
-
|
19
|
-
Or install it yourself as:
|
20
|
-
|
21
|
-
$ gem install oak-api
|
22
|
-
|
23
|
-
## Usage
|
24
|
-
|
25
|
-
TODO: Write usage instructions here
|
26
|
-
|
27
|
-
## Development
|
28
|
-
|
29
|
-
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
-
|
31
|
-
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
-
|
33
|
-
## Contributing
|
34
|
-
|
35
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/oak-api.
|
36
|
-
|
37
|
-
## License
|
38
|
-
|
39
|
-
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/exe/oak
CHANGED
data/lib/oak/easter_egg.rb
CHANGED
@@ -2,13 +2,13 @@ require 'zlib'
|
|
2
2
|
|
3
3
|
module Oak
|
4
4
|
OakString = <<~tree
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
5
|
+
eJyNUrFqwzAQ3fULXQ4tbsGSWzxmTCMO2uKhhlBqkBGCdAmGzv74PsVWLFsk
|
6
|
+
9EDI3Hv37t1ZgjZhS1XIGL1SWqxgoAnXlqVS1KWUspgRpYKCN1P6KeFUOFpJ
|
7
|
+
dhMpUiqx1ggy7CBlvZFKB2NijSMVeuBLSjjV1k6Ex9xqjD7O00Nwwu18lthF
|
8
|
+
JzMDV68KdjBhrdaple4CYxYNAvdKezbyOgj2FxQAEzET+QSLEUBg3mRIgJin
|
9
|
+
9dibkZfRyMyXqooevl929a6uz3Q8vO+bjwMyz+dtQXdDZAx3klvU2oZa3oiN
|
10
|
+
/1TJxI5N8/oZte6pUJcMvllLda9uNWz61Jbw4Los2+V2tDd+dPjj22aROlyJ
|
11
|
+
bDyP7NoVeRBw8BVWgmlKtAUJLP4ZYAAv7O13OJ3AEH+N0q0z
|
12
12
|
tree
|
13
13
|
.delete("\s")
|
14
14
|
|
data/lib/oak/errors.rb
CHANGED
data/lib/oak/monkey.rb
ADDED
data/lib/oak/version.rb
CHANGED
data/lib/oak_api.rb
CHANGED
@@ -2,46 +2,127 @@ $LOAD_PATH.unshift __dir__
|
|
2
2
|
|
3
3
|
# stdlib
|
4
4
|
require 'optparse'
|
5
|
+
require 'net/http'
|
6
|
+
require 'json'
|
5
7
|
|
6
8
|
# internal
|
7
|
-
require 'oak/api'
|
8
9
|
require 'oak/version'
|
10
|
+
require 'oak/monkey'
|
9
11
|
require 'oak/easter_egg'
|
10
12
|
|
11
13
|
module Oak
|
12
|
-
def self.
|
13
|
-
|
14
|
+
def self.go(args)
|
15
|
+
Oak::Request.new(args).go
|
14
16
|
end
|
15
17
|
|
16
|
-
class
|
17
|
-
|
18
|
-
options = {}
|
18
|
+
class Request
|
19
|
+
DEFAULT_HEADERS = {'authorization' => ENV['OAK_API_KEY']}
|
19
20
|
|
20
|
-
|
21
|
-
|
22
|
-
opts.banner = "Usage: #{opts.program_name} [options]"
|
21
|
+
class HTTP
|
22
|
+
attr_reader :verb, :uri, :headers, :body
|
23
23
|
|
24
|
-
|
25
|
-
opts.separator = "Options:"
|
24
|
+
VERBS = { g: :get, p: :post, c: :patch, d: :delete }
|
26
25
|
|
27
|
-
|
28
|
-
|
29
|
-
|
26
|
+
def initialize(args, base_url, api_version, headers, debug=nil)
|
27
|
+
@verb = args.shift.to_sym
|
28
|
+
@uri = URI("#{base_url}/api/#{api_version}/#{args.shift}")
|
29
|
+
@body = args.shift
|
30
|
+
@verb = VERBS[@verb] || @verb
|
31
|
+
@headers = headers
|
32
|
+
raise UnknownHTTPVerb unless VERBS.values.include?(@verb)
|
33
|
+
end
|
30
34
|
|
31
|
-
|
32
|
-
|
33
|
-
|
35
|
+
def set_request
|
36
|
+
@req = Net::HTTP.const_get(verb.to_s.capitalize).new(uri, headers)
|
37
|
+
@req.body = body
|
38
|
+
@req
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
attr_reader :options, :base_url, :args, :debug, :headers
|
43
|
+
|
44
|
+
def initialize(args)
|
45
|
+
@options = Options.parse(args)
|
46
|
+
@args = args
|
47
|
+
@base_url = development? ? 'http://localhost:3000' : 'https://oak.software'
|
48
|
+
@options[:headers] = @options[:headers].to_h.merge({'authorization' => ENV['OAK_API_KEY_DEVEL']}) if development?
|
49
|
+
@headers = DEFAULT_HEADERS.merge(@options[:headers].to_h)
|
50
|
+
@debug = @options[:debug]
|
51
|
+
info self if @debug
|
52
|
+
end
|
53
|
+
|
54
|
+
def development?
|
55
|
+
@options[:environment] == 'development'
|
56
|
+
end
|
57
|
+
|
58
|
+
def go
|
59
|
+
if @options[:list]
|
60
|
+
args.unshift(?g, "endpoints")
|
61
|
+
end
|
62
|
+
|
63
|
+
req = HTTP.new(args, base_url, options[:api], headers, debug).set_request
|
64
|
+
|
65
|
+
info [req, req.uri, req.uri.host, req.uri.port, req.body] if debug
|
66
|
+
info req.to_hash if debug
|
67
|
+
|
68
|
+
http = Net::HTTP.new(req.uri.host, req.uri.port)
|
69
|
+
http.use_ssl = true unless development?
|
70
|
+
res = http.request(req)
|
71
|
+
|
72
|
+
puts res.body
|
73
|
+
end
|
74
|
+
|
75
|
+
class Options
|
76
|
+
def self.parse(args)
|
77
|
+
options = {}
|
78
|
+
|
79
|
+
OptionParser.new do |opts|
|
80
|
+
opts.program_name = 'oak-api'
|
81
|
+
opts.banner = "Usage: #{opts.program_name} [options] [http_verb] [endpoint] [http_body]"
|
82
|
+
|
83
|
+
opts.separator ""
|
84
|
+
opts.separator "Options:"
|
85
|
+
|
86
|
+
opts.on("-d", "--debug", "Enable debug mode") do |v|
|
87
|
+
options[:debug] = v
|
88
|
+
end
|
89
|
+
|
90
|
+
opts.on("-e", "--environment=ENV", "Enable debug mode ") do |v|
|
91
|
+
options[:environment] = v
|
92
|
+
end
|
93
|
+
|
94
|
+
opts.on("-l", "--list", "List API endpoints") do |v=x|
|
95
|
+
options[:list] = v
|
96
|
+
end
|
97
|
+
|
98
|
+
opts.on_tail("-a", "--api=VERSION", "Target a specific API version (defaults to latest)") do |v|
|
99
|
+
options[:api] = v
|
100
|
+
end
|
101
|
+
|
102
|
+
opts.on_tail("-H", "--headers=HEADERS", "HEADERS is a JSON string with HTTP headers") do |v|
|
103
|
+
options[:headers] = JSON.parse(v)
|
104
|
+
end
|
105
|
+
|
106
|
+
opts.on("-o", "--output=NAME", "Specify output file name") do |v|
|
107
|
+
options[:output] = v
|
108
|
+
end
|
109
|
+
|
110
|
+
opts.on("-t", "--tree", "Print a welcome message") do |v|
|
111
|
+
Oak.greetings
|
112
|
+
abort
|
113
|
+
end
|
34
114
|
|
35
|
-
|
36
|
-
|
37
|
-
|
115
|
+
opts.on_tail("-h", "--help", "Print help", "something else") do |v|
|
116
|
+
abort opts.to_s
|
117
|
+
end
|
38
118
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
119
|
+
opts.on_tail("-v", "--version", "Print version") do |v|
|
120
|
+
abort "#{opts.program_name} #{VERSION}"
|
121
|
+
end
|
122
|
+
end.parse!(args)
|
43
123
|
|
44
|
-
|
124
|
+
options
|
125
|
+
end
|
45
126
|
end
|
46
127
|
end
|
47
128
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: oak-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Oak Software
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-03-
|
11
|
+
date: 2021-03-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: byebug
|
@@ -178,12 +178,10 @@ files:
|
|
178
178
|
- LICENSE.txt
|
179
179
|
- README.md
|
180
180
|
- Rakefile
|
181
|
-
- bin/console
|
182
|
-
- bin/setup
|
183
181
|
- exe/oak
|
184
|
-
- lib/oak/api.rb
|
185
182
|
- lib/oak/easter_egg.rb
|
186
183
|
- lib/oak/errors.rb
|
184
|
+
- lib/oak/monkey.rb
|
187
185
|
- lib/oak/version.rb
|
188
186
|
- lib/oak_api.rb
|
189
187
|
- oak-api.gemspec
|
data/bin/console
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# frozen_string_literal: true
|
3
|
-
|
4
|
-
require "bundler/setup"
|
5
|
-
require "oak/api"
|
6
|
-
|
7
|
-
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
-
# with your gem easier. You can also use a different console, if you like.
|
9
|
-
|
10
|
-
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
-
# require "pry"
|
12
|
-
# Pry.start
|
13
|
-
|
14
|
-
require "irb"
|
15
|
-
IRB.start(__FILE__)
|
data/bin/setup
DELETED