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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 16b5b5b9ec40a80d7ac06af58ebf2be1e0c773fe
4
- data.tar.gz: a695f11ee1b3eb7841def942d6239c3a589c0fba
3
+ metadata.gz: 2cbe04afb5b59a688197d7b89d4cae7988681347
4
+ data.tar.gz: 6e5f0fdf59a60dbf4547befbf281d2e00a0affc3
5
5
  SHA512:
6
- metadata.gz: 3a4e120811c3b4cef5d0cd919173c9b89e8e2b39834bbc103681056fa3e4355b371ff9a7cf27c1b22b3114e1c962f9c6fe45cf11a9a4d5317e9d6ce9d64e5e97
7
- data.tar.gz: 5ad761a53a1baeb2cbbc6d33aa0239c4742eb61406194a0e68b551ea6283372c84f320b631d255bdbd8e7eba524bf86e284eded0d4576d654390f444f73bb983
6
+ metadata.gz: 5a4272a774738e39cb87a6af8cbdbbed75adc043ee6fdd9bec905481f54d200c13e4ae51b97c88d3a29f282616332a917af81aa9d196c38a3124f41c07144926
7
+ data.tar.gz: 33ba2968b0cc98b836ecb1a4c5a177986b448c4da43578e4404c0a6915ab73bfe6e4fc45079e597ee9fad6e41ddcffddfdf8635a9244b36b49b31d7fb1e4574d
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,5 @@
1
+ ## Contributing
2
+
3
+ We welcome contributions to Heroics and discussion about its design and
4
+ functionality. Please open an issue or pull request on this repository to
5
+ propose a change.
data/CONTRIBUTORS.md ADDED
@@ -0,0 +1,7 @@
1
+ Andrea Salicetti <andrea.salicetti@gmail.com>
2
+ Jamu Kakar <jkakar@kakar.ca>
3
+ Jonathan Roes <jroes@jroes.net>
4
+ Mark Fine <mark.fine@gmail.com>
5
+ Mark McGranaghan <mmcgrana@gmail.com>
6
+ Neil Middleton <neil@heroku.com>
7
+ Wesley Beary <geemus+github@gmail.com>
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-generator MyApp schema.json https://api.myapp.com > client.rb
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
- bin/heroics-generator \
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
- bin/heroics-generator \
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 that doesn't appear to be compatible with GitHub Pages. If
77
- you're hosting your content there you can change the links:
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
 
@@ -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
- "#<Heroics::Client url=\"#{@url}\">"
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
@@ -1,3 +1,3 @@
1
1
  module Heroics
2
- VERSION = '0.0.8'
2
+ VERSION = '0.0.9'
3
3
  end
@@ -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 username [String] The username to use with the API.
15
- # @param password [String] The password to use with the API.
16
- # @param headers [Hash<String,String>] Optionally, custom to headers to
17
- # include with every response.
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(username, password, headers=nil)
21
- url = URI.parse("<%= @url %>")
22
- url.user = username
23
- url.password = password
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 headers [Hash<String,String>] Optionally, custom to headers to
41
- # include with every response.
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, headers=nil)
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 headers [Hash<String,String>] Optionally, custom to headers to
63
- # include with every response.
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, headers=nil)
50
+ def self.connect_token(token, options=nil)
51
+ options = custom_options(options)
67
52
  url = "<%= @url %>"
68
- default_headers = <%= @default_headers %>
69
- unless headers.nil?
70
- default_headers.merge!(headers)
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
- options = {
74
+ uri = URI.parse("<%= @url %>")
75
+ {
74
76
  default_headers: default_headers,
75
- cache: cache
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:bar@example.com">',
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.8
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-02 00:00:00.000000000 Z
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