heroku-api 0.3.5 → 0.3.6

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.
data/README.md CHANGED
@@ -14,7 +14,8 @@ Start by creating a connection to Heroku with your credentials:
14
14
 
15
15
  require 'heroku-api'
16
16
 
17
- heroku = Heroku::API.new(:api_key => API_KEY)
17
+ heroku = Heroku::API.new(:api_key => API_KEY) # use API Key
18
+ heroku = Heroku::API.new(:username => USERNAME, :password => PASSWORD) # use username and password
18
19
 
19
20
  NOTE: You can leave out the `:api_key` if `ENV['HEROKU_API_KEY']` is set instead.
20
21
 
@@ -61,7 +62,7 @@ For additional details about any of the commands, see the [API docs](http://api-
61
62
 
62
63
  heroku.delete_domain('app', 'example.com') # remove the 'example.com' domain from the 'app' app
63
64
  heroku.get_domains('app') # list configured domains for the 'app' app
64
- heroku.post_domains('app', 'example.com') # add 'example.com' domain to the 'app' app
65
+ heroku.post_domain('app', 'example.com') # add 'example.com' domain to the 'app' app
65
66
 
66
67
  ### Keys
67
68
 
@@ -1,3 +1,10 @@
1
+ 0.3.6 10/31/2012
2
+ ================
3
+
4
+ bump excon to latest
5
+ allow username/password params to automagically lookup api_key
6
+ readme cleanup/fixes
7
+
1
8
  0.3.5 09/11/2012
2
9
  ================
3
10
 
@@ -16,7 +16,7 @@ Gem::Specification.new do |s|
16
16
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
17
17
  s.require_paths = ["lib"]
18
18
 
19
- s.add_runtime_dependency 'excon', '~>0.16.1'
19
+ s.add_runtime_dependency 'excon', '~>0.16.7'
20
20
 
21
21
  s.add_development_dependency 'minitest'
22
22
  s.add_development_dependency 'rake'
@@ -36,24 +36,36 @@ srand
36
36
  module Heroku
37
37
  class API
38
38
 
39
+ HEADERS = {
40
+ 'Accept' => 'application/json',
41
+ 'Accept-Encoding' => 'gzip',
42
+ #'Accept-Language' => 'en-US, en;q=0.8',
43
+ 'User-Agent' => "heroku-rb/#{Heroku::API::VERSION}",
44
+ 'X-Ruby-Version' => RUBY_VERSION,
45
+ 'X-Ruby-Platform' => RUBY_PLATFORM
46
+ }
47
+
48
+ OPTIONS = {
49
+ :headers => {},
50
+ :host => 'api.heroku.com',
51
+ :nonblock => false,
52
+ :scheme => 'https'
53
+ }
54
+
39
55
  def initialize(options={})
56
+ options = OPTIONS.merge(options)
57
+
40
58
  @api_key = options.delete(:api_key) || ENV['HEROKU_API_KEY']
59
+ if !@api_key && options.has_key?(:username) && options.has_key?(:password)
60
+ @connection = Excon.new("#{options[:scheme]}://#{options[:host]}", options.merge(:headers => HEADERS))
61
+ @api_key = self.post_login(options[:username], options[:password]).body["api_key"]
62
+ end
63
+
41
64
  user_pass = ":#{@api_key}"
42
- options = {
43
- :headers => {},
44
- :host => 'api.heroku.com',
45
- :nonblock => false,
46
- :scheme => 'https'
47
- }.merge(options)
48
- options[:headers] = {
49
- 'Accept' => 'application/json',
50
- 'Accept-Encoding' => 'gzip',
51
- #'Accept-Language' => 'en-US, en;q=0.8',
52
- 'Authorization' => "Basic #{Base64.encode64(user_pass).gsub("\n", '')}",
53
- 'User-Agent' => "heroku-rb/#{Heroku::API::VERSION}",
54
- 'X-Ruby-Version' => RUBY_VERSION,
55
- 'X-Ruby-Platform' => RUBY_PLATFORM
56
- }.merge(options[:headers])
65
+ options[:headers] = HEADERS.merge({
66
+ 'Authorization' => "Basic #{Base64.encode64(user_pass).gsub("\n", '')}",
67
+ }).merge(options[:headers])
68
+
57
69
  @connection = Excon.new("#{options[:scheme]}://#{options[:host]}", options)
58
70
  end
59
71
 
@@ -137,15 +137,20 @@ module Heroku
137
137
  end
138
138
 
139
139
  def self.parse_stub_params(params)
140
- api_key = Base64.decode64(params[:headers]['Authorization']).split(':').last
140
+ mock_data = nil
141
141
 
142
- parsed = params.dup
143
- begin # try to JSON decode
144
- parsed[:body] &&= Heroku::API::OkJson.decode(parsed[:body])
145
- rescue # else leave as is
142
+ if params[:headers].has_key?('Authorization')
143
+ api_key = Base64.decode64(params[:headers]['Authorization']).split(':').last
144
+
145
+ parsed = params.dup
146
+ begin # try to JSON decode
147
+ parsed[:body] &&= Heroku::API::OkJson.decode(parsed[:body])
148
+ rescue # else leave as is
149
+ end
150
+ mock_data = @mock_data[api_key]
146
151
  end
147
152
 
148
- [parsed, @mock_data[api_key]]
153
+ [parsed, mock_data]
149
154
  end
150
155
 
151
156
  def self.remove_mock_app_addon(mock_data, app, addon)
@@ -1,5 +1,5 @@
1
1
  module Heroku
2
2
  class API
3
- VERSION = "0.3.5"
3
+ VERSION = "0.3.6"
4
4
  end
5
5
  end
@@ -9,4 +9,12 @@ class TestLogin < MiniTest::Unit::TestCase
9
9
  assert_equal(200, response.status)
10
10
  end
11
11
 
12
+ def test_post_login_implied
13
+ # FIXME: user/pass will only work in mock for now, maybe use ENV
14
+ _heroku_ = Heroku::API.new(:mock => true, :username => 'email@example.com', :password => 'fake_password')
15
+ response = _heroku_.get_apps
16
+
17
+ assert_equal(200, response.status)
18
+ end
19
+
12
20
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: heroku-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.5
4
+ version: 0.3.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,22 +9,27 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-09-11 00:00:00.000000000 Z
12
+ date: 2012-10-31 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: excon
16
- requirement: &70278785472920 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
20
20
  - !ruby/object:Gem::Version
21
- version: 0.16.1
21
+ version: 0.16.7
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70278785472920
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 0.16.7
25
30
  - !ruby/object:Gem::Dependency
26
31
  name: minitest
27
- requirement: &70278785471860 !ruby/object:Gem::Requirement
32
+ requirement: !ruby/object:Gem::Requirement
28
33
  none: false
29
34
  requirements:
30
35
  - - ! '>='
@@ -32,10 +37,15 @@ dependencies:
32
37
  version: '0'
33
38
  type: :development
34
39
  prerelease: false
35
- version_requirements: *70278785471860
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
36
46
  - !ruby/object:Gem::Dependency
37
47
  name: rake
38
- requirement: &70278785471240 !ruby/object:Gem::Requirement
48
+ requirement: !ruby/object:Gem::Requirement
39
49
  none: false
40
50
  requirements:
41
51
  - - ! '>='
@@ -43,7 +53,12 @@ dependencies:
43
53
  version: '0'
44
54
  type: :development
45
55
  prerelease: false
46
- version_requirements: *70278785471240
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
47
62
  description: Ruby Client for the Heroku API
48
63
  email:
49
64
  - wesley@heroku.com
@@ -126,21 +141,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
126
141
  - - ! '>='
127
142
  - !ruby/object:Gem::Version
128
143
  version: '0'
129
- segments:
130
- - 0
131
- hash: 3188437513510408421
132
144
  required_rubygems_version: !ruby/object:Gem::Requirement
133
145
  none: false
134
146
  requirements:
135
147
  - - ! '>='
136
148
  - !ruby/object:Gem::Version
137
149
  version: '0'
138
- segments:
139
- - 0
140
- hash: 3188437513510408421
141
150
  requirements: []
142
151
  rubyforge_project:
143
- rubygems_version: 1.8.15
152
+ rubygems_version: 1.8.23
144
153
  signing_key:
145
154
  specification_version: 3
146
155
  summary: Ruby Client for the Heroku API