heroku-platform-api 0.0.1 → 0.0.2

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,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- ZTQ3NDk4YzM0YjRjNGYwZmM5NmZkYTkzMjBmYTI2NjU5M2FkYTY2ZQ==
5
- data.tar.gz: !binary |-
6
- NGVhZmFmYjZlOWExNDNiNDRhOGY5Y2I5ZDI2N2I5NWRmMjdhMTNiNA==
7
- !binary "U0hBNTEy":
8
- metadata.gz: !binary |-
9
- OTY5YWYxOWQ5Y2RiYmMwOWEzMDZkM2FjYmZjY2JhMWY1N2NhNjA1NTg5NmRl
10
- OWIxNDJmMTY0ZDIxYWJkOGNmZjRmNzBlMmFhOWQ5MWUxODc0NjBlNmQ0NjQw
11
- OWZhMmM4YWZiY2RmMDg4NWQ3NGU3OTRjZjc0YWNkYTAwY2U1OTA=
12
- data.tar.gz: !binary |-
13
- YTUyYjg1NTY5NWM2YTM2M2YzYzAyNGNkMDY1OGI5YzZjMjc1NTM5YWI4MGE5
14
- YWUzY2RkNDc2MjdkMjU4YzE1OWMwZWQ3NTE4NjI3NDhhYzYxNGQwMjBlNGUz
15
- YTJhNjNlZjY0NDljYzQ0OTQ5NDE0M2U5ZGY3MDYzNzU0ZThhY2Y=
2
+ SHA1:
3
+ metadata.gz: c7f7e4cbb482c412c1002594b40754d94ba3cf06
4
+ data.tar.gz: f67cf4b4890a7b814431265766a93d2f5daa190f
5
+ SHA512:
6
+ metadata.gz: 38cff0d17794488c35465a1a72a5fdbdfcc6a8fe6b2c4550f55f85e95261a14c2c9242d289de6bbbb9f9ea65983c69134f12ad13b1c8bfd1ef003c5c00fddd38
7
+ data.tar.gz: 58ea6ce9f9a2d497c1aeaafcc5fdd24265cf040b60424f57cd9be080867363bb7f603b32849237e7a9cd2dc12ca4c2a8ec8783ae9e39e54939897ebea193c9f7
@@ -0,0 +1,9 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ script:
5
+ - bundle install
6
+ - CODECLIMATE_REPO_TOKEN=9e979646269338662e0e529e8d8f0ca1a50ba26ca18c1f18caaa29344b76badf bundle exec rspec
7
+ addons:
8
+ code_climate:
9
+ repo_token: 9e979646269338662e0e529e8d8f0ca1a50ba26ca18c1f18caaa29344b76badf
@@ -18,9 +18,9 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_dependency "git"
21
+ spec.add_dependency "git", "~> 1.2"
22
22
 
23
23
  spec.add_development_dependency "bundler", "~> 1.3"
24
- spec.add_development_dependency "rake"
25
- spec.add_development_dependency "rspec"
24
+ spec.add_development_dependency "rake", "~> 10.3"
25
+ spec.add_development_dependency "rspec", "~> 3"
26
26
  end
@@ -38,7 +38,7 @@ module Heroku
38
38
  Net::HTTPCreated
39
39
  cache.put(
40
40
  r_type, res["ETag"],
41
- JSON.parse(res.body)
41
+ parse_body(res)
42
42
  )
43
43
  when Net::HTTPPartialContent
44
44
  cache.put(
@@ -46,7 +46,7 @@ module Heroku
46
46
  gather_partial_content(api_req, res)
47
47
  )
48
48
  when Net::HTTPNotModified then cache.fetch(r_type, res["ETag"])
49
- when Net::HTTPSuccess then [res["ETag"], JSON.parse(res.body)]
49
+ when Net::HTTPSuccess then [res["ETag"], parse_body(res)]
50
50
  else raise_exception(res)
51
51
  end
52
52
  end
@@ -54,7 +54,7 @@ module Heroku
54
54
  def gather_partial_content(api_req, res)
55
55
  Heroku::Properties.logger.info("[Conn] Gathering Partial Content.")
56
56
 
57
- list_head = JSON.parse(res.body)
57
+ list_head = parse_body(res)
58
58
  etag, list_tail =
59
59
  self.send(
60
60
  api_req.method,
@@ -66,6 +66,7 @@ module Heroku
66
66
  end
67
67
 
68
68
  def self.raise_exception(res)
69
+ Heroku::Properties.logger.error("[Conn response] #{res.body.inspect}")
69
70
  Heroku::Properties.logger.error("[Conn] Uh oh, something went wrong with request #{res["Request-Id"]}.")
70
71
  raise res.class::EXCEPTION_TYPE.new(status(res.code), nil)
71
72
  end
@@ -79,7 +80,7 @@ module Heroku
79
80
  def self.headers(opts = {})
80
81
  {
81
82
  "Accept" => 'application/vnd.heroku+json; version=3',
82
- "Content-Type" => 'application/json',
83
+ "Content-Type" => 'application/json;charset=utf-8',
83
84
  "Authorization" => Heroku::Properties.auth_token,
84
85
  "User-Agent" => Heroku::Properties::USER_AGENT
85
86
  }.merge({}.tap do |header|
@@ -87,5 +88,23 @@ module Heroku
87
88
  header["Range"] = opts[:range] if opts[:range]
88
89
  end)
89
90
  end
91
+
92
+ def self.parse_body(res)
93
+ JSON.parse(decompress(res))
94
+ end
95
+
96
+ def self.decompress(res)
97
+ case res["content-encoding"]
98
+ when 'gzip'
99
+ Zlib::GzipReader.new(
100
+ StringIO.new(res.body),
101
+ encoding: "ASCII-8BIT"
102
+ ).read
103
+ when 'deflate'
104
+ Zlib::Inflate.inflate(res.body)
105
+ else
106
+ res.body
107
+ end
108
+ end
90
109
  end
91
110
  end
@@ -1,3 +1,3 @@
1
1
  module Heroku
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -1,7 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Heroku::Conn do
4
-
5
4
  describe ".check_response" do
6
5
  context "when the response is unsuccessful" do
7
6
  let(:unsuccessful_response) { Net::HTTPClientError.new() }
@@ -11,4 +10,76 @@ describe Heroku::Conn do
11
10
  end
12
11
  end
13
12
  end
13
+
14
+ describe "Parsing" do
15
+ let(:hash) { {"lorem" => "ipsum dolor sit amet"} }
16
+ let(:body) { hash.to_json }
17
+ let(:res) { double(:res) }
18
+
19
+ def set_body(res, body)
20
+ allow(res).to receive(:body).and_return(body)
21
+ end
22
+
23
+ def set_encoding(res, enc)
24
+ allow(res).to receive(:[])
25
+ .with("content-encoding")
26
+ .and_return(enc)
27
+ end
28
+
29
+ describe ".parse_body" do
30
+ before do
31
+ set_encoding(res, nil)
32
+ set_body(res, body)
33
+ end
34
+
35
+ it "attempts to decompress the body" do
36
+ expect(described_class).to receive(:decompress)
37
+ .with(res)
38
+ .and_call_original
39
+ described_class.send(:parse_body, res)
40
+ end
41
+
42
+ it "converts the body to json" do
43
+ expect(described_class.send(:parse_body, res)).to eq(hash)
44
+ end
45
+ end
46
+
47
+ describe ".decompress" do
48
+ def self.it_returns_the_body
49
+ it "returns the body" do
50
+ expect(described_class.send(:decompress, res)).to eq(body)
51
+ end
52
+ end
53
+
54
+ context "when the body is not encoded" do
55
+ before do
56
+ set_encoding(res, "identity")
57
+ set_body(res, body)
58
+ end
59
+
60
+ it_returns_the_body
61
+ end
62
+
63
+ context "when the body is deflated" do
64
+ before do
65
+ set_encoding(res, "deflate")
66
+ set_body(res, Zlib::Deflate.deflate(body))
67
+ end
68
+
69
+ it_returns_the_body
70
+ end
71
+
72
+ context "when the body is gzipped" do
73
+ before do
74
+ set_encoding(res, "gzip")
75
+
76
+ strio = StringIO.new
77
+ Zlib::GzipWriter.wrap(strio) { |gz| gz.write(body) }
78
+ set_body(res, strio.string)
79
+ end
80
+
81
+ it_returns_the_body
82
+ end
83
+ end
84
+ end
14
85
  end
@@ -53,18 +53,33 @@ describe Heroku::Model::ModelHelper do
53
53
 
54
54
  describe "#identifier" do
55
55
  context "when there are no identifiable parameters" do
56
- before { subject.should_receive(:identifiable).and_return({}) }
57
- its(:identifier) { should == "" }
56
+ before do
57
+ expect(subject).to receive(:identifiable).and_return({})
58
+ end
59
+
60
+ it "should return an empty identifier" do
61
+ expect(subject.identifier).to be_empty
62
+ end
58
63
  end
59
64
 
60
65
  context "when the identifier is one parameter" do
61
- before { subject.should_receive(:identifiable).and_return({ a: 1 }) }
62
- its(:identifier) { should == "a=1" }
66
+ before do
67
+ expect(subject).to receive(:identifiable).and_return({ a: 1 })
68
+ end
69
+
70
+ it "should appear in the identifier" do
71
+ expect(subject.identifier).to eq "a=1"
72
+ end
63
73
  end
64
74
 
65
75
  context "when the identifier contains multiple parameters" do
66
- before { subject.should_receive(:identifiable).and_return({ a: 1, b: 2}) }
67
- its(:identifier) { should == "a=1, b=2" }
76
+ before do
77
+ expect(subject).to receive(:identifiable).and_return({ a: 1, b: 2})
78
+ end
79
+
80
+ it "should return a comma separated list" do
81
+ expect(subject.identifier).to eq "a=1, b=2"
82
+ end
68
83
  end
69
84
  end
70
85
  end
@@ -14,7 +14,7 @@ describe Heroku::Properties::NullLogger do
14
14
 
15
15
  it { should respond_to(:tagged).with(1).argument }
16
16
  it "calls the block provided to it" do
17
- block_check.should_receive(:call).once
17
+ expect(block_check).to receive(:call).once
18
18
 
19
19
  subject.tagged("tag") do
20
20
  block_check.call
@@ -3,7 +3,6 @@ Bundler.setup
3
3
  require 'heroku_api'
4
4
 
5
5
  RSpec.configure do |config|
6
- config.treat_symbols_as_metadata_keys_with_true_values = true
7
6
  config.run_all_when_everything_filtered = true
8
7
  config.filter_run :focus
9
8
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: heroku-platform-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ashok Menon
@@ -9,64 +9,64 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-08-30 00:00:00.000000000 Z
12
+ date: 2014-06-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: git
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - ! '>='
18
+ - - "~>"
19
19
  - !ruby/object:Gem::Version
20
- version: '0'
20
+ version: '1.2'
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
- - - ! '>='
25
+ - - "~>"
26
26
  - !ruby/object:Gem::Version
27
- version: '0'
27
+ version: '1.2'
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: bundler
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
- - - ~>
32
+ - - "~>"
33
33
  - !ruby/object:Gem::Version
34
34
  version: '1.3'
35
35
  type: :development
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
- - - ~>
39
+ - - "~>"
40
40
  - !ruby/object:Gem::Version
41
41
  version: '1.3'
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: rake
44
44
  requirement: !ruby/object:Gem::Requirement
45
45
  requirements:
46
- - - ! '>='
46
+ - - "~>"
47
47
  - !ruby/object:Gem::Version
48
- version: '0'
48
+ version: '10.3'
49
49
  type: :development
50
50
  prerelease: false
51
51
  version_requirements: !ruby/object:Gem::Requirement
52
52
  requirements:
53
- - - ! '>='
53
+ - - "~>"
54
54
  - !ruby/object:Gem::Version
55
- version: '0'
55
+ version: '10.3'
56
56
  - !ruby/object:Gem::Dependency
57
57
  name: rspec
58
58
  requirement: !ruby/object:Gem::Requirement
59
59
  requirements:
60
- - - ! '>='
60
+ - - "~>"
61
61
  - !ruby/object:Gem::Version
62
- version: '0'
62
+ version: '3'
63
63
  type: :development
64
64
  prerelease: false
65
65
  version_requirements: !ruby/object:Gem::Requirement
66
66
  requirements:
67
- - - ! '>='
67
+ - - "~>"
68
68
  - !ruby/object:Gem::Version
69
- version: '0'
69
+ version: '3'
70
70
  description: Create, destroy and manage your heroku applications programmatically,
71
71
  using the Heroku Platform API.
72
72
  email:
@@ -76,8 +76,9 @@ executables: []
76
76
  extensions: []
77
77
  extra_rdoc_files: []
78
78
  files:
79
- - .gitignore
80
- - .rspec
79
+ - ".gitignore"
80
+ - ".rspec"
81
+ - ".travis.yml"
81
82
  - Gemfile
82
83
  - LICENSE.txt
83
84
  - README.md
@@ -118,17 +119,17 @@ require_paths:
118
119
  - lib
119
120
  required_ruby_version: !ruby/object:Gem::Requirement
120
121
  requirements:
121
- - - ! '>='
122
+ - - ">="
122
123
  - !ruby/object:Gem::Version
123
124
  version: '0'
124
125
  required_rubygems_version: !ruby/object:Gem::Requirement
125
126
  requirements:
126
- - - ! '>='
127
+ - - ">="
127
128
  - !ruby/object:Gem::Version
128
129
  version: '0'
129
130
  requirements: []
130
131
  rubyforge_project:
131
- rubygems_version: 2.0.6
132
+ rubygems_version: 2.2.2
132
133
  signing_key:
133
134
  specification_version: 4
134
135
  summary: Ruby client for the Heroku Platform API.
@@ -139,3 +140,4 @@ test_files:
139
140
  - spec/heroku/properties/null_logger_spec.rb
140
141
  - spec/heroku/properties_spec.rb
141
142
  - spec/spec_helper.rb
143
+ has_rdoc: