heroics 0.0.8 → 0.0.9
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.
- checksums.yaml +4 -4
- data/CONTRIBUTING.md +5 -0
- data/CONTRIBUTORS.md +7 -0
- data/README.md +6 -10
- data/lib/heroics/client.rb +5 -1
- data/lib/heroics/version.rb +1 -1
- data/lib/heroics/views/client.erb +43 -40
- data/test/client_test.rb +3 -2
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2cbe04afb5b59a688197d7b89d4cae7988681347
|
4
|
+
data.tar.gz: 6e5f0fdf59a60dbf4547befbf281d2e00a0affc3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5a4272a774738e39cb87a6af8cbdbbed75adc043ee6fdd9bec905481f54d200c13e4ae51b97c88d3a29f282616332a917af81aa9d196c38a3124f41c07144926
|
7
|
+
data.tar.gz: 33ba2968b0cc98b836ecb1a4c5a177986b448c4da43578e4404c0a6915ab73bfe6e4fc45079e597ee9fad6e41ddcffddfdf8635a9244b36b49b31d7fb1e4574d
|
data/CONTRIBUTING.md
ADDED
data/CONTRIBUTORS.md
ADDED
data/README.md
CHANGED
@@ -27,7 +27,7 @@ JSON schema. When you have a JSON schema prepared you can generate a client
|
|
27
27
|
for your API:
|
28
28
|
|
29
29
|
```
|
30
|
-
bin/heroics-
|
30
|
+
bin/heroics-generate MyApp schema.json https://api.myapp.com > client.rb
|
31
31
|
```
|
32
32
|
|
33
33
|
### Passing custom headers
|
@@ -36,7 +36,7 @@ If your client needs to pass custom headers with each request these can be
|
|
36
36
|
specified using `-H`:
|
37
37
|
|
38
38
|
```
|
39
|
-
|
39
|
+
heroics-generate \
|
40
40
|
-H "Accept: application/vnd.myapp+json; version=3" \
|
41
41
|
MyApp \
|
42
42
|
schema.json \
|
@@ -52,7 +52,7 @@ default, this data is cached in memory and is only used during the lifetime of
|
|
52
52
|
a single instance. You can specify a directory for cache data:
|
53
53
|
|
54
54
|
```
|
55
|
-
|
55
|
+
heroics-generate \
|
56
56
|
-c "~/.heroics/myapp" \
|
57
57
|
MyApp \
|
58
58
|
schema.json \
|
@@ -73,13 +73,9 @@ yard doc -m markdown client.rb
|
|
73
73
|
```
|
74
74
|
|
75
75
|
This will generate HTML in the `docs` directory. Note that Yard creates an
|
76
|
-
`_index.html` page
|
77
|
-
|
78
|
-
|
79
|
-
```
|
80
|
-
cd docs
|
81
|
-
sed -e 's/_index\.html/index\.html/g' -i `grep _index.html * -rl`
|
82
|
-
```
|
76
|
+
`_index.html` page won't be served by Jekyll on GitHub Pages. Add a
|
77
|
+
`.nojekyll` file to your project to prevent GitHub from passing the content
|
78
|
+
through Jekyll.
|
83
79
|
|
84
80
|
### Handling failures
|
85
81
|
|
data/lib/heroics/client.rb
CHANGED
@@ -27,7 +27,11 @@ module Heroics
|
|
27
27
|
|
28
28
|
# Get a simple human-readable representation of this client instance.
|
29
29
|
def inspect
|
30
|
-
|
30
|
+
url = URI.parse(@url)
|
31
|
+
unless url.password.nil?
|
32
|
+
url.password = 'REDACTED'
|
33
|
+
end
|
34
|
+
"#<Heroics::Client url=\"#{url.to_s}\">"
|
31
35
|
end
|
32
36
|
alias to_s inspect
|
33
37
|
end
|
data/lib/heroics/version.rb
CHANGED
@@ -11,47 +11,30 @@ require 'uri'
|
|
11
11
|
module <%= @module_name %>
|
12
12
|
# Get a Client configured to use HTTP Basic authentication.
|
13
13
|
#
|
14
|
-
# @param
|
15
|
-
# @param
|
16
|
-
#
|
17
|
-
#
|
14
|
+
# @param api_key [String] The API key to use when connecting.
|
15
|
+
# @param options [Hash<Symbol,String>] Optionally, custom settings
|
16
|
+
# to use with the client. Allowed options are `default_headers`,
|
17
|
+
# `cache` and `host`.
|
18
18
|
# @return [Client] A client configured to use the API with HTTP Basic
|
19
19
|
# authentication.
|
20
|
-
def self.connect(
|
21
|
-
|
22
|
-
url
|
23
|
-
|
24
|
-
default_headers = <%= @default_headers %>
|
25
|
-
unless headers.nil?
|
26
|
-
default_headers.merge!(headers)
|
27
|
-
end
|
28
|
-
cache = <%= @cache %>
|
29
|
-
options = {
|
30
|
-
default_headers: default_headers,
|
31
|
-
cache: cache
|
32
|
-
}
|
33
|
-
client = Heroics.client_from_schema(SCHEMA, url.to_s, options)
|
20
|
+
def self.connect(api_key, options=nil)
|
21
|
+
options = custom_options(options)
|
22
|
+
url = "https://:#{api_key}@#{options[:host]}"
|
23
|
+
client = Heroics.client_from_schema(SCHEMA, url, options)
|
34
24
|
Client.new(client)
|
35
25
|
end
|
36
26
|
|
37
27
|
# Get a Client configured to use OAuth authentication.
|
38
28
|
#
|
39
29
|
# @param oauth_token [String] The OAuth token to use with the API.
|
40
|
-
# @param
|
41
|
-
#
|
30
|
+
# @param options [Hash<Symbol,String>] Optionally, custom settings
|
31
|
+
# to use with the client. Allowed options are `default_headers`,
|
32
|
+
# `cache` and `host`.
|
42
33
|
# @return [Client] A client configured to use the API with OAuth
|
43
34
|
# authentication.
|
44
|
-
def self.connect_oauth(oauth_token,
|
35
|
+
def self.connect_oauth(oauth_token, options=nil)
|
36
|
+
options = custom_options(options)
|
45
37
|
url = "<%= @url %>"
|
46
|
-
default_headers = <%= @default_headers %>
|
47
|
-
unless headers.nil?
|
48
|
-
default_headers.merge!(headers)
|
49
|
-
end
|
50
|
-
cache = <%= @cache %>
|
51
|
-
options = {
|
52
|
-
default_headers: default_headers,
|
53
|
-
cache: cache
|
54
|
-
}
|
55
38
|
client = Heroics.oauth_client_from_schema(oauth_token, SCHEMA, url, options)
|
56
39
|
Client.new(client)
|
57
40
|
end
|
@@ -59,25 +42,45 @@ module <%= @module_name %>
|
|
59
42
|
# Get a Client configured to use Token authentication.
|
60
43
|
#
|
61
44
|
# @param token [String] The token to use with the API.
|
62
|
-
# @param
|
63
|
-
#
|
45
|
+
# @param options [Hash<Symbol,String>] Optionally, custom settings
|
46
|
+
# to use with the client. Allowed options are `default_headers`,
|
47
|
+
# `cache` and `host`.
|
64
48
|
# @return [Client] A client configured to use the API with OAuth
|
65
49
|
# authentication.
|
66
|
-
def self.connect_token(token,
|
50
|
+
def self.connect_token(token, options=nil)
|
51
|
+
options = custom_options(options)
|
67
52
|
url = "<%= @url %>"
|
68
|
-
|
69
|
-
|
70
|
-
|
53
|
+
client = Heroics.token_client_from_schema(token, SCHEMA, url, options)
|
54
|
+
Client.new(client)
|
55
|
+
end
|
56
|
+
|
57
|
+
# Get customized options.
|
58
|
+
def self.custom_options(options)
|
59
|
+
return default_options if options.nil?
|
60
|
+
|
61
|
+
final_options = default_options
|
62
|
+
if options[:default_headers]
|
63
|
+
final_options[:default_headers].merge!(options[:default_headers])
|
71
64
|
end
|
65
|
+
final_options[:cache] = options[:cache] if options[:cache]
|
66
|
+
final_options[:host] = options[:host] if options[:host]
|
67
|
+
final_options
|
68
|
+
end
|
69
|
+
|
70
|
+
# Get the default options.
|
71
|
+
def self.default_options
|
72
|
+
default_headers = <%= @default_headers %>
|
72
73
|
cache = <%= @cache %>
|
73
|
-
|
74
|
+
uri = URI.parse("<%= @url %>")
|
75
|
+
{
|
74
76
|
default_headers: default_headers,
|
75
|
-
|
77
|
+
cache: cache,
|
78
|
+
host: uri.host
|
76
79
|
}
|
77
|
-
client = Heroics.token_client_from_schema(token, SCHEMA, url, options)
|
78
|
-
Client.new(client)
|
79
80
|
end
|
80
81
|
|
82
|
+
private_class_method :default_options, :custom_options
|
83
|
+
|
81
84
|
# <%= @description %>
|
82
85
|
class Client
|
83
86
|
def initialize(client)
|
data/test/client_test.rb
CHANGED
@@ -4,10 +4,11 @@ class ClientTest < MiniTest::Unit::TestCase
|
|
4
4
|
include ExconHelper
|
5
5
|
|
6
6
|
# Client.to_s returns a simple human-readable description of the client
|
7
|
-
# instance with the URL embedded in it.
|
7
|
+
# instance with the URL embedded in it. A password, if present in the URL,
|
8
|
+
# is redacted to avoid leaking credentials.
|
8
9
|
def test_to_s
|
9
10
|
client = Heroics::Client.new({}, 'http://foo:bar@example.com')
|
10
|
-
assert_equal('#<Heroics::Client url="http://foo:
|
11
|
+
assert_equal('#<Heroics::Client url="http://foo:REDACTED@example.com">',
|
11
12
|
client.to_s)
|
12
13
|
end
|
13
14
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: heroics
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- geemus
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-05-
|
12
|
+
date: 2014-05-15 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -149,6 +149,8 @@ extra_rdoc_files: []
|
|
149
149
|
files:
|
150
150
|
- .gitignore
|
151
151
|
- .travis.yml
|
152
|
+
- CONTRIBUTING.md
|
153
|
+
- CONTRIBUTORS.md
|
152
154
|
- Gemfile
|
153
155
|
- LICENSE.txt
|
154
156
|
- README.md
|